:root {
  color-scheme: light;
  --ink: #0B1220;
  --ink-2: #151E36;
  --brand: #6C5CE7;
  --brand-hover: #5A4BD6;
  --accent: #6C5CE7;
  --accent-hover: #5A4BD6;
  --navy: var(--ink);
  --navy-2: var(--ink-2);
  --bg: #F6F7FB;
  --card: #ffffff;
  --surface-2: #f8fafc;
  --hover: #fafbfc;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --heading: var(--ink);
  --input-bg: #ffffff;
  --unread: #EEF0FF;
  --success: #17C08A;
  --error: #dc2626;
  --info: #2563eb;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(11,18,32,.08), 0 4px 12px rgba(11,18,32,.04);
  --sidebar-w: 240px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
}

@media (prefers-reduced-motion: no-preference) {
  body,
  .topbar,
  .topbar__title,
  .card,
  .card__label,
  .card__value,
  .card__hint,
  .panel,
  .panel__head,
  .panel__head h2,
  table.data th,
  table.data td,
  .btn,
  .btn--secondary,
  .btn--ghost,
  .field input, .field select, .field textarea,
  .form-row input, .form-row select, .form-row textarea,
  .help,
  .flash,
  .pill,
  .progress-bar,
  .notif__bell,
  .notif__panel,
  .notif__head,
  .notif__foot,
  .notif__item,
  .notif__title,
  .notif__meta,
  .dropzone,
  .dropzone__list li,
  .quick-panel {
    transition:
      background-color .22s ease,
      color .22s ease,
      border-color .22s ease,
      box-shadow .22s ease;
  }
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

.app { min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
}
.sidebar__brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar__brand img { height: 28px; width: 28px; border-radius: 7px; }
.sidebar__brand .wordmark {
  color: #fff; font-size: 1.2rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.1;
}
.sidebar__brand .wordmark__vora { color: #A78BFA; }
.sidebar__brand .wordmark__sub {
  display: block; font-size: .68rem; color: #94a3b8; font-weight: 400; letter-spacing: 0; margin-top: 2px;
}
.sidebar__nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.sidebar__nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  color: #cbd5e1; font-size: .9rem; margin-bottom: 2px;
}
.sidebar__nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar__nav a.active { background: rgba(108,92,231,.22); color: #fff; }
.sidebar__nav .nav-section {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .06em;
  color: #64748b; padding: 14px 12px 6px;
}
.sidebar__foot {
  padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08);
  font-size: .8rem; color: #94a3b8;
}
.sidebar__foot a { color: #e2e8f0; }
.sidebar__legal {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: .68rem;
  line-height: 1.4;
  color: #64748b;
}

.theme-toggle {
  display: flex;
  gap: 2px;
  margin-bottom: 12px;
  padding: 3px;
  border-radius: 8px;
  background: rgba(255,255,255,.06);
}
.theme-toggle__btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  line-height: 0;
}
.theme-toggle__btn:hover { color: #fff; background: rgba(255,255,255,.06); }
.theme-toggle__btn[aria-pressed="true"] {
  background: rgba(255,116,37,.22);
  color: #fff;
}
.theme-toggle__btn svg { display: block; }

.main { margin-left: var(--sidebar-w); min-width: 0; }
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  position: sticky; top: 0; z-index: 30;
}
.topbar__title { font-size: 1.1rem; font-weight: 600; margin: 0; color: var(--heading); }
.topbar__actions { display: flex; align-items: center; gap: 12px; }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--accent); color: #fff; border-radius: 99px;
  font-size: .7rem; font-weight: 700;
}
.impersonate-banner {
  background: #fef3c7; color: #92400e; padding: 8px 24px;
  font-size: .85rem; border-bottom: 1px solid #fcd34d;
  display: flex; justify-content: space-between; align-items: center;
}

.content { padding: 24px; width: 100%; max-width: 100%; box-sizing: border-box; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.card__label { font-size: .8rem; color: var(--muted); margin-bottom: 4px; }
.card__value { font-size: 1.5rem; font-weight: 700; color: var(--heading); }
.card__hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }

.panel {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 24px;
}
.panel__head {
  padding: 14px 12px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.panel__head h2 { margin: 0; font-size: 1rem; color: var(--heading); }
.panel__body { padding: 18px; }
.panel__intro {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px 16px;
}
.panel__intro > .help,
.panel__intro > .flash {
  margin: 0;
  line-height: 1.45;
}

.po-side-panels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
  align-items: start;
}
.po-side-panels > .panel { margin-bottom: 0; min-width: 0; }

/* Invoice review: form is primary, original file fixed on the right */
.invoice-review.has-preview {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.7fr);
  gap: 20px;
  align-items: start;
}
.invoice-review__main { min-width: 0; }
.invoice-review__preview {
  position: sticky;
  top: 76px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 100px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.invoice-preview__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}
.invoice-preview__head strong {
  font-size: .85rem;
  color: var(--heading);
}
.invoice-preview__body {
  flex: 1;
  min-height: 0;
  background: #0b1220;
}
.invoice-preview__body iframe,
.invoice-preview__body img {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}
.invoice-preview__body img {
  object-fit: contain;
  background: #111827;
}
.invoice-preview__fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  height: 100%;
  padding: 24px;
  color: #cbd5e1;
  text-align: center;
}

.table-wrap { overflow-x: auto; }
table.data {
  width: 100%; border-collapse: collapse; font-size: .9rem;
}
table.data th, table.data td {
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data th {
  font-size: .75rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 600; background: var(--surface-2);
}
table.data tr:hover td { background: var(--hover); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .muted { color: var(--muted); }
.cell-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}
.cell-actions form { margin: 0; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid transparent;
  font-size: .875rem; font-weight: 600; cursor: pointer;
  background: var(--accent); color: #fff; text-decoration: none;
}
.btn:hover { background: var(--accent-hover); color: #fff; }
.btn--secondary { background: var(--card); color: var(--heading); border-color: var(--border); }
.btn--secondary:hover { background: var(--surface-2); color: var(--heading); }
.btn--danger { background: var(--error); }
.btn--sm { padding: 5px 10px; font-size: .8rem; }
.btn--ghost { background: transparent; color: var(--muted); border-color: transparent; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.form-row { margin-bottom: 14px; }
.form-row label, .field label {
  display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 4px;
}
.field input, .field select, .field textarea,
.form-row input, .form-row select, .form-row textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 8px; font: inherit; background: var(--input-bg); color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus,
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  outline: 2px solid rgba(108,92,231,.35); border-color: var(--accent);
}
.field textarea, .form-row textarea { min-height: 80px; resize: vertical; }
.help { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.checkbox { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.checkbox input { width: auto; }

.flash-stack { margin-bottom: 16px; }
.flash {
  padding: 12px 14px; border-radius: 8px; font-size: .9rem; margin-bottom: 8px;
}
.flash--success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash--error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.flash--info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

.pill {
  display: inline-block; padding: 2px 8px; border-radius: 99px;
  font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
}
.pill--draft { background: #f1f5f9; color: #475569; }
.pill--pending_approval, .pill--pending_review { background: #fef3c7; color: #92400e; }
.pill--approved, .pill--active, .pill--sent, .pill--received { background: #d1fae5; color: #065f46; }
.pill--cancelled, .pill--cancelled { background: #fee2e2; color: #991b1b; }
.pill--partially_received { background: #cffafe; color: #155e75; }
.pill--matched { background: #e0e7ff; color: #3730a3; }

.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(145deg, var(--ink) 0%, var(--ink-2) 60%, #1e2a4a 100%);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 400px; background: #fff;
  border-radius: 14px; padding: 32px; box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-card__brand { text-align: center; margin-bottom: 28px; }
.login-card__brand img { border-radius: 12px; }
.login-card__brand .wordmark {
  margin: 14px 0 6px;
  color: var(--ink);
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -.04em;
  line-height: 1;
}
.login-card__brand .wordmark__vora { color: var(--brand); }
.login-card__brand p { margin: 0; color: var(--muted); font-size: .95rem; }

.lines-table { table-layout: fixed; }
.lines-table th, .lines-table td { vertical-align: top; }
.lines-table .col-desc { width: 36%; }
.lines-table .col-ref { width: 10%; }
.lines-table .col-num { width: 8%; }
.lines-table .col-account { width: 22%; }
.lines-table .col-conf { width: 7%; }
.lines-table .col-pack-flag { width: 4%; text-align: center; }
.lines-table .col-pack-size { width: 7%; }
.lines-table tr:not(.is-pack-priced) .col-pack-size .line-pack { display: none; }
.lines-table .pack-size-placeholder { display: inline-block; padding-top: 8px; }
.lines-table input, .lines-table select, .lines-table textarea {
  font-size: .85rem; padding: 6px 8px; width: 100%; box-sizing: border-box;
}
.lines-table textarea {
  min-height: 4.5rem;
  resize: vertical;
  line-height: 1.35;
  font: inherit;
}
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.platform-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.platform-tabs { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.platform-toolbar > .btn:last-child { margin-left: auto; }
.platform-tabs .btn.is-active {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}
.platform-tabs .btn.is-active:hover { background: var(--navy-2); color: #fff; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.progress-bar {
  height: 8px; background: var(--border); border-radius: 99px; overflow: hidden; margin-top: 8px;
}
.progress-bar > span { display: block; height: 100%; background: var(--accent); transition: width .35s ease; }
.progress-bar > span.over { background: var(--error); }
.progress-bar > span.done { background: #059669; }
.progress-bar--item { height: 10px; }
.scan-item__status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.scan-item__pct { font-size: .8rem; min-width: 2.5rem; }
.scan-item__error { margin-top: 4px; font-size: .8rem; color: var(--error); max-width: 420px; }

.btn--lg { padding: 12px 20px; font-size: 1rem; }
.btn--upload {
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  padding: 10px 18px;
  box-shadow: 0 2px 8px rgba(255,116,37,.35);
}
.btn--upload:hover { background: var(--accent-hover); color: #fff; }
.topbar__tenant { white-space: nowrap; }

.notif { position: relative; }
.notif__bell {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--card); color: var(--heading);
  cursor: pointer;
}
.notif__bell:hover { background: var(--surface-2); }
.notif__badge {
  position: absolute; top: 4px; right: 4px;
  min-width: 16px; height: 16px; font-size: .65rem;
}
.notif__panel {
  position: absolute; right: 0; top: calc(100% + 8px);
  width: min(380px, calc(100vw - 32px));
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 40px rgba(15,28,46,.16); z-index: 50; overflow: hidden;
}
.notif__head, .notif__foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.notif__foot { border-bottom: 0; border-top: 1px solid var(--border); }
.notif__list { max-height: 360px; overflow-y: auto; }
.notif__item {
  display: flex; gap: 10px; align-items: flex-start; justify-content: space-between;
  padding: 12px; border-bottom: 1px solid var(--border);
}
.notif__item:last-child { border-bottom: 0; }
.notif__item.is-unread { background: var(--unread); }
.notif__title { font-size: .9rem; font-weight: 600; color: var(--heading); }
.notif__meta { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.notif__empty { padding: 24px; text-align: center; color: var(--muted); font-size: .9rem; }
.notif__item-actions { flex-shrink: 0; }

.dropzone {
  border: 2px dashed var(--border); border-radius: 12px;
  padding: 18px; background: var(--surface-2); text-align: center;
}
.dropzone.is-drag { border-color: var(--accent); background: var(--unread); }
.dropzone__pick {
  position: relative; min-height: 96px;
  display: flex; align-items: center; justify-content: center;
}
.dropzone__pick input[type=file] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.dropzone__copy { pointer-events: none; padding: 12px; }
.dropzone__list {
  list-style: none; margin: 16px 0 0; padding: 0; text-align: left;
  max-height: 220px; overflow: auto; position: relative; z-index: 1;
}
.dropzone__list li {
  font-size: .85rem; padding: 6px 8px; background: var(--card);
  border: 1px solid var(--border); border-radius: 6px; margin-bottom: 6px;
}

.toast-stack {
  position: fixed; right: 20px; bottom: 20px; z-index: 80;
  display: flex; flex-direction: column; gap: 10px; width: min(360px, calc(100vw - 32px));
}
.toast {
  background: var(--navy); color: #fff; border-radius: 12px; padding: 14px 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25); animation: toast-in .2s ease-out;
}
.toast__title { font-weight: 700; margin-bottom: 4px; }
.toast__body { font-size: .85rem; color: #cbd5e1; margin-bottom: 10px; }
.toast .btn { background: var(--accent); }
@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.quick-panel {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px;
  background: var(--surface-2);
}

@media (max-width: 860px) {
  .sidebar { position: static; width: 100%; }
  .main { margin-left: 0; }
  .topbar { flex-wrap: wrap; }
  .btn--upload { order: -1; width: 100%; justify-content: center; }
  .po-side-panels { grid-template-columns: 1fr; }
}

@media (max-width: 1100px) {
  .invoice-review.has-preview {
    grid-template-columns: 1fr;
  }
  .invoice-review__preview {
    position: static;
    height: 55vh;
  }
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #080d18;
  --card: #121a2e;
  --surface-2: #151E36;
  --hover: #1a243d;
  --border: #2a3550;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --heading: #f1f5f9;
  --input-bg: #151E36;
  --unread: rgba(108,92,231,.16);
  --shadow: 0 1px 3px rgba(0,0,0,.45), 0 4px 12px rgba(0,0,0,.35);
}
[data-theme="dark"] .flash--success { background: #052e22; color: #6ee7b7; border-color: #065f46; }
[data-theme="dark"] .flash--error { background: #3b0d0d; color: #fca5a5; border-color: #7f1d1d; }
[data-theme="dark"] .flash--info { background: #0c1e3a; color: #93c5fd; border-color: #1e40af; }
[data-theme="dark"] .pill--draft { background: #1e293b; color: #cbd5e1; }
[data-theme="dark"] .pill--pending_approval,
[data-theme="dark"] .pill--pending_review { background: #3b2f0a; color: #fcd34d; }
[data-theme="dark"] .pill--approved,
[data-theme="dark"] .pill--active,
[data-theme="dark"] .pill--sent,
[data-theme="dark"] .pill--received { background: #052e22; color: #6ee7b7; }
[data-theme="dark"] .pill--cancelled,
[data-theme="dark"] .pill--cancelled { background: #3b0d0d; color: #fca5a5; }
[data-theme="dark"] .pill--partially_received { background: #0c2f38; color: #67e8f9; }
[data-theme="dark"] .pill--matched { background: #1e1b4b; color: #a5b4fc; }
[data-theme="dark"] .notif__panel {
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
}
