/* ---------------------------------------------------------------
   Auour Portal — shared design tokens and primitives.
   Loaded before every product stylesheet. Product classes
   (.dh-*, .sx-*, .av-*) are grouped here so existing markup
   picks up the shared look without renames.
--------------------------------------------------------------- */
:root {
  /* surfaces */
  --bg: #FAF9F7;
  --surface: #FFFFFF;
  --fill: #F2F1EE;
  --fill-hover: #EAE8E3;
  --fill-active: #E2DFD8;

  /* text */
  --ink: #0D1A2B;
  --ink-2: #4F5866;
  --ink-3: #646C78;
  --hairline: rgba(13, 26, 43, 0.08);
  --hairline-strong: rgba(13, 26, 43, 0.14);

  /* brand + action */
  --accent: #16283F;
  --accent-hover: #0D1A2B;
  --gold: #C9A227;
  --gold-tint: #F6EFD8;
  --focus: rgba(201, 162, 39, 0.55);

  /* status (all AA on white) */
  --pos: #1E7A4F;
  --pos-tint: #E6F2EB;
  --neg: #B4382B;
  --neg-tint: #FBEBE8;
  --warn: #8A5A00;
  --warn-tint: #FAF0D9;
  --info: #2F5F8A;
  --info-tint: #E8EFF6;

  /* type */
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-title: 'Spectral', Georgia, serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 15px;
  --fs-lg: 17px;
  --fs-xl: 22px;
  --fs-2xl: 28px;
  --fs-3xl: 34px;

  /* shape + depth */
  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-pill: 999px;
  --shadow-1: 0 1px 2px rgba(13, 26, 43, 0.04), 0 4px 16px rgba(13, 26, 43, 0.05);
  --shadow-2: 0 2px 4px rgba(13, 26, 43, 0.05), 0 12px 32px rgba(13, 26, 43, 0.08);
  --shadow-3: 0 4px 8px rgba(13, 26, 43, 0.06), 0 24px 56px rgba(13, 26, 43, 0.14);

  /* motion */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --dur: 180ms;

  /* layout */
  --top-h: 56px;
  --measure: 1120px;
}

/* ---------- App frames ---------- */
.pu-app,
.dh-app,
.sx-app,
.av-app {
  min-height: var(--app-height, 100vh);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.pu-app h1, .dh-app h1, .sx-app h1, .av-app h1 {
  font-family: var(--font-title);
  font-weight: 500;
  font-size: var(--fs-3xl);
  line-height: 1.15;
  letter-spacing: -0.015em;
  color: var(--ink);
}

.pu-app h2, .dh-app h2, .sx-app h2, .av-app h2,
.pu-app h3, .dh-app h3, .sx-app h3, .av-app h3 {
  font-family: var(--font-ui);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.pu-app h2, .dh-app h2, .sx-app h2, .av-app h2 { font-size: var(--fs-lg); }
.pu-app h3, .dh-app h3, .sx-app h3, .av-app h3 { font-size: var(--fs-md); }

.pu-main,
.dh-main,
.sx-main {
  flex: 1;
  width: min(var(--measure), 100%);
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* ---------- Shared header ---------- */
.pu-top {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--top-h);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  padding: 0 16px 0 12px;
  background: rgba(250, 249, 247, 0.82);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--hairline);
}

.pu-top-lead {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.pu-home {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  flex: none;
  transition: background var(--dur) var(--ease);
}

.pu-home:hover { background: var(--fill); }
.pu-home svg { width: 22px; height: 22px; }
.pu-home .pu-home-needle { color: var(--gold); }

.pu-product {
  font-size: var(--fs-lg);
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pu-crumb {
  color: var(--ink-3);
  font-size: var(--fs-md);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pu-top-nav { display: flex; justify-content: center; min-width: 0; }

.pu-top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.pu-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  flex: none;
  user-select: none;
}

@media (max-width: 720px) {
  .pu-top {
    grid-template-columns: minmax(0, 1fr) auto;
    height: auto;
    min-height: var(--top-h);
    padding-top: env(safe-area-inset-top, 0px);
    row-gap: 0;
  }
  .pu-top-nav {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-start;
    overflow-x: auto;
    padding: 0 0 10px 4px;
  }
  .pu-top-nav:empty { display: none; }
}

/* ---------- Buttons ---------- */
.pu-btn,
.dh-btn,
.sx-btn,
.av-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--fill);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-sm);
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.pu-btn:hover, .dh-btn:hover, .sx-btn:hover, .av-btn:hover { background: var(--fill-hover); }
.pu-btn:active, .dh-btn:active, .sx-btn:active, .av-btn:active { background: var(--fill-active); }

.pu-btn:disabled, .dh-btn:disabled, .sx-btn:disabled, .av-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.pu-btn-primary,
.dh-btn-primary,
.sx-btn-primary,
.av-btn-primary {
  background: var(--accent);
  color: #fff;
}

.pu-btn-primary:hover, .dh-btn-primary:hover, .sx-btn-primary:hover, .av-btn-primary:hover { background: var(--accent-hover); }
.pu-btn-primary:active, .dh-btn-primary:active, .sx-btn-primary:active, .av-btn-primary:active { background: #060E18; }

.pu-btn-plain,
.dh-btn-ghost,
.sx-btn-ghost,
.av-btn-ghost {
  background: transparent;
  color: var(--ink-2);
}

.pu-btn-plain:hover, .dh-btn-ghost:hover, .sx-btn-ghost:hover, .av-btn-ghost:hover {
  background: var(--fill);
  color: var(--ink);
}

.pu-btn-small,
.av-btn-small {
  min-height: 28px;
  padding: 0 10px;
  font-size: var(--fs-xs);
  border-radius: var(--r-xs);
}

.pu-btn-icon {
  width: 36px;
  padding: 0;
}

.pu-link,
.av-link {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  color: var(--info);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
}

.pu-link:hover, .av-link:hover { text-decoration: underline; }

/* ---------- Segmented control ---------- */
.pu-seg,
.dh-tabs,
.av-tabs,
.av-lenses {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border-radius: 9px;
  background: var(--fill);
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}

.pu-seg::-webkit-scrollbar, .dh-tabs::-webkit-scrollbar, .av-tabs::-webkit-scrollbar { display: none; }

.pu-seg-btn,
.dh-tab,
.av-tab,
.av-lenses button {
  appearance: none;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-2);
  min-height: 30px;
  padding: 0 14px;
  font-family: var(--font-ui);
  font-size: var(--fs-sm);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.pu-seg-btn:hover, .dh-tab:hover, .av-tab:hover, .av-lenses button:hover { color: var(--ink); }

.pu-seg-btn.is-active,
.pu-seg-btn[aria-pressed="true"],
.dh-tab.is-active,
.av-tab.is-active,
.av-lenses button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(13, 26, 43, 0.08), 0 1px 6px rgba(13, 26, 43, 0.06);
}

/* ---------- Cards ---------- */
.pu-card,
.dh-panel,
.sx-panel,
.av-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: 24px;
  box-shadow: var(--shadow-1);
}

.pu-card > h2:first-child,
.dh-panel > h2:first-child,
.sx-panel > h2:first-child { margin: 0 0 12px; }

/* ---------- Fields ---------- */
.pu-field,
.dh-field,
.sx-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.pu-field label,
.dh-field label,
.sx-field label {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink-2);
}

.pu-input,
.pu-field input, .pu-field select, .pu-field textarea,
.dh-field input, .dh-field select, .dh-field textarea,
.sx-field input, .sx-field select, .sx-field textarea,
.av-dialog input, .av-dialog select, .av-dialog textarea,
.av-inspect-form input, .av-inspect-form select, .av-inspect-form textarea,
.av-map-picker select {
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  color: var(--ink);
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.pu-field textarea, .dh-field textarea, .sx-field textarea, .av-dialog textarea, .av-inspect-form textarea {
  min-height: 88px;
  line-height: 1.5;
}

.pu-input:focus,
.pu-field :is(input, select, textarea):focus,
.dh-field :is(input, select, textarea):focus,
.sx-field :is(input, select, textarea):focus,
.av-dialog :is(input, select, textarea):focus,
.av-inspect-form :is(input, select, textarea):focus,
.av-map-picker select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 40, 63, 0.12);
}

.pu-app input[type="file"],
.dh-app input[type="file"],
.sx-app input[type="file"],
.av-app input[type="file"] {
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  font-family: var(--font-ui);
  font-size: var(--fs-sm);
  color: var(--ink-2);
}

.pu-app input[type="file"]::file-selector-button,
.dh-app input[type="file"]::file-selector-button,
.sx-app input[type="file"]::file-selector-button,
.av-app input[type="file"]::file-selector-button {
  margin-right: 12px;
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--fill);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

.pu-app input[type="file"]::file-selector-button:hover,
.dh-app input[type="file"]::file-selector-button:hover,
.sx-app input[type="file"]::file-selector-button:hover,
.av-app input[type="file"]::file-selector-button:hover { background: var(--fill-hover); }

.pu-help,
.dh-help,
.sx-note {
  font-size: var(--fs-sm);
  color: var(--ink-3);
  line-height: 1.45;
}

/* ---------- Badges ---------- */
.pu-badge,
.dh-pill,
.sx-badge,
.sx-status,
.sx-file-ok {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  background: var(--fill);
  color: var(--ink-2);
  font-family: var(--font-ui);
  font-size: var(--fs-xs);
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  line-height: 1.5;
  white-space: nowrap;
}

.pu-badge.is-pos, .dh-pill, .sx-file-ok { background: var(--pos-tint); color: var(--pos); }
.pu-badge.is-warn, .dh-pill.warn, .sx-badge { background: var(--warn-tint); color: var(--warn); }
.pu-badge.is-neg { background: var(--neg-tint); color: var(--neg); }
.pu-badge.is-info { background: var(--info-tint); color: var(--info); }

/* ---------- Tables ---------- */
.pu-table,
.dh-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

.pu-table th,
.dh-table th {
  text-align: left;
  padding: 8px 12px;
  font-family: var(--font-ui);
  font-size: var(--fs-xs);
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink-3);
  border-bottom: 1px solid var(--hairline-strong);
  vertical-align: bottom;
  white-space: nowrap;
}

.pu-table td,
.dh-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--hairline);
  vertical-align: middle;
}

.pu-table tbody tr,
.dh-table tbody tr { transition: background var(--dur) var(--ease); }
.pu-table tbody tr:hover,
.dh-table tbody tr:hover { background: rgba(13, 26, 43, 0.025); }
.pu-table tbody tr:last-child td,
.dh-table tbody tr:last-child td { border-bottom: 0; }

.pu-num,
.dh-table th.dh-num,
.dh-table td.dh-num {
  text-align: right;
  font-family: var(--font-ui);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.pu-pos, .dh-pos { color: var(--pos); }
.pu-neg, .dh-neg { color: var(--neg); }

/* ---------- Messages ---------- */
.pu-error,
.dh-error,
.av-error {
  margin: 0 0 16px;
  padding: 12px 16px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--neg-tint);
  color: var(--neg);
  font-size: var(--fs-sm);
}

.pu-empty,
.sx-empty,
.av-empty {
  color: var(--ink-3);
  font-style: normal;
  opacity: 1;
}

.pu-muted,
.dh-muted,
.av-muted { color: var(--ink-3); }

/* ---------- Dialogs ---------- */
.pu-overlay,
.av-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(13, 26, 43, 0.24);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.pu-dialog,
.av-dialog {
  width: min(440px, 100%);
  max-height: calc(100% - 32px);
  overflow: auto;
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 24px;
  box-shadow: var(--shadow-3);
}

/* ---------- Focus ---------- */
.pu-app :focus-visible,
.dh-app :focus-visible,
.sx-app :focus-visible,
.av-app :focus-visible,
.portal-hub :focus-visible,
.app :focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
