/* =========================================================
   Catat Warung — app styles. Tokens live in tokens.css (load it first).
   ========================================================= */

/* =========================================================
   Base
   ========================================================= */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-sm);
  line-height: 1.45;
  color: var(--text);
  background: var(--desk);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }

.ico {
  width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

/* Desktop preview frame; full screen on phones */
.device { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.app {
  position: relative;
  width: 390px;
  height: min(844px, calc(100vh - 48px));
  background: var(--bg);
  border-radius: 40px;
  box-shadow: 0 0 0 1px var(--border-strong), 0 24px 64px rgba(0, 0, 0, .12);
  overflow: hidden;
  display: flex; flex-direction: column;
}
@media (max-width: 480px) {
  .device { padding: 0; display: block; }
  .app { width: 100%; height: 100dvh; border-radius: 0; box-shadow: none; }
}

.view {
  flex: 1; overflow-y: auto; overflow-x: hidden; outline: none;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--s5));
  scrollbar-width: none;
}
.view::-webkit-scrollbar { display: none; }
.view.no-tabbar { padding-bottom: var(--s6); }
.view.has-bar { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
.view.full { padding-bottom: 0; }
.view:has(> .fab) { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 56px + var(--s4) * 2); }

/* =========================================================
   Header & sections
   ========================================================= */
.header {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  min-height: 60px;
  padding: var(--s4) var(--gutter) var(--s3);
  display: flex; align-items: center; gap: var(--s3);
}
.header h1 { flex: 1; min-width: 0; font-size: var(--fs-title); font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.header .eyebrow { font-size: var(--fs-sm); color: var(--text-3); margin-bottom: 2px; }
.header .title-wrap { flex: 1; min-width: 0; }
.header.compact { padding-top: var(--s3); }
.header.compact h1 { font-size: var(--fs-body); font-weight: 600; text-align: center; }
.header-spacer { width: 40px; flex: none; }

.icon-btn {
  width: 40px; height: 40px; border-radius: var(--r-pill); flex: none;
  border: 0; background: transparent; display: grid; place-items: center;
}
.icon-btn:active { background: var(--surface-2); }

.section { padding: 0 var(--gutter); margin-top: var(--s5); }
.section.tight { margin-top: var(--s3); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s2); }
.section-head h2 { font-size: var(--fs-body); font-weight: 600; }
.section-head .note { font-size: var(--fs-meta); color: var(--text-3); }
.link { font-size: var(--fs-sm); font-weight: 600; color: var(--text); text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px; }

/* =========================================================
   Summary figure & metrics (no cards)
   ========================================================= */
.summary { padding: var(--s2) var(--gutter) 0; }
.summary-label { font-size: var(--fs-sm); color: var(--text-2); }
.summary-value { font-size: var(--fs-display); font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; margin-top: var(--s1); overflow-wrap: anywhere; }
.summary-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin-top: var(--s2); font-size: var(--fs-meta); color: var(--text-3); }

.delta {
  display: inline-flex; align-items: center; gap: 2px;
  font-size: var(--fs-meta); font-weight: 600; color: var(--text);
  background: var(--surface-2); border-radius: var(--r-pill); padding: 2px 8px;
}

/* Home hero: the headline figure as one solid yellow card, the heaviest element on screen */
.summary.hero {
  margin: var(--s2) var(--gutter) 0;
  padding: var(--s5) var(--s4) var(--s4);
  background: var(--accent); color: var(--on-accent);
  border-radius: var(--r-lg);
}
.hero .summary-label { color: var(--on-accent); opacity: .72; font-weight: 500; }
.hero .summary-value { font-size: 36px; font-weight: 800; margin-top: var(--s2); }
.hero .summary-meta { color: var(--on-accent); opacity: .85; margin-top: var(--s3); }
.hero .delta { background: var(--on-accent); color: var(--accent); }
.section + .summary.hero { margin-top: var(--s4); }

.metrics {
  display: grid; grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.metrics.three { grid-template-columns: repeat(3, 1fr); }
.metric { padding: var(--s3) 0; min-width: 0; }
.metric:nth-child(odd) { padding-right: var(--s3); }
.metrics:not(.three) .metric:nth-child(even) { padding-left: var(--s4); border-left: 1px solid var(--border); }
.metrics:not(.three) .metric:nth-child(n+3) { border-top: 1px solid var(--border); }
.metrics.three .metric { padding: var(--s3) var(--s2); }
.metrics.three .metric:first-child { padding-left: 0; }
.metrics.three .metric + .metric { border-left: 1px solid var(--border); padding-left: var(--s3); }
.metrics.three .metric-value { font-size: var(--fs-sm); }
.metric-label { font-size: var(--fs-meta); color: var(--text-3); }
.metric-value { font-size: clamp(var(--fs-sm), 4.4vw, var(--fs-body)); font-weight: 600; margin-top: 2px; overflow-wrap: break-word; }
.metric-meta { font-size: var(--fs-meta); color: var(--text-3); margin-top: 2px; }

.meter { height: 4px; background: var(--surface-2); border-radius: var(--r-pill); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--chart-1); border-radius: var(--r-pill); }

/* =========================================================
   Lists — one row pattern for transactions, products, settings
   ========================================================= */
.list { display: flex; flex-direction: column; }
.group-title {
  display: flex; justify-content: space-between; gap: var(--s3);
  font-size: var(--fs-sm); font-weight: 600; color: var(--text-2);
  padding: var(--s5) 0 var(--s1);
  border-bottom: 1px solid var(--border);
}
.list-row {
  display: flex; align-items: center; gap: var(--s3);
  width: 100%; min-height: 60px; padding: var(--s3) 0;
  border: 0; border-bottom: 1px solid var(--border); background: none;
  text-align: left; color: inherit;
}
.list > .list-row:last-child { border-bottom: 0; }
button.list-row:active, a.list-row:active { background: var(--surface-2); }
.list-row.is-selected { background: var(--accent-soft); margin: 0 calc(var(--gutter) * -1); padding-left: var(--gutter); padding-right: var(--gutter); width: auto; }
.row-main { flex: 1; min-width: 0; }
.row-title {
  font-size: var(--fs-sm); font-weight: 500; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.row-title.strong { font-weight: 600; }
.row-meta { font-size: var(--fs-meta); color: var(--text-3); margin-top: 2px; }
.row-trail { text-align: right; flex: none; max-width: 48%; }
.row-trail .amount { font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; }
.row-trail .amount.muted { color: var(--text-2); }
.row-trail .row-meta { overflow-wrap: anywhere; }
.row-chev { color: var(--text-3); }

.thumb {
  width: 40px; height: 40px; flex: none; position: relative;
  border-radius: var(--r-md); background: var(--surface-2); color: var(--text-2);
  display: grid; place-items: center; overflow: hidden;
  font-size: var(--fs-meta); font-weight: 600;
}
.thumb.lg { width: 48px; height: 48px; font-size: var(--fs-sm); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .rank {
  position: absolute; left: 0; top: 0;
  min-width: 18px; height: 18px; padding: 0 5px; border-bottom-right-radius: var(--r-sm);
  background: var(--inverse); color: var(--on-inverse);
  font-size: var(--fs-meta); font-weight: 700; line-height: 18px; text-align: center;
}

.info-row {
  display: flex; justify-content: space-between; gap: var(--s4);
  padding: var(--s3) 0; border-bottom: 1px solid var(--border); font-size: var(--fs-sm);
}
.info-row:last-child { border-bottom: 0; }
.info-row span { color: var(--text-3); flex: none; }
.info-row b { font-weight: 500; text-align: right; min-width: 0; overflow-wrap: anywhere; }

.empty { text-align: center; color: var(--text-3); padding: var(--s6) var(--s5); }
.empty .ico { width: 24px; height: 24px; margin-bottom: var(--s2); }
.empty p { font-size: var(--fs-sm); }
.empty .btn { margin-top: var(--s4); }
/* Skeleton placeholders while data loads (O.sk in utils.js) */
.sk {
  display: block; height: 14px; max-width: 100%; border-radius: var(--r-sm);
  background: var(--surface-2); position: relative; overflow: hidden;
}
.sk::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--sk-shine), transparent);
  animation: skShine 1.4s ease-in-out infinite;
}
@keyframes skShine { to { transform: translateX(100%); } }
.sk + .sk { margin-top: var(--s2); }
.express > .sk + .sk { margin-top: 0; }
.sk.thumb { border-radius: var(--r-md); }
.sk.round { border-radius: var(--r-pill); }
.sk-row { display: flex; align-items: center; gap: var(--s3); min-height: 60px; padding: var(--s3) 0; border-bottom: 1px solid var(--border); }
.sk-row:last-child { border-bottom: 0; }
.sk-row .row-main .sk + .sk { margin-top: 6px; }
.hero .sk { background: color-mix(in srgb, var(--on-accent) 12%, transparent); }
.sk-wrap { pointer-events: none; }

/* =========================================================
   Buttons
   ========================================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: var(--control-h); padding: 0 var(--s5);
  border-radius: var(--r-md); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  font-size: var(--fs-body); font-weight: 600; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:active { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:active { background: var(--accent-pressed); border-color: var(--accent-pressed); }
.btn.sm { height: var(--control-h-sm); padding: 0 var(--s3); font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn.text { border-color: transparent; background: transparent; padding: 0 var(--s2); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn .ico { width: 18px; height: 18px; }

.linkish { border: 0; background: none; padding: 0; font-weight: 600; color: var(--text); text-decoration: underline; text-underline-offset: 3px; }

/* =========================================================
   Controls
   ========================================================= */
.segmented { display: flex; gap: 2px; padding: 3px; background: var(--surface-2); border-radius: var(--r-pill); }
.segmented button {
  flex: 1; min-height: 36px; border: 0; border-radius: var(--r-pill); background: transparent;
  font-size: var(--fs-sm); font-weight: 500; color: var(--text-2);
}
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); font-weight: 600; }

.chips { display: flex; gap: var(--s2); overflow-x: auto; scrollbar-width: none; margin: 0 calc(var(--gutter) * -1); padding: 0 var(--gutter); }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 36px; padding: 0 var(--s4); border-radius: var(--r-pill);
  border: 1px solid var(--border-strong); background: transparent;
  font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }

.search {
  display: flex; align-items: center; gap: var(--s2);
  height: 44px; padding: 0 var(--s3); border-radius: var(--r-md); background: var(--surface-2);
}
.search .ico { color: var(--text-3); width: 18px; height: 18px; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: var(--fs-body); }
.search:focus-within { box-shadow: var(--focus); }

.stepper { display: flex; align-items: center; border: 1px solid var(--border-strong); border-radius: var(--r-pill); }
.stepper button { width: 36px; height: 36px; border: 0; background: transparent; display: grid; place-items: center; border-radius: var(--r-pill); color: var(--text); }
.stepper button:active { background: var(--surface-2); }
.stepper .ico { width: 16px; height: 16px; }
.stepper .q { min-width: 24px; text-align: center; font-weight: 600; }

.qty-badge {
  min-width: 32px; height: 32px; padding: 0 var(--s2); border-radius: var(--r-pill);
  background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center; font-weight: 700;
}
.add-btn {
  width: 32px; height: 32px; border-radius: var(--r-pill); flex: none;
  border: 1px solid var(--border-strong); display: grid; place-items: center; color: var(--text);
}
.add-btn .ico { width: 16px; height: 16px; }

/* =========================================================
   Forms
   ========================================================= */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--s4); }
.field label, .field .label { font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); }
.field .optional { font-weight: 400; color: var(--text-3); }
.field .req { margin-left: 2px; color: var(--text); }
.form-legend { margin: 0 0 var(--s3); font-size: var(--fs-sm); color: var(--text-3); }
.field input, .field textarea, .field select {
  min-height: var(--control-h); padding: 0 var(--s3);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  background: var(--surface); font-size: var(--fs-body); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { padding: var(--s3); min-height: 96px; resize: none; line-height: 1.45; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--text); box-shadow: var(--focus); }
.field input.invalid, .field textarea.invalid { border-color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger); }
.field .hint { font-size: var(--fs-meta); color: var(--text-3); }
/* The error replaces the hint instead of repeating under it */
.field .hint:has(~ .field-error:not(:empty)) { display: none; }
.field-error { font-size: var(--fs-meta); font-weight: 600; color: var(--danger); }
.field-error:empty { display: none; }
.field-error::before { content: "! "; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.field-row .field { min-width: 0; }

.money-input { position: relative; }
.money-input span { position: absolute; left: var(--s3); top: 50%; transform: translateY(-50%); color: var(--text-3); font-size: var(--fs-body); }
.money-input input { width: 100%; padding-left: 40px; }
.money-input.big input { min-height: 64px; font-size: var(--fs-display); font-weight: 700; padding-left: 52px; }
.money-input.big span { font-size: var(--fs-title); font-weight: 600; }

.pw-input { position: relative; }
.pw-input input { width: 100%; padding-right: 48px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 40px; height: 40px; border: 0; background: none; color: var(--text-3);
  display: grid; place-items: center; border-radius: var(--r-pill);
}
.pw-rules { display: flex; flex-direction: column; gap: 6px; margin: calc(var(--s2) * -1) 0 var(--s4); font-size: var(--fs-sm); color: var(--text-3); }
.pw-rules span { display: flex; align-items: center; gap: var(--s2); }
.pw-rules .ico { width: 16px; height: 16px; padding: 2px; border-radius: var(--r-pill); border: 1px solid var(--border-strong); stroke-width: 3; color: transparent; box-sizing: border-box; }
.pw-rules .ok { color: var(--text); }
.pw-rules .ok .ico { background: var(--text); border-color: var(--text); color: var(--bg); }

.photo-picker {
  position: relative; width: 100%; aspect-ratio: 16 / 10; overflow: hidden;
  border: 1px dashed var(--border-strong); border-radius: var(--r-md); background: var(--surface-2);
  display: grid; place-items: center; text-align: center; color: var(--text-3); font-size: var(--fs-sm);
}
.photo-picker img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.photo-picker input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photo-picker .ico { width: 24px; height: 24px; display: block; margin: 0 auto var(--s1); }
.margin-preview { display: flex; justify-content: space-between; gap: var(--s3); padding: var(--s3) 0; margin-bottom: var(--s4); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); font-size: var(--fs-sm); color: var(--text-2); }
.margin-preview b { color: var(--text); font-weight: 600; }
.form-actions { display: flex; flex-direction: column; gap: var(--s2); margin-top: var(--s5); }

/* =========================================================
   Overlays: sheet, toast, tooltip
   ========================================================= */
.sheet-backdrop { position: absolute; inset: 0; z-index: 20; background: var(--overlay); opacity: 0; transition: opacity .25s var(--ease); }
.sheet-backdrop.open { opacity: 1; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 21;
  max-height: 88%; overflow-y: auto;
  background: var(--surface); border-radius: var(--r-lg) var(--r-lg) 0 0; box-shadow: var(--shadow-overlay);
  padding: var(--s2) var(--gutter) calc(var(--s5) + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .3s var(--ease);
}
.sheet.open { transform: translateY(0); }
.sheet .grabber { width: 36px; height: 4px; border-radius: var(--r-pill); background: var(--border-strong); margin: 0 auto var(--s4); }
.sheet h3 { font-size: var(--fs-title); font-weight: 700; margin-bottom: var(--s4); }
.sheet .sheet-text { font-size: var(--fs-sm); color: var(--text-2); margin: calc(var(--s2) * -1) 0 var(--s5); }
.sheet .actions { display: flex; gap: var(--s2); margin-top: var(--s4); }
.sheet .actions .btn { flex: 1; }
.sheet.tall { height: 88%; overflow: hidden; display: flex; flex-direction: column; padding-bottom: 0; }
.sheet.tall .picker-head h3 { margin-bottom: var(--s3); }
.sheet.tall .chips { margin-top: var(--s3); }
.sheet.tall #plist { flex: 1; overflow-y: auto; margin-top: var(--s2); scrollbar-width: none; }
.picker-foot { padding: var(--s3) 0 calc(var(--s4) + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--surface); }

.receipt { margin-bottom: var(--s2); }
.receipt .meta { font-size: var(--fs-meta); color: var(--text-3); display: flex; justify-content: space-between; gap: var(--s3); padding-bottom: var(--s3); border-bottom: 1px solid var(--border); }
.receipt .line { display: flex; justify-content: space-between; gap: var(--s3); padding: var(--s3) 0; border-bottom: 1px solid var(--border); font-size: var(--fs-sm); }
.receipt .line > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.receipt .line .muted { display: block; font-size: var(--fs-meta); color: var(--text-3); margin-top: 2px; }
.receipt .line .amount { white-space: nowrap; font-weight: 500; }
.receipt .total { font-size: var(--fs-body); font-weight: 700; border-bottom: 0; }
.receipt .foot { font-size: var(--fs-meta); color: var(--text-3); display: flex; justify-content: space-between; gap: var(--s3); }
.receipt .text { font-size: var(--fs-body); padding: var(--s3) 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }

.toast {
  position: absolute; left: 50%; top: var(--s4); z-index: 40;
  transform: translate(-50%, -200%); visibility: hidden;
  max-width: calc(100% - 32px);
  background: var(--inverse); color: var(--on-inverse); box-shadow: var(--shadow-overlay);
  font-size: var(--fs-sm); font-weight: 500;
  padding: 10px var(--s4); border-radius: var(--r-pill);
  display: flex; align-items: center; gap: var(--s2);
  transition: transform .3s var(--ease), visibility .3s;
}
.toast.show { transform: translate(-50%, 0); visibility: visible; }
.toast .ico { width: 16px; height: 16px; color: var(--accent); }

.tooltip {
  position: absolute; z-index: 30; pointer-events: none; min-width: 128px;
  background: var(--inverse); color: var(--on-inverse); box-shadow: var(--shadow-overlay);
  font-size: var(--fs-meta); padding: var(--s2) var(--s3); border-radius: var(--r-sm);
}
.tooltip .t-title { font-weight: 600; margin-bottom: var(--s1); }
.tooltip .t-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.tooltip .t-row span:first-child { display: flex; align-items: center; gap: 6px; opacity: .75; }
.tooltip .sw { width: 12px; height: 0; border-top: 2px solid var(--on-inverse); }
.tooltip .sw.dash { border-top-style: dashed; opacity: .7; }

/* =========================================================
   Charts
   ========================================================= */
.chart { width: 100%; display: block; overflow: visible; }
.chart text { font-family: var(--font); font-size: var(--fs-meta); fill: var(--text-3); }
/* Value labels sit over the bars: a background-coloured halo keeps them readable */
.chart .axis { paint-order: stroke; stroke: var(--bg); stroke-width: 4px; stroke-linejoin: round; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .baseline { stroke: var(--border-strong); stroke-width: 1; }
.chart .bar { fill: var(--chart-muted); transition: fill .15s; }
.chart .bar.current { fill: var(--chart-1); }
.chart .bar-group:hover .bar:not(.current) { fill: var(--chart-2); }
.chart .bar-hit { fill: transparent; cursor: pointer; }
.chart .s1 { stroke: var(--chart-1); stroke-width: 2; fill: none; }
.chart .s2 { stroke: var(--chart-2); stroke-width: 2; fill: none; stroke-dasharray: 5 4; }
.chart .area { fill: var(--chart-area); }
.chart .crosshair { stroke: var(--border-strong); stroke-width: 1; }
.chart .dot { stroke: var(--bg); stroke-width: 2; }
.chart .dot.s1d { fill: var(--chart-1); }
.chart .dot.s2d { fill: var(--chart-2); }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); margin-bottom: var(--s3); }
.chart-head .value { font-size: var(--fs-title); font-weight: 700; }
.legend { display: flex; gap: var(--s4); font-size: var(--fs-meta); color: var(--text-2); margin-bottom: var(--s3); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 16px; height: 0; border-top: 2px solid var(--chart-1); }
.legend i.dash { border-top: 2px dashed var(--chart-2); }

/* =========================================================
   P&L report
   ========================================================= */
.pnl { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.pnl td { padding: var(--s3) 0; vertical-align: baseline; }
.pnl td.amt { text-align: right; white-space: nowrap; padding-left: var(--s2); }
.pnl td.pct { text-align: right; width: 48px; white-space: nowrap; color: var(--text-3); font-size: var(--fs-meta); padding-left: var(--s3); }
.pnl tr.sub td { color: var(--text-2); }
.pnl tr.sub td:first-child { padding-left: var(--s4); }
.pnl tr.subtotal td { font-weight: 600; border-top: 1px solid var(--border-strong); }
.pnl tr.total td { font-size: var(--fs-body); font-weight: 700; border-top: 3px double var(--text); }
.pnl tr.total td.pct { font-size: var(--fs-meta); font-weight: 500; }
.pnl thead td { font-size: var(--fs-meta); color: var(--text-3); padding: 0 0 var(--s2); border-bottom: 1px solid var(--border); }

/* Floating action button: anchored to .app, so it stays put while #view scrolls */
.fab {
  position: absolute; z-index: 9;
  right: var(--gutter);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--s4));
  width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center; border: 0; padding: 0; cursor: pointer;
  background: var(--text); color: var(--bg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 4px 12px rgba(0, 0, 0, .10);
  transition: transform .15s var(--ease);
}
.fab .ico { width: 24px; height: 24px; stroke-width: 2.2; }
.fab:active { transform: scale(.94); }
.fab:focus-visible { border-radius: 50%; }

/* =========================================================
   Tab bar
   ========================================================= */
.tabbar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 10;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; align-items: stretch;
  background: var(--bg); border-top: 1px solid var(--border);
}
.tabbar a {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--text-3);
}
.tabbar a span { font-size: 11px; font-weight: 500; line-height: 1.2; white-space: nowrap; }
.tabbar a[aria-current="page"] span { color: var(--text); font-weight: 700; }
.tabbar svg {
  width: 22px; height: 22px; padding: 4px 14px; box-sizing: content-box;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
  border-radius: var(--r-pill); transition: background .2s var(--ease);
}
.tabbar a[aria-current="page"] { color: var(--on-accent); }
.tabbar a[aria-current="page"] svg { background: var(--accent); stroke-width: 2; }
.tabbar.hidden { display: none; }

/* Sticky bottom action (checkout) */
.checkout-bar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 8;
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--gutter) calc(var(--s3) + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--border);
}
.checkout-bar .info { flex: 1; min-width: 0; }
.checkout-bar .label { font-size: var(--fs-meta); color: var(--text-3); }
.checkout-bar .value { font-size: var(--fs-title); font-weight: 700; overflow-wrap: anywhere; line-height: 1.2; }
.checkout-bar .btn { flex: none; }

.cart-empty {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s2);
  padding: var(--s6) var(--s5); margin-top: var(--s2);
  border: 1px dashed var(--border-strong); border-radius: var(--r-md);
}
.cart-empty .ico { width: 24px; height: 24px; color: var(--text-3); }
.cart-empty p { font-size: var(--fs-sm); color: var(--text-3); }
.cart-empty .btn { margin-top: var(--s2); }

/* =========================================================
   Express card (home quick actions) & plain-language summaries
   ========================================================= */
.express-hint { font-size: var(--fs-sm); color: var(--text-2); margin-bottom: var(--s2); }
.express { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.express-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--s3);
  min-height: 96px; padding: var(--s4); text-align: left;
  border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  background: var(--surface); color: var(--text);
  transition: transform .15s var(--ease), background .15s;
}
.express-btn:active { transform: scale(.98); background: var(--surface-2); }
.express-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.express-btn.primary:active { background: var(--accent-pressed); }
.express-btn .ico { width: 24px; height: 24px; stroke-width: 2.2; }
.express-btn b { display: block; font-size: var(--fs-body); font-weight: 700; }
.express-btn small { display: block; font-size: var(--fs-meta); opacity: .75; margin-top: 2px; }
.express-btn:focus-visible { border-radius: var(--r-lg); }

.quick-links { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); margin-top: var(--s3); }
.quick-links a {
  display: flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px; border-radius: var(--r-md); background: var(--surface-2);
  font-size: var(--fs-sm); font-weight: 600;
}
.quick-links .ico { width: 18px; height: 18px; }

.today, .explain { border-top: 1px solid var(--border); }
.today-row, .explain-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3);
  padding: var(--s3) 0; border-bottom: 1px solid var(--border); font-size: var(--fs-body);
}
.today-row span, .explain-row span { color: var(--text-2); min-width: 0; }
.today-row b, .explain-row b { font-weight: 600; white-space: nowrap; }
.today-row.total, .explain-row.total { border-bottom: 0; }
.today-row.total span, .explain-row.total span { color: var(--text); font-weight: 600; }
.today-row.total b, .explain-row.total b { font-size: var(--fs-title); font-weight: 700; }

/* Product analysis */
.list-row.static { border-bottom: 0; }
.explain-row.bar-row { align-items: center; }
.bar-row span { flex: none; width: 104px; }
.bar-row small { font-size: var(--fs-meta); color: var(--text-3); }
.bar-row .meter { flex: 1; }
.bar-row b { width: 40px; text-align: right; }
/* Selling price split into HPP and margin; neutral marks like the charts */
.split { display: flex; height: 10px; margin-top: var(--s4); border-radius: var(--r-pill); overflow: hidden; background: var(--chart-1); }
.split-hpp { background: var(--chart-muted); }
.split-laba { flex: 1; }
.split-legend { display: flex; justify-content: space-between; gap: var(--s3); margin: var(--s2) 0 var(--s4); font-size: var(--fs-meta); color: var(--text-2); }
.split-legend span { display: inline-flex; align-items: center; gap: 6px; }
.split-legend i { width: 10px; height: 10px; border-radius: 3px; }
.sw-hpp { background: var(--chart-muted); }
.sw-laba { background: var(--chart-1); }
.callout { margin: 0 0 var(--s4); padding: var(--s3); border-radius: var(--r-md); background: var(--surface-2); font-size: var(--fs-sm); color: var(--text); }
.fineprint { margin-top: var(--s3); font-size: var(--fs-meta); color: var(--text-3); line-height: 1.5; }

.more summary {
  display: flex; align-items: center; justify-content: center; min-height: var(--control-h);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  font-size: var(--fs-sm); font-weight: 600; cursor: pointer; list-style: none;
}
.more summary::-webkit-details-marker { display: none; }
.more[open] summary { margin-bottom: var(--s5); }
.more .sub-head { margin-top: var(--s6); }


/* =========================================================
   Profile
   ========================================================= */
.avatar-btn {
  width: 40px; height: 40px; flex: none; border-radius: var(--r-pill); overflow: hidden;
  background: var(--surface-2); color: var(--text-2);
  display: grid; place-items: center; font-size: var(--fs-sm); font-weight: 600;
}
.avatar-btn img, .profile-logo img { width: 100%; height: 100%; object-fit: cover; }
.profile-id { display: flex; align-items: center; gap: var(--s4); padding: var(--s2) var(--gutter) 0; }
.profile-logo {
  width: 64px; height: 64px; flex: none; border-radius: var(--r-lg); overflow: hidden;
  background: var(--surface-2); color: var(--text-2);
  display: grid; place-items: center; font-size: var(--fs-title); font-weight: 700;
}
.profile-id h2 { font-size: var(--fs-title); font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.profile-id p { font-size: var(--fs-sm); color: var(--text-3); margin-top: 2px; }
.profile-stats { padding: var(--s3) var(--gutter) 0; font-size: var(--fs-sm); color: var(--text-2); }
.menu-row { min-height: 52px; font-size: var(--fs-body); }
.menu-row .row-main { font-weight: 500; }
.app-version { text-align: center; font-size: var(--fs-meta); color: var(--text-3); margin-top: var(--s5); }
.logo-picker { display: flex; align-items: center; gap: var(--s4); margin-bottom: var(--s5); }
.logo-picker .actions { display: flex; flex-direction: column; align-items: flex-start; gap: var(--s1); }
/* Photo crop sheet: the frame matches .profile-logo's corner ratio (20px on 64px) */
.crop-stage {
  position: relative; width: min(100%, 300px); aspect-ratio: 1; margin: 0 auto;
  border-radius: var(--r-md); overflow: hidden; background: var(--surface-2);
  touch-action: none; cursor: grab; user-select: none;
}
.crop-stage.dragging { cursor: grabbing; }
.crop-stage img { position: absolute; left: 50%; top: 50%; max-width: none; pointer-events: none; }
.crop-frame {
  position: absolute; inset: 10%; border-radius: 31%; pointer-events: none;
  box-shadow: 0 0 0 2px #fff, 0 0 0 999px rgba(0, 0, 0, .55);
}
.crop-zoom { display: flex; align-items: center; gap: var(--s3); width: min(100%, 300px); margin: var(--s4) auto 0; color: var(--text-3); }
.crop-zoom input { flex: 1; accent-color: var(--accent); }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.form-intro { font-size: var(--fs-sm); color: var(--text-2); margin-bottom: var(--s5); }

/* =========================================================
   Welcome & login
   ========================================================= */
.welcome { min-height: 100%; display: flex; flex-direction: column; background: var(--bg); }
.welcome-photo { position: relative; height: 42%; min-height: 240px; flex: none; overflow: hidden; background: var(--surface-2); }
.welcome-photo img { width: 100%; height: 100%; object-fit: cover; object-position: 75% 35%; display: block; }
.brand {
  position: absolute; left: var(--gutter); top: var(--s4);
  display: flex; align-items: center; gap: var(--s2);
  padding: 6px 12px 6px 6px; border-radius: var(--r-pill); background: var(--bg);
  font-size: var(--fs-body); font-weight: 700;
}
.slides { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; flex: 1; }
.slides::-webkit-scrollbar { display: none; }
.slide { flex: 0 0 100%; scroll-snap-align: start; padding: var(--s5) var(--gutter) 0; }
.slide .step { font-size: var(--fs-meta); font-weight: 600; color: var(--text-3); }
.slide h1 { font-size: var(--fs-display); font-weight: 700; line-height: 1.15; letter-spacing: -0.02em; margin-top: var(--s2); }
.slide p { font-size: var(--fs-body); line-height: 1.5; color: var(--text-2); margin-top: var(--s3); }
.dots { display: flex; gap: 6px; padding: var(--s4) var(--gutter); }
.dots button { width: 8px; height: 8px; padding: 0; border: 0; border-radius: var(--r-pill); background: var(--border-strong); transition: width .25s var(--ease), background .25s; }
.dots button.on { width: 24px; background: var(--accent); }
.welcome-actions { padding: 0 var(--gutter) calc(var(--s5) + env(safe-area-inset-bottom)); }
.welcome-actions p { text-align: center; font-size: var(--fs-sm); color: var(--text-2); margin-top: var(--s4); }

.auth { padding-top: var(--s2); }
.auth h2 { font-size: var(--fs-display); font-weight: 700; letter-spacing: -0.02em; margin-top: var(--s4); }
.auth-sub { font-size: var(--fs-body); color: var(--text-2); margin: var(--s2) 0 var(--s5); }
.auth-error { display: block; margin-bottom: var(--s3); }
.auth-error:empty { display: none; }
.auth-foot { text-align: center; font-size: var(--fs-sm); color: var(--text-2); margin-top: var(--s4); }

/* =========================================================
   Motion
   ========================================================= */
.fade-in { animation: fadeIn .2s var(--ease); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
