/* Qwenturo app styles. Lines up to 'Stage 4 additions' are the legacy app's styles, unchanged. */
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: .45; } 50% { opacity: 1; } }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(350%); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

:root {
  --bg: #0a0d12; --surface: #12151b; --surface2: #171b22; --border: #23272e;
  --gold: #c9a84c; --gold-light: #d4b970; --gold-dim: #c9a84c1a; --gold-border: #c9a84c55; --on-accent: #12151b;
  --text: #ece9e2; --text-mid: #aaa89f; --text-dim: #807e76; --row-hover: rgba(255,255,255,.035);
  --green: #63c267; --red: #ec6a6a; --amber: #e3a94f;
  --font: 'Inter', -apple-system, system-ui, sans-serif;
  --font-display: 'Fraunces', Georgia, serif;
  --ease: cubic-bezier(.22,1,.36,1);
  --radius: 10px;
}
[hidden] { display: none !important; }
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.55; -webkit-font-smoothing: antialiased; display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
h1, h2 { font-family: var(--font-display); font-weight: 700; letter-spacing: -.01em; }
::selection { background: var(--gold); color: var(--on-accent); }
::-webkit-scrollbar { width: 6px; height: 6px; } ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-dim); font-size: 12.5px; }
.sm-only { display: none; }
kbd { font-family: var(--font); font-size: 11px; border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; color: var(--text-dim); }

/* ---------- Side nav (collapsible) ---------- */
.sidenav { width: 200px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 16px 10px 12px; gap: 2px; flex-shrink: 0; overflow-y: auto; overflow-x: hidden; transition: width .22s var(--ease); }
.nav-top { display: flex; align-items: flex-start; gap: 4px; margin-bottom: 14px; min-height: 34px; }
.brand { flex: 1; min-width: 0; font-family: var(--font-display); font-size: 16px; line-height: 1.25; font-weight: 700; color: var(--gold-light); padding: 6px 8px 0; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }
.nav-toggle { flex-shrink: 0; font-size: 16px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; border: none; background: none; color: var(--text-dim); font-size: 13.5px; font-weight: 500; width: 100%; text-align: left; position: relative; transition: background .15s, color .15s; white-space: nowrap; }
.nav-item:hover { background: var(--gold-dim); color: var(--text); }
.nav-item.active { background: var(--gold-dim); color: var(--gold-light); }
.nav-icon { display: flex; flex-shrink: 0; }
.nav-icon svg { width: 18px; height: 18px; }
.nav-label { overflow: hidden; text-overflow: ellipsis; }
.nav-badge { margin-left: auto; background: var(--red); color: #fff; font-size: 10.5px; font-weight: 700; padding: 0 6px; border-radius: 9px; line-height: 17px; }
.nav-sep { height: 1px; background: var(--border); margin: 8px 6px; }
.nav-more { display: none; position: relative; border: none; background: none; color: var(--text-dim); font-weight: 500; }
.nav-more.active { color: var(--gold-light); background: var(--gold-dim); }
.cart-bar { display: none; }
.fund-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; margin-bottom: 16px; }
.fund-card { text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 7px; }
.fund-card:hover { border-color: var(--gold-border); }
.fc-name { font-weight: 700; color: var(--text); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fc-row { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--text-mid); font-variant-numeric: tabular-nums; }
.fc-bar { height: 6px; background: var(--surface2); border-radius: 3px; overflow: hidden; }
.fc-bar span { display: block; height: 100%; background: var(--gold); border-radius: 3px; }
.fc-bal { display: flex; justify-content: space-between; font-weight: 700; font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums; }
.check-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); font-size: 13.5px; cursor: pointer; margin-top: 12px; }
.deliver-toggle { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); font-size: 13.5px; font-weight: 500; color: var(--text); cursor: pointer; }
.deliver-toggle.on { border-color: var(--gold-border); background: var(--gold-dim); }
.deliver-toggle .hint { margin-left: auto; font-size: 12px; color: var(--text-dim); font-weight: 400; }
.deliver-fields { display: flex; flex-direction: column; gap: 8px; }
.nav-spacer { flex: 1; }
.watermark { font-size: 10px; color: var(--text-dim); text-align: center; padding: 14px 0 2px; white-space: nowrap; }
.watermark a { color: inherit; text-decoration: none; }
@media (min-width: 761px) {
  .sidenav.collapsed { width: 64px; padding-left: 8px; padding-right: 8px; }
  .sidenav.collapsed .brand, .sidenav.collapsed .nav-label, .sidenav.collapsed .watermark { display: none; }
  .sidenav.collapsed .nav-top { justify-content: center; }
  .sidenav.collapsed .nav-item { justify-content: center; padding: 10px; }
  .sidenav.collapsed .nav-badge { position: absolute; top: 2px; right: 2px; margin: 0; font-size: 9.5px; line-height: 15px; padding: 0 5px; }
}

/* ---------- Main ---------- */
.content { flex: 1; min-width: 0; overflow-y: auto; padding: 22px 34px 40px; }
.view { display: none; max-width: 1240px; margin-left: auto; margin-right: auto; }
.view.active { display: block; animation: fadeIn .12s var(--ease); }

.topbar { position: sticky; top: -22px; z-index: 10; background: var(--bg); padding: 22px 0 10px; margin-top: -22px; max-width: 1240px; margin-left: auto; margin-right: auto; }
.biz-header { display: block; font-family: var(--font-display); font-size: 15px; color: var(--gold-light); margin-bottom: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quickadd { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 5px 5px 5px 12px; transition: border-color .2s; }
.quickadd:focus-within { border-color: var(--gold-border); }
.quickadd svg { width: 16px; height: 16px; color: var(--text-dim); flex-shrink: 0; }
.quickadd input { flex: 1; min-width: 0; background: none; border: none; font-size: 14px; padding: 8px 4px; outline: none; }
.quickadd input::placeholder { color: var(--text-dim); }
.strip { display: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin-top: 8px; font-size: 13.5px; animation: fadeIn .12s var(--ease); }
.strip.show { display: block; }
.strip.error { border-color: var(--red); }
.strip-row { display: flex; gap: 10px; align-items: flex-start; }
.strip-text { flex: 1; white-space: pre-line; color: var(--text-mid); padding-top: 5px; }
.strip-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.strip-actions:empty { display: none; }

/* ---------- Buttons ---------- */
.btn-add, .btn-secondary, .btn-danger { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 8px; font-size: 13px; font-weight: 600; padding: 8px 14px; border: 1px solid transparent; transition: filter .15s, transform .1s, border-color .15s, color .15s; white-space: nowrap; }
.btn-add { background: var(--gold); color: var(--on-accent); }
.btn-add:hover:not(:disabled) { filter: brightness(1.07); }
.btn-add:active:not(:disabled) { transform: scale(.97); }
.btn-secondary { background: var(--surface); color: var(--text-mid); border-color: var(--border); font-weight: 500; }
.btn-secondary:hover:not(:disabled) { border-color: var(--gold-border); color: var(--text); }
.btn-danger { background: none; color: var(--red); border-color: var(--border); font-weight: 500; }
.btn-danger:hover:not(:disabled), .btn-danger.armed { border-color: var(--red); }
.btn-danger.armed { background: var(--red); color: #fff; }
button:disabled { opacity: .75; }
.btn-spin { width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; flex-shrink: 0; }
.icon-btn { background: none; border: none; color: var(--text-dim); font-size: 22px; line-height: 1; width: 34px; height: 34px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.icon-btn:hover { color: var(--text); background: var(--surface2); }

/* ---------- Page chrome ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 16px 0 14px; }
.page-head h1 { font-size: 23px; display: flex; align-items: baseline; gap: 10px; }
.head-count { font-family: var(--font); font-size: 12px; color: var(--text-dim); background: var(--surface); border: 1px solid var(--border); padding: 1px 9px; border-radius: 12px; font-weight: 600; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.date { font-size: 13px; color: var(--text-dim); }
.row-of-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--text-mid); padding: 5px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 500; }
.chip[aria-pressed="true"] { background: var(--gold-dim); border-color: var(--gold-border); color: var(--gold-light); }
.chip .n { margin-left: 5px; opacity: .75; font-variant-numeric: tabular-nums; }
.summary-line { font-size: 13px; color: var(--text-dim); margin: -6px 0 12px; }
.table-search { width: 100%; padding: 9px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; font-size: 13.5px; margin-bottom: 12px; outline: none; }
.table-search:focus { border-color: var(--gold-border); }
.table-search::placeholder { color: var(--text-dim); }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.table-scroll table { width: 100%; border-collapse: collapse; min-width: 560px; }
th { text-align: left; padding: 10px 12px; font-size: 12px; font-weight: 600; color: var(--text-dim); border-bottom: 1px solid var(--border); background: var(--surface2); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--border); font-size: 13.5px; color: var(--text-mid); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--row-hover); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-main { color: var(--text); font-weight: 600; }
.cell-sub { font-size: 12px; color: var(--text-dim); }
.actions-cell { text-align: right; white-space: nowrap; width: 1%; }
.empty-row td { text-align: center; color: var(--text-dim); padding: 30px 16px; }
.error-row td { text-align: center; color: var(--red); padding: 24px 16px; }
.row-btn { background: none; border: 1px solid var(--border); color: var(--text-mid); padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 500; transition: border-color .15s, color .15s; }
.row-btn:hover:not(:disabled) { border-color: var(--gold-border); color: var(--text); }
.qty-btn { width: 32px; height: 30px; padding: 0; font-size: 17px; font-weight: 600; line-height: 1; }
.qty-btn + .qty-btn { margin-left: 4px; }
.qty-low { color: var(--amber); font-weight: 700; }
.qty-out { color: var(--red); font-weight: 700; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 10px; border: 1px solid currentColor; white-space: nowrap; }
.tag-green { color: var(--green); } .tag-amber { color: var(--amber); } .tag-red { color: var(--red); } .tag-dim { color: var(--text-dim); }

/* ---------- Dashboard ---------- */
.hero-number { padding: 20px 0 16px; }
.hero-number .label { display: block; font-size: 13px; color: var(--text-dim); }
.hero-number .value { font-family: var(--font-display); font-size: 46px; font-weight: 700; font-variant-numeric: tabular-nums; }
.insight { border-left: 2px solid var(--gold); padding: 4px 0 4px 14px; margin-bottom: 18px; font-size: 13.5px; color: var(--text-mid); max-width: 70ch; }
.insight.loading { animation: pulse 1.5s ease infinite; }
.ledger { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 22px; overflow: hidden; }
.stat { padding: 14px 16px; border: none; border-right: 1px solid var(--border); background: none; text-align: left; }
.stat:last-child { border-right: none; }
button.stat:hover { background: var(--row-hover); }
.stat-label { display: block; font-size: 12px; color: var(--text-dim); }
.stat-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.warn .stat-value { color: var(--amber); }
.section-title { font-size: 14px; font-weight: 600; color: var(--text-mid); margin: 6px 0 10px; }

/* ---------- Analytics ---------- */
.ask { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 18px; }
.ask-title { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 10px; }
.ask-title .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }
.ask-title .muted { font-weight: 400; }
.ask-row { display: flex; gap: 8px; }
.ask-row input { flex: 1; min-width: 0; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; font-size: 14px; outline: none; }
.ask-row input:focus { border-color: var(--gold); }
.ask .chips { margin: 10px 0 0; }
.answer { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 14px; color: var(--text); max-width: 75ch; }
.answer p + p, .answer ul + p, .answer p + ul { margin-top: 8px; }
.answer ul { padding-left: 18px; }
.answer li { margin: 3px 0; }
.answer .answer-meta { font-size: 11.5px; color: var(--text-dim); margin-top: 10px; }
.answer.loading { color: var(--text-dim); display: flex; align-items: center; gap: 10px; }
.answer.error { color: var(--red); }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 18px; }
.kpi { background: var(--surface); padding: 14px 16px; border: none; text-align: left; min-width: 0; }
button.kpi:hover { background: var(--surface2); }
.kpi-label { font-size: 12px; color: var(--text-dim); }
.kpi-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 2px 0; }
.kpi-sub { font-size: 12px; color: var(--text-dim); }
.up { color: var(--green); } .down { color: var(--red); }
.panels { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.panel.wide { grid-column: 1 / -1; }
.panel h3 { font-family: var(--font); font-size: 13.5px; font-weight: 600; color: var(--text); margin-bottom: 2px; }
.panel .panel-sub { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; width: 100%; background: none; border-left: none; border-right: none; border-top: none; text-align: left; color: var(--text-mid); }
.list-row:last-child { border-bottom: none; }
button.list-row:hover .lr-main { color: var(--gold-light); }
.lr-main { flex: 1; min-width: 0; color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lr-sub { font-size: 12px; color: var(--text-dim); font-weight: 400; }
.lr-val { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.bar-row { display: grid; grid-template-columns: minmax(80px, 34%) 1fr auto; gap: 10px; align-items: center; font-size: 12.5px; padding: 5px 0; }
.bar-row .bl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-mid); }
.bar-track { height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--gold); border-radius: 4px; }
.bar-row .bv { font-variant-numeric: tabular-nums; color: var(--text); }
.chart svg { display: block; width: 100%; height: auto; }
.chart .axis { fill: var(--text-dim); font-size: 10px; font-family: var(--font); }
.chart .gridline { stroke: var(--border); stroke-width: 1; }
.chart rect.b { fill: var(--gold); }
.chart rect.b:hover { fill: var(--gold-light); }
.close-row { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.close-row:last-child { border-bottom: none; }
.close-row span:last-child { font-variant-numeric: tabular-nums; }
.close-row.total { font-weight: 700; color: var(--text); font-size: 15px; }
.an-loading { padding: 40px 0; display: flex; flex-direction: column; align-items: center; gap: 12px; color: var(--text-dim); font-size: 13px; }

/* ---------- Checkout ---------- */
.checkout-layout { display: flex; gap: 18px; align-items: flex-start; }
.checkout-browse { flex: 1.5; min-width: 0; }
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 8px; max-height: 60vh; overflow-y: auto; }
.item-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 10px; text-align: center; display: flex; flex-direction: column; gap: 2px; transition: border-color .15s, background .15s; }
.item-card:hover:not(:disabled) { border-color: var(--gold-border); background: var(--gold-dim); }
.item-card:disabled { opacity: .45; }
.ic-name { font-size: 12.5px; line-height: 1.3; font-weight: 600; color: var(--text); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; min-height: 2.6em; word-break: break-word; }
.ic-price { font-size: 12px; color: var(--text-mid); font-variant-numeric: tabular-nums; }
.ic-qty { font-size: 11px; color: var(--text-dim); }
.cart-panel { flex: 1; min-width: 270px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 8px; position: sticky; top: 130px; }
.cart-header { font-family: var(--font-display); font-size: 17px; font-weight: 700; }
.cart-lines { max-height: 38vh; overflow-y: auto; }
.cart-empty { text-align: center; padding: 26px 0; color: var(--text-dim); font-size: 13px; }
.cart-line { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.cl-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cl-controls { display: flex; align-items: center; gap: 6px; }
.cl-controls button { background: none; border: 1px solid var(--border); color: var(--text-mid); width: 26px; height: 26px; border-radius: 6px; font-size: 15px; line-height: 1; }
.cl-qty { min-width: 18px; text-align: center; font-variant-numeric: tabular-nums; }
.cl-total { min-width: 72px; text-align: right; color: var(--text-mid); font-variant-numeric: tabular-nums; }
.cart-total-row { display: flex; justify-content: space-between; align-items: baseline; padding-top: 6px; }
.cart-total-amount { font-family: var(--font-display); font-size: 23px; font-weight: 700; font-variant-numeric: tabular-nums; }
.cart-panel input, .cart-panel select { width: 100%; padding: 9px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; font-size: 13.5px; outline: none; }
.cart-panel .btn-add { width: 100%; padding: 12px; font-size: 14px; }

/* ---------- Drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); opacity: 0; pointer-events: none; transition: opacity .14s; z-index: 30; }
.scrim.open { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: 420px; max-width: 100%; background: var(--surface); border-left: 1px solid var(--border); transform: translateX(100%); transition: transform .15s var(--ease); z-index: 31; display: flex; flex-direction: column; visibility: hidden; }
.drawer.open { transform: none; visibility: visible; }
.drawer-header { display: flex; align-items: center; gap: 6px; padding: 14px 14px 14px 20px; border-bottom: 1px solid var(--border); }
.drawer-header #drawerTitle { flex: 1; min-width: 0; font-family: var(--font-display); font-size: 18px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-body { padding: 18px 20px calc(24px + env(safe-area-inset-bottom, 0px)); overflow-y: auto; flex: 1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fld { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.fld.half { grid-column: span 1; }
.fld > span { font-size: 12.5px; color: var(--text-mid); font-weight: 500; }
.fld em { font-style: normal; color: var(--text-dim); font-weight: 400; }
.fld input, .fld select, .fld textarea { width: 100%; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; font-size: 14px; outline: none; min-height: 42px; }
.fld textarea { resize: vertical; min-height: 70px; }
.fld input:focus, .fld select:focus, .fld textarea:focus { border-color: var(--gold); }
.fld .invalid { border-color: var(--red) !important; }
.fld .prefilled { border-color: var(--gold-border); background: var(--gold-dim); }
.more { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.more summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text-mid); margin-bottom: 12px; }
.more summary span { font-weight: 400; color: var(--text-dim); }
.form-intro { font-size: 13.5px; color: var(--text-mid); margin-bottom: 14px; }
.form-intro strong { color: var(--text); }
.form-note { font-size: 12.5px; color: var(--text-dim); margin-top: 12px; }
.preview { font-size: 13.5px; color: var(--gold-light); font-weight: 600; min-height: 20px; margin-top: 12px; font-variant-numeric: tabular-nums; }
.form-error { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }
.submit { width: 100%; margin-top: 16px; padding: 12px; font-size: 14px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; }
.fact { background: var(--surface); padding: 9px 12px; min-width: 0; }
.fact-k { font-size: 11.5px; color: var(--text-dim); }
.fact-v { font-size: 14px; font-weight: 600; color: var(--text); word-break: break-word; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.action-grid button { padding: 11px 10px; }
.danger-zone { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 18px; }
.log-title { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; font-weight: 600; color: var(--text-mid); margin: 6px 0 8px; }
.rc { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.rc-head { text-align: center; padding-bottom: 10px; border-bottom: 1px dashed var(--border); margin-bottom: 10px; }
.rc-biz { font-family: var(--font-display); font-size: 18px; font-weight: 700; color: var(--text); }
.rc-meta { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 12.5px; color: var(--text-mid); margin-bottom: 10px; }
.rc-meta span:nth-child(odd) { color: var(--text-dim); }
.rc-lines { width: 100%; border-collapse: collapse; font-size: 13px; }
.rc-lines th { background: none; padding: 6px 0; font-size: 11.5px; }
.rc-lines td { padding: 7px 0; color: var(--text); }
.rc-lines th + th, .rc-lines td + td { padding-left: 8px; }
.rc-total { display: flex; justify-content: space-between; align-items: baseline; border-top: 1px dashed var(--border); margin-top: 6px; padding-top: 10px; font-weight: 700; }
.rc-total span:last-child { font-family: var(--font-display); font-size: 22px; font-variant-numeric: tabular-nums; }
.status-pick { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.status-pick .chip { flex: 1; padding: 9px 12px; font-size: 13px; }
.log-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.log-row:last-child { border-bottom: none; }
.log-main { flex: 1; min-width: 0; }
.log-main .cell-sub { word-break: break-word; }
.log-row.is-fixed .log-change { text-decoration: line-through; opacity: .55; }
.log-change { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.log-change.up { color: var(--green); } .log-change.down { color: var(--red); }

/* ---------- Settings ---------- */
.settings-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40; align-items: center; justify-content: center; }
.settings-overlay.open { display: flex; }
.settings-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; width: 460px; max-width: 94vw; max-height: 88vh; display: flex; flex-direction: column; animation: fadeIn .12s var(--ease); }
.settings-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 16px 16px 22px; border-bottom: 1px solid var(--border); }
.settings-header h2 { font-size: 19px; }
.settings-body { padding: 18px 22px; overflow-y: auto; flex: 1; }
.settings-footer { display: flex; gap: 8px; padding: 14px 22px calc(14px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--border); }
.settings-footer button { flex: 1; padding: 11px; }
.settings-group { margin-bottom: 22px; }
.settings-label { font-size: 13px; color: var(--text); margin-bottom: 4px; font-weight: 600; }
.settings-hint { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }
.settings-input { width: 100%; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; font-size: 14px; outline: none; margin-bottom: 8px; }
.settings-input:focus { border-color: var(--gold-border); }
.module-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.module-row:last-child { border-bottom: none; }
.switch { position: relative; width: 40px; height: 24px; flex-shrink: 0; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch .slider { position: absolute; inset: 0; background: var(--border); border-radius: 12px; transition: background .15s; }
.switch .slider::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: var(--text-dim); border-radius: 50%; transition: transform .15s var(--ease), background .15s; }
.switch input:checked + .slider { background: var(--gold); }
.switch input:checked + .slider::before { transform: translateX(16px); background: var(--on-accent); }
.switch input:focus-visible + .slider { outline: 2px solid var(--gold); outline-offset: 2px; }
.module-rename { flex: 1; min-width: 0; padding: 7px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; font-size: 13px; outline: none; }
.module-rename:focus { border-color: var(--gold-border); }
.module-rename:disabled { opacity: .5; }
.swatch-group-label { font-size: 12px; color: var(--text-dim); margin: 10px 0 6px; }
.swatches { display: flex; gap: 9px; flex-wrap: wrap; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 1px solid rgba(128,128,128,.45); transition: transform .12s; }
.swatch:hover { transform: scale(1.08); }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }
.custom-row { display: flex; align-items: center; gap: 10px; }
.custom-row input[type="color"] { width: 40px; height: 34px; border: 1px solid var(--border); border-radius: 8px; background: none; padding: 2px; cursor: pointer; }

/* ---------- Boot, toast, loading bar ---------- */
.boot-overlay { position: fixed; inset: 0; background: var(--bg); z-index: 100; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 14px; transition: opacity .15s var(--ease); }
.boot-overlay.hide { opacity: 0; pointer-events: none; }
.boot-title { font-family: var(--font-display); font-size: 28px; font-weight: 700; color: var(--gold-light); text-align: center; padding: 0 20px; }
.boot-sub { font-size: 13px; color: var(--text-dim); }
.spinner { width: 30px; height: 30px; border: 3px solid var(--border); border-top-color: var(--gold); border-radius: 50%; animation: spin .7s linear infinite; }
/* ---------- Loading animations (chosen in Settings) ---------- */
.loader { position: relative; width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; gap: 5px; color: var(--gold); flex-shrink: 0; vertical-align: middle; }
.loader.sm { width: 20px; height: 20px; gap: 3px; }
.loader i { display: none; }
.loader:not([data-kind])::before, .loader[data-kind="ring"]::before { content: ''; position: absolute; inset: 0; border: 3px solid var(--border); border-top-color: currentColor; border-radius: 50%; animation: spin .7s linear infinite; }
.loader.sm:not([data-kind])::before, .loader.sm[data-kind="ring"]::before { border-width: 2px; }
.loader[data-kind="dots"] i { display: block; width: 8px; height: 8px; border-radius: 50%; background: currentColor; animation: ldBounce 1s ease-in-out infinite; }
.loader.sm[data-kind="dots"] i { width: 5px; height: 5px; }
.loader[data-kind="bars"] i { display: block; width: 5px; height: 24px; border-radius: 3px; background: currentColor; animation: ldBars 1s ease-in-out infinite; }
.loader.sm[data-kind="bars"] i { width: 3px; height: 14px; }
.loader i:nth-child(2) { animation-delay: .15s; } .loader i:nth-child(3) { animation-delay: .3s; }
.loader[data-kind="pulse"]::before { content: ''; position: absolute; inset: 3px; border-radius: 50%; background: currentColor; animation: ldPulse 1.2s ease-in-out infinite; }
.loader[data-kind="orbit"]::before { content: ''; position: absolute; inset: 0; border: 2px solid var(--border); border-radius: 50%; }
.loader[data-kind="orbit"]::after { content: ''; position: absolute; inset: 0; border-radius: 50%; background: radial-gradient(circle at 50% 4px, currentColor 3.5px, transparent 4px); animation: spin 1s linear infinite; }
.loader.sm[data-kind="orbit"]::after { background: radial-gradient(circle at 50% 3px, currentColor 2.5px, transparent 3px); }
.loader[data-kind="gem"]::before { content: ''; width: 45%; height: 45%; border: 2.5px solid currentColor; border-radius: 2px; animation: ldGem 1.4s ease-in-out infinite; }
@keyframes ldBounce { 0%, 80%, 100% { transform: translateY(0); opacity: .4; } 40% { transform: translateY(-7px); opacity: 1; } }
@keyframes ldBars { 0%, 100% { transform: scaleY(.35); opacity: .5; } 50% { transform: scaleY(1); opacity: 1; } }
@keyframes ldPulse { 0%, 100% { transform: scale(.5); opacity: .3; } 50% { transform: scale(1); opacity: 1; } }
@keyframes ldGem { 0% { transform: rotate(45deg) scale(.8); } 50% { transform: rotate(225deg) scale(1.15); } 100% { transform: rotate(405deg) scale(.8); } }
.loader-picks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.loader-pick { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 6px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; font-size: 12px; color: var(--text-mid); }
.loader-pick[aria-pressed="true"] { border-color: var(--gold); background: var(--gold-dim); color: var(--gold-light); font-weight: 600; }
.inline-loading { display: flex; align-items: center; gap: 10px; color: var(--text-dim); font-size: 13px; padding: 6px 0; }
.loading-bar { position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 60; overflow: hidden; pointer-events: none; }
.loading-bar.active::after { content: ''; display: block; height: 100%; width: 30%; background: var(--gold); animation: slide 1s ease infinite; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(120px); background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 10px 18px; border-radius: 8px; font-size: 13.5px; z-index: 70; transition: transform .2s var(--ease); max-width: min(92vw, 520px); text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--red); }

/* ---------- Tablet ---------- */
@media (max-width: 1024px) and (min-width: 761px) {
  .content { padding: 20px 20px 40px; }
  .cart-panel { min-width: 230px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  body { flex-direction: column; }
  /* Bottom bar: 4 main tabs + More */
  .sidenav { order: 2; width: 100%; flex-direction: row; padding: 0 0 env(safe-area-inset-bottom, 0px); border-right: none; border-top: 1px solid var(--border); gap: 0; overflow: hidden; flex-shrink: 0; }
  .nav-top, .watermark, .nav-spacer, .nav-sep, .nav-item.nav-overflow { display: none; }
  .nav-item, .nav-more { display: flex; width: auto; flex: 1 1 0; min-width: 0; flex-direction: column; align-items: center; gap: 3px; padding: 8px 2px 7px; font-size: 10.5px; text-align: center; justify-content: center; border-radius: 0; }
  .nav-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .nav-icon svg { width: 21px; height: 21px; }
  .nav-badge { position: absolute; top: 4px; left: 50%; transform: translateX(6px); margin: 0; font-size: 9.5px; line-height: 15px; padding: 0 5px; }
  .content { order: 1; padding: 10px 12px 24px; }
  .topbar { top: -10px; padding-top: 10px; margin-top: -10px; }
  .biz-header { font-size: 13px; margin-bottom: 6px; }
  .page-head { margin: 12px 0 10px; }
  .page-head h1 { font-size: 21px; }
  .head-actions { width: 100%; }
  .head-actions > * { flex: 1; }
  .hide-sm { display: none !important; }
  .sm-only { display: inline; }
  .hero-number { padding: 12px 0 12px; }
  .hero-number .value { font-size: 34px; }
  .ledger, .kpis { grid-template-columns: 1fr 1fr; }
  .stat:nth-child(2) { border-right: none; }
  .stat:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
  .kpi { padding: 12px; } .kpi-value { font-size: 17px; }
  .panels { grid-template-columns: 1fr; }
  .row-of-actions, .chips { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; margin-left: -12px; margin-right: -12px; padding: 0 12px 2px; }
  .row-of-actions::-webkit-scrollbar, .chips::-webkit-scrollbar { display: none; }
  .row-of-actions > *, .chips > * { flex-shrink: 0; }
  .page-head .chips { margin: 0 -12px; width: calc(100% + 24px); }
  .status-pick { flex-wrap: nowrap; }
  .ask { padding: 12px; }
  .ask .chips { margin: 10px -12px 0; padding: 0 12px 2px; }
  .ask-title .muted { display: none; }

  /* Tables become cards */
  .table-scroll { border: none; background: none; overflow: visible; border-radius: 0; }
  .table-scroll table, .table-scroll tbody { display: block; min-width: 0; }
  .table-scroll thead { display: none; }
  .table-scroll tbody tr { display: grid; column-gap: 12px; row-gap: 2px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; margin-bottom: 8px; }
  .table-scroll tbody tr.empty-row, .table-scroll tbody tr.error-row { display: block; }
  .table-scroll td { display: block; padding: 0; border: none; font-size: 13.5px; min-width: 0; }
  .table-scroll tr.empty-row td, .table-scroll tr.error-row td { padding: 22px 8px; }
  tr.clickable:active { transform: scale(.99); }
  #inventoryBody tr { grid-template-columns: 1fr auto auto; grid-template-areas: "name qty act" "name price act"; }
  #inventoryBody td:nth-child(1) { grid-area: name; } #inventoryBody td:nth-child(2) { grid-area: qty; font-size: 15px; }
  #inventoryBody td:nth-child(3) { grid-area: price; font-size: 12px; color: var(--text-dim); } #inventoryBody td:nth-child(7) { grid-area: act; }
  #inventoryBody .qty-btn { width: 38px; height: 38px; font-size: 19px; }
  #transactionsBody tr, #recentTxnBody tr { grid-template-columns: 1fr auto; grid-template-areas: "items total" "date total"; }
  #transactionsBody td:nth-child(1), #recentTxnBody td:nth-child(1) { grid-area: date; font-size: 12px; color: var(--text-dim); }
  #transactionsBody td:nth-child(2), #recentTxnBody td:nth-child(2) { grid-area: items; }
  #transactionsBody td:nth-child(3), #recentTxnBody td:nth-child(3) { grid-area: total; font-weight: 700; color: var(--text); }
  #expensesBody tr { grid-template-columns: 1fr auto; grid-template-areas: "cat amt" "date amt"; }
  #expensesBody td:nth-child(1) { grid-area: date; font-size: 12px; color: var(--text-dim); } #expensesBody td:nth-child(2) { grid-area: cat; }
  #expensesBody td:nth-child(4) { grid-area: amt; font-weight: 700; color: var(--text); }
  #contactsBody tr { grid-template-columns: 1fr auto; grid-template-areas: "name owes" "name spent"; }
  #contactsBody td:nth-child(1) { grid-area: name; } #contactsBody td:nth-child(4) { grid-area: owes; }
  #contactsBody td:nth-child(3) { grid-area: spent; font-size: 12px; color: var(--text-dim); }
  #deliveriesBody tr { grid-template-columns: 1fr auto; grid-template-areas: "cust status" "date total"; }
  #deliveriesBody td:nth-child(1) { grid-area: date; font-size: 12px; color: var(--text-dim); } #deliveriesBody td:nth-child(2) { grid-area: cust; }
  #deliveriesBody td:nth-child(4) { grid-area: total; } #deliveriesBody td:nth-child(5) { grid-area: status; text-align: right; }

  /* Checkout: full-width grid, floating cart bar */
  .checkout-layout { flex-direction: column; align-items: stretch; }
  .item-grid { max-height: none; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 6px; }
  .cart-panel { position: static; width: 100%; min-width: 0; }
  #view-checkout.active { padding-bottom: 70px; }
  .cart-bar:not([hidden]) { display: flex; position: fixed; left: 12px; right: 12px; bottom: calc(66px + env(safe-area-inset-bottom, 0px)); z-index: 12; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border: none; border-radius: 12px; background: var(--gold); color: var(--on-accent); font-weight: 700; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.3); }

  .drawer { width: 100%; border-left: none; }
  .settings-overlay { align-items: flex-end; }
  .settings-panel { width: 100%; max-width: 100%; border-radius: 16px 16px 0 0; max-height: 92vh; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
  .kbd-hint { display: none; }
  .deliver-toggle .hint { display: none; }
  .fund-cards { grid-template-columns: 1fr; }
  #fundsBody tr { grid-template-columns: 1fr auto; grid-template-areas: "src amt" "date amt"; }
  #fundsBody td:nth-child(1) { grid-area: date; font-size: 12px; color: var(--text-dim); } #fundsBody td:nth-child(2) { grid-area: src; }
  #fundsBody td:nth-child(4) { grid-area: amt; font-weight: 700; color: var(--text); }
}
@media (max-width: 360px) {
  .form-grid { grid-template-columns: 1fr; }
  .fld.half { grid-column: 1 / -1; }
  .hero-number .value { font-size: 30px; }
}

/* ================= Stage 4 additions ================= */
/* Sign-in and store screens (shown instead of the app shell) */
body.gated .sidenav, body.gated .content { display: none; }
.gate { position: fixed; inset: 0; overflow-y: auto; background: var(--bg); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 40px; }
.gate-card { width: 100%; max-width: 420px; animation: fadeIn .12s var(--ease); }
.gate-brand { font-family: var(--font-display); font-size: 30px; font-weight: 700; color: var(--gold-light); text-align: center; margin-bottom: 4px; }
.gate-sub { text-align: center; color: var(--text-dim); font-size: 13.5px; margin-bottom: 22px; }
.gate-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 20px; }
.gate-panel h2 { font-size: 19px; margin-bottom: 4px; }
.gate-panel .form-intro { margin-bottom: 16px; }
.gate-panel .btn-add, .gate-panel .btn-secondary { width: 100%; padding: 12px; font-size: 14px; }
.gate-or { display: flex; align-items: center; gap: 10px; color: var(--text-dim); font-size: 12px; margin: 16px 0; }
.gate-or::before, .gate-or::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.gate-msg { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 13px; color: var(--text-mid); margin-bottom: 14px; background: var(--bg); }
.gate-msg.error { border-color: var(--red); color: var(--text); }
.gate-msg.ok { border-color: var(--gold-border); }
.gate-foot { text-align: center; font-size: 12px; color: var(--text-dim); margin-top: 18px; }
.gate-foot a, .link-btn { color: var(--gold-light); background: none; border: none; padding: 0; font: inherit; text-decoration: underline; cursor: pointer; }
.g-logo { width: 18px; height: 18px; flex-shrink: 0; }
.code-input { letter-spacing: .35em; font-size: 20px !important; text-align: center; font-variant-numeric: tabular-nums; }
.store-row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 14px; margin-bottom: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; color: var(--text); }
.store-row:hover { border-color: var(--gold-border); }
.store-row .lr-main { white-space: normal; }

/* Team and account */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card h3 { font-family: var(--font); font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.card .panel-sub { font-size: 12.5px; color: var(--text-dim); margin-bottom: 12px; }
.member-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.member-row:last-child { border-bottom: none; }
.member-row .lr-main { min-width: 160px; white-space: normal; word-break: break-word; }
.member-row select { padding: 7px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input, .inline-form select { flex: 1; min-width: 150px; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; font-size: 14px; outline: none; }
.inline-form input:focus, .inline-form select:focus { border-color: var(--gold); }
.done-by { color: var(--text-dim); }
@media (max-width: 760px) {
  .gate { padding-top: 5vh; }
  .member-row select { flex: 1; }
}

/* Speed: waiting indicators appear only when a wait lasts longer than 300 ms, so quick answers never flash a loader */
@keyframes qwAppear { from { visibility: hidden; } to { visibility: visible; } }
.inline-loading, .an-loading, #bootLoader, .boot-sub { animation: qwAppear 0s linear .3s both; }
.insight.loading { animation: qwAppear 0s linear .3s both, pulse 1.5s ease .3s infinite; }
.loading-bar.active::after { animation: qwAppear 0s linear .3s both, slide 1s ease .3s infinite; }
