:root {
  --bg: #0c1311;
  --surface: #131c19;
  --surface-2: #18231f;
  --border: #24322d;
  --border-strong: #31443d;
  --text: #e8efec;
  --text-2: #a5b5af;
  --text-3: #71847d;
  --accent: #1f8a5b;
  --accent-strong: #26a56d;
  --accent-soft: rgba(38, 165, 109, 0.14);
  --pos: #3ccf8e;
  --neg: #ff6b6b;
  --warn: #f3b74f;
  --blue: #7fa6dc;
  --c1: #4a78b8; --c2: #6f9bd6; --c3: #9cbbe6; --c4: #d98a6a; --c5: #c9d6e8; --c6: #8a8fd8; --c7: #b98ad8; --c8: #5fb3b3;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 0 rgba(255,255,255,0.03) inset, 0 10px 30px -18px rgba(0,0,0,0.6);
  --font: 'Hind Siliguri', 'Noto Sans Bengali', system-ui, sans-serif;
  color-scheme: dark;
}
:root[data-theme='light'] {
  --bg: #f3f6f4;
  --surface: #ffffff;
  --surface-2: #f6f9f7;
  --border: #e1e8e4;
  --border-strong: #cfdad4;
  --text: #13201b;
  --text-2: #4c5e57;
  --text-3: #7d8e87;
  --accent: #157a4f;
  --accent-strong: #138a57;
  --accent-soft: rgba(21, 122, 79, 0.1);
  --pos: #12935c;
  --neg: #d64545;
  --warn: #b7791f;
  --blue: #2f5f9e;
  --shadow: 0 1px 2px rgba(16, 24, 20, 0.04), 0 8px 24px -16px rgba(16, 24, 20, 0.18);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* component display rules must never un-hide */
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; font-family: 'Inter', var(--font); }

/* ---------- layout ---------- */
.container { max-width: 1180px; margin: 0 auto; padding: 24px 16px 48px; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.brand h1 { font-size: 26px; line-height: 1.2; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
.brand p { margin: 2px 0 0; color: var(--text-3); font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: 380px 1fr; gap: 20px; align-items: start; }
.stack { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
.grid > *, .grid-2 > * { min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.sticky { position: sticky; top: 16px; }
@media (max-width: 920px) {
  .grid, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .sticky { position: static; }
}

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.card-title { font-size: 18px; font-weight: 700; margin: 0; line-height: 1.25; }
.sub:empty, .brand p:empty { display: none !important; }
.lang-seg { align-self: center; }
.sub { display: block; font-size: 12px; color: var(--text-3); font-weight: 400; margin-top: 1px; }
.section-label { font-size: 13px; font-weight: 700; color: var(--text-2); margin: 18px 0 10px; display: flex; gap: 6px; align-items: baseline; }
.section-label:first-child { margin-top: 0; }
.divider { height: 1px; background: var(--border); margin: 18px 0; border: 0; }

/* ---------- form ---------- */
.field { display: grid; gap: 6px; }
.field > label { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.25; }
.field > label .sub { font-size: 11.5px; }
.row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field { min-width: 0; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 520px) {
  .row-3 { grid-template-columns: 1fr 1fr; }
  .card { padding: 16px; }
  .brand h1 { font-size: 22px; }
  .row[style] { grid-template-columns: 1fr !important; }
  .legend-row { grid-template-columns: 12px 1fr auto 44px; gap: 8px; }
}
.input {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0 12px; height: 44px; transition: border-color .15s, box-shadow .15s;
}
.input:focus-within { border-color: var(--accent-strong); box-shadow: 0 0 0 3px var(--accent-soft); }
.input input, .input select { flex: 1; min-width: 0; width: 100%; background: none; border: 0; outline: 0; height: 100%; font-weight: 600; font-size: 15px; }
.input select { cursor: pointer; }
.input select option { background: var(--surface); }
.input .affix { color: var(--text-3); font-size: 14px; font-weight: 500; }
.input input::placeholder { color: var(--text-3); font-weight: 500; }
.input.lg { height: 54px; }
.input.lg input { font-size: 22px; font-weight: 700; }
.hint { font-size: 11.5px; color: var(--text-3); }
.hint b { color: var(--text-2); font-weight: 600; }
textarea.textarea { width: 100%; min-height: 80px; resize: vertical; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; outline: 0; }
textarea.textarea:focus { border-color: var(--accent-strong); }

/* ---------- buttons, chips ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface);
  font-weight: 600; font-size: 13.5px; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.danger { color: var(--neg); }
.btn.sm { height: 32px; padding: 0 10px; font-size: 12.5px; }
.btn.icon { width: 38px; padding: 0; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600; color: var(--text-2); cursor: pointer; }
.seg.full { display: flex; width: 100%; border-radius: 12px; }
.seg.full button { flex: 1; padding: 8px 10px; border-radius: 9px; font-size: 13.5px; }
.seg button:disabled { cursor: not-allowed; opacity: .7; }
.seg button.on { background: var(--text); color: var(--bg); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; background: var(--accent-soft); color: var(--pos); white-space: nowrap; }
.badge.warn { background: rgba(243, 183, 79, .14); color: var(--warn); }
.badge.neg { background: rgba(255, 107, 107, .14); color: var(--neg); }
.badge.muted { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }

/* ---------- price tag hero ---------- */
.hero {
  position: relative; overflow: hidden; border-radius: 18px; padding: 26px 26px 22px;
  background: linear-gradient(135deg, #17885a 0%, #0f6a45 100%); color: #fff;
  box-shadow: 0 20px 40px -24px rgba(16, 120, 78, .7);
}
.hero::after { content: ''; position: absolute; inset: 10px; border: 1.5px dashed rgba(255,255,255,.22); border-radius: 12px; pointer-events: none; }
.hero .label { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hero .label .sub { color: rgba(255,255,255,.7); }
.hero .price { font-size: clamp(48px, 9vw, 76px); font-weight: 800; letter-spacing: -0.03em; line-height: 1; margin: 14px 0 16px; font-family: 'Inter', var(--font); }
.hero .price small { font-size: .45em; vertical-align: top; margin-right: 4px; font-weight: 700; opacity: .9; }
.hero .seg { background: rgba(0,0,0,.18); border-color: rgba(255,255,255,.15); position: relative; z-index: 1; }
.hero .seg button { color: rgba(255,255,255,.85); }
.hero .seg button.on { background: #fff; color: #0f6a45; }
.hero .seg-label { font-size: 12px; color: rgba(255,255,255,.8); margin-right: 8px; }
.hero-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-top: 18px; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.2); position: relative; z-index: 1; }
.hero-stats .k { font-size: 12.5px; font-weight: 600; line-height: 1.2; }
.hero-stats .k .sub { color: rgba(255,255,255,.65); font-size: 11px; }
.hero-stats .v { font-size: 20px; font-weight: 800; margin-top: 4px; font-family: 'Inter', var(--font); }
@media (max-width: 640px) { .hero-stats { grid-template-columns: 1fr 1fr; } .hero { padding: 22px 20px 20px; } }
.hero.loss { background: linear-gradient(135deg, #a33d3d 0%, #7d2b2b 100%); }
.hero .lock { font-size: 11.5px; background: rgba(255,255,255,.18); padding: 3px 9px; border-radius: 999px; font-weight: 700; }

/* ---------- breakdown ---------- */
.bar { display: flex; height: 26px; border-radius: 8px; overflow: hidden; gap: 2px; background: var(--surface-2); }
.bar > div { min-width: 3px; transition: flex-grow .3s ease; }
.legend { margin-top: 14px; display: grid; }
.legend-row { display: grid; grid-template-columns: 12px 1fr auto 52px; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--border); }
.legend-row:last-child { border-bottom: 0; }
.legend-row .dot { width: 10px; height: 10px; border-radius: 3px; }
.legend-row .name { font-size: 13.5px; font-weight: 600; line-height: 1.2; }
.legend-row .val { font-weight: 700; text-align: right; }
.legend-row .pct { font-size: 12px; color: var(--text-3); text-align: right; }
.legend-row.total .val { color: var(--pos); }
.legend-row.total.neg .val { color: var(--neg); }

/* ---------- stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr)); gap: 12px; }
.tile { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 14px; min-width: 0; }
.tile .k { font-size: 13px; font-weight: 600; line-height: 1.25; }
.tile .v { white-space: nowrap; font-size: clamp(18px, 5.4vw, 24px); font-weight: 800; margin-top: 8px; line-height: 1.1; font-family: 'Inter', var(--font); letter-spacing: -0.01em; }
.tile .f { font-size: 11.5px; color: var(--text-3); margin-top: 6px; }
.tile.pos .v { color: var(--pos); }
.tile.neg .v { color: var(--neg); }
.tile.blue .v { color: var(--blue); }
.tile.hl { background: var(--accent-soft); border-color: transparent; }

.rate-bar { display: flex; height: 8px; border-radius: 999px; overflow: hidden; gap: 2px; margin: 8px 0 12px; }
.rate-bar .s { background: var(--pos); }
.rate-bar .c { background: var(--neg); }
.rate-bar .r { background: var(--c4); }

/* ---------- list rows ---------- */
.kv { display: grid; }
.kv-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.kv-row:last-child { border-bottom: 0; }
.kv-row .k { font-size: 14px; font-weight: 600; line-height: 1.25; }
.kv-row .v { text-align: right; font-weight: 800; font-size: 18px; font-family: 'Inter', var(--font); }
.kv-row .v .sub { font-weight: 500; text-align: right; font-family: var(--font); }
.kv-row .v.pos { color: var(--pos); }
.kv-row .v.blue { color: var(--blue); }
.kv-row .v.neg { color: var(--neg); }

.big-number { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.big-number .n { font-size: 52px; font-weight: 800; line-height: 1; font-family: 'Inter', var(--font); letter-spacing: -0.03em; }
.big-number .t { font-size: 18px; font-weight: 700; }

/* ---------- details / formula ---------- */
details.explain { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
details.explain summary { cursor: pointer; padding: 14px 18px; font-weight: 700; font-size: 14px; list-style: none; display: flex; align-items: center; gap: 8px; }
details.explain summary::-webkit-details-marker { display: none; }
details.explain summary::before { content: '▸'; transition: transform .15s; display: inline-block; }
details.explain[open] summary::before { transform: rotate(90deg); }
details.explain .body { padding: 0 18px 16px; font-size: 13.5px; color: var(--text-2); }
.formula { display: grid; gap: 8px; }
.formula div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dashed var(--border); padding-bottom: 8px; }
.formula code { font-family: 'Inter', var(--font); color: var(--text); font-weight: 600; text-align: right; }

details.adv { border: 1px dashed var(--border-strong); border-radius: 12px; margin-top: 16px; }
details.adv summary { cursor: pointer; padding: 12px 14px; font-weight: 700; font-size: 13.5px; display: flex; justify-content: space-between; align-items: center; list-style: none; }
details.adv summary::-webkit-details-marker { display: none; }
details.adv .body { padding: 2px 14px 14px; display: grid; gap: 12px; }

.notice { display: flex; gap: 10px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; font-size: 13px; color: var(--text-2); margin-top: 20px; }
.empty { color: var(--text-3); text-align: center; padding: 24px; font-size: 14px; }
.error-box.info-box { background: var(--surface); color: var(--text-2); border-color: var(--border); }
.input:has(input:disabled) { opacity: .65; }
.error-box { background: rgba(255,107,107,.1); color: var(--neg); border: 1px solid rgba(255,107,107,.3); padding: 12px 14px; border-radius: 12px; font-weight: 600; font-size: 14px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px; opacity: 0; transition: .2s; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- admin ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; font-weight: 600; color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent-strong); }
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
.save-bar { position: sticky; bottom: 0; margin-top: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; box-shadow: 0 -10px 30px -20px rgba(0,0,0,.5); flex-wrap: wrap; }
.save-bar .status { font-size: 13.5px; color: var(--text-2); font-weight: 600; }
.save-bar .status.dirty { color: var(--warn); }
.login { max-width: 380px; margin: 10vh auto; }
.search { max-width: 280px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }

/* ---------- admin: labelled field lists (no tables) ---------- */
.list { display: grid; gap: 10px; }
.item { display: grid; gap: 12px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.item-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.f { display: grid; gap: 4px; flex: 1 1 120px; min-width: 0; }
.f.w2 { flex: 2 1 200px; }
.f > span { font-size: 12px; font-weight: 600; color: var(--text-2); }
.inp { height: 38px; width: 100%; min-width: 0; padding: 0 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; outline: 0; font-weight: 600; }
.inp:focus { border-color: var(--accent-strong); box-shadow: 0 0 0 3px var(--accent-soft); }
.inp::placeholder { color: var(--text-3); font-weight: 500; }
select.inp { cursor: pointer; }
.sentence { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.sentence input.inp { width: 96px; }
.sentence.big { font-size: 16px; }
.sentence.big input.inp { height: 44px; font-size: 18px; width: 110px; }
.list > .sentence { padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.result-line { font-size: 13px; color: var(--text-2); line-height: 1.7; }
.result-line b { color: var(--text); font-family: 'Inter', var(--font); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; font-weight: 600; cursor: pointer; }
.check input { margin-top: 4px; width: 16px; height: 16px; flex: none; }
details.more > summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text-2); list-style: none; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: '▸ '; }
details.more[open] > summary::before { content: '▾ '; }
details.more[open] > .item-row { margin-top: 10px; }
.toolbar > .btn { flex: none; }

/* ---------- visitors chart (single series: one hue, no legend) ---------- */
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--pos); margin-right: 6px; vertical-align: middle; box-shadow: 0 0 0 0 var(--pos); animation: livePulse 1.8s infinite; }
@keyframes livePulse { 0% { box-shadow: 0 0 0 0 rgba(60, 207, 142, .5); } 70% { box-shadow: 0 0 0 8px rgba(60, 207, 142, 0); } 100% { box-shadow: 0 0 0 0 rgba(60, 207, 142, 0); } }
.vchart { position: relative; display: flex; align-items: flex-end; gap: 2px; height: 180px; padding-top: 18px; border-bottom: 1px solid var(--border-strong); }
.vchart-max { position: absolute; top: 0; left: 0; font-size: 11px; color: var(--text-3); font-family: 'Inter', var(--font); }
.vcol { position: relative; flex: 1; height: 100%; display: flex; align-items: flex-end; cursor: default; }
.vbar { width: 100%; min-height: 2px; background: var(--accent-strong); border-radius: 4px 4px 0 0; opacity: .85; }
.vcol.today .vbar { opacity: 1; }
.vcol:hover .vbar { opacity: 1; filter: brightness(1.15); }
.vcol:hover::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); white-space: nowrap; background: var(--text); color: var(--bg); font-size: 12px; font-weight: 600; padding: 4px 8px; border-radius: 6px; z-index: 2; pointer-events: none; }
.vcol:first-child:hover::after { left: 0; transform: none; }
.vcol:last-child:hover::after { left: auto; right: 0; transform: none; }
.vchart-axis { display: flex; gap: 2px; margin-top: 6px; }
.vchart-axis span { flex: 1; font-size: 11px; color: var(--text-3); text-align: center; white-space: nowrap; overflow: visible; }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }

/* ---------- users & activity timeline ---------- */
.dtable tr.click { cursor: pointer; }
.dtable tr.click:hover td { background: var(--surface-2); }
.dtable td .sub { display: block; }
.user-detail { border: 1px solid var(--border-strong); border-radius: 12px; padding: 14px; margin-bottom: 14px; background: var(--surface-2); }
.ud-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
.ud-head .sub { display: block; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; max-height: 420px; overflow-y: auto; }
.timeline li { display: grid; grid-template-columns: 130px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.timeline li:last-child { border-bottom: 0; }
.tl-time { color: var(--text-3); font-size: 12px; font-family: 'Inter', var(--font); }
@media (max-width: 520px) { .timeline li { grid-template-columns: 1fr; gap: 2px; } }

/* ---------- date filter (Shopify-style popover) ---------- */
.date-filter { position: relative; }
.date-filter #rangeBtn b { font-weight: 700; }
.date-filter #rangeBtn .sub { margin: 0 2px 0 6px; }
.date-pop { position: absolute; top: calc(100% + 6px); left: 0; z-index: 20; display: grid; grid-template-columns: 170px 260px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: 0 20px 40px -20px rgba(0,0,0,.6); overflow: hidden; }
.date-pop[hidden] { display: none; }
.date-presets { display: grid; align-content: start; padding: 6px; border-right: 1px solid var(--border); }
.date-presets button { text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 8px; font-weight: 600; font-size: 13.5px; color: var(--text-2); cursor: pointer; }
.date-presets button:hover { background: var(--surface-2); color: var(--text); }
.date-presets button.on { background: var(--accent-soft); color: var(--pos); }
.date-custom { display: grid; gap: 10px; padding: 14px; align-content: start; }
.date-custom input[type=date] { color-scheme: inherit; }
@media (max-width: 520px) {
  .date-pop { grid-template-columns: 1fr; left: 0; right: 0; }
  .date-presets { grid-template-columns: 1fr 1fr; border-right: 0; border-bottom: 1px solid var(--border); }
}
.vchart.few { justify-content: flex-start; }
.vchart.few .vcol, .vchart-axis.few span { flex: 0 0 min(64px, 13%); }
.vchart-axis.few { justify-content: flex-start; }

/* ---------- info strip (read-only admin values) ---------- */
.info { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; display: grid; gap: 6px; }
.info-row { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--text-2); }
.info-row b { color: var(--text); font-family: 'Inter', var(--font); font-weight: 700; white-space: nowrap; }
.info .lock-note { font-size: 11.5px; color: var(--text-3); border-top: 1px dashed var(--border); padding-top: 6px; }

/* ---------- compact data table (results) ---------- */
.dtable { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.dtable th { text-align: right; font-size: 11.5px; font-weight: 600; color: var(--text-3); padding: 8px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.dtable th:first-child, .dtable td:first-child { text-align: left; }
.dtable td { text-align: right; padding: 9px 8px; border-bottom: 1px solid var(--border); font-weight: 700; font-family: 'Inter', var(--font); white-space: nowrap; }
.dtable tr:last-child td { border-bottom: 0; }
.dtable tr.cur td { background: var(--accent-soft); }
.dtable td.pos { color: var(--pos); }
.dtable td.neg { color: var(--neg); }
.dtable td .sub { font-family: var(--font); font-weight: 500; }

/* ---------- tips ---------- */
.tips { display: grid; gap: 10px; }
.tip { display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; padding: 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); font-size: 13.5px; color: var(--text-2); }
.tip .ic { font-size: 18px; line-height: 1.2; }
.tip b { color: var(--text); }
.tip.warn { border-color: rgba(243, 183, 79, .35); }
.tip.bad { border-color: rgba(255, 107, 107, .35); }

/* ---------- responsive: tables become cards on small screens ---------- */
@media (max-width: 760px) {
  .tabs { flex-wrap: wrap; overflow: visible; }
  .tabs button { padding: 8px 10px; }
  .table-wrap { margin: 0; padding: 0; }
  .hide-sm { display: none; }
}
@media (max-width: 360px) {
  .row { grid-template-columns: minmax(0, 1fr); }
  .hide-xs { display: none; }
}
@media (max-width: 420px) {
  .dtable th, .dtable td { white-space: normal; }
  .actions .btn { flex: 1 1 auto; justify-content: center; }
  .actions .btn.icon { flex: 0 0 38px; }
  .hero .price { margin: 10px 0 12px; }
  .hero-stats .v { font-size: 17px; }
  .big-number .n { font-size: 42px; }
  .dtable { font-size: 12.5px; }
  .dtable th, .dtable td { padding: 8px 5px; }
}

/* ---------- website gate ---------- */
.gate { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: color-mix(in srgb, var(--bg) 82%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.gate[hidden] { display: none; }
.gate-card { width: min(440px, 100%); display: grid; gap: 14px; text-align: center; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 18px; padding: 28px 22px; box-shadow: 0 30px 60px -30px rgba(0,0,0,.7); }
.gate-icon { width: 52px; height: 52px; margin: 0 auto; border-radius: 14px; display: grid; place-items: center; background: var(--accent); color: #fff; font-size: 28px; font-weight: 700; }
.gate-card h2 { margin: 0; font-size: 20px; line-height: 1.3; }
.gate-card p { margin: 0; color: var(--text-2); font-size: 14px; }
.gate-card .input input { text-align: center; font-size: 18px; }
.gate-card .btn { height: 48px; justify-content: center; font-size: 15px; }
.auth-form { display: grid; gap: 12px; text-align: left; }
.auth-form .field > span { font-size: 13px; font-weight: 600; }
.auth-form .btn { margin-top: 4px; }
.gate-card .auth-form .input input { text-align: left; font-size: 16px; }
.pw-toggle { background: none; border: 0; padding: 0 2px; font-size: 16px; cursor: pointer; opacity: .6; }
.pw-toggle.on { opacity: 1; }
.gate-card { max-height: 100dvh; overflow-y: auto; }
.gate-err { color: var(--neg); font-size: 13px; font-weight: 600; }
body.gated { overflow: hidden; }
.site-line { text-align: center; font-size: 12.5px; color: var(--text-3); margin: 12px 0 0; }
.site-line b { color: var(--text-2); }
.linkbtn { background: none; border: 0; padding: 0; color: var(--pos); font-weight: 600; cursor: pointer; text-decoration: underline; }
@media (max-width: 640px) {
  .gate { align-items: end; padding: 0; }
  .gate-card { width: 100%; border-radius: 20px 20px 0 0; border-left: 0; border-right: 0; border-bottom: 0; padding: 24px 18px calc(20px + env(safe-area-inset-bottom)); }
}

/* ---------- price bar (mobile: keeps the answer in view while scrolling) ---------- */
.price-bar { display: none; }

/* ================= Mobile first-class: native-app layout ================= */
html { -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; }
button, .btn, .seg button, a { touch-action: manipulation; }
@media (max-width: 640px) {
  body { font-size: 15px; }
  /* Edge-to-edge: no outer gutters, one level of padding inside each section. */
  .container { padding: 0 0 calc(76px + env(safe-area-inset-bottom)); }
  .grid, .grid-2 { gap: 8px; }
  .stack { gap: 8px; }
  .card, .notice, details.explain {
    border-radius: 0; border-left: 0; border-right: 0; box-shadow: none;
    padding-left: 16px; padding-right: 16px;
  }
  .card { padding-top: 16px; padding-bottom: 16px; }
  .notice { margin: 8px 0 0; }
  details.explain summary { padding: 14px 16px; }
  details.explain .body { padding: 0 16px 16px; }

  /* App bar */
  .topbar {
    position: sticky; top: 0; z-index: 30; margin: 0 0 8px;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px 16px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
    flex-wrap: nowrap; align-items: center; gap: 8px;
  }
  .brand { min-width: 0; flex: 1; }
  .brand h1 { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .brand p { display: none; }
  .topbar .actions { flex-wrap: nowrap; gap: 4px; flex: none; }
  .topbar .actions .btn { flex: none; width: 40px; height: 40px; padding: 0; justify-content: center; border-color: transparent; background: transparent; }
  .topbar .actions .btn svg { width: 20px; height: 20px; }
  .topbar .actions .btn > span, .topbar .actions .btn.text-only { display: none; }
  .topbar .actions .btn.keep { width: auto; padding: 0 10px; display: inline-flex; }
  .topbar .actions .btn.primary { background: transparent; color: var(--pos); }
  .lang-seg button { padding: 6px 9px; font-size: 12px; }
  #printBtn { display: none !important; } /* printing from a phone is rare; keeps the app bar to one row */

  /* Hero edge-to-edge */
  .hero { border-radius: 0; padding: 20px 16px 18px; box-shadow: none; }
  .hero::after { inset: 8px; border-radius: 10px; }
  .hero .price { font-size: clamp(52px, 16vw, 72px); }
  .hero-stats { gap: 12px; }

  /* Inputs: 16px stops iOS zoom-on-focus; 48px tap targets */
  .input { height: 48px; border-radius: 12px; }
  .input input, .input select, .inp, textarea.textarea { font-size: 16px; }
  .input.lg { height: 56px; }
  .input.lg input { font-size: 24px; }
  .inp { height: 44px; }
  .btn { min-height: 40px; }
  .seg.full button { padding: 11px 8px; font-size: 14px; }
  .seg button { padding: 8px 12px; }

  /* Cost panel: no nested box inside the card */
  details.adv { border: 0; border-top: 1px solid var(--border); border-radius: 0; margin: 14px -16px 0; }
  details.adv summary { padding: 14px 16px; }
  details.adv .body { padding: 0 16px 4px; }

  .tiles { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stack > .tiles { padding: 0 8px; }
  .formula div { flex-direction: column; gap: 2px; }
  .formula code { text-align: left; }
  .tile { padding: 12px; border-radius: 12px; }

  /* Bottom price bar */
  .price-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: linear-gradient(135deg, #17885a 0%, #0f6a45 100%); color: #fff;
    box-shadow: 0 -8px 24px -12px rgba(0,0,0,.5);
    transform: translateY(110%); transition: transform .2s ease;
  }
  .price-bar.show { transform: none; }
  .price-bar .pb-label { font-size: 12px; opacity: .85; line-height: 1.2; }
  .price-bar .pb-price { font-size: 24px; font-weight: 800; font-family: 'Inter', var(--font); line-height: 1.1; }
  .price-bar .pb-side { text-align: right; font-size: 12px; opacity: .9; line-height: 1.35; }
  .price-bar .pb-side b { font-family: 'Inter', var(--font); font-size: 14px; }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }

  /* Admin */
  .tabs { position: sticky; top: calc(61px + env(safe-area-inset-top)); z-index: 25; background: var(--bg); margin: 0 0 8px; padding: 0 8px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { padding: 12px 10px; }
  .save-bar { position: fixed; left: 0; right: 0; bottom: 0; margin: 0; border-radius: 0; border-left: 0; border-right: 0; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); z-index: 40; }
  .save-bar .actions { flex-wrap: nowrap; }
  .login { margin: 0; min-height: 100dvh; border-radius: 0; border: 0; padding-top: calc(24px + env(safe-area-inset-top)); }
  .toolbar { gap: 8px; }
  .item { padding: 12px; }
  .date-filter { padding: 0 16px; }
  .date-pop { left: 16px; right: 16px; }
}

@media (max-width: 380px) {
  .topbar .actions .btn { width: 36px; height: 36px; }
  .lang-seg button { padding: 5px 7px; }
}

@media print {
  :root { --bg: #fff; --surface: #fff; --surface-2: #f6f6f6; --text: #111; --text-2: #333; --text-3: #666; --border: #ddd; }
  .actions, details.adv, .no-print { display: none !important; }
  .grid { grid-template-columns: 1fr; }
  .card, .hero { box-shadow: none; break-inside: avoid; }
  details.explain { display: block; }
}
