/* ==========================================================================
   BSS Accounting — design system
   Tokens → base → layout → components → pages. No framework.
   ========================================================================== */

:root {
  /* Neutrals */
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-muted: #f9fafb;
  --surface-sunken: #f2f4f7;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #101828;
  --text-secondary: #344054;
  --text-muted: #667085;
  --text-faint: #98a2b3;

  /* Brand */
  --primary: #1f4fd1;
  --primary-hover: #1941b0;
  --primary-soft: #eef3ff;
  --primary-ring: rgba(31, 79, 209, 0.18);
  --ink: #0f1b33;

  /* Status */
  --success: #067647;  --success-soft: #ecfdf3;  --success-border: #abefc6;
  --warning: #b54708;  --warning-soft: #fffaeb;  --warning-border: #fedf89;
  --danger:  #b42318;  --danger-soft:  #fef3f2;  --danger-border:  #fecdca;
  --info:    #175cd3;  --info-soft:    #eff8ff;  --info-border:    #b2ddff;

  /* Typography */
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-md: 0.875rem;
  --fs-base: 0.9375rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.375rem;
  --fs-2xl: 1.75rem;

  /* Spacing (4px grid) */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px;
  --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px; --s-16: 64px;

  /* Shape */
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 8px 24px -6px rgba(16, 24, 40, 0.12), 0 2px 6px rgba(16, 24, 40, 0.05);

  --sidebar-w: 248px;
  --topbar-h: 60px;
  --content-max: 1180px;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}
h1, h2, h3, h4 { margin: 0; color: var(--text); letter-spacing: -0.012em; line-height: 1.25; }
h1 { font-size: var(--fs-2xl); font-weight: 650; }
h2 { font-size: var(--fs-lg); font-weight: 600; }
h3 { font-size: var(--fs-base); font-weight: 600; }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }
.icon { flex-shrink: 0; display: inline-block; vertical-align: middle; }
.muted { color: var(--text-muted); }
.small { font-size: var(--fs-sm); }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.stack > * + * { margin-top: var(--s-4); }
.stack-lg > * + * { margin-top: var(--s-6); }
.row { display: flex; align-items: center; gap: var(--s-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); }
.spacer { flex: 1; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: 38px; padding: 0 var(--s-4);
  font: inherit; font-size: var(--fs-md); font-weight: 550; line-height: 1;
  border-radius: var(--radius); border: 1px solid transparent;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background-color .12s ease, border-color .12s ease, box-shadow .12s ease, color .12s ease;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-xs); }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text-secondary); border-color: var(--border-strong); box-shadow: var(--shadow-xs); }
.btn-secondary:hover { background: var(--surface-muted); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-sunken); color: var(--text); }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); color: var(--danger); }
.btn-sm { height: 32px; padding: 0 var(--s-3); font-size: var(--fs-sm); }
.btn-lg { height: 44px; padding: 0 var(--s-5); font-size: var(--fs-base); }
.btn-block { width: 100%; }
.btn[disabled], .btn.is-disabled { opacity: .5; cursor: not-allowed; pointer-events: none; box-shadow: none; }
.btn-link { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }
.btn-link:hover { text-decoration: underline; }

/* ---------- Forms ---------- */
.form { display: grid; gap: var(--s-5); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-5) var(--s-4); }
.form-grid .span-2 { grid-column: 1 / -1; }
.field { display: grid; gap: 6px; min-width: 0; }
.field-label { font-size: var(--fs-md); font-weight: 550; color: var(--text-secondary); }
.field-label .optional { font-weight: 400; color: var(--text-faint); margin-left: 4px; }
.field-help { font-size: var(--fs-sm); color: var(--text-muted); }
.field-help ul { margin: 0; padding-left: 1.1em; }
.field-errors { list-style: none; margin: 0; padding: 0; font-size: var(--fs-sm); color: var(--danger); }
.form-errors { list-style: none; margin: 0; }

.field input:not([type=checkbox]):not([type=radio]),
.field select,
.field textarea,
.input {
  width: 100%; height: 40px; padding: 0 var(--s-3);
  font: inherit; font-size: var(--fs-base); color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.field textarea { height: auto; min-height: 96px; padding: var(--s-2) var(--s-3); resize: vertical; }
.field select {
  appearance: none; padding-right: 36px;
  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 10px center;
}
.field input:focus, .field select:focus, .field textarea:focus, .input:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-ring);
}
.field input::placeholder { color: var(--text-faint); }
.field input:disabled, .field select:disabled, .field textarea:disabled {
  background: var(--surface-muted); color: var(--text-muted); box-shadow: none; cursor: not-allowed;
}
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: #fda29b; }
.field.has-error input:focus { box-shadow: 0 0 0 4px rgba(240, 68, 56, 0.15); }

/* Radio cards (ERP selection) */
.radio-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: var(--s-3); }
.radio-card {
  position: relative; display: flex; gap: var(--s-3); align-items: flex-start;
  padding: var(--s-4); border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; transition: border-color .12s, box-shadow .12s, background .12s;
}
.radio-card:hover { border-color: var(--text-faint); }
.radio-card input { margin: 3px 0 0; accent-color: var(--primary); }
.radio-card-title { font-weight: 600; font-size: var(--fs-md); }
.radio-card-meta { font-size: var(--fs-sm); color: var(--text-muted); }
.radio-card:has(input:checked) { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); background: var(--primary-soft); }
.radio-card:has(input:disabled) { cursor: not-allowed; opacity: .75; }

/* ---------- Alerts ---------- */
.alert {
  display: flex; gap: var(--s-3); align-items: flex-start;
  padding: var(--s-3) var(--s-4); border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface-muted);
  font-size: var(--fs-md); color: var(--text-secondary);
}
.alert .icon { margin-top: 2px; }
.alert-success { background: var(--success-soft); border-color: var(--success-border); color: var(--success); }
.alert-warning { background: var(--warning-soft); border-color: var(--warning-border); color: var(--warning); }
.alert-error, .alert-danger { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger); }
.alert-info { background: var(--info-soft); border-color: var(--info-border); color: var(--info); }
.messages { display: grid; gap: var(--s-2); margin-bottom: var(--s-5); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 var(--s-2);
  font-size: var(--fs-xs); font-weight: 550; line-height: 1;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface-muted); color: var(--text-secondary);
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.plain::before { display: none; }
.badge-success { background: var(--success-soft); border-color: var(--success-border); color: var(--success); }
.badge-warning { background: var(--warning-soft); border-color: var(--warning-border); color: var(--warning); }
.badge-danger { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger); }
.badge-info { background: var(--info-soft); border-color: var(--info-border); color: var(--info); }
.badge-neutral { color: var(--text-muted); }
.badge-role { background: var(--surface); color: var(--text-secondary); }
.badge-role::before { display: none; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); padding: var(--s-5) var(--s-6); border-bottom: 1px solid var(--border); }
.card-header p { color: var(--text-muted); font-size: var(--fs-md); margin-top: 2px; }
.card-body { padding: var(--s-6); }
.card-footer { display: flex; justify-content: flex-end; align-items: center; gap: var(--s-3); padding: var(--s-4) var(--s-6); border-top: 1px solid var(--border); background: var(--surface-muted); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.card-flush .card-body { padding: 0; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-md); }
.table th {
  text-align: left; font-size: var(--fs-xs); font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-muted); background: var(--surface-muted);
  padding: var(--s-3) var(--s-6); border-bottom: 1px solid var(--border);
}
.table td { padding: var(--s-3) var(--s-6); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .actions { text-align: right; }
.person { display: flex; align-items: center; gap: var(--s-3); }
.person-name { font-weight: 550; }
.person-meta { font-size: var(--fs-sm); color: var(--text-muted); }

/* ---------- Avatar ---------- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  font-size: var(--fs-xs); font-weight: 650; letter-spacing: .02em; flex-shrink: 0;
}
.avatar-square { border-radius: var(--radius); background: var(--ink); color: #fff; }

/* ---------- Key/value list ---------- */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0; }
.kv-item { padding: var(--s-5) var(--s-6); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.kv-label { font-size: var(--fs-sm); color: var(--text-muted); margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.kv-value { font-size: var(--fs-base); font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.kv-value.empty { color: var(--text-faint); font-weight: 450; }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: var(--s-16) var(--s-6); }
.empty-state-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; border-radius: var(--radius-lg);
  border: 1px solid var(--border); background: var(--surface-muted); color: var(--text-muted);
  margin-bottom: var(--s-4); box-shadow: var(--shadow-xs);
}
.empty-state h3 { font-size: var(--fs-lg); }
.empty-state p { color: var(--text-muted); max-width: 440px; margin: var(--s-2) auto 0; }
.empty-state .actions { margin-top: var(--s-6); display: flex; justify-content: center; gap: var(--s-3); flex-wrap: wrap; }

.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-3); }
.checklist li { display: flex; gap: var(--s-3); align-items: flex-start; color: var(--text-secondary); font-size: var(--fs-md); }
.checklist .icon { color: var(--primary); margin-top: 2px; }

/* ==========================================================================
   App shell
   ========================================================================== */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
}
.sidebar-brand { display: flex; align-items: center; gap: var(--s-3); height: var(--topbar-h); padding: 0 var(--s-5); border-bottom: 1px solid var(--border); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; color: var(--text); }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--ink); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; letter-spacing: .02em; }
.brand-name small { display: block; font-size: var(--fs-xs); color: var(--text-muted); font-weight: 450; letter-spacing: 0; }

.company-switcher { padding: var(--s-3) var(--s-3) 0; }
.company-switcher details { position: relative; }
.company-switcher summary {
  list-style: none; display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-2); border-radius: var(--radius); border: 1px solid var(--border); cursor: pointer; background: var(--surface-muted);
}
.company-switcher summary::-webkit-details-marker { display: none; }
.company-switcher summary:hover { border-color: var(--border-strong); }
.company-switcher .company-name { font-weight: 600; font-size: var(--fs-md); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.company-switcher .company-meta { font-size: var(--fs-xs); color: var(--text-muted); }
.company-switcher .text { min-width: 0; flex: 1; }

.nav { flex: 1; overflow-y: auto; padding: var(--s-4) var(--s-3); }
.nav-section-label { font-size: var(--fs-xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); padding: var(--s-4) var(--s-3) var(--s-2); }
.nav a {
  display: flex; align-items: center; gap: var(--s-3);
  height: 36px; padding: 0 var(--s-3); margin-bottom: 2px;
  color: var(--text-secondary); font-size: var(--fs-md); font-weight: 500;
  border-radius: var(--radius);
}
.nav a:hover { background: var(--surface-sunken); color: var(--text); text-decoration: none; }
.nav a .icon { color: var(--text-muted); }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav a.active .icon { color: var(--primary); }

.sidebar-footer { border-top: 1px solid var(--border); padding: var(--s-3); }
.user-chip { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2); }
.user-chip .text { min-width: 0; flex: 1; }
.user-chip .name { font-size: var(--fs-md); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .email { font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: var(--s-4);
  height: var(--topbar-h); padding: 0 var(--s-8);
  background: rgba(255, 255, 255, 0.92); backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: var(--fs-md); color: var(--text-muted); }
.topbar-title strong { color: var(--text); font-weight: 600; }
.menu-toggle { display: none; }
.content { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: var(--s-8); }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-6); flex-wrap: wrap; }
.page-header p { color: var(--text-muted); margin-top: var(--s-1); }
.eyebrow { font-size: var(--fs-xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); margin-bottom: var(--s-1); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-6); }
.grid-main-aside { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--s-6); align-items: start; }

.sidebar-backdrop { display: none; }

/* Settings layout */
.settings-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: var(--s-8); align-items: start; }
.subnav { display: grid; gap: 2px; position: sticky; top: calc(var(--topbar-h) + var(--s-6)); }
.subnav a { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-3); border-radius: var(--radius); color: var(--text-secondary); font-size: var(--fs-md); font-weight: 500; }
.subnav a:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.subnav a.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-xs); border: 1px solid var(--border); }
.subnav-label { font-size: var(--fs-xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); padding: var(--s-4) var(--s-3) var(--s-1); }
.subnav-label:first-child { padding-top: 0; }

/* ==========================================================================
   Auth & onboarding shells
   ========================================================================== */
.auth-shell { min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: var(--s-12) var(--s-4); }
.auth-shell .brand { margin-bottom: var(--s-8); }
.auth-card { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: var(--s-8); }
.auth-card.wide { max-width: 560px; }
.auth-card h1 { font-size: var(--fs-xl); }
.auth-card .lead { color: var(--text-muted); margin-top: var(--s-2); margin-bottom: var(--s-6); font-size: var(--fs-md); }
.auth-footer { margin-top: var(--s-6); font-size: var(--fs-md); color: var(--text-muted); text-align: center; }
.auth-legal { margin-top: auto; padding-top: var(--s-8); font-size: var(--fs-xs); color: var(--text-faint); }
.auth-steps { display: flex; align-items: center; gap: var(--s-2); font-size: var(--fs-xs); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted); margin-bottom: var(--s-4); }
.auth-steps .bar { display: flex; gap: 4px; }
.auth-steps .bar span { width: 24px; height: 4px; border-radius: 2px; background: var(--border); }
.auth-steps .bar span.on { background: var(--primary); }
.divider { display: flex; align-items: center; gap: var(--s-3); color: var(--text-faint); font-size: var(--fs-sm); margin: var(--s-2) 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.label-row { display: flex; justify-content: space-between; align-items: baseline; }

.onboarding-shell { min-height: 100vh; display: grid; grid-template-columns: 300px minmax(0, 1fr); }
.onboarding-aside { background: var(--ink); color: #c8d0e0; padding: var(--s-8); display: flex; flex-direction: column; gap: var(--s-10); }
.onboarding-aside .brand { color: #fff; }
.onboarding-aside .brand-mark { background: #fff; color: var(--ink); }
.onboarding-aside .brand-name small { color: #8d99b3; }
.stepper { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-1); }
.stepper li a, .stepper li span.step-link { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3); border-radius: var(--radius); color: #8d99b3; font-size: var(--fs-md); font-weight: 500; }
.stepper li a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.stepper .num { width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid #3a4865; display: inline-flex; align-items: center; justify-content: center; font-size: var(--fs-xs); font-weight: 650; flex-shrink: 0; }
.stepper .current a, .stepper .current span.step-link { color: #fff; background: rgba(255,255,255,.08); }
.stepper .current .num { border-color: #fff; background: #fff; color: var(--ink); }
.stepper .done .num { border-color: #6f8cf0; background: #6f8cf0; color: #fff; }
.stepper .done a { color: #d7deef; }
.onboarding-aside .aside-note { margin-top: auto; font-size: var(--fs-sm); color: #8d99b3; }
.onboarding-main { display: flex; flex-direction: column; align-items: center; padding: var(--s-12) var(--s-8); }
.onboarding-panel { width: 100%; max-width: 680px; }
.onboarding-panel .step-count { font-size: var(--fs-xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--primary); margin-bottom: var(--s-2); }
.onboarding-panel h1 { margin-bottom: var(--s-2); }
.onboarding-panel .lead { color: var(--text-muted); margin-bottom: var(--s-8); }
.onboarding-actions { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-top: var(--s-8); padding-top: var(--s-6); border-top: 1px solid var(--border); }
.ready-mark { width: 56px; height: 56px; border-radius: 50%; background: var(--success-soft); color: var(--success); display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--success-border); margin-bottom: var(--s-5); }
.summary-list { display: grid; gap: 0; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.summary-list > div { display: flex; justify-content: space-between; gap: var(--s-4); padding: var(--s-3) var(--s-5); border-bottom: 1px solid var(--border); font-size: var(--fs-md); }
.summary-list > div:last-child { border-bottom: 0; }
.summary-list dt { color: var(--text-muted); }
.summary-list dd { margin: 0; font-weight: 600; text-align: right; }
.next-card { display: flex; gap: var(--s-4); align-items: flex-start; padding: var(--s-5); border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); background: var(--surface); }
.next-card .icon-box { width: 36px; height: 36px; border-radius: var(--radius); background: var(--primary-soft); color: var(--primary); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* Company switcher / dropdown */
.company-card { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2); border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-muted); }
.company-switcher .text > span, .company-card .text > span, .user-chip .text > span { display: block; }
.dropdown-panel { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md); padding: var(--s-1); }
.dropdown-item { display: flex; align-items: center; gap: var(--s-3); width: 100%; padding: var(--s-2); border: 0; background: none; border-radius: var(--radius-sm); font: inherit; font-size: var(--fs-md); color: var(--text-secondary); cursor: pointer; text-align: left; }
.dropdown-item:hover { background: var(--surface-sunken); color: var(--text); }
.dropdown-item.active { color: var(--primary); font-weight: 600; }

/* Team invitations */
.invite-body { border-bottom: 1px solid var(--border); display: grid; gap: var(--s-4); }
.invite-grid { display: grid; grid-template-columns: minmax(0, 1fr) 200px auto; gap: var(--s-4); align-items: start; }
.invite-grid > .btn { margin-top: 27px; height: 40px; }
@media (max-width: 700px) {
  .invite-grid { grid-template-columns: 1fr; }
  .invite-grid > .btn { margin-top: 0; }
}

.fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.fieldset legend { padding: 0; margin-bottom: 6px; }
[hidden] { display: none !important; }
.checklist .icon-muted { color: var(--text-faint); }

/* ==========================================================================
   Invoices & calculations
   ========================================================================== */
.num { text-align: right; font-variant-numeric: tabular-nums; }
.table th.num { text-align: right; }
.badge-row { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-3); }
.badge .icon { margin-left: -2px; }

/* Dropzone */
.dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius-lg); background: var(--surface-muted);
  padding: var(--s-10) var(--s-6); text-align: center; transition: border-color .12s, background .12s;
}
.dropzone.is-dragging { border-color: var(--primary); background: var(--primary-soft); }
.dropzone-icon { display: inline-flex; width: 44px; height: 44px; align-items: center; justify-content: center; border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--border); color: var(--primary); margin-bottom: var(--s-3); }
.dropzone-title { font-weight: 600; font-size: var(--fs-lg); }
.dropzone-hint { color: var(--text-muted); font-size: var(--fs-sm); margin-top: var(--s-1); }
.dropzone-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); justify-content: center; margin-top: var(--s-5); }
.dropzone-actions label { cursor: pointer; }
.add-pages .dropzone { padding: var(--s-6); }
.mobile-only { display: none !important; }
@media (hover: none) and (pointer: coarse), (max-width: 700px) {
  .mobile-only { display: inline-flex !important; }
  .desktop-only { display: none !important; }
}
.upload-progress { display: none; align-items: center; gap: var(--s-2); margin-top: var(--s-4); color: var(--text-muted); font-size: var(--fs-md); }
.htmx-request .upload-progress, .upload-progress.htmx-request { display: flex; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--primary); display: inline-block; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Page list */
.page-list { list-style: none; margin: 0; padding: 0; }
.page-row { display: flex; align-items: center; gap: var(--s-4); padding: var(--s-3) var(--s-6); border-bottom: 1px solid var(--border); }
.page-thumb { width: 56px; height: 72px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-muted); overflow: hidden; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.page-thumb img { width: 100%; height: 100%; object-fit: cover; }
.pdf-badge { font-size: var(--fs-xs); font-weight: 700; color: var(--danger); letter-spacing: .04em; }
.page-info { flex: 1; min-width: 0; }
.page-label { font-weight: 600; }
.page-meta { font-size: var(--fs-sm); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-actions { display: flex; gap: 2px; }
.action-bar { display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); }

/* Progress */
.progress-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-3); }
.progress-steps li { display: flex; align-items: center; gap: var(--s-3); color: var(--text-faint); font-size: var(--fs-md); }
.progress-steps .dot { width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--border-strong); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.progress-steps .done { color: var(--text-secondary); }
.progress-steps .done .dot { background: var(--success); border-color: var(--success); color: #fff; }
.progress-steps .current { color: var(--text); font-weight: 600; }
.progress-steps .current .dot { border-color: var(--primary); }

/* Review screen */
.review-top { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: var(--s-6); align-items: start; }
.thumb-strip { display: flex; gap: var(--s-2); padding: var(--s-3) var(--s-5); border-bottom: 1px solid var(--border); overflow-x: auto; }
.thumb { position: relative; width: 48px; height: 62px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-muted); padding: 0; cursor: pointer; overflow: hidden; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb > span:last-child { position: absolute; right: 2px; bottom: 2px; font-size: 10px; font-weight: 700; background: rgba(255,255,255,.9); border-radius: 3px; padding: 0 3px; }
.thumb.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-ring); }
.viewer { background: var(--surface-sunken); height: 620px; display: flex; align-items: center; justify-content: center; overflow: auto; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.details-panel { max-height: 740px; overflow-y: auto; }
.detail-section { border-bottom: 1px solid var(--border); }
.detail-section > summary { cursor: pointer; padding: var(--s-3) var(--s-6); font-size: var(--fs-xs); font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); list-style: none; }
.detail-section > summary::-webkit-details-marker { display: none; }
.detail-section > summary::before { content: "▸"; display: inline-block; width: 14px; transition: transform .12s; }
.detail-section[open] > summary::before { transform: rotate(90deg); }
.dl { margin: 0; padding: 0 var(--s-6) var(--s-4); display: grid; gap: 0; }
.dl > div { display: flex; justify-content: space-between; gap: var(--s-4); padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: var(--fs-md); }
.dl > div:last-child { border-bottom: 0; }
.dl dt { color: var(--text-muted); }
.dl dd { margin: 0; font-weight: 550; text-align: right; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.table-compact th, .table-compact td { padding: var(--s-2) var(--s-6); }

.totals-grid { display: grid; grid-template-columns: 1fr 1fr 220px; gap: 0; }
.totals-grid > div { padding: var(--s-5) 0; border-right: 1px solid var(--border); }
.totals-grid > div:last-child { border-right: 0; }
.totals-grid .dl { padding-bottom: 0; }
.totals-title { font-size: var(--fs-xs); font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); padding: 0 var(--s-6) var(--s-2); }
.difference-box { text-align: center; }
.difference-value { font-size: var(--fs-2xl); font-weight: 650; font-variant-numeric: tabular-nums; margin: var(--s-2) 0; }
.issues { border-top: 1px solid var(--border); }
.issues .totals-title { padding-left: 0; }
.issue-list { margin: 0; padding-left: 1.1em; display: grid; gap: 4px; font-size: var(--fs-md); }
.issue-list .sev-critical { color: var(--danger); }
.issue-list .sev-major { color: var(--warning); }

.calc-toolbar { display: flex; flex-wrap: wrap; gap: var(--s-4); padding: var(--s-4) var(--s-6); border-bottom: 1px solid var(--border); background: var(--surface-muted); align-items: flex-end; }
.calc-toolbar .field { min-width: 160px; }
.calc-toolbar input, .calc-toolbar select { height: 34px !important; }
.calc-toolbar .notes-field { flex: 1; min-width: 240px; }
.calc-toolbar textarea { min-height: 34px !important; height: 34px; }
.calc-table { font-size: var(--fs-sm); }
.calc-table th { padding: var(--s-2) var(--s-2); white-space: nowrap; position: sticky; top: 0; z-index: 1; }
.calc-table td { padding: 6px var(--s-2); }
.calc-table th:first-child, .calc-table td:first-child { padding-left: var(--s-4); }
.calc-table input {
  width: 100%; height: 30px; padding: 0 6px; font: inherit; font-size: var(--fs-sm); color: var(--text);
  border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; font-variant-numeric: tabular-nums;
}
.calc-table input:hover { border-color: var(--border); background: var(--surface); }
.calc-table input:focus { outline: none; border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 3px var(--primary-ring); }
.calc-table input:disabled { color: var(--text); cursor: default; }
.calc-table .w-num input { width: 92px; text-align: right; }
.calc-table .w-vat input { width: 64px; text-align: right; }
.calc-table .w-disc input { width: 72px; }
.calc-table .w-unit input { width: 56px; }
.calc-table td:nth-child(2) input { width: 128px; }
.calc-table .col-desc { min-width: 240px; }
.calc-table .out { color: var(--text-secondary); white-space: nowrap; }
.calc-table .pos { color: var(--text-muted); }
.calc-table tr.needs-review td { background: #fffcf5; }
.calc-table tr.below-cost [data-out="effective"] { color: var(--danger); font-weight: 600; }
.cell-meta { font-size: 11px; color: var(--text-faint); padding-left: 7px; }
.final-cell { position: relative; white-space: nowrap; }
.final-cell input { font-weight: 600; }
.reset-final { border: 0; background: none; color: var(--primary); cursor: pointer; font-size: 14px; padding: 0 2px; }
.row-notes td { background: var(--surface-muted); padding-top: 4px !important; padding-bottom: 6px !important; }
.row-notes span { display: inline-block; font-size: 12px; margin-right: var(--s-4); }
.note-error { color: var(--danger); }
.note-warn { color: var(--warning); }
.sticky-actions {
  position: sticky; bottom: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3);
  margin-top: var(--s-4); padding: var(--s-4) var(--s-5); background: rgba(255,255,255,.96); backdrop-filter: blur(6px);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
}
.approve-confirm { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; }
.approve-confirm .input { width: 320px; height: 38px; }
.check { display: inline-flex; align-items: center; gap: var(--s-2); font-size: var(--fs-md); color: var(--text-secondary); }

details.menu { position: relative; }
details.menu > summary { list-style: none; }
details.menu > summary::-webkit-details-marker { display: none; }
.menu-panel { position: absolute; right: 0; top: calc(100% + 6px); width: 300px; z-index: 20; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md); padding: var(--s-3); display: grid; gap: var(--s-1); }
.menu-panel p { padding: 0 var(--s-2) var(--s-2); }
tr.clickable:hover td { background: var(--surface-muted); }

@media (max-width: 1080px) {
  .review-top { grid-template-columns: 1fr; }
  .viewer { height: 480px; }
  .totals-grid { grid-template-columns: 1fr; }
  .totals-grid > div { border-right: 0; border-bottom: 1px solid var(--border); }
}

/* ==========================================================================
   Collapsible sidebar & focus mode
   ========================================================================== */
:root { --sidebar-w-collapsed: 64px; }
.sidebar-brand { justify-content: space-between; }
.sidebar-toggle {
  display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; flex-shrink: 0;
  border: 1px solid transparent; border-radius: var(--radius-sm); background: none; color: var(--text-muted); cursor: pointer;
}
.sidebar-toggle:hover { background: var(--surface-sunken); color: var(--text); }
.app { transition: grid-template-columns .16s ease; }
.app.sidebar-collapsed, .app.focus-mode { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }
.app.sidebar-collapsed .sidebar-brand, .app.focus-mode .sidebar-brand { padding: 0; justify-content: center; }
.app.sidebar-collapsed .brand, .app.focus-mode .brand,
.app.sidebar-collapsed .company-switcher .text, .app.focus-mode .company-switcher .text,
.app.sidebar-collapsed .company-switcher summary > .icon, .app.focus-mode .company-switcher summary > .icon,
.app.sidebar-collapsed .nav-label, .app.focus-mode .nav-label,
.app.sidebar-collapsed .nav-section-label, .app.focus-mode .nav-section-label,
.app.sidebar-collapsed .user-chip .text, .app.focus-mode .user-chip .text { display: none; }
.app.sidebar-collapsed .company-switcher, .app.focus-mode .company-switcher { padding: var(--s-3) var(--s-2) 0; }
.app.sidebar-collapsed .company-card, .app.focus-mode .company-card,
.app.sidebar-collapsed .company-switcher summary, .app.focus-mode .company-switcher summary { justify-content: center; padding: 6px; }
.app.sidebar-collapsed .nav, .app.focus-mode .nav { padding: var(--s-3) var(--s-2); }
.app.sidebar-collapsed .nav a, .app.focus-mode .nav a { justify-content: center; padding: 0; }
.app.sidebar-collapsed .user-chip, .app.focus-mode .user-chip { flex-direction: column; padding: var(--s-1) 0; }
/* Calculation review is a workspace: it always uses the full browser width (no max-width);
   collapsing the sidebar or focus mode adds the sidebar's width on top. */
.app[data-focus-scope] .content { max-width: none; width: 100%; padding: var(--s-5) var(--s-5); }
.app.focus-mode .content,
.app.sidebar-collapsed[data-focus-scope] .content { max-width: none; width: 100%; padding: var(--s-4) var(--s-4); }
.app.focus-mode .review-context { display: none; }
.app.focus-mode .review-header { margin-bottom: var(--s-3); }
.app.focus-mode .review-header p, .app.focus-mode .review-header .eyebrow { display: none; }
.app.focus-mode .review-header h1 { font-size: var(--fs-xl); }
.focus-toggle[aria-pressed="true"] { background: var(--primary-soft); color: var(--primary); border-color: var(--primary-ring); }
@media (max-width: 900px) {
  .sidebar-toggle { display: none; }
  .app.sidebar-collapsed, .app.focus-mode { grid-template-columns: 1fr; }
}

/* ==========================================================================
   Invoice interpretation panel
   ========================================================================== */
.interpretation-panel { margin-top: var(--s-6); padding: var(--s-4) var(--s-5); }
.interp-head { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; margin-bottom: var(--s-3); }
.interp-head h2 { font-size: var(--fs-base); }
.interp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--s-2) var(--s-5); margin: 0; }
.interp-item dt { font-size: var(--fs-xs); font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); }
.interp-item dd { margin: 2px 0 0; font-size: var(--fs-md); font-weight: 550; }
.interp-item.is-unknown dd { color: var(--warning); display: flex; align-items: center; gap: 4px; }
.interp-edit { display: none; margin-top: var(--s-4); padding-top: var(--s-4); border-top: 1px dashed var(--border); gap: var(--s-4); flex-wrap: wrap; }
.interpretation-panel.is-editing .interp-edit { display: flex; }
.interp-edit fieldset { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.interp-edit legend { font-size: var(--fs-xs); font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 4px; width: 100%; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--border-strong); border-radius: 999px; font-size: var(--fs-sm); cursor: pointer; background: var(--surface); }
.pill:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.pill input { accent-color: var(--primary); margin: 0; }
.interp-note { width: 100%; }
.interp-columns { margin-top: var(--s-3); font-size: var(--fs-sm); }
.interp-columns summary { cursor: pointer; color: var(--text-muted); }

/* ==========================================================================
   Calculation table: sticky header + sticky "#" and Article columns
   The table scrolls inside its own container, so header and left columns stay
   visible while scrolling in both directions (hundreds of lines).
   ========================================================================== */
.calc-card { margin-top: var(--s-4); }
.calc-scroll {
  position: relative; overflow: auto; max-height: calc(100vh - var(--topbar-h) - 150px);
  border-top: 1px solid var(--border); overscroll-behavior: contain;
}
.app.focus-mode .calc-scroll { max-height: calc(100vh - var(--topbar-h) - 120px); }
.sticky-table { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); }
.sticky-table th, .sticky-table td { background: var(--surface); border-bottom: 1px solid var(--border); padding: 4px 6px; vertical-align: middle; }
.sticky-table thead th {
  position: sticky; top: 0; z-index: 3; background: var(--surface-muted);
  font-size: 11px; font-weight: 650; letter-spacing: .03em; text-transform: uppercase; color: var(--text-muted);
  white-space: nowrap; text-align: left; height: 30px;
}
.sticky-table thead tr:nth-child(2) th { top: 30px; }
.sticky-table thead .group-row th { text-align: center; color: var(--text-secondary); border-bottom: 1px solid var(--border); }
.sticky-table thead .group-source { background: #f3f6fb; }
.sticky-table thead .group-retail { background: #f4f8f5; }
.sticky-table .group-retail-start { border-left: 2px solid var(--border-strong); }
.sticky-table .has-tip { cursor: help; text-decoration: underline dotted var(--text-faint); text-underline-offset: 3px; }
/* Sticky left columns */
.sticky-table .sticky-col { position: sticky; z-index: 2; }
.sticky-table .col-num { left: 0; width: 52px; min-width: 52px; max-width: 52px; text-align: right; padding-right: 10px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.sticky-table .col-article { left: 52px; width: 230px; min-width: 230px; max-width: 230px; box-shadow: inset -1px 0 0 var(--border), 6px 0 8px -6px rgba(16, 24, 40, .18); }
/* Intersection: sticky top AND sticky left — must sit above everything */
.sticky-table thead th.sticky-col { z-index: 5; background: var(--surface-muted); }
.sticky-table tbody td.col-num { font-weight: 600; }
/* Column widths: compact numeric inputs */
.sticky-table input { width: 100%; height: 28px; padding: 0 5px; font: inherit; font-size: var(--fs-sm); color: var(--text);
  border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; font-variant-numeric: tabular-nums; }
.sticky-table input:hover { border-color: var(--border); background: var(--surface); }
.sticky-table input:focus { outline: none; border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 2px var(--primary-ring); }
.sticky-table input:disabled { color: var(--text); cursor: default; }
.calc-scroll { width: 100%; }
/* Widths are sized so typical values are fully visible (values show no trailing zeros):
   Qty "1234.5", U/Pack "1000", VAT/Margin "25.5", money "12345.67", discount "10+5+3". */
.sticky-table .col-qty { width: 68px; min-width: 68px; }
.sticky-table .col-unit { width: 44px; min-width: 44px; max-width: 44px; }
.sticky-table .col-upack { width: 52px; min-width: 52px; max-width: 52px; }
.sticky-table .col-money { width: 86px; min-width: 86px; }
.sticky-table .col-pct { width: 54px; min-width: 54px; }
.sticky-table .col-disc { width: 64px; min-width: 64px; }
.sticky-table .col-status { width: 88px; min-width: 88px; white-space: nowrap; }
.sticky-table .col-qty input, .sticky-table .col-upack input, .sticky-table .col-money input, .sticky-table .col-pct input { text-align: right; }
.sticky-table .col-unit input { padding: 0 3px; }
.sticky-table .article-meta input[name$="-barcode"] { width: 100%; height: 20px; font-size: 11px; color: var(--text-faint); padding: 0 5px; }
.sticky-table .retail-qty { text-align: right; padding-right: 6px; color: var(--primary); }
.sticky-table td.out { text-align: right; color: var(--text-secondary); white-space: nowrap; font-variant-numeric: tabular-nums; }
.sticky-table .col-article input[name$="-description"] { font-weight: 550; text-overflow: ellipsis; }
.sticky-table .col-article .cell-meta { display: flex; align-items: center; gap: 6px; padding-left: 0; }
.sticky-table .col-article .cell-meta input { height: 20px; width: 100%; font-size: 11px; color: var(--text-muted); }
.sticky-table .cell-meta { font-size: 11px; color: var(--text-faint); }
.sticky-table .col-pct .cell-meta { text-align: right; padding-right: 6px; }
.sticky-table .with-reset { position: relative; }
.sticky-table .with-reset input { padding-right: 16px; }
.sticky-table .reset { position: absolute; right: 7px; top: 8px; border: 0; background: none; color: var(--primary); cursor: pointer; font-size: 13px; padding: 0; line-height: 1; }
.sticky-table .col-pct.with-reset { width: 64px; min-width: 64px; }
.sticky-table tr.below-cost [data-prov="effective_percent"] input { color: var(--danger); font-weight: 600; }
/* Provenance: invoice values plain, calculated values muted/italic, user edits marked blue.
   The exact origin is in the cell tooltip. */
.sticky-table td.prov-derived input { color: var(--text-secondary); font-style: italic; }
.sticky-table td.prov-user input { color: var(--primary); font-weight: 600; }
.sticky-table td.prov-user { box-shadow: inset 2px 0 0 var(--primary); }
/* Row states (opaque colours so sticky cells never show through) */
.sticky-table tr.needs-review td { background: #fffcf5; }
.sticky-table tr.free-item td { background: #f7fbff; }
.sticky-table tr.is-edited td { background: #f5f8ff; }
.sticky-table tr.is-edited td.col-num { box-shadow: inset 3px 0 0 var(--primary); }
.sticky-table tr.below-cost [data-out="effective"] { color: var(--danger); font-weight: 600; }
.sticky-table tbody tr:hover td { background: #f8f9fb; }
.edited-chip { display: inline-block; margin-left: 4px; font-size: 10px; font-weight: 650; color: var(--primary); text-transform: uppercase; letter-spacing: .04em; }
.sticky-table .row-notes td { background: var(--surface-muted); padding-top: 2px; padding-bottom: 6px; }
.sticky-table .row-notes .notes-cell { white-space: normal; }
.sticky-table .row-notes span { display: block; font-size: 11px; line-height: 1.35; }
.unsaved-hint { display: none; }
body.has-unsaved-edits .unsaved-hint { display: inline; }

/* Error pages */
.error-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--s-6); text-align: center; }
.error-code { font-size: var(--fs-sm); font-weight: 650; letter-spacing: .08em; color: var(--primary); margin-bottom: var(--s-3); }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1080px) {
  .grid-main-aside { grid-template-columns: 1fr; }
  .settings-layout { grid-template-columns: 1fr; gap: var(--s-5); }
  .subnav { position: static; display: flex; overflow-x: auto; gap: var(--s-1); padding-bottom: var(--s-1); }
  .subnav a { white-space: nowrap; }
  .subnav-label { display: none; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40; transform: translateX(-100%); transition: transform .18s ease; box-shadow: var(--shadow-md); }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(16, 24, 40, .35); z-index: 30; }
  .menu-toggle { display: inline-flex; }
  .topbar { padding: 0 var(--s-4); }
  .content { padding: var(--s-5) var(--s-4); }
  .grid-2 { grid-template-columns: 1fr; }
  .onboarding-shell { grid-template-columns: 1fr; }
  .onboarding-aside { padding: var(--s-5); gap: var(--s-5); }
  .onboarding-aside .aside-note { display: none; }
  .stepper { grid-template-columns: repeat(4, 1fr); }
  .stepper li a, .stepper li span.step-link { flex-direction: column; gap: var(--s-1); font-size: var(--fs-xs); text-align: center; padding: var(--s-2); }
  .onboarding-main { padding: var(--s-8) var(--s-4); }
}

@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
  .auth-card { padding: var(--s-6); }
  .table th, .table td { padding: var(--s-3) var(--s-4); }
  .card-header, .card-body { padding: var(--s-4); }
  .kv-item { padding: var(--s-4); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ------------------------------------------------------------------ Products */
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: var(--fs-sm); }
.product-filters { display: flex; flex-wrap: wrap; gap: 8px; padding: 16px; border-bottom: 1px solid var(--border); }
.product-filters .input[type="search"] { flex: 1 1 260px; }
.product-filters select.input { width: auto; flex: 0 1 200px; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); }
.product-section { border: 0; padding: 0; margin: 0 0 24px; }
.product-section legend { font-weight: 650; font-size: var(--fs-base); margin-bottom: 12px; }
.product-section.is-secondary legend { color: var(--text-muted); }
.import-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px; margin-bottom: 12px; }
.import-summary > div { display: flex; flex-direction: column; gap: 4px; }
.import-summary strong { font-size: var(--fs-xl); }
.import-preview th { vertical-align: top; min-width: 140px; }
.import-preview select { width: 100%; }
.history-chart { width: 100%; max-width: 720px; height: auto; display: block; }
.history-chart polyline { fill: none; stroke-width: 2; }
.history-chart .line-cost { stroke: var(--text-muted); stroke-dasharray: 5 3; }
.history-chart .line-sale { stroke: var(--primary); }
.history-chart .axis { font-size: 11px; fill: var(--text-faint); }
.legend-cost { color: var(--text-muted); } .legend-sale { color: var(--primary); }

/* Product memory in the calculation grid */
.sticky-table .product-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sticky-table .product-meta .btn-link, .sticky-table .ref-meta .btn-link { font-size: 11px; padding: 0; }
.match { font-size: 11px; font-weight: 600; white-space: nowrap; }
.match-ok { color: var(--success); }
.match-new { color: var(--info); }
.match-warn { color: var(--warning); }
.sticky-table .product-name { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.sticky-table .ref-meta { text-align: right; padding-right: 6px; white-space: nowrap; color: var(--text-muted); }
.sticky-table td.out .ref-meta { padding-right: 0; }
.package-prompt { margin-bottom: 16px; border-color: var(--warning-border); background: var(--warning-soft); }
.prompt-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.prompt-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* Modal dialogs (native <dialog>) */
dialog.modal { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 0; width: min(640px, calc(100vw - 32px)); box-shadow: var(--shadow-md); }
dialog.modal-wide { width: min(980px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(16, 24, 40, 0.45); }
.modal-body { padding: 24px; display: grid; gap: 12px; }
.modal-body h2 { margin: 0; font-size: var(--fs-lg); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.modal-table { max-height: 50vh; overflow: auto; }
.search-results { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow: auto; display: grid; gap: 4px; }
.search-result { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; text-align: left; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; }
.search-result:hover, .search-result:focus-visible { border-color: var(--primary); background: var(--primary-soft); }
.sticky-table .ref-meta.is-loss, .sticky-table .ref-meta.is-loss [data-out] { color: var(--danger); font-weight: 600; }
.table td.negative { color: var(--danger); }
.current-state { margin-bottom: 16px; }

/* AI usage */
.usage-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; margin-bottom: 16px; }
.usage-kpis > div { display: flex; flex-direction: column; gap: 2px; }
.usage-kpis strong { font-size: var(--fs-xl); font-variant-numeric: tabular-nums; }
.usage-bar { height: 10px; border-radius: 999px; background: var(--surface-sunken); overflow: hidden; margin-bottom: 8px; }
.usage-bar span { display: block; height: 100%; background: var(--primary); }
.usage-bar.is-full span { background: var(--danger); }
.internal-box { margin-top: 12px; padding: 10px 12px; border: 1px dashed var(--border-strong); border-radius: var(--radius); font-size: var(--fs-sm); color: var(--text-secondary); }

/* Supplier & VAT panel (calculation header) */
.supplier-panel { margin-bottom: 16px; }
.supplier-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 20px; padding: 14px 18px; }
.supplier-grid select { max-width: 220px; }

/* U/Pack memory + printed retail price hints */
.sticky-table .upack-saved { color: var(--success); text-align: right; padding-right: 4px; }
.sticky-table .upack-review { color: var(--warning); text-align: right; padding-right: 4px; }
.sticky-table .upack-remember { font-size: 12px; padding: 0 2px; float: right; }
.sticky-table .printed-meta { color: var(--info); }

/* ERP normalisation (product calculation rule) */
.sticky-table .source-qty { text-align: right; padding-right: 6px; color: var(--text-muted); white-space: nowrap; }
.sticky-table .upack-conversion { text-align: right; padding: 4px 6px 0 0; font-variant-numeric: tabular-nums; }

/* Calculation list: row delete action */
.table .col-actions { width: 1%; white-space: nowrap; text-align: right; }
.table .col-actions form { display: inline; }

/* "Set calculation rule" on packaged lines without a confirmed product rule */
.sticky-table .rule-meta { margin-top: 2px; }
.sticky-table .rule-setup { font-weight: 600; white-space: nowrap; }

/* Calculation totals / posting summary (under the items) */
.posting-summary { margin-top: 16px; }
.posting-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0; }
.posting-group { padding: 16px 20px; }
.posting-group + .posting-group { border-left: 1px solid var(--border); }
@media (max-width: 720px) { .posting-group + .posting-group { border-left: 0; border-top: 1px solid var(--border); } }
.posting-list { margin: 0; }
.posting-list > div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 5px 0; border-bottom: 1px dashed var(--border); }
.posting-list dt { color: var(--text); }
.posting-list dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.posting-list .posting-total { border-bottom: 0; border-top: 2px solid var(--border); margin-top: 2px; font-weight: 700; }
.posting-list .posting-muted, .posting-list .posting-check { color: var(--text-muted); font-size: 0.9em; }
.posting-summary .local-term { display: block; font-size: 0.78em; font-weight: 400; color: var(--text-muted); }
.posting-summary .totals-title .local-term { display: inline; margin-left: 6px; }
.posting-rates { margin-top: 10px; }
.warning-text { color: var(--warning); }

/* Business units */
.unit-line { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--text-muted); margin-top: 4px; }
.unit-choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.unit-choice { display: flex; gap: 10px; align-items: flex-start; padding: 14px 16px; border: 1px solid var(--border); border-radius: 10px; color: var(--text); text-decoration: none; }
.unit-choice:hover, .unit-choice:focus { border-color: var(--primary, #2563eb); outline: none; }
.unit-choice.is-default { border-width: 2px; }
.choice-list { border: 0; padding: 0; margin: 0; display: grid; gap: 10px; }
.choice-card { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.muted-row td { color: var(--text-muted); }
.sticky-table .ref-origin { color: var(--text-muted); white-space: nowrap; }

/* ---- stock transfers ------------------------------------------------------- */
.transfer-route { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.transfer-code-row, .transfer-qty-row { display: flex; gap: var(--s-3); align-items: flex-end; flex-wrap: wrap; }
.transfer-qty-row .field { flex: 1 1 140px; }
.input.input-lg { height: 48px; font-size: 18px; }
.input.input-sm { height: 32px; width: 90px; padding: 0 8px; }
.transfer-scanner { margin-top: var(--s-3); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; background: #000; }
.transfer-scanner video { display: block; width: 100%; max-height: 320px; object-fit: cover; }
.transfer-scanner-bar { display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); padding: 8px 12px; background: var(--surface); }
.transfer-candidates { display: grid; gap: 6px; margin-top: var(--s-3); }
.transfer-candidates button { text-align: left; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; font: inherit; color: inherit; }
.transfer-candidates button:hover, .transfer-candidates button:focus { border-color: var(--primary, #2563eb); outline: none; }
.transfer-chosen { margin-top: var(--s-4); padding: var(--s-4); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-muted); }
.transfer-prices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-3); margin: var(--s-3) 0; }
.transfer-prices dt { font-size: var(--fs-sm); color: var(--text-muted); }
.transfer-prices dd { margin: 0; font-size: 18px; font-weight: 600; }
.transfer-inline { display: inline; }
.transfer-actions { margin-top: var(--s-5); }
@media (max-width: 600px) {
  .hide-sm { display: none; }
  .transfer-prices { grid-template-columns: 1fr 1fr; }
}
.lang-switch { display: inline-flex; align-items: center; margin-left: 8px; }
.lang-select { height: 32px; padding: 0 8px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text-secondary); font: inherit; font-size: var(--fs-sm); cursor: pointer; }
