/* YA Market OS v2 — design system (RTL, Arabic-first) */

:root {
  --navy: #10284F;
  --navy-2: #0B1C38;
  --gold: #C4A15A;
  --gold-soft: #F8F3E6;
  --bg: #F3F6FB;
  --surface: #fff;
  --surface-2: #F8FAFD;
  --ink: #10284F;
  --ink-2: #5B6B85;
  --line: #E3E8F1;
  --ok: #1E8E5A;
  --danger: #D64545;
  --warn: #D28A1E;
  --info: #2E6FD1;
  /* text-safe variants: the base status colors are below 4.5:1 on white */
  --ok-ink: #177347;
  --danger-ink: #B83232;
  --warn-ink: #8F5500;
  --info-ink: #2A62B8;
  --ok-soft: #E7F5EE;
  --danger-soft: #FCECEC;
  --warn-soft: #FCF3E4;
  --info-soft: #EAF1FC;
  --shopee: #EE4D2D;
  --tt-ink: #161823;
  --tt-cyan: #25F4EE;
  --tt-red: #FE2C55;

  --s0: #2E6FD1; --s1: #1E8E5A; --s2: #8E44AD; --s3: #D28A1E;
  --s4: #0FA3B1; --s5: #C0392B; --s6: #6D4C41; --s7: #3949AB;

  --primary: var(--navy);
  --primary-hover: #1A3A6E;
  --on-primary: #fff;

  --font: 'Cairo', system-ui, 'Segoe UI', Tahoma, sans-serif;
  --fs-12: 12px; --fs-13: 13px; --fs-14: 14px; --fs-16: 16px;
  --fs-20: 20px; --fs-24: 24px; --fs-32: 32px;

  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;

  --r-input: 8px; --r-card: 14px; --r-pill: 999px;

  --sh-1: 0 1px 2px rgba(16, 40, 79, .06), 0 2px 8px rgba(16, 40, 79, .05);
  --sh-2: 0 2px 4px rgba(16, 40, 79, .07), 0 8px 24px rgba(16, 40, 79, .08);
  --sh-float: 0 8px 16px rgba(11, 28, 56, .14), 0 24px 64px rgba(11, 28, 56, .22);

  --t-press: 120ms; --t-ui: 180ms; --t-enter: 260ms; --t-count: 400ms;
  --ease: cubic-bezier(.2, .8, .2, 1);

  --topbar-h: 64px;
  --strip-h: 56px;
  --assist-h: 56px;
  --tabs-h: 64px;

  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0B1220;
  --surface: #121B2E;
  --surface-2: #17223A;
  --ink: #E8EDF6;
  --ink-2: #9AA8C2;
  --line: #22304A;
  --gold-soft: #2A2518;
  --ok-ink: #5FD39A;
  --danger-ink: #FF8C8C;
  --warn-ink: #F0B45A;
  --info-ink: #86B2FF;
  --ok-soft: #13301F;
  --danger-soft: #3A1A1D;
  --warn-soft: #362812;
  --info-soft: #152A4A;
  --primary: #3B5B9A;
  --primary-hover: #4A6CAE;
  --sh-1: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 8px rgba(0, 0, 0, .25);
  --sh-2: 0 2px 4px rgba(0, 0, 0, .35), 0 8px 24px rgba(0, 0, 0, .3);
  --sh-float: 0 8px 16px rgba(0, 0, 0, .4), 0 24px 64px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-14);
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--info-ink); }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; font-weight: 800; }
h1 { font-size: var(--fs-24); }
h2 { font-size: var(--fs-20); }
h3 { font-size: var(--fs-16); }
p { margin: 0; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.num, .tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.small { font-size: var(--fs-12); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.ico { width: 20px; height: 20px; flex: none; }
.ico svg { width: 100%; height: 100%; }
.row { display: flex; align-items: center; gap: var(--sp-2); }
.row-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: var(--sp-3); }
.grid { display: grid; gap: var(--sp-4); }
.grid-2 { display: grid; gap: var(--sp-4); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-4 { display: grid; gap: var(--sp-4); grid-template-columns: repeat(4, minmax(0, 1fr)); }
.section-title { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.section-title h2, .section-title h3 { flex: 1; }

/* ---------- buttons ---------- */
.btn {
  --btn-bg: var(--primary);
  --btn-fg: var(--on-primary);
  --btn-bd: transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 44px; padding: 0 var(--sp-4);
  border: 1px solid var(--btn-bd); border-radius: var(--r-input);
  background: var(--btn-bg); color: var(--btn-fg);
  font-weight: 600; font-size: var(--fs-14); line-height: 1;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background var(--t-ui) var(--ease), border-color var(--t-ui) var(--ease),
    transform var(--t-press) var(--ease), box-shadow var(--t-ui) var(--ease);
}
.btn:hover { --btn-bg: var(--primary-hover); }
.btn:active { transform: scale(.98); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn.is-loading { position: relative; color: transparent; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--btn-fg); border-inline-end-color: transparent;
  animation: spin .7s linear infinite;
}
.btn.is-error { box-shadow: 0 0 0 2px var(--danger); }
.btn-gold { --btn-bg: var(--surface); --btn-fg: var(--ink); --btn-bd: var(--gold); }
.btn-gold:hover { --btn-bg: var(--gold-soft); }
.btn-danger { --btn-bg: var(--danger-ink); --btn-fg: #fff; }
.btn-danger:hover { --btn-bg: #9E2626; }
[data-theme="dark"] .btn-danger { --btn-bg: #C23B3B; }
.btn-ghost { --btn-bg: transparent; --btn-fg: var(--ink); }
.btn-ghost:hover { --btn-bg: var(--surface-2); }
.btn-sm { min-height: 36px; padding: 0 var(--sp-3); font-size: var(--fs-13); }
.btn-icon { width: 44px; padding: 0; }
.btn-block { width: 100%; }

/* ---------- badges / chips / status ---------- */
.badge {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  min-height: 22px; padding: 0 var(--sp-2);
  border-radius: var(--r-pill); font-size: var(--fs-12); font-weight: 600;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.badge-ok { background: var(--ok-soft); color: var(--ok-ink); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger-ink); border-color: transparent; }
.badge-warn { background: var(--warn-soft); color: var(--warn-ink); border-color: transparent; }
.badge-info { background: var(--info-soft); color: var(--info-ink); border-color: transparent; }
.badge-gold { background: var(--gold-soft); color: var(--ink); border-color: var(--gold); }

.pbadge {
  position: relative; display: inline-grid; place-items: center;
  width: 20px; height: 20px; border-radius: 6px; flex: none;
  font-size: 11px; font-weight: 800; line-height: 1; color: #fff;
}
.pbadge.shopee { background: var(--shopee); }
.pbadge.tiktok { background: var(--tt-ink); overflow: hidden; }
.pbadge.tiktok::after {
  content: ""; position: absolute; inset-inline: 3px; bottom: 3px; height: 2px;
  background: linear-gradient(90deg, var(--tt-cyan) 0 50%, var(--tt-red) 50% 100%);
}
[data-theme="dark"] .pbadge.tiktok { box-shadow: 0 0 0 1px #33384A; }

.chip {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  min-height: 44px; padding: 0 var(--sp-3);
  border: 1px solid var(--line); border-radius: var(--r-input);
  background: var(--surface); color: var(--ink);
  font-weight: 600; cursor: pointer; white-space: nowrap; position: relative;
  transition: border-color var(--t-ui) var(--ease), background var(--t-ui) var(--ease), transform var(--t-press) var(--ease);
}
.chip:hover { background: var(--surface-2); }
.chip:active { transform: scale(.98); }
.chip:disabled { opacity: .5; cursor: not-allowed; }
.chip[aria-pressed="true"] { border-bottom: 3px solid var(--gold); background: var(--gold-soft); }
.chip .stripe-l {
  position: absolute; left: 0; top: 6px; bottom: 6px; width: 4px;
  border-radius: 0 4px 4px 0; background: var(--chip-color, var(--line));
}
.chip .cnt {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-pill);
  font-size: 11px; line-height: 18px; text-align: center; color: #fff;
  font-variant-numeric: tabular-nums;
}
.chip .cnt-urgent { background: var(--danger-ink); }
.chip .cnt-unread { background: var(--info-ink); }
[data-theme="dark"] .chip .cnt-urgent { background: #C23B3B; }
[data-theme="dark"] .chip .cnt-unread { background: #2E6FD1; }
.chip .relink-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--warn);
  box-shadow: 0 0 0 2px var(--warn-soft);
}

.status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-13); font-weight: 600; color: var(--ink-2); white-space: nowrap;
}
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.status-ok { color: var(--ok-ink); }
.status-danger { color: var(--danger-ink); }
.status-warn { color: var(--warn-ink); }
.status-info { color: var(--info-ink); }

.kbd {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px;
  background: var(--surface-2); color: var(--ink-2);
  font-family: ui-monospace, Consolas, monospace; font-size: var(--fs-12);
}

/* ---------- cards / tiles ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-card); box-shadow: var(--sh-1); padding: var(--sp-4);
  position: relative;
}
.card.is-clickable { cursor: pointer; transition: box-shadow var(--t-ui) var(--ease), transform var(--t-press) var(--ease); }
.card.is-clickable:hover { box-shadow: var(--sh-2); }
.card.is-clickable:active { transform: scale(.98); }
.card.is-error { border-color: var(--danger); }
.card.is-loading { pointer-events: none; }
.card.has-stripe { padding-inline-start: calc(var(--sp-4) + 4px); overflow: hidden; }
.card.has-stripe::before {
  content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 4px;
  background: var(--row-color, var(--line));
}
.card-head { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.card-head h3 { flex: 1; }

.tile {
  display: flex; flex-direction: column; justify-content: space-between;
  height: 140px; padding: var(--sp-4);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-card); box-shadow: var(--sh-1);
  text-align: start; color: var(--ink); position: relative; overflow: hidden;
}
button.tile, a.tile { cursor: pointer; text-decoration: none; transition: box-shadow var(--t-ui) var(--ease), transform var(--t-press) var(--ease); }
button.tile:hover, a.tile:hover { box-shadow: var(--sh-2); }
button.tile:active, a.tile:active { transform: scale(.98); }
.tile:disabled { opacity: .5; cursor: not-allowed; }
.tile-label { font-size: var(--fs-13); color: var(--ink-2); font-weight: 600; }
.tile-value { font-size: var(--fs-32); font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile-delta { font-size: var(--fs-12); font-weight: 600; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.tile-delta.up { color: var(--ok-ink); }
.tile-delta.down { color: var(--danger-ink); }
.tile-spark { position: absolute; inset-inline: 0; bottom: 0; height: 36px; opacity: .5; pointer-events: none; }
.tile.is-danger .tile-value { color: var(--danger-ink); }
.tile.is-error { border-color: var(--danger); }

.delta { font-size: var(--fs-12); font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.delta.up { color: var(--ok-ink); }
.delta.down { color: var(--danger-ink); }

.progress { height: 10px; border-radius: var(--r-pill); background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.progress > span {
  display: block; height: 100%; background: var(--gold); border-radius: inherit;
  transition: width var(--t-count) var(--ease);
}
.progress.is-behind > span { background: var(--warn); }
.progress.is-done > span { background: var(--ok); }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field-label { font-size: var(--fs-13); font-weight: 600; color: var(--ink); }
.field-msg { font-size: var(--fs-12); color: var(--ink-2); min-height: 1.4em; }
.field.is-error .field-msg, .field-msg.is-error { color: var(--danger-ink); }
.field.is-warn .field-msg, .field-msg.is-warn { color: var(--warn-ink); }
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: 0 var(--sp-3);
  border: 1px solid var(--line); border-radius: var(--r-input);
  background: var(--surface); color: var(--ink);
  transition: border-color var(--t-ui) var(--ease), box-shadow var(--t-ui) var(--ease);
}
.textarea { padding: var(--sp-2) var(--sp-3); min-height: 96px; resize: vertical; line-height: 1.6; }
.select { appearance: none; padding-inline-end: var(--sp-3); padding-inline-start: 32px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: 14px 50%, 19px 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.input:hover, .select:hover, .textarea:hover { border-color: #C9D2E1; }
[data-theme="dark"] .input:hover, [data-theme="dark"] .select:hover, [data-theme="dark"] .textarea:hover { border-color: #33466A; }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible {
  outline: none; border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold);
}
.input:disabled, .select:disabled, .textarea:disabled { opacity: .55; cursor: not-allowed; background: var(--surface-2); }
.field.is-error .input, .field.is-error .select, .field.is-error .textarea, .input.is-error { border-color: var(--danger); }
.input.is-loading {
  background-image: linear-gradient(90deg, transparent, var(--gold-soft), transparent);
  background-size: 200% 100%; animation: shimmer 1.2s linear infinite;
}
.input::placeholder, .textarea::placeholder { color: var(--ink-2); opacity: .85; }
.checkbox { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }

/* ---------- table ---------- */
.table-wrap {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card);
  box-shadow: var(--sh-1); overflow: auto; max-height: calc(100vh - 220px);
}
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; }
.table th, .table td {
  height: 48px; padding: 0 var(--sp-3); text-align: start; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.table thead th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2);
  font-size: var(--fs-12); font-weight: 600; color: var(--ink-2);
}
.table tbody tr { position: relative; cursor: pointer; transition: background var(--t-ui) var(--ease); }
.table tbody tr > :first-child { box-shadow: inset -4px 0 0 var(--row-color, transparent); }
[dir="ltr"] .table tbody tr > :first-child { box-shadow: inset 4px 0 0 var(--row-color, transparent); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr.is-selected { background: var(--gold-soft); }
.table tbody tr:focus, .table tbody tr.row-focus { outline: 2px solid var(--gold); outline-offset: -2px; }
.table tbody tr.is-disabled { opacity: .5; cursor: default; }
.table td.sel, .table th.sel { width: 44px; text-align: center; }
.table td.num, .table th.num { text-align: end; }
.table tbody tr.urgent > td:first-child { box-shadow: inset -4px 0 0 var(--danger); }
.table-empty { padding: var(--sp-6); }

/* ---------- countdown / urgency ---------- */
.countdown {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 0 var(--sp-2); min-height: 24px; border-radius: var(--r-pill);
  font-size: var(--fs-12); font-weight: 600; font-variant-numeric: tabular-nums;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.countdown.is-danger { background: var(--danger-soft); color: var(--danger-ink); border-color: transparent; }
.countdown.is-overdue { background: #B83232; color: #fff; border-color: transparent; }
.urgent { box-shadow: 0 0 0 1px var(--danger); animation: pulse-border 2s ease-in-out infinite; }
.urgent.urgent-fast { animation-duration: .9s; }
tr.urgent { box-shadow: none; outline: 1px solid var(--danger); outline-offset: -1px; animation: pulse-outline 2s ease-in-out infinite; }
tr.urgent.urgent-fast { animation-duration: .9s; }

/* ---------- empty / skeleton / locked / suggest ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-3); padding: var(--sp-7) var(--sp-4); text-align: center; color: var(--ink-2);
}
.empty svg { width: 120px; height: 90px; color: var(--ink-2); opacity: .7; }
.empty p { font-size: var(--fs-16); color: var(--ink); font-weight: 600; max-width: 40ch; }

.skeleton { display: flex; flex-direction: column; gap: var(--sp-2); }
.sk {
  border-radius: var(--r-input); min-height: 14px;
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--line) 50%, var(--surface-2) 100%);
  background-size: 200% 100%; animation: shimmer 1.2s linear infinite;
}
.sk-row { height: 48px; }
.sk-tile { height: 140px; border-radius: var(--r-card); }
.sk-card { height: 120px; border-radius: var(--r-card); }
.sk-line { height: 14px; }

.locked {
  display: flex; align-items: flex-start; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4); border-radius: var(--r-input);
  background: var(--warn-soft); color: var(--warn-ink);
  border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  font-weight: 600; font-size: var(--fs-13);
}
.locked .ico { margin-top: 2px; }

.suggest {
  display: flex; flex-direction: column; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4); border-radius: var(--r-card);
  background: var(--gold-soft); border: 1px solid var(--gold); color: var(--ink);
}
.suggest-head { display: flex; align-items: center; gap: var(--sp-2); }
.suggest-head::before {
  content: "اقتراح"; font-size: var(--fs-12); font-weight: 800; padding: 0 var(--sp-2);
  border-radius: var(--r-pill); background: var(--gold); color: var(--navy-2);
}
.suggest-actions { display: flex; gap: var(--sp-2); }
.suggest.is-dismissed { display: none; }

.error-box {
  padding: var(--sp-3) var(--sp-4); border-radius: var(--r-input);
  background: var(--danger-soft); color: var(--danger-ink); font-weight: 600;
}
.warn-text { color: var(--warn-ink); }
.danger-text { color: var(--danger-ink); }
.ok-text { color: var(--ok-ink); }

/* ---------- app shell ---------- */
.app-body { min-height: 100vh; }
.topbar {
  position: fixed; inset-inline: 0; top: 0; z-index: 40; height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-4);
  background: var(--navy-2); color: #fff; box-shadow: var(--sh-1);
}
.topbar .brand { display: flex; align-items: center; gap: var(--sp-2); text-decoration: none; color: #fff; }
.topbar .brand img { height: 44px; width: 44px; object-fit: cover; border-radius: 10px; }
.topbar .brand span { font-size: var(--fs-12); color: #D9C79A; font-weight: 600; }
.topbar .btn-ghost { --btn-fg: #fff; }
.topbar .btn-ghost:hover { --btn-bg: rgba(255, 255, 255, .08); }
.gsearch { position: relative; flex: 1; max-width: 640px; margin-inline: auto; }
.gsearch .input {
  background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .14); color: #fff;
  padding-inline-start: 40px;
}
.gsearch .input::placeholder { color: #B7C3D8; }
.gsearch > .ico { position: absolute; inset-inline-start: 12px; top: 12px; color: #B7C3D8; pointer-events: none; }
.gsearch-results {
  position: absolute; top: calc(100% + 6px); inset-inline: 0; z-index: 60;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--r-card); box-shadow: var(--sh-float);
  max-height: 60vh; overflow: auto; padding: var(--sp-1);
}
.gsearch-results[hidden] { display: none; }
.sr-item {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%;
  min-height: 48px; padding: var(--sp-2) var(--sp-3); border: 0; border-radius: var(--r-input);
  background: transparent; text-align: start; cursor: pointer; position: relative;
  box-shadow: inset -4px 0 0 var(--row-color, transparent);
}
.sr-item:hover, .sr-item[aria-selected="true"] { background: var(--surface-2); }
.sr-item .t { font-weight: 600; }
.sr-item .s { font-size: var(--fs-12); color: var(--ink-2); }
.sr-empty { padding: var(--sp-4); color: var(--ink-2); text-align: center; }

.menu {
  position: absolute; top: calc(100% + 6px); inset-inline-end: 0; z-index: 60; min-width: 240px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--r-card); box-shadow: var(--sh-float); padding: var(--sp-2);
}
.menu[hidden] { display: none; }
.menu-head { padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--line); margin-bottom: var(--sp-1); }
.menu-head .email { font-weight: 600; word-break: break-all; }
.menu-item {
  display: flex; align-items: center; gap: var(--sp-2); width: 100%; min-height: 44px;
  padding: 0 var(--sp-3); border: 0; border-radius: var(--r-input); background: transparent;
  cursor: pointer; text-align: start;
}
.menu-item:hover { background: var(--surface-2); }
.menu-item.danger { color: var(--danger-ink); }
.acct { position: relative; }

.strip {
  position: sticky; top: var(--topbar-h); z-index: 30; height: var(--strip-h);
  display: flex; align-items: center; gap: var(--sp-2); padding: 0 var(--sp-4);
  background: var(--surface); border-bottom: 1px solid var(--line);
  overflow-x: auto; overflow-y: hidden; scrollbar-width: thin;
}
.strip .chip { min-height: 40px; }
.strip .chip.is-relink { border-style: dashed; }

.shell { padding-top: var(--topbar-h); }
.layout {
  display: grid; grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 0; min-height: calc(100vh - var(--topbar-h) - var(--strip-h));
}
.sidenav {
  grid-column: span 2; position: sticky; top: calc(var(--topbar-h) + var(--strip-h));
  align-self: start; height: calc(100vh - var(--topbar-h) - var(--strip-h));
  overflow-y: auto; padding: var(--sp-3); border-inline-end: 1px solid var(--line);
  background: var(--surface);
}
.nav-link {
  display: flex; align-items: center; gap: var(--sp-3); min-height: 44px;
  padding: 0 var(--sp-3); margin-bottom: 2px; border-radius: var(--r-input);
  color: var(--ink-2); text-decoration: none; font-weight: 600;
  transition: background var(--t-ui) var(--ease), color var(--t-ui) var(--ease);
  position: relative;
}
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link[aria-current="page"] { background: var(--gold-soft); color: var(--ink); }
.nav-link[aria-current="page"]::before {
  content: ""; position: absolute; inset-inline-start: 0; top: 10px; bottom: 10px; width: 3px;
  border-radius: 3px; background: var(--gold);
}
.nav-sep { height: 1px; background: var(--line); margin: var(--sp-2) 0; }

.main {
  grid-column: span 10; min-width: 0;
  padding: var(--sp-5) var(--sp-5) calc(var(--assist-h) + var(--sp-7));
}
#view { min-height: 60vh; }
.view-enter { animation: slide-in var(--t-enter) var(--ease) both; }

.tabbar { display: none; }

/* ---------- drawer ---------- */
.drawer {
  position: fixed; top: var(--topbar-h); bottom: 0; inset-inline-start: 0; z-index: 50;
  width: 40%; min-width: 420px; max-width: 760px;
  background: var(--surface); border-inline-end: 1px solid var(--line); box-shadow: var(--sh-float);
  display: flex; flex-direction: column;
  transform: translateX(100%); visibility: hidden;
  transition: transform var(--t-enter) var(--ease), visibility 0s linear var(--t-enter);
}
[dir="ltr"] .drawer { transform: translateX(-100%); }
.drawer.is-open { transform: none; visibility: visible; transition: transform var(--t-enter) var(--ease); }
.drawer-head {
  display: flex; align-items: center; gap: var(--sp-2); min-height: 56px;
  padding: 0 var(--sp-3) 0 var(--sp-4); border-bottom: 1px solid var(--line);
}
.drawer-head h2 { flex: 1; font-size: var(--fs-16); }
.drawer-body { flex: 1; overflow: auto; padding: var(--sp-4); }
.drawer-foot { padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--line); display: flex; gap: var(--sp-2); }

/* ---------- sheet / modal ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 70; background: rgba(8, 16, 32, .5);
  animation: fade-in var(--t-ui) var(--ease) both;
}
.sheet {
  position: fixed; bottom: 0; left: 50%; z-index: 71;
  width: min(680px, 100%); max-height: 88vh; overflow: auto;
  transform: translateX(-50%);
  background: var(--surface); color: var(--ink);
  border-radius: var(--r-card) var(--r-card) 0 0; box-shadow: var(--sh-float);
  padding: var(--sp-5); animation: sheet-up var(--t-enter) var(--ease) both;
}
.sheet::before {
  content: ""; display: block; width: 40px; height: 4px; border-radius: 4px;
  background: var(--line); margin: calc(-1 * var(--sp-3)) auto var(--sp-4);
}
.sheet-head { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.sheet-head h2 { flex: 1; font-size: var(--fs-20); }
.sheet-actions { display: flex; gap: var(--sp-2); justify-content: flex-end; margin-top: var(--sp-5); flex-wrap: wrap; }
.sheet .kv { display: grid; grid-template-columns: auto 1fr; gap: var(--sp-2) var(--sp-4); }
.sheet .kv dt { color: var(--ink-2); font-size: var(--fs-13); }
.sheet .kv dd { margin: 0; font-weight: 600; }
.sheet ul { margin: 0; padding-inline-start: var(--sp-5); }
.ba-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.ba-table th, .ba-table td { padding: var(--sp-2) var(--sp-3); border: 1px solid var(--line); text-align: start; vertical-align: top; }
.ba-table th { background: var(--surface-2); font-size: var(--fs-12); color: var(--ink-2); }
.ba-table td.after { background: var(--gold-soft); font-weight: 600; }
.warnings { color: var(--warn-ink); font-weight: 600; }

.modal {
  position: fixed; top: 12vh; left: 50%; z-index: 71; transform: translateX(-50%);
  width: min(580px, calc(100% - 24px)); max-height: 72vh; display: flex; flex-direction: column;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--r-card); box-shadow: var(--sh-float); overflow: hidden;
  animation: fade-in var(--t-ui) var(--ease) both;
}
.modal .input { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; min-height: 56px; font-size: var(--fs-16); padding: 0 var(--sp-4); }
.modal .input:focus-visible { box-shadow: none; border-color: var(--gold); }
.modal-list { overflow: auto; padding: var(--sp-2); }
.modal-foot { padding: var(--sp-2) var(--sp-4); border-top: 1px solid var(--line); font-size: var(--fs-12); color: var(--ink-2); display: flex; gap: var(--sp-3); flex-wrap: wrap; }
.pal-item {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%; min-height: 44px;
  padding: 0 var(--sp-3); border: 0; border-radius: var(--r-input); background: transparent;
  text-align: start; cursor: pointer; position: relative;
  box-shadow: inset -4px 0 0 var(--row-color, transparent);
}
.pal-item[aria-selected="true"], .pal-item:hover { background: var(--gold-soft); }
.pal-item .hint { margin-inline-start: auto; font-size: var(--fs-12); color: var(--ink-2); }
.pal-group { font-size: var(--fs-12); color: var(--ink-2); padding: var(--sp-2) var(--sp-3) var(--sp-1); font-weight: 600; }

.popover {
  position: fixed; bottom: calc(var(--assist-h) + 28px); left: 16px; z-index: 65; width: 300px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card);
  box-shadow: var(--sh-float); padding: var(--sp-4);
  animation: fade-in var(--t-ui) var(--ease) both;
}
.popover[hidden] { display: none; }
.shortcut-list { display: grid; grid-template-columns: auto 1fr; gap: var(--sp-2) var(--sp-3); align-items: center; margin-top: var(--sp-3); }

/* ---------- assistant ---------- */
.assist {
  position: fixed; z-index: 45; bottom: 12px; left: 16px;
  right: calc(100% / 12 * 2 + 16px);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-card); box-shadow: var(--sh-2);
  transition: box-shadow var(--t-ui) var(--ease);
}
.assist-bar { display: flex; align-items: center; gap: var(--sp-2); height: var(--assist-h); padding: 0 var(--sp-2) 0 var(--sp-3); }
.assist-bar .ico { color: var(--gold); }
.assist-bar .input { border: 0; background: transparent; min-height: 44px; }
.assist-bar .input:focus-visible { box-shadow: none; }
.assist-body { display: none; max-height: 50vh; overflow: auto; padding: 0 var(--sp-4) var(--sp-4); border-top: 1px solid var(--line); }
.assist.is-open { box-shadow: var(--sh-float); }
.assist.is-open .assist-body { display: block; animation: fade-in var(--t-ui) var(--ease) both; }
.assist-reply { padding-top: var(--sp-3); white-space: pre-wrap; }
.task-card {
  display: grid; grid-template-columns: 1fr auto; gap: var(--sp-2) var(--sp-3); align-items: center;
  margin-top: var(--sp-3); padding: var(--sp-3); border: 1px solid var(--line);
  border-radius: var(--r-input); background: var(--surface-2);
  box-shadow: inset -4px 0 0 var(--row-color, var(--line));
}
.task-card .meta { font-size: var(--fs-12); color: var(--ink-2); }

/* ---------- toast ---------- */
.toasts {
  position: fixed; left: 16px; bottom: calc(var(--assist-h) + 28px); z-index: 90;
  display: flex; flex-direction: column-reverse; gap: var(--sp-2); width: min(360px, calc(100% - 32px));
  pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-input); background: var(--navy-2); color: #fff;
  box-shadow: var(--sh-float); font-weight: 600; pointer-events: auto;
  border-inline-start: 4px solid var(--info);
  animation: toast-in var(--t-enter) var(--ease) both;
}
.toast.success { border-inline-start-color: var(--ok); animation: toast-in var(--t-enter) var(--ease) both, shake 360ms var(--ease) var(--t-enter) 1; }
.toast.error { border-inline-start-color: var(--danger); }
.toast.warn { border-inline-start-color: var(--warn); }
.toast.is-leaving { opacity: 0; transform: translateY(8px); transition: opacity var(--t-ui) var(--ease), transform var(--t-ui) var(--ease); }
.toast span { flex: 1; }

/* ---------- boot / tour ---------- */
.boot-sk { width: min(480px, 90vw); }
.boot { display: grid; place-items: center; min-height: 60vh; gap: var(--sp-3); color: var(--ink-2); }
.tourbar {
  position: fixed; z-index: 66; top: calc(var(--topbar-h) + var(--strip-h) + 12px); left: 50%;
  transform: translateX(-50%); width: min(560px, calc(100% - 24px));
  display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3);
  background: var(--navy-2); color: #fff; border-radius: var(--r-card); box-shadow: var(--sh-float);
  border-bottom: 3px solid var(--gold); animation: fade-in var(--t-ui) var(--ease) both;
}
.tourbar .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.tourbar .btn-ghost { --btn-fg: #fff; }
.tourbar .btn-ghost:hover { --btn-bg: rgba(255, 255, 255, .1); }

/* ---------- page / view building blocks ---------- */
.page-head { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.page-head h1 { margin-inline-end: var(--sp-1); }
#view > div > * + * { margin-top: var(--sp-5); }
#view > div > .page-head + * { margin-top: 0; }
.today-grid { display: grid; gap: var(--sp-4); grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
.todo-title { display: block; margin-top: var(--sp-2); }
.stat { display: flex; flex-direction: column; gap: 2px; padding-bottom: var(--sp-3); border-bottom: 1px solid var(--line); }
.stat:last-child { border-bottom: 0; padding-bottom: 0; }
.stat-label { font-size: var(--fs-12); color: var(--ink-2); font-weight: 600; }
.stat-value { font-size: var(--fs-24); font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; }
.goal-meta { margin-top: var(--sp-2); }
.store-grid { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.store-card { display: flex; flex-direction: column; gap: var(--sp-2); width: 100%; text-align: start; font: inherit; color: inherit; }
.store-stats { display: flex; flex-wrap: wrap; gap: var(--sp-3); font-size: var(--fs-13); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.store-stats b { color: var(--ink); font-weight: 800; }
.timeline { list-style: none; margin: 0; padding: 0; }
.tl-item {
  display: flex; align-items: center; gap: var(--sp-2); min-height: 44px; padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--line); box-shadow: inset -3px 0 0 var(--row-color, transparent);
}
.tl-item:last-child { border-bottom: 0; }
.tl-time { font-size: var(--fs-12); color: var(--ink-2); font-variant-numeric: tabular-nums; min-width: 52px; }
.tl-shop { font-size: var(--fs-12); font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.tl-text { flex: 1; min-width: 0; }
.tl-empty { padding: var(--sp-4); text-align: center; }
.tl-filters .select { min-width: 140px; }
@media (max-width: 1100px) { .today-grid { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 719px) {
  .tl-filters { flex-wrap: wrap; width: 100%; }
  .tl-filters .select { flex: 1; min-width: 0; }
  .card-head { flex-wrap: wrap; }
}

/* ---------- motion helpers ---------- */
.enter { animation: rise var(--t-enter) var(--ease) both; animation-delay: calc(var(--i, 0) * 40ms); }
.live-new { animation: live-bg 2s ease-out both, drop-in var(--t-enter) var(--ease) both; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes drop-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
@keyframes slide-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes sheet-up { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes shake { 0%, 100% { transform: none; } 25% { transform: translateX(-4px); } 50% { transform: translateX(3px); } 75% { transform: translateX(-2px); } }
@keyframes live-bg { from { background-color: var(--gold-soft); } to { background-color: transparent; } }
@keyframes pulse-border {
  0%, 100% { box-shadow: 0 0 0 1px var(--danger); }
  50% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 45%, transparent); }
}
@keyframes pulse-outline {
  0%, 100% { outline-color: var(--danger); }
  50% { outline-color: color-mix(in srgb, var(--danger) 30%, transparent); }
}
[dir="ltr"] .view-enter { animation-name: slide-in-ltr; }
@keyframes slide-in-ltr { from { opacity: 0; transform: translateX(-16px); } to { opacity: 1; transform: none; } }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .sidenav { grid-column: auto; width: 72px; padding: var(--sp-2); }
  .sidenav .nav-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .nav-link { justify-content: center; padding: 0; }
  .layout { grid-template-columns: 72px minmax(0, 1fr); }
  .main { grid-column: auto; padding: var(--sp-4) var(--sp-4) calc(var(--assist-h) + var(--sp-7)); }
  .assist { right: 88px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar .brand span { display: none; }
}

@media (max-width: 719px) {
  :root { --topbar-h: 56px; }
  .topbar { gap: var(--sp-2); padding: 0 var(--sp-2); }
  .topbar .brand img { height: 40px; width: 40px; }
  .gsearch .input { padding-inline-start: 36px; }
  .gsearch .kbd-hint { display: none; }
  .layout { display: block; }
  .sidenav { display: none; }
  .main { padding: var(--sp-3) var(--sp-3) calc(var(--tabs-h) + var(--assist-h) + var(--sp-6)); }
  .strip { padding: 0 var(--sp-2); }
  .grid-2, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .grid-4.keep-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tabbar {
    display: flex; position: fixed; inset-inline: 0; bottom: 0; z-index: 46; height: var(--tabs-h);
    background: var(--surface); border-top: 1px solid var(--line); box-shadow: var(--sh-2);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tab {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 44px; border: 0; background: transparent; color: var(--ink-2); text-decoration: none;
    font-size: 11px; font-weight: 600; cursor: pointer;
  }
  .tab[aria-current="page"] { color: var(--ink); box-shadow: inset 0 3px 0 var(--gold); }
  .assist { left: 8px; right: 8px; bottom: calc(var(--tabs-h) + 8px); }
  .toasts { bottom: calc(var(--tabs-h) + var(--assist-h) + 24px); left: 8px; }
  .popover { bottom: calc(var(--tabs-h) + var(--assist-h) + 24px); left: 8px; }
  .drawer { top: 0; width: 100%; min-width: 0; max-width: none; z-index: 80; }
  .sheet { padding: var(--sp-4); }
  .tile { height: 120px; }
  .tile-value { font-size: var(--fs-24); }
  .card-hide-sm { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- login / public pages ---------- */
.public {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: var(--sp-6) var(--sp-4); color: #fff;
  background:
    radial-gradient(600px 380px at 50% 18%, rgba(196, 161, 90, .22), transparent 70%),
    linear-gradient(160deg, #0B1C38 0%, #10284F 100%);
}
.public .logo {
  width: 132px; height: 132px; object-fit: cover; border-radius: 28px;
  box-shadow: 0 0 0 1px rgba(196, 161, 90, .4), 0 12px 48px rgba(196, 161, 90, .25);
  animation: rise 600ms var(--ease) both;
}
.public .tagline { margin-top: var(--sp-4); font-size: var(--fs-24); font-weight: 800; color: #E9D7A8; }
.public .sub { margin-top: var(--sp-1); color: #C6D1E4; text-align: center; }
.login-card {
  width: min(400px, 100%); margin-top: var(--sp-5); padding: var(--sp-5);
  background: #fff; color: #10284F; border-radius: var(--r-card); box-shadow: var(--sh-float);
  display: flex; flex-direction: column; gap: var(--sp-3);
}
.login-card .input { background: #fff; color: #10284F; border-color: #E3E8F1; }
.login-card .field-msg.is-error { color: #8F5500; }
.login-card .btn { --btn-bg: #10284F; --btn-fg: #fff; }
.login-card .btn:hover { --btn-bg: #1A3A6E; }
.code-step { display: grid; grid-template-rows: 0fr; opacity: 0; transition: grid-template-rows var(--t-enter) var(--ease), opacity var(--t-enter) var(--ease); }
.code-step > div { overflow: hidden; display: flex; flex-direction: column; gap: var(--sp-3); }
.code-step.is-open { grid-template-rows: 1fr; opacity: 1; }
.code-input { letter-spacing: .5em; text-align: center; font-size: var(--fs-20); font-weight: 800; direction: ltr; font-variant-numeric: tabular-nums; }
.public-foot { margin-top: var(--sp-5); display: flex; gap: var(--sp-5); }
.public-foot a { color: #D9C79A; text-decoration: none; font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; }
.public-foot a:hover { text-decoration: underline; }

.policy { max-width: 760px; margin: 0 auto; padding: var(--sp-6) var(--sp-4) var(--sp-7); }
.policy .card { padding: var(--sp-5); }
.policy .card + .card { margin-top: var(--sp-5); }
.policy h1 { margin-bottom: var(--sp-3); }
.policy h2 { margin: var(--sp-5) 0 var(--sp-2); font-size: var(--fs-16); }
.policy ul { padding-inline-start: var(--sp-5); margin: var(--sp-2) 0; }
.policy li { margin-bottom: var(--sp-1); }
.policy .en { direction: ltr; text-align: left; }
.policy-head { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-5); }
.policy-head img { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; }

.lang-select { width: auto; min-width: 140px; padding-block: 6px; font-size: var(--fs-14); }
.lang-pick { display: inline-flex; align-items: center; gap: var(--sp-2); margin-inline-start: auto; }
.public-foot .lang-select { min-width: 120px; }
