/* COSMO ERP design system — Bible §23.9
   Self-contained: no CDN, no build step. A shared host without SSH cannot run
   a bundler, so tokens and components ship as plain CSS.

   Layout is direction-agnostic: only logical properties (inline-start/end),
   so the same sheet renders LTR English and RTL Persian. */

/* Vazirmatn (SIL OFL 1.1, see fonts/OFL-Vazirmatn.txt) — bundled locally
   because the target host must work with no external requests at all.
   Variable weight axis 100-900 in one 108KB file. */
@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/Vazirmatn-var.woff2") format("woff2-variations"),
       url("fonts/Vazirmatn-var.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  /* Colour — semantic roles, not brand expression (§23.9).
     Light by default: this is a system people stare at for a full shift, so the
     page is white and the greys are neutral (no blue cast, which reads as cold
     and tires the eye). Every pair below meets WCAG AA — see docs/OPERATIONS.md. */
  --surface: #ffffff;        /* cards, inputs        */
  --surface-2: #fbfbfc;      /* page background      */
  --surface-3: #f1f1f4;      /* subtle fills, chips  */
  --border: #e6e6ea;
  --border-strong: #cfcfd6;
  --content: #191a1d;        /* 17.4:1 on white      */
  --content-2: #5b5d66;      /*  6.6:1               */
  --content-3: #8a8d97;      /*  3.3:1 — labels only */

  /* Accent: a muted plum. Warm enough to suit a cosmetics brand, and clearly
     distinct from the semantic info-blue so an accent button is never mistaken
     for an informational state. */
  --accent: #8f4460;
  --accent-ink: #ffffff;
  --accent-soft: #f8eef2;

  --success: #1e7a4c; --success-soft: #e8f5ee;
  --warning: #8a5a08; --warning-soft: #fdf3e0;
  --danger:  #a52a2a; --danger-soft:  #fceaea;
  --info:    #2a5f9e; --info-soft:    #e9f0fa;

  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;

  --radius: 10px; --radius-sm: 6px;
  --shadow-1: 0 1px 2px rgba(20,20,28,.05), 0 1px 3px rgba(20,20,28,.06);
  --shadow-2: 0 6px 18px rgba(20,20,28,.10);

  --font: "Vazirmatn", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Tahoma, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Dark is available but never automatic: an operator opts in with
   <html data-theme="dark">. The OS preference is deliberately NOT followed —
   a warehouse or finance screen should look the same on every desk. */
:root[data-theme="dark"] {
  --surface: #17181c; --surface-2: #101115; --surface-3: #202228;
  --border: #2a2c33; --border-strong: #3b3e47;
  --content: #ecedf0; --content-2: #a8abb4; --content-3: #7f838d;
  --accent: #d98fac; --accent-ink: #24101a; --accent-soft: #2c1c24;
  --success:#4cb98a; --success-soft:#12291f;
  --warning:#d8a54a; --warning-soft:#2e2410;
  --danger: #e58080; --danger-soft: #301818;
  --info:   #7fa9de; --info-soft:   #162335;
  --shadow-1: 0 1px 2px rgba(0,0,0,.35);
  --shadow-2: 0 6px 18px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.55;
  color: var(--content); background: var(--surface-2);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
/* Persian is a joining script: letter-spacing breaks ligatures, and the taller
   ascenders of Vazirmatn want a touch more line height. */
[dir="rtl"] body { line-height: 1.7; }
[dir="rtl"] .brand, [dir="rtl"] .nav-group, [dir="rtl"] .stat .label,
[dir="rtl"] .card-head h2, [dir="rtl"] .stat .value { letter-spacing: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex: 0 0 232px; background: var(--surface-2);
  border-inline-end: 1px solid var(--border); padding: var(--sp-4) 0;
  display: flex; flex-direction: column;
  /* Pinned: navigation and the account card must stay reachable no matter how
     long the table below is. The column scrolls on its own if it overflows. */
  position: sticky; top: 0; height: 100vh;
}
/* Only the link list scrolls; the account card stays pinned to the bottom so
   "who am I / sign out" is never something you have to hunt for. */
.sidebar-panel { overflow: hidden; }
.nav { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin; }
.sidebar-foot { flex: none; }
.main { background: var(--surface-2); min-width: 0; }
.brand-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-2); padding: 0 var(--sp-4) var(--sp-4);
}
.brand {
  display: flex; align-items: center; gap: var(--sp-2);
  font-weight: 700; letter-spacing: .3px; min-width: 0;
}
.brand > span { min-width: 0; }

/* The disclosure control. Off-screen but focusable, so tab order still works. */
.nav-toggle { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.nav-burger { display: none; }

.sidebar-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; }
/* ---------- account card ----------
   Who am I, and the three things I might do about it. Three stacked buttons
   shouted; an identity card with quiet inline actions reads as considered. */
.sidebar-foot { margin-top: auto; padding: var(--sp-4) var(--sp-2) 0; }
.account {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); padding: var(--sp-3);
}
.account-id { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.avatar {
  width: 32px; height: 32px; flex: none; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-size: 12.5px; font-weight: 700;
  letter-spacing: .3px; border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
}
.account-name { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.account-name strong {
  font-size: 13.5px; font-weight: 650; color: var(--content);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.account-name small {
  font-size: 11.5px; color: var(--content-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.account-actions {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  margin-top: var(--sp-3); padding-top: var(--sp-2);
  border-top: 1px solid var(--border);
}
.account-actions form { margin: 0; display: inline; }
.account-actions .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--border-strong); }

/* A text action: no chrome until you reach for it. */
.link-btn {
  background: none; border: 0; padding: 2px 3px; margin: 0; cursor: pointer;
  font: inherit; font-size: 12px; font-weight: 600; color: var(--content-2);
  border-radius: 4px; text-decoration: none; transition: color .12s ease, background-color .12s ease;
}
.link-btn:hover { color: var(--accent); background: var(--accent-soft); text-decoration: none; }
.link-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; background: var(--accent);
  color: var(--accent-ink); display: grid; place-items: center;
  font-size: 14px; font-weight: 700; flex: none; box-shadow: var(--shadow-1);
}
.brand small { display:block; font-weight: 500; font-size: 11px; color: var(--content-3); letter-spacing: .4px; }
.nav { display: flex; flex-direction: column; gap: 1px; padding: 0 var(--sp-2); }
.nav-group { padding: var(--sp-4) var(--sp-3) var(--sp-1); font-size: 11px;
  text-transform: uppercase; letter-spacing: .7px; color: var(--content-3); font-weight: 600; }
.nav a {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  padding: 8px var(--sp-3); border-radius: var(--radius-sm);
  color: var(--content-2); font-size: 14px;
}
.nav a:hover { background: var(--surface-2); color: var(--content); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.nav a.active::after {
  content: ""; width: 3px; height: 18px; border-radius: 3px; background: var(--accent);
  margin-inline-start: auto;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-5); background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { letter-spacing: -.2px; }
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; }
.content { padding: var(--sp-5); max-width: 1400px; width: 100%; }

/* ---------- cards & grid ---------- */
.grid { display: grid; gap: var(--sp-4); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-1); overflow: hidden;
}
.card-head {
  padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
}
.card-head h2 { margin: 0; font-size: 14px; font-weight: 650; letter-spacing: .2px; }
.card-body { padding: var(--sp-4); }
.card-body.tight { padding: 0; }

/* ---------- stat tiles ---------- */
.stat { padding: var(--sp-4); }
.stat .label { font-size: 12px; color: var(--content-3); font-weight: 600;
  text-transform: uppercase; letter-spacing: .5px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 2px; letter-spacing: -.5px; }
.stat .sub { font-size: 12.5px; color: var(--content-2); margin-top: 2px; }
.stat.danger .value { color: var(--danger); }
.stat.warning .value { color: var(--warning); }
.stat.success .value { color: var(--success); }
.stat .value { font-variant-numeric: tabular-nums; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: start; padding: 9px var(--sp-3); border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--content-3); font-weight: 650; background: var(--surface);
  border-bottom: 1px solid var(--border-strong); position: sticky; top: 0; }
tbody tr { transition: background-color .1s ease; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 13px; }
[dir="rtl"] td.num, [dir="rtl"] th.num { font-family: var(--font); font-size: 13.5px; }
/* Latin codes (SKU, order numbers) inside an RTL page keep their own direction
   so `SO-26-00001` never renders as `00001-26-SO`. */
[dir="rtl"] .mono { direction: ltr; unicode-bidi: isolate; display: inline-block; }
[dir="rtl"] td.mono, [dir="rtl"] th.mono { display: table-cell; }
.mono, td.mono, .num { white-space: nowrap; }
tr:last-child td { border-bottom: none; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px;
  border-radius: 100px; font-size: 11.5px; font-weight: 650; white-space: nowrap;
  background: var(--surface-3); color: var(--content-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok      { background: var(--success-soft); color: var(--success); }
.badge.warn    { background: var(--warning-soft); color: var(--warning); }
.badge.bad     { background: var(--danger-soft);  color: var(--danger); }
.badge.info    { background: var(--info-soft);    color: var(--info); }
.badge.neutral { background: var(--surface-3);    color: var(--content-2); }
.badge.plain::before { display: none; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--content); font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit; min-height: 38px; text-decoration: none;
}
.btn { transition: background-color .12s ease, filter .12s ease, box-shadow .12s ease, transform .06s ease; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.sm { padding: 5px 10px; min-height: 30px; font-size: 13px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }

/* ---------- forms ---------- */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--content-2); }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--content);
  font-family: inherit; font-size: 14px; min-height: 38px;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
input::placeholder, textarea::placeholder { color: var(--content-3); opacity: .8; }
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: var(--sp-3); }
.field .hint { font-size: 12px; color: var(--content-3); margin-top: 3px; }
.field .err { font-size: 12.5px; color: var(--danger); margin-top: 3px; font-weight: 600; }
.inline-form { display: flex; gap: var(--sp-2); align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { margin-bottom: 0; }

/* ---------- alerts ---------- */
.alert {
  padding: var(--sp-3) var(--sp-4); border-radius: var(--radius);
  border: 1px solid; border-inline-start-width: 4px;
  margin-bottom: var(--sp-4); font-size: 14px;
}
.alert.ok   { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.alert.bad  { background: var(--danger-soft);  border-color: var(--danger);  color: var(--danger); }
.alert.warn { background: var(--warning-soft); border-color: var(--warning); color: var(--warning); }
.alert.info { background: var(--info-soft);    border-color: var(--info);    color: var(--info); }
.alert a { color: inherit; text-decoration: underline; font-weight: 650; }
.alert ul { margin: var(--sp-2) 0 0; padding-inline-start: var(--sp-5); }
.alert strong { font-weight: 700; }

/* ---------- states (§23.4) ---------- */
.empty { padding: var(--sp-7) var(--sp-4); text-align: center; color: var(--content-2); }

.pagination { display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); flex-wrap: wrap; }
.pagination-links { display: flex; align-items: center; gap: var(--sp-1); flex-wrap: wrap; }
.empty .title { font-weight: 650; color: var(--content); margin-bottom: 4px; font-size: 15px; }
.empty .hint { font-size: 13.5px; }
.stale { font-size: 12px; color: var(--content-3); }

/* ---------- misc ---------- */
.muted { color: var(--content-2); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 13px; }
.row { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.sep { height: 1px; background: var(--border); margin: var(--sp-3) 0; }
.kv { display: grid; grid-template-columns: minmax(140px, auto) 1fr; gap: 6px var(--sp-4); font-size: 13.5px; }
.kv dt { color: var(--content-3); font-weight: 600; }
.kv dd { margin: 0; }
.meter { height: 7px; background: var(--surface-3); border-radius: 100px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 100px; }
.meter.warn > span { background: var(--warning); }
.meter.bad > span  { background: var(--danger); }
.pagination { display: flex; gap: 4px; padding: var(--sp-3); flex-wrap: wrap; }
.pagination a, .pagination span { padding: 5px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); font-size: 13px; }
.pagination .active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: var(--sp-2) 0 var(--sp-2) var(--sp-4); border-inline-start: 2px solid var(--border);
  position: relative; font-size: 13.5px; }
.timeline li::before { content:""; position:absolute; inset-inline-start:-5px; top:14px;
  width:8px; height:8px; border-radius:50%; background: var(--border-strong); }
.timeline li.hl::before { background: var(--accent); }

/* ---------- product grid (partner catalog) ---------- */
.products { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: var(--sp-4); }
.product { display: flex; flex-direction: column; }
.product .body { padding: var(--sp-3); flex: 1; display: flex; flex-direction: column; gap: 6px; }
.product .name { font-weight: 620; font-size: 14px; line-height: 1.35; }
.product .code { font-family: var(--mono); font-size: 11.5px; color: var(--content-3); }
.product .price { font-size: 18px; font-weight: 700; letter-spacing: -.3px; }
.product .foot { padding: var(--sp-3); border-top: 1px solid var(--border); background: var(--surface-2); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: var(--sp-4); }
.auth .card { width: 100%; max-width: 400px; }

/* ---------- responsive: the portal must work at 375px (§23.11) ---------- */
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; border-inline-end: none; border-bottom: 1px solid var(--border);
    padding: 0; position: sticky; top: 0; z-index: 30;
  }

  /* Header collapses to a single row: brand at the start, burger at the end. */
  .brand-row { padding: var(--sp-2) var(--sp-3); }
  .nav-burger {
    display: grid; place-items: center; width: 40px; height: 40px; flex: none;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--surface); cursor: pointer;
  }
  .nav-burger-bars, .nav-burger-bars::before, .nav-burger-bars::after {
    display: block; width: 18px; height: 2px; border-radius: 2px;
    background: var(--content); content: "";
    transition: transform .18s ease, background-color .18s ease;
  }
  /* Pin both bars to the same box as the middle one, otherwise the rotated
     halves pivot around different origins and read as a bowtie, not an ✕. */
  .nav-burger-bars { position: relative; }
  .nav-burger-bars::before,
  .nav-burger-bars::after { position: absolute; inset-inline-start: 0; }
  .nav-burger-bars::before { top: -6px; }
  .nav-burger-bars::after  { top: 6px; }

  /* Open state: bars morph to an ✕ so the control reads as a toggle. */
  .nav-toggle:checked ~ .sidebar .nav-burger-bars { background: transparent; }
  .nav-toggle:checked ~ .sidebar .nav-burger-bars::before { top: 0; transform: rotate(45deg); }
  .nav-toggle:checked ~ .sidebar .nav-burger-bars::after  { top: 0; transform: rotate(-45deg); }
  .nav-toggle:focus-visible ~ .sidebar .nav-burger { outline: 2px solid var(--accent); outline-offset: 2px; }

  /* The menu itself: closed by default, revealed by the checkbox. */
  .sidebar-panel {
    display: none; border-top: 1px solid var(--border);
    max-height: calc(100vh - 56px); overflow-y: auto;
    padding: var(--sp-2) 0 var(--sp-3);
  }
  .sidebar { position: sticky; height: auto; }
  .nav-toggle:checked ~ .sidebar .sidebar-panel { display: block; }

  .nav { gap: 2px; padding: 0 var(--sp-2); flex: none; overflow: visible; }
  .nav a { padding: 10px var(--sp-3); line-height: 1.3; min-height: 44px; }  /* touch target */
  .nav-group { padding: var(--sp-3) var(--sp-3) 2px; line-height: 1.3; }
  .sidebar-foot { margin-top: var(--sp-3); padding: var(--sp-3) var(--sp-2) 0;
    border-top: 1px solid var(--border); }
  .account { background: var(--surface-2); }

  .content { padding: var(--sp-3); }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .topbar { padding: var(--sp-3); position: static; }
  .topbar h1 { font-size: 16px; }
  table { font-size: 13px; min-width: 560px; }
  th, td { padding: 8px 10px; }
  .products { grid-template-columns: 1fr; }

  /* Make the scrollability visible rather than something to discover. */
  .table-wrap {
    -webkit-overflow-scrolling: touch;
    background:
      linear-gradient(to right, var(--surface) 30%, transparent) 0 0 / 24px 100% no-repeat,
      linear-gradient(to left,  var(--surface) 30%, transparent) 100% 0 / 24px 100% no-repeat,
      radial-gradient(farthest-side at 0 50%, rgba(20,20,28,.12), transparent) 0 0 / 12px 100% no-repeat,
      radial-gradient(farthest-side at 100% 50%, rgba(20,20,28,.12), transparent) 100% 0 / 12px 100% no-repeat;
    background-attachment: local, local, scroll, scroll;
  }
}

/* Tablet: two product columns rather than one. */
@media (min-width: 620px) and (max-width: 900px) {
  .grid.cols-2, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

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

/* ---------- print (statement, ledger, invoices) ---------- */
@media print {
  :root { --surface:#fff; --surface-2:#fff; --surface-3:#f2f2f2;
    --content:#000; --content-2:#333; --content-3:#555; --border:#bbb; --border-strong:#999; }
  body { background: #fff; font-size: 12px; }
  .sidebar, .topbar .row, .inline-form, .btn, form, .pagination { display: none !important; }
  .app, .main { display: block; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; border-color: #bbb; break-inside: avoid; }
  th { position: static; }
  a { color: inherit; text-decoration: none; }
}
