/* ==========================================================================
   Private ERP — application stylesheet
   Design system: TailAdmin-inspired light admin theme, Private ERP palette.
   Brand navy #02093a, brand blue #2537b1, accent blue #097fe8, red #f64932.
   Type: Outfit (bundled, works offline). No external requests.
   ========================================================================== */

/* ---------- fonts ---------- */
@font-face { font-family: 'Outfit'; font-style: normal; font-weight: 400; font-display: swap; src: url('../fonts/outfit-400.woff2') format('woff2'); }
@font-face { font-family: 'Outfit'; font-style: normal; font-weight: 500; font-display: swap; src: url('../fonts/outfit-500.woff2') format('woff2'); }
@font-face { font-family: 'Outfit'; font-style: normal; font-weight: 600; font-display: swap; src: url('../fonts/outfit-600.woff2') format('woff2'); }
@font-face { font-family: 'Outfit'; font-style: normal; font-weight: 700; font-display: swap; src: url('../fonts/outfit-700.woff2') format('woff2'); }

/* ---------- tokens ---------- */
:root {
  /* brand */
  --navy: #02093a;
  --brand: #2537b1;
  --brand-strong: #1d2c8f;
  --brand-soft: #eceffc;
  --brand-softer: #f5f7fe;
  --brand-ring: rgba(37, 55, 177, 0.12);
  --accent: #097fe8;
  --red: #f64932;

  /* semantic */
  --success: #039855;
  --success-soft: #ecfdf3;
  --warning: #f79009;
  --warning-text: #b54708;
  --warning-soft: #fffaeb;
  --danger: #d63a26;
  --danger-bright: #f64932;
  --danger-soft: #feeae6;
  --info: #097fe8;
  --info-soft: #eaf4fd;
  --neutral-soft: #f2f4f7;

  /* neutrals (TailAdmin gray scale) */
  --ink: #1d2939;
  --text: #344054;
  --muted: #667085;
  --faint: #98a2b3;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --page: #f9fafb;
  --surface: #ffffff;
  --sunken: #f2f4f7;

  /* geometry */
  --r-sm: 4px;
  --r-md: 6px;
  --r-control: 8px;
  --r-lg: 12px;
  --r-card: 16px;
  --r-pill: 9999px;

  /* spacing (4px grid) */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px;
  --s7: 28px; --s8: 32px; --s10: 40px; --s12: 48px; --s16: 64px;

  /* shadows (subtle, TailAdmin evidence-based) */
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 8px -2px rgba(16, 24, 40, 0.10), 0 2px 4px -2px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 12px 16px -4px rgba(16, 24, 40, 0.08), 0 4px 6px -2px rgba(16, 24, 40, 0.03);

  /* type */
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
  --fs-display-hero: 36px; --lh-display-hero: 44px;
  --fs-display-lg: 30px;   --lh-display-lg: 38px;
  --fs-heading-xl: 24px;   --lh-heading-xl: 32px;
  --fs-heading-l: 20px;    --lh-heading-l: 28px;
  --fs-heading-m: 18px;    --lh-heading-m: 28px;
  --fs-heading-s: 16px;    --lh-heading-s: 24px;
  --fs-body-lg: 16px;      --lh-body-lg: 24px;
  --fs-body: 14px;         --lh-body: 22px;
  --fs-label: 14px;        --lh-label: 20px;
  --fs-small: 12px;        --lh-small: 18px;

  /* metrics */
  --sidebar-width: 290px;
  --sidebar-collapsed: 84px;
  --topbar-height: 72px;
  --bottomnav-height: 64px;
  --content-max: 1560px;
  --gutter: 24px;

  --z-dropdown: 100; --z-sticky: 200; --z-drawer: 300; --z-modal: 400; --z-toast: 500;
  --transition-fast: 120ms ease;
  --transition-base: 180ms ease;

  /* ---- legacy aliases (older views and inline styles keep working) ---- */
  --surface-white: #ffffff;
  --surface-base: #f9fafb;
  --surface-raised: #ffffff;
  --surface-sunken: #f2f4f7;
  --hero-dark-navy: #02093a;
  --accent-blue: #097fe8;
  --accent-red: #f64932;
  --brand-blue: #2537b1;
  --text-primary: #1d2939;
  --text-medium: #344054;
  --text-muted: #667085;
  --text-inverse: #ffffff;
  --success-surface: #ecfdf3;
  --warning-surface: #fffaeb;
  --danger-surface: #feeae6;
  --info-surface: #eaf4fd;
  --accent-surface: #eaf4fd;
  --border-subtle: #e4e7ec;
  --border-medium: #d0d5dd;
  --border-strong: #98a2b3;
  --radius-sm: 4px;
  --radius-control: 8px;
  --radius-card: 16px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-pill: 9999px;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 20px;
  --space-6: 24px; --space-7: 28px; --space-8: 32px; --space-10: 40px; --space-12: 48px; --space-16: 64px;
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
}

/* ---------- reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--text);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
[hidden] { display: none !important; }
img, svg, video { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { color: var(--ink); font-weight: 600; line-height: 1.3; }
ul[role='list'], ol[role='list'] { list-style: none; padding: 0; }
::placeholder { color: var(--faint); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: var(--r-sm); }
::selection { background: var(--brand-soft); }

.icon { width: 20px; height: 20px; flex: 0 0 auto; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.sr-only-focusable:focus { position: static; width: auto; height: auto; clip: auto; white-space: normal; }
.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: var(--z-toast);
  background: var(--navy); color: #fff; padding: 8px 14px; border-radius: var(--r-control);
  transition: top var(--transition-fast);
}
.skip-link:focus { top: 12px; text-decoration: none; }

/* ---------- typography utilities ---------- */
.t-display-hero { font-size: var(--fs-display-hero); line-height: var(--lh-display-hero); font-weight: 600; color: var(--ink); letter-spacing: -0.01em; }
.t-display-lg   { font-size: var(--fs-display-lg); line-height: var(--lh-display-lg); font-weight: 700; color: var(--ink); }
.t-heading-xl   { font-size: var(--fs-heading-xl); line-height: var(--lh-heading-xl); font-weight: 600; color: var(--ink); }
.t-heading-l    { font-size: var(--fs-heading-l); line-height: var(--lh-heading-l); font-weight: 600; color: var(--ink); }
.t-heading-m    { font-size: var(--fs-heading-m); line-height: var(--lh-heading-m); font-weight: 600; color: var(--ink); }
.t-heading-s    { font-size: var(--fs-heading-s); line-height: var(--lh-heading-s); font-weight: 600; color: var(--ink); }
.t-body-lg      { font-size: var(--fs-body-lg); line-height: var(--lh-body-lg); }
.t-body, .t-regular { font-size: var(--fs-body); line-height: var(--lh-body); }
.t-label        { font-size: var(--fs-label); line-height: var(--lh-label); font-weight: 500; }
.t-small        { font-size: var(--fs-small); line-height: var(--lh-small); }
.t-muted        { color: var(--muted); }
.t-primary      { color: var(--text); }
.t-accent       { color: var(--brand); }
.t-info         { color: var(--info); }
.t-success      { color: var(--success); }
.t-warning      { color: var(--warning-text); }
.t-danger       { color: var(--danger); }
.t-bold         { font-weight: 700; }
.t-semibold     { font-weight: 600; }
.t-medium, .t-medium-w { font-weight: 500; }
.t-center       { text-align: center; }
.t-right        { text-align: right; }
.t-nowrap       { white-space: nowrap; }
.t-truncate     { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.t-break        { overflow-wrap: anywhere; word-break: break-word; }
.t-uppercase    { text-transform: uppercase; letter-spacing: 0.04em; }
.t-tabular, .num, .money { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum'; }
.mono { font-family: var(--font-mono); }
.no-underline, .no-underline:hover { text-decoration: none; }

/* ---------- layout helpers ---------- */
.d-flex { display: flex; } .d-block { display: block; } .hidden { display: none !important; }
.d-none { display: none; }
.flex-1 { flex: 1 1 0%; min-width: 0; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; } .items-start { align-items: flex-start; } .items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; } .justify-center { justify-content: center; } .justify-end { justify-content: flex-end; }
.relative { position: relative; } .overflow-hidden { overflow: hidden; }
.w-full { width: 100%; } .h-full { height: 100%; }
.spacer { flex: 1 1 auto; }
.rounded { border-radius: var(--r-control); }
.border-t { border-top: 1px solid var(--line); }
.border-b { border-bottom: 1px solid var(--line); }
.bg-white, .bg-base { background: var(--surface); } .bg-sunken { background: var(--sunken); }
.cursor-pointer { cursor: pointer; }
.gap-1 { gap: var(--s1); } .gap-2 { gap: var(--s2); } .gap-3 { gap: var(--s3); }
.gap-4 { gap: var(--s4); } .gap-5 { gap: var(--s5); } .gap-6 { gap: var(--s6); }
.p-0 { padding: 0; } .p-3 { padding: var(--s3); } .p-4 { padding: var(--s4); } .p-5 { padding: var(--s5); }
.pl-4 { padding-left: var(--s5); }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: var(--s1); } .mb-2 { margin-bottom: var(--s2); }
.mb-3 { margin-bottom: var(--s3); } .mb-4 { margin-bottom: var(--s4); } .mb-5 { margin-bottom: var(--s5); }
.mb-6 { margin-bottom: var(--s6); } .mb-8 { margin-bottom: var(--s8); }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: var(--s1); } .mt-2 { margin-top: var(--s2); }
.mt-3 { margin-top: var(--s3); } .mt-4 { margin-top: var(--s4); } .mt-5 { margin-top: var(--s5); }
.mt-6 { margin-top: var(--s6); } .mt-8 { margin-top: var(--s8); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; }
.row-tight { display: flex; align-items: center; gap: var(--s2); }
.row-end { display: flex; align-items: center; justify-content: flex-end; gap: var(--s2); }
.stack > * + * { margin-top: var(--s4); }
.stack-sm > * + * { margin-top: var(--s2); }
.stack-lg > * + * { margin-top: var(--s6); }
.grid { display: grid; gap: var(--s4); }
.grid-2 { display: grid; gap: var(--s4); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; gap: var(--s4); grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { display: grid; gap: var(--s4); grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-6 { display: grid; gap: var(--s4); grid-template-columns: repeat(6, minmax(0, 1fr)); }
.grid-2-1 { display: grid; gap: var(--s4); grid-template-columns: 2fr 1fr; }
.grid-1-2 { display: grid; gap: var(--s4); grid-template-columns: 1fr 2fr; }
.grid-3-2 { display: grid; gap: var(--s4); grid-template-columns: 3fr 2fr; }
.grid-auto { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-kpi { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.sep { border: 0; border-top: 1px solid var(--line); margin: var(--s4) 0; }
.spinner { width: 20px; height: 20px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: erp-spin 0.8s linear infinite; display: inline-block; }
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }
@keyframes erp-spin { to { transform: rotate(360deg); } }
.loading-overlay { position: absolute; inset: 0; background: rgba(255, 255, 255, 0.6); display: flex; align-items: center; justify-content: center; z-index: 5; }

/* ==========================================================================
   App shell
   ========================================================================== */
.app-shell { display: flex; min-height: 100vh; min-height: 100dvh; }

/* ---------- sidebar ---------- */
.sidebar {
  width: var(--sidebar-width); flex: 0 0 var(--sidebar-width);
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  z-index: var(--z-drawer);
  transition: margin var(--transition-base), transform var(--transition-base);
}
.sidebar-brand {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s5) var(--s5) var(--s4);
  min-height: var(--topbar-height);
}
.sidebar-logo {
  width: 40px; height: 40px; flex: 0 0 40px;
  display: flex; align-items: center; justify-content: center;
  background: var(--brand); color: #fff;
  font-weight: 700; font-size: 15px; letter-spacing: 0.01em;
  border-radius: 10px;
}
.sidebar-name {
  font-weight: 700; font-size: 17px; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-nav { flex: 1 1 auto; overflow-y: auto; padding: 0 var(--s3) var(--s3); scrollbar-width: thin; }
.sidebar-section-label {
  font-size: 11px; font-weight: 500; color: var(--faint);
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 0 var(--s3); margin: var(--s2) 0 var(--s2);
}
.sidebar-nav .nav-item {
  display: flex; align-items: center; gap: var(--s3);
  padding: 10px var(--s3); margin-bottom: 2px;
  border-radius: var(--r-control);
  color: var(--text); font-size: 14px; font-weight: 500; line-height: 20px;
  text-decoration: none;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.sidebar-nav .nav-item .icon { width: 20px; height: 20px; color: var(--muted); transition: color var(--transition-fast); }
.sidebar-nav .nav-item:hover { background: var(--sunken); text-decoration: none; color: var(--ink); }
.sidebar-nav .nav-item:hover .icon { color: var(--text); }
.sidebar-nav .nav-item.is-active { background: var(--brand-soft); color: var(--brand); font-weight: 500; }
.sidebar-nav .nav-item.is-active .icon { color: var(--brand); }
.nav-item-label { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-badge {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--danger-bright); color: #fff;
  font-size: 11px; font-weight: 600; border-radius: var(--r-pill);
}
.sidebar-footer { padding: var(--s3) var(--s5) var(--s5); border-top: 1px solid var(--line); }
.sidebar-footer-text { color: var(--faint); }
.sidebar-footer-text a { color: var(--muted); }

/* collapsed (desktop, icons only) */
.sidebar-collapsed .sidebar { width: var(--sidebar-collapsed); flex-basis: var(--sidebar-collapsed); }
.sidebar-collapsed .sidebar-name,
.sidebar-collapsed .sidebar-footer,
.sidebar-collapsed .sidebar-section-label,
.sidebar-collapsed .nav-item-label,
.sidebar-collapsed .nav-badge { display: none; }
.sidebar-collapsed .sidebar-brand { justify-content: center; padding: var(--s5) var(--s2) var(--s4); }
.sidebar-collapsed .sidebar-nav .nav-item { justify-content: center; padding: 10px; }

/* ---------- main column ---------- */
.main-area { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.main-content {
  flex: 1 1 auto; width: 100%; max-width: var(--content-max);
  margin: 0 auto; padding: var(--s6) var(--s6) var(--s8);
}
.main-content:focus { outline: none; }
@media (min-width: 1280px) { .main-content { padding: 30px 30px var(--s10); } }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: var(--z-sticky);
  height: var(--topbar-height);
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: 0 var(--s6);
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar-left { display: flex; align-items: center; gap: var(--s3); min-width: 0; flex: 1 1 auto; }
.topbar-right { display: flex; align-items: center; gap: var(--s2); flex: 0 0 auto; }
.topbar .btn-icon { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: var(--r-pill); color: var(--muted); background: var(--surface); }
.topbar .btn-icon:hover { background: var(--page); color: var(--text); border-color: var(--line); text-decoration: none; }

/* global search */
.global-search { position: relative; width: 100%; max-width: 430px; }
.global-search .input { padding-left: 40px; background: var(--surface); }
.input-with-icon { position: relative; }
.input-with-icon > .icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--faint); pointer-events: none;
}
.input-with-icon .input { padding-left: 42px; }
.search-kbd {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  display: inline-flex; align-items: center; gap: 4px;
  font-family: var(--font-sans); font-size: 11.5px; font-weight: 500; color: var(--faint);
  background: var(--sunken); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 2px 7px; pointer-events: none;
}
.search-results {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  max-height: 380px; overflow: auto; padding: var(--s2); z-index: var(--z-dropdown);
}
.search-result-group { padding: var(--s2) var(--s2) var(--s1); font-size: 11px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: 0.05em; }
.search-results a, .search-results .result-row {
  display: flex; align-items: center; gap: var(--s2);
  padding: 8px 10px; border-radius: var(--r-control); color: var(--text); text-decoration: none;
}
.search-results a:hover { background: var(--sunken); text-decoration: none; }

/* bell */
.bell-btn { position: relative; }
.bell-dot {
  position: absolute; top: 9px; right: 10px;
  min-width: 16px; height: 16px; padding: 0 4px;
  background: var(--warning); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
  border-radius: var(--r-pill); border: 2px solid var(--surface);
}
.bell-dot:empty { width: 8px; min-width: 8px; height: 8px; padding: 0; }

/* user chip */
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 6px 4px 4px; border-radius: var(--r-pill);
  transition: background var(--transition-fast);
}
.user-chip:hover { background: var(--sunken); }
.user-chip .icon { width: 16px; height: 16px; color: var(--faint); }
.user-chip-text { text-align: left; line-height: 1.2; }
.user-chip-name { display: block; font-size: 13.5px; font-weight: 600; color: var(--ink); }
.user-chip-role { display: block; font-size: 11.5px; color: var(--muted); }

.avatar {
  width: 40px; height: 40px; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand); color: #fff;
  border-radius: var(--r-pill);
  font-size: 13px; font-weight: 600; letter-spacing: 0.02em;
  object-fit: cover; overflow: hidden;
}
.avatar-sm { width: 32px; height: 32px; font-size: 11px; }
.avatar-lg { width: 48px; height: 48px; font-size: 15px; }
.avatar-xl { width: 72px; height: 72px; font-size: 22px; }
.avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-form { display: inline-block; margin: 0; }

/* ---------- page headers ---------- */
.page-head, .page-header { margin-bottom: var(--s5); }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; }
.page-title { font-size: var(--fs-heading-xl); line-height: var(--lh-heading-xl); font-weight: 600; color: var(--ink); }
.page-subtitle { margin-top: 2px; font-size: var(--fs-body); color: var(--muted); }
.page-actions { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.page-gap { margin-bottom: var(--s5); }
.breadcrumbs { font-size: 13px; color: var(--faint); margin-bottom: var(--s2); }
.breadcrumbs a { color: var(--muted); }

/* ==========================================================================
   Cards
   ========================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-sm);
  padding: var(--s6);
}
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s4); }
.card-title { font-size: var(--fs-heading-m); line-height: var(--lh-heading-m); font-weight: 600; color: var(--ink); }
.card-subtitle { margin-top: 2px; font-size: var(--fs-body); color: var(--muted); }
.card-body { min-width: 0; }
.card-pad { padding: var(--s6); }
.card-body-flush { margin: 0 calc(-1 * var(--s6)) calc(-1 * var(--s6)); }
.card-body-flush > .tablewrap, .card-body-flush > .table-wrap { border: 0; border-radius: 0; }
.card-footer { margin-top: var(--s4); padding-top: var(--s4); border-top: 1px solid var(--line); }
.card + .card { margin-top: var(--s4); }

/* KPI metric cards */
.kpis { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); margin-bottom: var(--s5); }
.kpi {
  position: relative; padding: var(--s5) var(--s5);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card);
  box-shadow: var(--shadow-sm);
}
.kpi-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s2); }
.kpi-head .icon, .kpi-icon { color: var(--muted); }
.kpi-label { font-size: 13.5px; font-weight: 500; color: var(--muted); }
.kpi-value { margin-top: 10px; font-size: 26px; line-height: 34px; font-weight: 700; color: var(--ink); letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-sub, .kpi-meta { margin-top: 4px; font-size: 12.5px; color: var(--faint); }
.kpi-prev { color: var(--faint); }
.kpi-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s2); }
.kpi-ico { display: inline-flex; color: var(--muted); }
.kpi-ico .icon { width: 18px; height: 18px; }
.kpi-ico.c-brand { color: var(--brand); } .kpi-ico.c-green { color: var(--success); }
.kpi-ico.c-blue { color: var(--accent); } .kpi-ico.c-orange { color: var(--warning); }
.kpi-ico.c-red { color: var(--danger-bright); }
.kpi-delta { margin-top: 6px; font-size: 12px; display: flex; align-items: center; gap: 5px; }
.kpi-delta .up { color: var(--success); font-weight: 600; }
.kpi-delta .down { color: var(--danger); font-weight: 600; }
.kpi-foot, .kpi-bottom { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s2); margin-top: 10px; }
.kpi-bottom { margin-top: 4px; }
.kpi-bottom .kpi-meta { margin-top: 0; }
.kpi-foot .kpi-value { margin-top: 0; }
.kpi-spark-svg { flex: 0 0 auto; opacity: 0.95; }
.kpi-link { position: absolute; inset: 0; border-radius: var(--r-card); text-decoration: none; }
.kpi-link:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.metric-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); }
.metric-label { color: var(--muted); font-size: 13.5px; }
.metric-value { font-weight: 700; color: var(--ink); }

/* trend chips */
.trend { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 500; padding: 2px 8px; border-radius: var(--r-pill); }
.trend-up { color: var(--success); background: var(--success-soft); }
.trend-down { color: var(--danger); background: var(--danger-soft); }
.trend-flat { color: var(--muted); background: var(--neutral-soft); }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 9px 16px;
  font-size: var(--fs-label); line-height: var(--lh-label); font-weight: 500;
  border-radius: var(--r-control); border: 1px solid transparent;
  text-decoration: none; white-space: nowrap; user-select: none;
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
}
.btn:hover { text-decoration: none; }
.btn .icon { width: 18px; height: 18px; }
.btn:active { transform: translateY(0.5px); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--brand-strong); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--page); border-color: var(--line-strong); color: var(--ink); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--sunken); }
.btn-danger { background: var(--danger-bright); color: #fff; box-shadow: var(--shadow-sm); }
.btn-danger:hover { background: var(--danger); }
.btn-dark { background: var(--navy); color: #fff; }
.btn-dark:hover { background: #081249; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #027a48; }
.btn-danger-soft { background: var(--danger-soft); color: var(--danger); }
.btn-danger-soft:hover { background: #fdd9d4; }
.btn-lg { min-height: 48px; padding: 12px 22px; font-size: 15px; }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: 13px; gap: 6px; }
.btn-sm .icon { width: 16px; height: 16px; }
.btn-block { width: 100%; }
.btn-icon { width: 40px; min-width: 40px; height: 40px; padding: 0; }
.btn-icon.btn-sm { width: 34px; min-width: 34px; height: 34px; }
.btn[disabled], .btn.is-disabled { opacity: 0.5; pointer-events: none; }
.btn.is-loading { pointer-events: none; opacity: 0.75; }
.btnrow, .form-actions { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.form-actions { margin-top: var(--s4); }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--r-control) 0 0 var(--r-control); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--r-control) var(--r-control) 0; }
.actions { display: inline-flex; align-items: center; gap: 6px; }
.actions-cell { text-align: right; white-space: nowrap; }
.actions-cell .actions { justify-content: flex-end; }
.action-buttons { display: flex; gap: var(--s2); flex-wrap: wrap; }

/* ==========================================================================
   Tables
   ========================================================================== */
.tablewrap, .table-wrap {
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface); overflow-x: auto; box-shadow: var(--shadow-sm);
}
.card .tablewrap, .card .table-wrap { border-radius: var(--r-lg); }
table, .table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; padding: 11px 14px;
  font-size: 12px; font-weight: 500; color: var(--muted);
  background: var(--page); border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); color: var(--text); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--page); }
.table a { font-weight: 500; }
.table .num, .table .money, td.num, td.money { text-align: right; font-variant-numeric: tabular-nums; }
.table-compact th, .table-compact td { padding: 7px 10px; font-size: 13px; }
.table-fixed { table-layout: fixed; }
.table-selectable tbody tr { cursor: pointer; }
.table-selectable tbody tr.is-selected td { background: var(--brand-soft); }
.headrow td, .headrow th { font-weight: 600; color: var(--ink); background: var(--page); }
.row-section td { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint); background: var(--page); padding: 8px 14px; }
.row-subtotal td { font-weight: 600; background: var(--page); }
.row-total td, .row-total th { font-weight: 700; color: var(--ink); border-top: 2px solid var(--ink); background: var(--page); }
tr.is-active td { background: var(--brand-softer); }
tr.ghost td, .ghost { opacity: 0.55; }
tr.is-danger td { background: var(--danger-soft); }
.primary { color: var(--ink); font-weight: 500; }
.danger { color: var(--danger); } .high { color: var(--warning-text); } .urgent { color: var(--danger); font-weight: 600; }
.d90plus { color: var(--danger); font-weight: 600; }
.current td { background: var(--brand-softer); }
.amount-in { color: var(--success); font-weight: 500; font-variant-numeric: tabular-nums; }
.amount-out { color: var(--danger); font-weight: 500; font-variant-numeric: tabular-nums; }
.entry-reversed td, .entry-reversed { opacity: 0.55; }
.entry-reversed .t-bold, .entry-reversed td:first-child { text-decoration: line-through; }
.line-head td { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--page); text-transform: uppercase; letter-spacing: 0.04em; }
.line-foot td { font-weight: 700; color: var(--ink); background: var(--page); }
.line-row td { vertical-align: top; }
.line-remove { color: var(--faint); } .line-remove:hover { color: var(--danger); }
.line-sum { text-align: right; font-variant-numeric: tabular-nums; }
.line-total { text-align: right; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.line-items .input, .line-items .select { min-height: 38px; }
.line-items-simple td { padding: 8px 10px; }

/* mobile stacked tables */
@media (max-width: 768px) {
  .table-cards thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr { border: 1px solid var(--line); border-radius: var(--r-lg); margin-bottom: var(--s3); padding: var(--s2) var(--s3); background: var(--surface); }
  .table-cards td { border: 0; padding: 6px 0; display: flex; justify-content: space-between; gap: var(--s3); }
  .table-cards td::before { content: attr(data-label); font-size: 12px; font-weight: 500; color: var(--muted); }
  .table-cards td.no-label::before { content: none; }
  .table-cards.table, .table-wrap .table-cards { border: 0; }
}

/* ==========================================================================
   Badges & chips
   ========================================================================== */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: var(--r-pill);
  font-size: 12px; font-weight: 500; line-height: 20px; white-space: nowrap;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning-text); }
.badge-danger  { background: var(--danger-soft); color: var(--danger); }
.badge-info    { background: var(--info-soft); color: var(--info); }
.badge-neutral { background: var(--neutral-soft); color: var(--muted); }
.badge-outline { background: var(--surface); border: 1px solid var(--line-strong); color: var(--text); }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; padding: 0; }
.b-ok { color: var(--success); } .b-warn { color: var(--warning-text); } .b-danger { color: var(--danger); }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--r-pill);
  background: var(--sunken); color: var(--text); font-size: 12.5px; font-weight: 500;
}
.chip-remove { color: var(--faint); display: inline-flex; }
.chip-remove:hover { color: var(--danger); }
.severity-success { color: var(--success); } .severity-warning { color: var(--warning-text); }
.severity-critical { color: var(--danger); } .severity-info { color: var(--info); }

/* ==========================================================================
   Alerts, toasts, empty states
   ========================================================================== */
.alert {
  display: flex; align-items: flex-start; gap: var(--s3);
  padding: 14px 16px; margin-bottom: var(--s4);
  border-radius: var(--r-lg); border: 1px solid;
  font-size: 13.5px;
}
.alert > .icon { width: 20px; height: 20px; flex: 0 0 auto; margin-top: 1px; }
.alert-body { flex: 1 1 auto; min-width: 0; color: var(--text); }
.alert-title { font-weight: 600; color: var(--ink); margin-bottom: 2px; }
.alert-success { background: var(--success-soft); border-color: #a6f4c5; color: var(--text); }
.alert-success > .icon { color: var(--success); }
.alert-warning { background: var(--warning-soft); border-color: #fedf89; }
.alert-warning > .icon { color: var(--warning); }
.alert-danger { background: var(--danger-soft); border-color: #fecdca; }
.alert-danger > .icon { color: var(--danger-bright); }
.alert-info { background: var(--info-soft); border-color: #b2ddff; }
.alert-info > .icon { color: var(--info); }
.alert-neutral { background: var(--sunken); border-color: var(--line); }
.alert-neutral > .icon { color: var(--muted); }
.alert-close { color: var(--muted); display: inline-flex; padding: 2px; border-radius: var(--r-sm); }
.alert-close:hover { color: var(--ink); background: rgba(0, 0, 0, 0.05); }
.alert-close .icon { width: 16px; height: 16px; }
.alert-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }

.toast-region { position: fixed; right: 16px; bottom: 16px; z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--s2); max-width: 360px; }
.toast {
  display: flex; align-items: flex-start; gap: var(--s2);
  padding: 12px 14px; border-radius: var(--r-lg);
  background: var(--navy); color: #fff; box-shadow: var(--shadow-lg);
  font-size: 13.5px;
}
.toast-success { background: var(--success); }
.toast-danger { background: var(--danger-bright); }
.toast-warning { background: var(--warning); color: var(--ink); }
.toast-info { background: var(--info); }

.empty-state { text-align: center; padding: var(--s10) var(--s6); color: var(--muted); }
.empty-icon {
  width: 48px; height: 48px; margin: 0 auto var(--s3);
  display: flex; align-items: center; justify-content: center;
  background: var(--sunken); color: var(--muted); border-radius: var(--r-pill);
}
.empty-title { font-size: 15px; font-weight: 600; color: var(--ink); margin-bottom: 4px; }
.empty-text { font-size: 13.5px; }

/* ==========================================================================
   Forms
   ========================================================================== */
.label, label:not(.check):not(.switch):not(.nav-item):not(.dropdown-item):not(.sheet-tile):not(.mobile-nav-item):not(.user-chip) {
  display: block; font-size: var(--fs-label); line-height: var(--lh-label);
  font-weight: 500; color: var(--text); margin-bottom: 6px;
}
.req { color: var(--danger-bright); margin-left: 2px; }
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: 10px 14px;
  font-size: 14px; line-height: 20px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r-control); box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.textarea { min-height: 96px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-ring);
}
.input:disabled, .select:disabled, .textarea:disabled { background: var(--sunken); color: var(--muted); cursor: not-allowed; }
.input[readonly] { background: var(--page); }
.input-sm, .select-sm { min-height: 36px; padding: 6px 10px; font-size: 13px; }
.input-error, .select-error, .textarea-error, .input.is-danger { border-color: var(--danger-bright); }
.input-error:focus { box-shadow: 0 0 0 4px rgba(246, 73, 50, 0.12); }
.select {
  appearance: none; padding-right: 40px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.select:invalid { color: var(--faint); }
.field { margin-bottom: var(--s4); min-width: 0; }
.field-full { grid-column: 1 / -1; }
.field-help, .hint { margin-top: 6px; font-size: 12px; color: var(--muted); }
.field-error, .err { margin-top: 6px; font-size: 12px; color: var(--danger); }
.label-hint { font-weight: 400; color: var(--faint); }
.form-grid { display: grid; gap: var(--s4) var(--s5); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid-3 { display: grid; gap: var(--s4) var(--s5); grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .field, .form-grid-3 .field { margin-bottom: 0; }
.fieldrow { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.fieldset { border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s5); margin-bottom: var(--s4); }
.fieldset > legend { font-size: var(--fs-label); font-weight: 600; color: var(--ink); padding: 0 var(--s2); }
.form-inline, .inline-form { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.form-inline .input, .form-inline .select, .inline-form .input, .inline-form .select { width: auto; }
.searchbar { display: flex; gap: var(--s2); align-items: center; }
.searchbar .input { max-width: 340px; }
.search-box { position: relative; }
.toolbar { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; margin-bottom: var(--s4); }
.toolbar-sticky { position: sticky; top: var(--topbar-height); z-index: var(--z-dropdown); background: var(--page); padding: var(--s2) 0; }

/* input groups (prefix/suffix) */
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: 0 var(--r-control) var(--r-control) 0; margin-left: -1px; }
.input-group .input:first-child { border-radius: var(--r-control) 0 0 var(--r-control); margin-left: 0; }
.input-prefix, .prefix-text {
  display: inline-flex; align-items: center; padding: 0 12px;
  background: var(--page); border: 1px solid var(--line-strong);
  color: var(--muted); font-size: 13.5px; flex: 0 0 auto;
}
.input-group > :first-child { border-radius: var(--r-control) 0 0 var(--r-control); }
.input-group > :last-child { border-radius: 0 var(--r-control) var(--r-control) 0; }
.input-group > :only-child { border-radius: var(--r-control); }

/* password field */
.password-wrap { position: relative; }
.password-wrap .input { padding-right: 44px; }
.password-toggle {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--faint); border-radius: var(--r-control);
}
.password-toggle:hover { color: var(--text); background: var(--sunken); }
.password-toggle .icon { width: 18px; height: 18px; }

/* checkbox & radio (input is the visual control) */
.check, .check-inline { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.check input[type='checkbox'], .check input[type='radio'], input[type='checkbox'].check-input {
  appearance: none; -webkit-appearance: none;
  width: 20px; height: 20px; flex: 0 0 20px; margin: 1px 0 0;
  border: 1.5px solid var(--line-strong); border-radius: 6px;
  background: var(--surface); cursor: pointer; position: relative;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.check input[type='radio'] { border-radius: 50%; }
.check input[type='checkbox']:checked {
  background: var(--brand); border-color: var(--brand);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: center;
}
.check input[type='radio']:checked { border: 6px solid var(--brand); background: #fff; }
.check input:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--brand-ring); border-color: var(--brand); }
.check input:disabled { background: var(--sunken); cursor: not-allowed; }
.check-label { font-size: 14px; font-weight: 500; color: var(--text); line-height: 21px; }
.check-desc { display: block; font-size: 12.5px; color: var(--muted); font-weight: 400; margin-top: 1px; }
.check-inline { display: inline-flex; margin-right: var(--s4); }

/* toggle switch */
.switch { display: flex; align-items: flex-start; gap: var(--s3); cursor: pointer; }
.switch input[type='checkbox'] {
  position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none;
}
.switch-track {
  width: 44px; height: 24px; flex: 0 0 44px; margin-top: 1px;
  background: var(--line); border-radius: var(--r-pill);
  position: relative; transition: background var(--transition-fast);
}
.switch-track::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(16, 24, 40, 0.25);
  transition: transform var(--transition-base);
}
.switch input:checked + .switch-track { background: var(--brand); }
.switch input:checked + .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 4px var(--brand-ring); }
.switch-text { font-size: 14px; font-weight: 500; color: var(--text); line-height: 21px; }

/* segmented tabs (Overview / Sales / Revenue pill group) */
.tabs { display: inline-flex; gap: 2px; background: var(--sunken); padding: 3px; border-radius: var(--r-pill); }
.tabs a, .tabs button, .tabs-pill a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: var(--r-pill);
  font-size: 13px; font-weight: 500; color: var(--muted); text-decoration: none;
}
.tabs a:hover, .tabs button:hover { color: var(--text); text-decoration: none; }
.tabs a.is-active, .tabs button.is-active, .tabs a[aria-current],
.tabs-pill a.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.tab { padding: 8px 2px; font-size: 14px; font-weight: 500; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.is-active { color: var(--brand); border-color: var(--brand); }

/* otp boxes, qr, recovery codes */
.otp-input { display: flex; gap: var(--s2); }
.otp-input input {
  width: 48px; height: 52px; text-align: center; font-size: 20px; font-weight: 600;
  border: 1px solid var(--line-strong); border-radius: var(--r-control); background: var(--surface);
}
.otp-input input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-ring); }
.qr-box { display: inline-block; padding: var(--s4); border: 1px solid var(--line); border-radius: var(--r-lg); background: #fff; }
.recovery-codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); font-family: var(--font-mono); font-size: 13px; }
.recovery-codes code { background: var(--sunken); border: 1px solid var(--line); border-radius: var(--r-md); padding: 6px 10px; text-align: center; }

/* strength meter */
.strength { margin-top: var(--s2); }
.strength-bar { height: 6px; border-radius: var(--r-pill); background: var(--sunken); overflow: hidden; }
.strength-seg, .strength-bar > div { height: 100%; width: 0; background: var(--danger-bright); border-radius: var(--r-pill); transition: width var(--transition-base), background var(--transition-base); }
.strength-text { font-size: 12px; color: var(--muted); margin-top: 4px; }
.strength-rules { font-size: 12.5px; color: var(--muted); list-style: none; padding: 0; margin: var(--s2) 0 0; }
.strength-rules li { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.strength-rules li.met { color: var(--success); }

/* filter sheet trigger */
.filter-group { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.filter-count { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; background: var(--brand); color: #fff; border-radius: var(--r-pill); font-size: 11px; font-weight: 600; }

/* date range */
.daterange { display: inline-flex; align-items: center; gap: var(--s2); }
.daterange-custom { display: flex; gap: var(--s2); align-items: center; }

/* product picker & suggestion rows (JS-built) */
.picker-wrap { position: relative; }
.picker-list {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: var(--z-dropdown);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); max-height: 320px; overflow: auto; padding: var(--s1);
}
.picker-item { display: flex; align-items: center; gap: var(--s2); width: 100%; text-align: left; padding: 8px 10px; border-radius: var(--r-control); }
.picker-item:hover, .picker-item.is-active { background: var(--sunken); }
.picker-main { flex: 1 1 auto; min-width: 0; color: var(--text); }
.picker-meta { font-size: 12px; color: var(--muted); }
.picker-right { flex: 0 0 auto; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.picker-empty { padding: var(--s4); text-align: center; color: var(--muted); font-size: 13px; }
.suggest-group { margin-bottom: var(--s2); }
.suggest-group-head { padding: 6px 10px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint); }
.suggest-group-title { font-weight: 600; color: var(--ink); }
.suggestion-chip { margin: 2px; }

/* ==========================================================================
   Dropdowns, modals, drawers
   ========================================================================== */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 230px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  padding: var(--s2); z-index: var(--z-dropdown);
}
.dropdown-header { padding: 8px 12px; font-size: 13.5px; font-weight: 600; color: var(--ink); }
.dropdown-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 12px; border-radius: var(--r-control);
  font-size: 13.5px; color: var(--text); text-decoration: none; text-align: left;
}
.dropdown-item .icon { width: 17px; height: 17px; color: var(--muted); }
.dropdown-item:hover { background: var(--sunken); text-decoration: none; color: var(--ink); }
.dropdown-item:hover .icon { color: var(--text); }
.dropdown-item.is-danger { color: var(--danger); }
.dropdown-item.is-danger .icon { color: var(--danger); }
.dropdown-item.is-danger:hover { background: var(--danger-soft); }
.dropdown-divider { height: 1px; background: var(--line); margin: 6px 4px; }

.modal-backdrop {
  position: fixed; inset: 0; z-index: var(--z-modal);
  background: rgba(16, 24, 40, 0.55);
  display: flex; align-items: center; justify-content: center; padding: var(--s4);
  overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: var(--r-card);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 520px;
  padding: var(--s6); margin: auto;
}
.modal-lg { max-width: 760px; }
.modal-xl { max-width: 1020px; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); }
.modal-title { font-size: var(--fs-heading-m); font-weight: 600; color: var(--ink); }
.modal-desc { font-size: 13.5px; color: var(--muted); }
.modal-body { min-width: 0; }
.modal-footer { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s5); }
.modal-close {
  width: 36px; height: 36px; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); border-radius: var(--r-control);
}
.modal-close:hover { background: var(--sunken); color: var(--ink); }
.modal-close .icon { width: 18px; height: 18px; }
.confirm-impact { background: var(--page); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s3); font-size: 13px; }
.confirm-danger .btn-primary { background: var(--danger-bright); }
.confirm-danger .btn-primary:hover { background: var(--danger); }

/* mobile drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(16, 24, 40, 0.5); z-index: calc(var(--z-drawer) - 1); }

/* info tip popover */
.info-tip { position: relative; display: inline-flex; }
.info-tip-btn { color: var(--faint); display: inline-flex; }
.info-tip-btn:hover { color: var(--text); }
.info-tip-content {
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  min-width: 200px; max-width: 280px; padding: 10px 12px;
  background: var(--navy); color: #fff; font-size: 12.5px; font-weight: 400;
  border-radius: var(--r-control); box-shadow: var(--shadow-lg); z-index: var(--z-dropdown);
}

/* ==========================================================================
   Bottom sheet (mobile) & settings tiles
   ========================================================================== */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-modal);
  background: var(--surface); border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow-lg); max-height: 82vh; overflow-y: auto;
  padding: var(--s3) var(--s5) var(--s6);
}
.sheet-handle { width: 40px; height: 4px; border-radius: var(--r-pill); background: var(--line-strong); margin: var(--s1) auto var(--s3); }
.sheet-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s3); }
.sheet-title { font-size: var(--fs-heading-m); font-weight: 600; color: var(--ink); }
.sheet-body { min-width: 0; }
.sheet-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s2); }
.sheet-tile {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: var(--s4) var(--s2); border-radius: var(--r-lg);
  border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font-size: 12.5px; font-weight: 500; text-decoration: none; text-align: center;
}
.sheet-tile:hover { background: var(--page); text-decoration: none; border-color: var(--line-strong); }
.sheet-tile .icon { color: var(--muted); }
.sheet-footer { margin-top: var(--s4); padding-top: var(--s4); border-top: 1px solid var(--line); }

/* ==========================================================================
   Settings
   ========================================================================== */
.settings-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: var(--s5); align-items: start; }
.settings-nav { position: sticky; top: calc(var(--topbar-height) + var(--s4)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow-sm); padding: var(--s2); }
.settings-nav a {
  display: flex; align-items: center; gap: var(--s2);
  padding: 9px 12px; border-radius: var(--r-control);
  font-size: 13.5px; font-weight: 500; color: var(--text); text-decoration: none;
}
.settings-nav a:hover { background: var(--sunken); text-decoration: none; }
.settings-nav a.is-active { background: var(--brand-soft); color: var(--brand); }

/* ==========================================================================
   Mobile bottom navigation
   ========================================================================== */
.mobile-nav { display: none; }
.mobile-nav-badge {
  position: absolute; top: 2px; right: 14px;
  min-width: 16px; height: 16px; padding: 0 4px;
  background: var(--danger-bright); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
  border-radius: var(--r-pill);
}

/* ==========================================================================
   Auth pages (TailAdmin split: form left, navy visual right)
   ========================================================================== */
.auth-page { display: grid; grid-template-columns: 1fr 1fr; min-height: 100vh; min-height: 100dvh; background: var(--surface); }
.auth-form-side { display: flex; align-items: center; justify-content: center; padding: var(--s8) var(--s5); order: 1; }
.auth-card { width: 100%; max-width: 430px; }
.auth-brand { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s8); }
.auth-brand-logo, .brand-mark {
  width: 44px; height: 44px; flex: 0 0 44px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 16px;
  border-radius: 12px;
}
.auth-brand-name { font-size: 17px; font-weight: 700; color: var(--ink); line-height: 1.25; }
.auth-brand-sub { font-size: 13px; color: var(--muted); }
.auth-title { font-size: 30px; line-height: 38px; font-weight: 700; color: var(--ink); letter-spacing: -0.01em; }
.auth-subtitle { margin: var(--s2) 0 var(--s6); font-size: 14.5px; color: var(--muted); }
.auth-footer { margin-top: var(--s8); font-size: 13px; color: var(--faint); text-align: center; }
.auth-footer a { color: var(--muted); }
.auth-visual {
  order: 2; position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: var(--s10) var(--s12);
  color: #fff; background: var(--navy);
  background-image:
    radial-gradient(ellipse 600px 400px at 85% 108%, rgba(37, 55, 177, 0.5), transparent 65%),
    radial-gradient(ellipse 500px 360px at 8% -8%, rgba(9, 127, 232, 0.28), transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='56'%3E%3Ccircle cx='1.6' cy='1.6' r='1.6' fill='%23ffffff' fill-opacity='0.10'/%3E%3C/svg%3E");
  background-size: auto, auto, 56px 56px;
}
.auth-visual-title { font-size: 30px; line-height: 1.3; font-weight: 700; color: #fff; letter-spacing: -0.01em; max-width: 480px; }
.auth-visual-text { margin-top: var(--s4); font-size: 15px; line-height: 1.65; color: rgba(255, 255, 255, 0.72); max-width: 480px; }
.auth-points { list-style: none; padding: 0; margin: var(--s6) 0 0; }
.auth-points li { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 500; color: rgba(255, 255, 255, 0.92); margin-top: 10px; }
.auth-points .icon { width: 18px; height: 18px; color: #6d8dff; }

/* ==========================================================================
   Pagination
   ========================================================================== */
.pagination, .pagination-links { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pagination-info { font-size: 13px; color: var(--muted); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-top: var(--s4); flex-wrap: wrap; }
.page-link {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 36px; height: 36px; padding: 0 10px;
  border: 1px solid var(--line-strong); border-radius: var(--r-control);
  background: var(--surface); color: var(--text); font-size: 13px; font-weight: 500; text-decoration: none;
}
.page-link:hover { background: var(--page); text-decoration: none; }
.page-link.is-active, .page-link[aria-current] { background: var(--brand); border-color: var(--brand); color: #fff; }
.page-link.is-disabled { opacity: 0.45; pointer-events: none; }

/* ==========================================================================
   Description lists, timeline, progress, bars
   ========================================================================== */
.dl { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; row-gap: 10px; column-gap: var(--s5); font-size: 13.5px; }
.dl dt { color: var(--muted); } .dl dd { color: var(--ink); font-weight: 500; margin: 0; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline-item { position: relative; padding: 0 0 var(--s5) var(--s6); border-left: 2px solid var(--line); margin-left: 8px; }
.timeline-item:last-child { padding-bottom: 0; border-left-color: transparent; }
.timeline-dot {
  position: absolute; left: -7px; top: 4px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--surface); border: 2.5px solid var(--brand);
}
.timeline-title { font-size: 13.5px; font-weight: 600; color: var(--ink); }
.timeline-meta { font-size: 12px; color: var(--muted); margin-top: 1px; }
.timeline-body { font-size: 13px; color: var(--text); margin-top: 4px; }
.progress { height: 8px; background: var(--sunken); border-radius: var(--r-pill); overflow: hidden; }
.progress-fill { height: 100%; background: var(--brand); border-radius: var(--r-pill); }
.bar-list { list-style: none; padding: 0; margin: 0; }
.bar-row { display: flex; align-items: center; gap: var(--s3); margin-top: var(--s3); }
.bar-label { flex: 0 0 160px; font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1 1 auto; height: 8px; background: var(--sunken); border-radius: var(--r-pill); overflow: hidden; }
.bar-fill { height: 100%; background: var(--brand); border-radius: var(--r-pill); }
.bar-value { flex: 0 0 auto; font-size: 12.5px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Charts, skeletons
   ========================================================================== */
.chart-wrap { position: relative; }
.chart-canvas { width: 100%; }
.chart-legend { display: flex; flex-wrap: wrap; gap: var(--s3) var(--s5); margin-top: var(--s3); font-size: 12.5px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-summary { font-size: 13px; color: var(--muted); }
.chart-tooltip {
  position: absolute; pointer-events: none; z-index: var(--z-dropdown);
  background: var(--navy); color: #fff; font-size: 12px;
  padding: 8px 10px; border-radius: var(--r-control); box-shadow: var(--shadow-lg);
}
.skeleton { position: relative; overflow: hidden; background: var(--sunken); border-radius: var(--r-md); }
.skeleton::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.65), transparent);
  animation: erp-shimmer 1.4s infinite;
}
@keyframes erp-shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.skeleton-title { height: 22px; width: 40%; margin-bottom: var(--s3); }
.skeleton-text { height: 13px; margin-top: 8px; }
.skeleton-row { height: 44px; margin-top: 8px; }
.skeleton-kpi { height: 110px; border-radius: var(--r-card); }
.skeleton-chart { height: 260px; border-radius: var(--r-card); }

/* ==========================================================================
   Misc components
   ========================================================================== */
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain > li { padding: var(--s2) 0; border-bottom: 1px solid var(--line); }
.list-plain > li:last-child { border-bottom: 0; }
.list-row { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.contact-actions { display: inline-flex; align-items: center; gap: var(--s1); flex-wrap: wrap; }
.contact-actions .btn { padding-inline: var(--s2); }
.contact-wa { color: var(--success); }
.contact-wa:hover { background: var(--success-soft); }
.account-tile {
  display: block; padding: var(--s4);
  border: 1px solid var(--line); border-radius: var(--r-card);
  background: var(--surface); text-decoration: none; color: inherit;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.account-tile:hover { border-color: var(--brand); box-shadow: var(--shadow-md); text-decoration: none; }
.account-tile-name { font-weight: 600; color: var(--ink); }
.account-tile-meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.account-tile-balance { margin-top: var(--s3); font-size: 22px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.action-item { display: flex; gap: var(--s3); padding: var(--s3) 0; border-bottom: 1px solid var(--line); }
.action-item:last-child { border-bottom: 0; }
.action-content { flex: 1 1 auto; min-width: 0; }
.action-title { font-weight: 600; color: var(--ink); font-size: 13.5px; }
.action-desc { font-size: 13px; color: var(--muted); margin-top: 1px; }
.action-meta { font-size: 12px; color: var(--faint); margin-top: 2px; }
.action-severity { flex: 0 0 auto; }
.formula { font-family: var(--font-mono); font-size: 12.5px; background: var(--sunken); border: 1px solid var(--line); border-radius: var(--r-md); padding: 2px 8px; }
.stat-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: 10px 0; border-bottom: 1px solid var(--line); }
.stat-row:last-child { border-bottom: 0; }
.preview-old, .preview-new { border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s4); background: var(--surface); min-width: 0; }
.preview-new { border-color: var(--brand); }
.preview-table { font-size: 12.5px; }
.info-tip + .field-help { display: inline; }

/* support chat */
.msg { display: flex; gap: var(--s3); margin-bottom: var(--s4); }
.msg-avatar { flex: 0 0 auto; }
.msg-content { flex: 1 1 auto; min-width: 0; background: var(--sunken); border-radius: var(--r-lg); padding: 10px 14px; font-size: 13.5px; }
.msg-user .msg-content { background: var(--brand-soft); }
.msg-actions { font-size: 12px; color: var(--faint); margin-top: 4px; }
.msg-assistant .msg-content { background: var(--info-soft); }
.msg-typing { display: inline-flex; gap: 3px; padding: 6px 0; }
.msg-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); animation: erp-blink 1.2s infinite; }
.msg-typing i:nth-child(2) { animation-delay: 0.2s; } .msg-typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes erp-blink { 0%, 60%, 100% { opacity: 0.3; } 30% { opacity: 1; } }

/* legacy assistant floating panel (only renders if explicitly enabled) */
.assistant-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: var(--z-toast);
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--brand); color: #fff; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; justify-content: center;
}
.assistant-panel {
  position: fixed; right: 20px; bottom: 84px; z-index: var(--z-toast);
  width: min(400px, calc(100vw - 40px)); max-height: 70vh;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-card); box-shadow: var(--shadow-lg); overflow: hidden;
}
.assistant-header { display: flex; align-items: center; justify-content: space-between; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); font-weight: 600; color: var(--ink); }
.assistant-body { flex: 1 1 auto; overflow-y: auto; padding: var(--s4); }
.assistant-suggestions { display: flex; flex-wrap: wrap; gap: var(--s2); padding: 0 var(--s4) var(--s3); }
.assistant-composer { display: flex; gap: var(--s2); padding: var(--s3) var(--s4); border-top: 1px solid var(--line); }
.assistant-footer { padding: 6px var(--s4); font-size: 11px; color: var(--faint); border-top: 1px solid var(--line); }

/* help centre */
.help-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: var(--s6); align-items: start; }
.help-side { position: sticky; top: calc(var(--topbar-height) + var(--s4)); }
.help-body { min-width: 0; max-width: 860px; }
.help-hero { background: var(--navy); border-radius: var(--r-card); padding: var(--s8); color: #fff; margin-bottom: var(--s5); }
.help-hero-title { font-size: 26px; line-height: 34px; font-weight: 700; color: #fff; }
.help-search { margin-top: var(--s4); max-width: 420px; }
.help-step { border: 1px solid var(--line); border-radius: var(--r-card); background: var(--surface); padding: var(--s5); margin-bottom: var(--s4); box-shadow: var(--shadow-sm); }
.help-sum { border: 1px solid var(--line); border-radius: var(--r-card); background: var(--surface); padding: var(--s5); box-shadow: var(--shadow-sm); }
.help-sum-row { display: flex; flex-wrap: nowrap; gap: var(--s3); align-items: start; }
.help-sum-label { flex: 1; min-width: 0; }
.help-sum-value { flex: 0 0 auto; }
.help-facts { background: var(--info-soft); border: 1px solid #b2ddff; border-radius: var(--r-lg); padding: var(--s4); }
.help-problem { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s4); }
.help-nextprev { display: flex; justify-content: space-between; gap: var(--s3); margin-top: var(--s5); }

/* ==========================================================================
   Responsive
   ========================================================================== */
.show-mobile { display: none !important; }
@media (max-width: 1024px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; height: 100dvh;
    transform: translateX(-100%); box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-collapsed .sidebar { width: var(--sidebar-width); flex-basis: var(--sidebar-width); }
  .sidebar-collapsed .sidebar-name,
  .sidebar-collapsed .sidebar-footer,
  .sidebar-collapsed .sidebar-section-label,
  .sidebar-collapsed .nav-item-label,
  .sidebar-collapsed .nav-badge { display: block; }
  .sidebar-collapsed .sidebar-nav .nav-item { justify-content: flex-start; padding: 10px var(--s3); }
  .main-content { padding: var(--s4) var(--s4) calc(var(--bottomnav-height) + var(--s6)); }
  .topbar { padding: 0 var(--s4); height: 64px; }
  .topbar .btn-icon { width: 40px; height: 40px; }
  .auth-page { grid-template-columns: 1fr; }
  .auth-visual { display: none; }
  .settings-layout { grid-template-columns: 1fr; }
  .settings-nav { position: static; }
  .help-layout { grid-template-columns: 1fr; }
  .help-side { position: static; }
  .mobile-nav {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-sticky);
    background: var(--surface); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .mobile-nav-inner { display: grid; grid-template-columns: repeat(5, 1fr); }
  .mobile-nav-item {
    position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 9px 4px 8px; font-size: 11px; font-weight: 500; color: var(--muted); text-decoration: none;
  }
  .mobile-nav-item .icon { width: 21px; height: 21px; }
  .mobile-nav-item.is-active { color: var(--brand); }
}
@media (max-width: 900px) {
  .grid-4, .grid-6, .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2-1, .grid-1-2, .grid-3-2 { grid-template-columns: 1fr; }
  .form-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-4, .grid-6, .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
  .kpis, .grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); }
  .kpi { padding: var(--s4); }
  .kpi-value { font-size: 21px; line-height: 28px; }
  .card, .card-pad { padding: var(--s4); }
  .card-body-flush { margin: 0 calc(-1 * var(--s4)) calc(-1 * var(--s4)); }
  .hide-mobile, .topbar .global-search { display: none !important; }
  .user-chip-text { display: none; }
  .dl { grid-template-columns: 1fr; }
  .auth-title { font-size: 26px; line-height: 34px; }
}
@media (max-width: 525px) {
  .kpis, .grid-kpi { grid-template-columns: 1fr; }
  .sheet-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 641px) and (max-width: 1024px) {
  .hide-mobile { display: none !important; }
  .show-mobile { display: inline-flex !important; }
}
@media (max-width: 640px) { .show-mobile { display: inline-flex !important; } }
.hide-tablet { }
@media (min-width: 641px) and (max-width: 1024px) { .hide-tablet { display: none !important; } }

/* ==========================================================================
   Print
   ========================================================================== */
@media print {
  .sidebar, .topbar, .mobile-nav, .page-actions, .header-search, .searchbar,
  .no-print, .sheet, .toast-region, .drawer-backdrop, .skip-link,
  .help-side, .help-nextprev, .help-search { display: none !important; }
  body { background: #fff; }
  .app-shell { display: block; }
  .main-content { max-width: none; padding: 0; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .tablewrap, .table-wrap { border: 0; overflow: visible; }
  .table th { background: #f2f4f7 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .row-total > th, .row-total > td { border-top: 2px solid #000; }
  .help-layout { grid-template-columns: 1fr; }
  .help-body { max-width: none; }
  .help-step, .help-sum, .help-facts, .help-problem { break-inside: avoid; }
  .help-problem p { display: block !important; }
  a { color: inherit; text-decoration: none; }
}

/* ==========================================================================
   Form compatibility pack.
   Many views use bare <input>/<select>/<textarea> elements and plain
   <label> stacks without wrapper divs. These rules give them the exact
   TailAdmin control look and restore the vertical rhythm the labels used
   to provide. Everything that targets only bare elements is wrapped in
   :where() so it has ZERO specificity: any component-level rule (search
   bars, table cells, otp boxes, inline forms) can still override it.
   ========================================================================== */
input:where(:not([class]):not([type=checkbox]):not([type=radio]):not([type=hidden]):not([type=submit]):not([type=button]):not([type=reset]):not([type=file]):not([type=range])),
select:where(:not([class])),
textarea:where(:not([class])) {
  width: 100%; min-height: 44px; padding: 10px 14px;
  font: inherit; font-size: 14px; line-height: 20px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r-control); box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
input:where(:not([class])):focus, select:where(:not([class])):focus, textarea:where(:not([class])):focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-ring);
}
input:where(:not([class])):disabled, select:where(:not([class])):disabled, textarea:where(:not([class])):disabled {
  background: var(--sunken); color: var(--muted); cursor: not-allowed;
}
select:where(:not([class])) {
  appearance: none; padding-right: 40px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
textarea:where(:not([class])) { min-height: 96px; resize: vertical; }
input[type="file"], input[type=file]:where(:not([class])) {
  width: 100%; min-height: 44px; padding: 6px;
  font: inherit; font-size: 13.5px; color: var(--muted);
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r-control); box-shadow: var(--shadow-sm); cursor: pointer;
}
input[type=file]::file-selector-button {
  margin-right: 12px; padding: 8px 14px; border: 0; border-radius: var(--r-md);
  background: var(--sunken); color: var(--text); font: inherit; font-weight: 500; cursor: pointer;
}
input[type=file]::file-selector-button:hover { background: var(--line); }

/* label rhythm: the spacing backbone of plain label+control stacks */
label:not(.check):not(.switch):not(.nav-item):not(.dropdown-item):not(.sheet-tile):not(.mobile-nav-item):not(.user-chip) {
  margin: var(--s4) 0 6px;
}
form > label:first-child, .card > label:first-child, fieldset > label:first-of-type,
.field label, .form-grid label, .form-grid-3 label, .fieldrow label, td label,
.modal-body label:first-child, .sheet-body label:first-child,
.settings-nav label, .topbar label { margin-top: 0; }

/* button rows never hug the control above them */
.btnrow { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; margin-top: var(--s4); }
.form-actions { margin-top: var(--s5); }
form > .btn { margin-top: var(--s2); }
form > .btn + .btn { margin-left: var(--s2); }

/* inline action forms (table cells, action rows) stay inline */
.inline-form { display: inline; }
.form-inline { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.form-inline label { margin: 0; }
.form-inline input:where(:not([class])), .form-inline select:where(:not([class])) { width: auto; min-width: 0; }

/* search / filter toolbar rows: controls auto-width, one shared height, real gaps */
.searchbar { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; margin-bottom: var(--s4); }
.searchbar input:where(:not([class])), .searchbar select:where(:not([class])) { width: auto; flex: 0 1 300px; min-width: 170px; max-width: 340px; }
.searchbar .btn { flex: 0 0 auto; }

/* controls inside table cells stay compact and aligned */
td input:where(:not([class])), td select:where(:not([class])) { min-height: 36px; padding: 6px 10px; font-size: 13px; }
td label { margin: 0; }

/* otp boxes override the bare control look */
.otp-input input { width: 48px; min-width: 48px; max-width: 48px; padding: 0; }

/* ==========================================================================
   D-17 - page rhythm, heading scale, tabs, tooltips, table avatars, charts.
   Finishes the TailAdmin page-level polish: nothing here removes or
   restyles existing components, it only adds the missing layout rules.
   ========================================================================== */

/* page-level vertical rhythm: top-level blocks breathe without manual margins */
main.main-content > * + * { margin-top: var(--s4); }

/* headrow: page title + actions used across list and form pages */
div.headrow { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; margin-bottom: var(--s5); }
div.headrow h1 { margin: 0 0 2px; }
div.headrow p { max-width: 640px; margin: 0; }

/* TailAdmin heading scale: page 24, section 18, sub 16 (UA margins kept) */
h1 { font-size: 24px; letter-spacing: -0.01em; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; }

/* sibling inline action buttons/forms never touch */
.inline-form + .inline-form, .inline-form + .btn, .btn + .inline-form { margin-left: var(--s2); }
td .btn + .btn { margin-left: var(--s2); }

/* --------------------------------------------------------------------
   Tabs with underline (icon slot supported: drop an inline SVG icon in).
   -------------------------------------------------------------------- */
.tabs-line { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: thin; }
.tabs-line a {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 12px 9px; margin-bottom: -1px; white-space: nowrap;
  font-size: 14px; font-weight: 500; color: var(--muted); text-decoration: none;
  border-bottom: 2px solid transparent;
  border-top-left-radius: var(--r-md); border-top-right-radius: var(--r-md);
  transition: color var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast);
}
.tabs-line a:hover { color: var(--ink); background: var(--sunken); }
.tabs-line a.is-active, .tabs-line a[aria-current="page"] { color: var(--brand); border-bottom-color: var(--brand); }
.tabs-line a:focus-visible { outline: none; background: var(--sunken); }
.tabs-line a .icon { width: 16px; height: 16px; }

/* --------------------------------------------------------------------
   Vertical tabs
   -------------------------------------------------------------------- */
.tabs-vertical { display: grid; grid-template-columns: minmax(180px, 230px) minmax(0, 1fr); gap: var(--s4); align-items: start; }
.tabs-vertical-nav { display: flex; flex-direction: column; gap: 2px; }
.tabs-vertical-nav a {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-radius: var(--r-md); font-size: 14px; font-weight: 500;
  color: var(--muted); text-decoration: none; white-space: nowrap;
  transition: color var(--transition-fast), background var(--transition-fast);
}
.tabs-vertical-nav a:hover { background: var(--sunken); color: var(--ink); }
.tabs-vertical-nav a.is-active, .tabs-vertical-nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }
.tabs-vertical-nav a .icon { width: 16px; height: 16px; }
@media (max-width: 767.98px) {
  .tabs-vertical { grid-template-columns: 1fr; }
  .tabs-vertical-nav { flex-direction: row; overflow-x: auto; }
}

/* --------------------------------------------------------------------
   Pure CSS tooltips: put data-tip="Text" on any element.
   -------------------------------------------------------------------- */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translate(-50%, 4px);
  z-index: var(--z-toast); width: max-content; max-width: 240px; white-space: normal;
  background: var(--navy); color: #fff; font-size: 12px; font-weight: 500; line-height: 1.45; text-align: center;
  padding: 6px 10px; border-radius: var(--r-md); box-shadow: var(--shadow-md);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity var(--transition-fast), transform var(--transition-fast), visibility var(--transition-fast);
}
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; visibility: visible; transform: translate(-50%, 0); }

/* single verification-code input: mono, spaced, readable (paste-friendly) */
.otp-single { font-family: var(--font-mono); font-size: 18px; font-weight: 600; letter-spacing: 4px; }

/* table cell: avatar + name stack */
.cell-user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cell-user .t-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* chart shells (rendered by erp.js) */
.chart-box { min-height: 220px; }
.chart-box svg { display: block; width: 100%; height: auto; }
.chart-box text { font-family: var(--font-sans); }
.chart-donut-wrap { display: flex; flex-direction: column; align-items: center; gap: var(--s4); }
svg.chart-donut { max-width: 220px; }
.chart-legend { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.chart-legend-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.chart-legend-label { color: var(--muted); }
.chart-legend-row .num { margin-left: auto; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.chart-dot { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }

/* --------------------------------------------------------------------
   Phase 1 additions: finance section pill navigation.
   -------------------------------------------------------------------- */
.pillnav { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--s4); }
.pillnav-link {
  display: inline-flex; align-items: center; padding: 7px 14px;
  border-radius: var(--r-pill); font-size: 13px; font-weight: 500; text-decoration: none;
  color: var(--muted); background: var(--surface); border: 1px solid var(--line);
  transition: color var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast);
}
.pillnav-link:hover { color: var(--ink); border-color: var(--line-strong); }
.pillnav-link.is-active { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
@media print { .pillnav { display: none !important; } }

/* ==================================================================
   PWA install (Install on mobile button + how-to modal)
   ================================================================== */
.sidebar-install {
  display: flex; align-items: center; gap: 10px; width: 100%;
  margin: 0 0 10px; padding: 9px 12px; border-radius: 8px; border: 1px dashed rgba(37, 55, 177, .45);
  background: rgba(37, 55, 177, .06); color: var(--brand); font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; text-align: left; transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.sidebar-install:hover, .sidebar-install:focus-visible { background: rgba(37, 55, 177, .12); border-color: var(--brand); outline: none; }
.sidebar-install svg { flex: 0 0 auto; opacity: .9; }
.sidebar-install .sidebar-install-sub { display: block; font-size: 11px; font-weight: 400; color: var(--muted); }
.sidebar-install:hover .sidebar-install-sub { color: var(--brand); }

.pwa-install-backdrop {
  position: fixed; inset: 0; z-index: 1200; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(2, 9, 58, .55); padding: 16px; animation: pwa-fade .18s ease;
}
@media (min-width: 641px) { .pwa-install-backdrop { align-items: center; } }
.pwa-install-modal {
  width: 100%; max-width: 430px; background: var(--surface-white, #fff); border-radius: 14px;
  box-shadow: 0 18px 50px rgba(2, 9, 58, .35); padding: 20px 22px; animation: pwa-rise .2s ease;
}
.pwa-install-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.pwa-install-head strong { font-size: 17px; color: var(--ink, #171716); }
.pwa-install-close {
  border: 0; background: transparent; font-size: 24px; line-height: 1; padding: 4px 8px; cursor: pointer;
  color: var(--muted, #615d59); border-radius: 6px;
}
.pwa-install-close:hover { background: var(--surface-base, #f6f5f4); color: var(--ink, #171716); }
.pwa-install-steps { margin: 6px 0 0 20px; padding: 0; color: var(--text-medium, #403d3a); font-size: 14px; }
.pwa-install-steps li { margin: 8px 0; }
.pwa-install-note { margin: 14px 0 0; font-size: 12.5px; color: var(--muted, #615d59); border-top: 1px solid var(--line, #e8e6e3); padding-top: 12px; }
@keyframes pwa-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pwa-rise { from { transform: translateY(14px); opacity: .6; } to { transform: none; opacity: 1; } }
@media print { .sidebar-install, .pwa-install-backdrop { display: none !important; } }

/* --- Phase 3 additions ---------------------------------------------------- */
.table-kv td { border: 0; padding: var(--s2) var(--s3); vertical-align: top; }
.table-kv td:first-child { width: 40%; }
.t-code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.inline-edit { position: relative; display: inline-block; }
.inline-edit > summary { list-style: none; cursor: pointer; }
.inline-edit > summary::-webkit-details-marker { display: none; }
.inline-edit[open] > summary { outline: 2px solid var(--brand-blue); }
.inline-edit form.card { box-shadow: var(--shadow-lg, 0 12px 30px rgba(2,9,58,.18)); max-height: 70vh; overflow: auto; }
.variant-slot { margin-top: 6px; }
.variant-select { font-size: 12.5px; padding: 4px 8px; max-width: 100%; }

/* --- Branding accent presets (Phase 3) ------------------------------------ */
html[data-accent="royal"] { --accent: #2537b1; --accent-blue: #2537b1; --accent-surface: #eceffc; }
html[data-accent="ember"] { --accent: #f64932; --accent-blue: #f64932; --accent-surface: #fdeeea; }
.sidebar-logo-img { background: #fff; display: flex; align-items: center; justify-content: center; padding: 4px; }
