/* Telavang Design System 1.0.1 — shared tokens (light only). Source: docs/design/TELAVANG_DESIGN_SYSTEM.md §2.7.
   This app uses plain CSS (no Tailwind); values are the standard's tokens, not app-specific choices. */

/* Vazirmatn 33.0.3 variable font, self-hosted (SIL OFL 1.1 — /fonts/Vazirmatn-OFL.txt) */
@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-Variable.woff2') format('woff2-variations'), url('/fonts/Vazirmatn-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  color-scheme: only light;
  --canvas: #f7f9fc;
  --surface: #ffffff;
  --surface-2: #fafbfd;
  --ink: #2f3a45;
  --ink-2: #6b7280;
  --ink-3: #6b7280;
  --separator: #dce3ea;
  --separator-strong: #c2ccd7;
  --header-line: #cdd3da;
  --selected: #eaf0f8;
  --row-hover: #f3f4f6;
  --hover: rgb(18 62 124 / 0.06);
  --accent: #123e7c;
  --accent-hover: #0d3163;
  --accent-soft: #e7eef7;
  --accent-press: #d3e1f2;
  --accent-ink: #ffffff;
  --brand-orange: #fd8204;
  --signal-overdue: #b42318;
  --signal-overdue-soft: #fdecea;
  --signal-overdue-press: #f8d7d3;
  --signal-done: #067647;
  --signal-done-soft: #e6f4ec;
  --signal-soon: #9a3d06;
  --signal-soon-soft: #fdf1e6;
  --focus: #123e7c;
  --shadow-pane: 0 1px 2px rgb(47 58 69 / 0.06);
  --touch: 44px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --font-sans: 'Vazirmatn', system-ui, sans-serif;
}

/* Secondary text on tinted surfaces keeps at least 4.5:1 (§2.3). */
.notice, .chip, .tabs button[aria-current='page'], tr.loss, tr.flagged, .viewas, .test-banner, th {
  --ink-2: #5b6370;
  --ink-3: #5b6370;
}

* { box-sizing: border-box; }
html { font-size: 100%; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--canvas); }
body {
  margin: 0;
  background: var(--canvas); color: var(--ink); font-family: var(--font-sans);
  font-size: 1rem; line-height: 1.8;
  font-variant-numeric: tabular-nums; font-feature-settings: 'tnum' 1;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden; min-height: 100dvh;
  padding-bottom: calc(57px + env(safe-area-inset-bottom));
}
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-sm); }
button, input, select, textarea { font: inherit; color: inherit; }
button, [role='button'], a, summary { cursor: pointer; touch-action: manipulation; }
::selection { background: var(--accent-soft); }
.ltr-run { unicode-bidi: isolate; direction: ltr; }

/* Phosphor icons (§3): inline default 18 px; never mirrored here (none of these imply direction) */
.ico { display: inline-flex; flex: none; line-height: 0; }
.ico svg { width: 18px; height: 18px; }
[hidden] { display: none !important; }

/* Type roles (§2.1) */
h1 { font-size: 20px; line-height: 28px; font-weight: 700; margin: 0 0 8px; }
h2 { font-size: 15px; line-height: 24px; font-weight: 600; margin: 0 0 8px; }
h3 { font-size: 15px; line-height: 24px; font-weight: 600; margin: 0; }
p { margin: 4px 0 12px; }
.muted { color: var(--ink-2); font-size: 14px; line-height: 24px; }
.small { font-size: 13px; line-height: 24px; }
.hint { font-size: 14px; line-height: 24px; color: var(--ink-2); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.big { font-size: 28px; line-height: 36px; font-weight: 700; }

/* Test-data banner (§4.11 banner, neutral condition) with a "soon" badge */
.test-banner {
  position: sticky; top: 0; z-index: 40;
  display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap;
  background: var(--surface-2); color: var(--ink);
  border-bottom: 1px solid var(--separator);
  padding: 8px 16px; font-size: 13.5px; line-height: 24px; text-align: center;
}
.test-banner strong {
  display: inline-flex; align-items: center; border-radius: 9999px; padding: 2px 8px;
  font-size: 12.5px; line-height: 20px; font-weight: 500; background: var(--signal-soon-soft); color: var(--signal-soon);
}

/* Top bar (§7.3) and header lock-up (§1.4). The crown is not shown until the official asset is supplied. */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 56px; padding: 6px 16px;
  background: var(--surface); color: var(--ink); border-bottom: 1px solid var(--separator);
}
@media (min-width: 768px) { .topbar { min-height: 64px; } }
.brand { display: flex; min-width: 0; }
.top-tools { display: flex; align-items: center; gap: 8px; min-width: 0; }
/* Version label (§2.1): 11.5 / 20, --ink-3 */
.version { font-size: 11.5px; line-height: 20px; color: var(--ink-3); white-space: nowrap; }
.login .version { text-align: center; margin-top: 16px; }
@media (max-width: 479px) { .top-tools .brand-sub { display: none; } }
.lockup { display: inline-flex; align-items: center; gap: 11px; min-height: var(--touch); color: var(--ink); text-decoration: none; }
/* Crown sized and aligned by its visible box (x 90–1684, y 35–842 of 1774 × 887); never recoloured or cropped */
.crown { --w: 30px; position: relative; display: inline-block; flex-shrink: 0; width: var(--w); height: calc(var(--w) * 807 / 1594); }
.crown img {
  position: absolute; max-width: none;
  width: calc(var(--w) * 1774 / 1594); height: calc(var(--w) * 887 / 1594);
  left: calc(var(--w) * -90 / 1594); top: calc(var(--w) * -35 / 1594);
}
.brand-title { font-size: 14px; line-height: 24px; font-weight: 600; }
@media (min-width: 768px) {
  .crown { --w: 36px; }
  .brand-title { font-size: 15px; }
}
.login-logo { display: block; height: 72px; width: auto; max-width: 140px; margin: 0 auto 22px; }
.brand-sub { font-size: 13px; line-height: 20px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.viewas { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 16px; background: var(--selected); border-bottom: 1px solid var(--separator); font-size: 15px; }
.viewas label { font-weight: 500; }
.viewas select { flex: 1; min-width: 160px; max-width: 320px; }

.container { max-width: 980px; margin: 0 auto; padding: 16px; }

/* Cards (§4.4) */
.card { background: var(--surface); border: 1px solid var(--separator); border-radius: var(--radius-lg); padding: 16px; margin-bottom: 16px; }
.card.flat { margin-bottom: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.grid { display: grid; gap: 16px; margin-bottom: 16px; }
.grid > .card { margin-bottom: 0; }
@media (min-width: 720px) {
  .grid.two { grid-template-columns: repeat(2, 1fr); }
  .grid.three { grid-template-columns: repeat(3, 1fr); }
}

/* Buttons (§4.2): md = 44 px; small = 36 px look with a 44 px hit target (T1). Hover/press = colour only. */
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--touch); padding: 0 16px; border-radius: var(--radius-md); border: 1px solid transparent;
  font-size: 15px; font-weight: 500; line-height: 24px; user-select: none; transition: background-color 150ms, border-color 150ms, color 150ms;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 1px 0 rgb(47 58 69 / 0.06);
}
.btn:enabled:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.light {
  background: var(--surface); color: var(--ink); border-color: var(--separator-strong); box-shadow: none;
}
.btn.light:enabled:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.btn.light:enabled:active { border-color: var(--accent); background: var(--accent-press); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--accent); border-color: transparent; box-shadow: none; }
.btn.ghost:enabled:hover { background: var(--accent-soft); }
.btn.ghost:enabled:active { background: var(--accent-press); }
.btn.small { min-height: 36px; min-width: 36px; padding: 0 12px; font-size: 14px; }
.btn.small::after { content: ''; position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; transform: translate(-50%, -50%); }
.btn.block { width: 100%; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.row.between { justify-content: space-between; }
label.row { min-height: var(--touch); margin-bottom: 0; font-size: 15px; font-weight: 400; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }

/* Form fields (§4.3) */
label { font-size: 15px; line-height: 24px; font-weight: 500; color: var(--ink); }
.field { display: grid; gap: 4px; margin-bottom: 12px; }
input:not([type]), input[type=text], input[type=password], input[type=number], input[inputmode], select {
  width: 100%; min-height: var(--touch); border: 1px solid var(--separator-strong); border-radius: var(--radius-md);
  background: var(--surface); padding: 0 12px; font-size: 16px; color: var(--ink); transition: border-color 150ms;
}
input::placeholder { color: var(--ink-3); }
input:hover, select:hover { border-color: var(--ink-3); }
input:focus, select:focus { border-color: var(--accent); }
select {
  appearance: none; padding-inline-end: 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='%235B6370' 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: left 12px center;
}
.ltr { direction: ltr; text-align: left; }
.login { max-width: 400px; margin: 32px auto; padding: 24px; box-shadow: var(--shadow-pane); }
.login h1 { font-size: 24px; line-height: 32px; }
.error { color: var(--signal-overdue); font-size: 14px; line-height: 24px; }
.error::before { content: '• '; }

/* Navigation. Phone: bottom tab bar with a 3 px orange line on top of the current cell.
   Desktop: tabs with a 2 px orange underline (§4.6, §7.3). Orange is only ever this marker. */
.tabs {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 30;
  display: flex; overflow-x: auto; background: var(--surface); border-top: 1px solid var(--separator);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  position: relative; flex: 1 0 auto; min-width: 72px; min-height: 56px; border: 0; background: none;
  padding: 4px 8px; color: var(--ink-2); font-size: 11px; line-height: 16px; font-weight: 500;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  transition: background-color 150ms, color 150ms;
}
.tabs .ico svg { width: 24px; height: 24px; }
.tabs button:hover { background: var(--hover); color: var(--ink); }
.tabs button[aria-current=page] { color: var(--accent); font-weight: 600; }
.tabs button[aria-current=page]::before {
  content: ''; position: absolute; inset-inline: 20px; top: 0; height: 3px; border-radius: 9999px; background: var(--brand-orange);
}
@media (min-width: 768px) {
  body { padding-bottom: 0; }
  .tabs { position: sticky; top: 41px; bottom: auto; z-index: 30; border-top: 0; border-bottom: 1px solid var(--separator); justify-content: center; padding-bottom: 0; }
  .tabs button { flex: 0 0 auto; flex-direction: row; min-height: var(--touch); font-size: 14.5px; line-height: 24px; padding: 0 16px; }
  .tabs .ico { display: none; } /* desktop tabs are text-only (§4.6) */
  .tabs button[aria-current=page]::before { top: auto; bottom: 0; inset-inline: 8px; height: 2px; }
}

/* Level summary (summary-card number role) */
.level-hero { display: flex; gap: 16px; align-items: center; }
.level-badge {
  flex: none; min-width: 56px; min-height: 56px; display: grid; place-items: center; padding: 0 8px;
  border-radius: var(--radius-md); background: var(--accent-soft); color: var(--accent);
  font-size: 28px; line-height: 36px; font-weight: 700;
}
.level-badge.l0 { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--separator); }
.level-badge .small { font-size: 13px; font-weight: 600; }

/* Badges / chips (§4.5): always a word, never colour alone */
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; border-radius: 9999px; padding: 2px 8px;
  font-size: 12.5px; line-height: 20px; font-weight: 500; white-space: nowrap;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--separator);
}
.chip.good { background: var(--signal-done-soft); color: var(--signal-done); border-color: transparent; }
.chip.warn { background: var(--signal-soon-soft); color: var(--signal-soon); border-color: transparent; }
.chip.bad { background: var(--signal-overdue-soft); color: var(--signal-overdue); border-color: transparent; }
.chip.off { background: var(--surface-2); color: var(--ink-2); }
label.chip { min-height: var(--touch); padding: 0 12px; font-size: 14px; cursor: pointer; }

/* Progress */
.prod { padding: 8px 0; border-top: 1px solid var(--separator); }
.prod:first-of-type { border-top: 0; }
.prod-line { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 15px; line-height: 24px; }
progress { width: 100%; height: 8px; appearance: none; border: 0; border-radius: 9999px; background: var(--separator); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--separator); border-radius: 9999px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 9999px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 9999px; }
progress.done::-webkit-progress-value { background: var(--signal-done); }
progress.done::-moz-progress-bar { background: var(--signal-done); }

.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 0; font-size: 14px; line-height: 24px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; font-weight: 500; text-align: end; }

/* Quantity steppers: every button is 44 × 44 */
.qty-list { display: grid; gap: 0; }
.qty { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--separator); }
.qty .name { font-size: 15px; font-weight: 500; }
.qty .price { font-size: 13px; line-height: 20px; color: var(--ink-2); }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--separator-strong); border-radius: var(--radius-md); overflow: hidden; background: var(--surface); }
.stepper button { width: var(--touch); height: var(--touch); border: 0; background: var(--surface); color: var(--accent); display: grid; place-items: center; transition: background-color 150ms; }
.stepper button:hover { background: var(--accent-soft); }
.stepper button:active { background: var(--accent-press); }
.stepper input { width: 80px; border: 0; border-radius: 0; text-align: center; padding: 0 4px; }

.proposal ul { padding-inline-start: 18px; margin: 4px 0 8px; font-size: 14px; }
.proposal .explain { background: var(--surface-2); border: 1px solid var(--separator); border-radius: var(--radius-md); padding: 8px 12px; font-size: 14px; line-height: 24px; }

/* Tables (§4.7, table inside content): scroll in their own frame */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 24px; }
th, td { padding: 0.3em 0.65em; border: 1px solid var(--separator-strong); text-align: start; vertical-align: top; }
th { background: #eef2f7; font-weight: 600; white-space: nowrap; }
td.n, th.n { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.loss td { background: var(--signal-overdue-soft); }
tr.flagged td { background: var(--signal-soon-soft); }
td input { min-width: 80px; }

/* Notes (§4.4): quiet note and caution note */
.notice {
  border-radius: var(--radius-md); padding: 10px 14px; margin-bottom: 16px; font-size: 14px; line-height: 24px;
  background: var(--signal-soon-soft); color: var(--ink); border: 1px solid rgb(154 61 6 / 0.4);
}
.notice.info { background: var(--surface-2); border-color: var(--separator-strong); font-size: 15px; line-height: 28px; padding: 12px 16px; }
.notice.bad { background: var(--signal-overdue-soft); border-color: rgb(180 35 24 / 0.4); }

/* Disclosure (§4.13) */
details { border-top: 1px solid var(--separator); padding-top: 8px; margin-bottom: 12px; }
details summary { min-height: var(--touch); display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; color: var(--accent); }
.card > details { border: 0; border-top: 1px solid var(--separator); }

/* Toast (§4.11, info kind) */
.toast {
  position: fixed; bottom: calc(env(safe-area-inset-bottom) + 5rem); inset-inline: 16px; z-index: 100; margin: 0 auto; max-width: 28rem;
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--separator-strong); border-radius: var(--radius-md);
  font-size: 15px; line-height: 24px; box-shadow: 0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1);
}
.toast .ico { color: var(--accent); }
.toast .ico svg { width: 22px; height: 22px; }
@media (min-width: 768px) { .toast { bottom: 24px; } }

.empty { text-align: center; color: var(--ink-2); padding: 64px 24px; font-size: 15px; }
.spinner { text-align: center; padding: 32px; color: var(--ink-2); font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
