/* Kudafushi Business Insights */
:root {
  color-scheme: light;
  --brand: #a88f83;          /* Kudafushi logo colour */
  --bg: #f6f3f0;
  --surface: #fdfcfb;
  --surface-2: #f1ece8;
  --line: #e7dfd9;
  --text: #1d1916;
  --text-2: #57504b;
  --text-3: #8a817b;
  --accent: #7a6357;         /* logo colour, darkened for readable text */
  --accent-ink: #ffffff;
  --accent-soft: #f1e9e4;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok-soft: #e6f4ea;
  --ok-ink: #1d6b33;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
  --grid: #ece6e1;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --brand: #c4ad9f;
    --bg: #141210;
    --surface: #1c1917;
    --surface-2: #27221f;
    --line: #352e2a;
    --text: #f2ede9;
    --text-2: #cbc1ba;
    --text-3: #998f88;
    --accent: #c4ad9f;
    --accent-ink: #241c18;
    --accent-soft: #352b26;
    --danger: #f2877d;
    --danger-soft: #3a1c19;
    --ok-soft: #173421;
    --ok-ink: #8fd4a0;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --grid: #2b2522;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); text-decoration: none; }
h1, h2 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 1.35rem; font-weight: 650; }
h2 { font-size: 1rem; font-weight: 600; }
.muted { color: var(--text-3); font-weight: 400; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: var(--surface); border-bottom: 1px solid var(--line);
  box-shadow: inset 0 3px 0 var(--brand);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600; letter-spacing: .02em; white-space: nowrap; }
.brand-mark {
  width: 34px; height: 34px; flex: none; display: inline-block;
  background: url("logo-mark.png") center/contain no-repeat;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand-mark { background-image: url("logo-mark-white.png"); opacity: .9; } }
.brand-logo { display: block; width: 220px; max-width: 80%; height: auto; margin: 0 auto 6px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand-logo { filter: brightness(1.25); } }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 7px 12px; border-radius: 8px; color: var(--text-2); font-weight: 500; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.who { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.who-name { color: var(--text-2); }
.link-btn { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 6px 0; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 20px 16px 48px; }

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: .9rem; }
.btn.block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font-size: 1.4rem; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); }

input, select {
  width: 100%; min-height: 42px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px;
}
input:focus, select:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: grid; gap: 6px; font-weight: 550; font-size: .92rem; color: var(--text-2); }
.stack { display: grid; gap: 14px; }
.grid2 { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.grid2.top { align-items: start; }
.row-end { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

fieldset.rights { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px 14px; margin: 0; }
fieldset.rights legend { padding: 0 6px; font-weight: 600; color: var(--text-2); font-size: .92rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; cursor: pointer; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip span {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text-2); font-weight: 500;
}
.chip input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); }
.chip input:checked + span::before { content: "✓ "; }
.switches { display: grid; gap: 10px; }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 550; color: var(--text); }
.switch input { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }

.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; }
.alert-ok { background: var(--ok-soft); color: var(--ok-ink); }
.alert-err { background: var(--danger-soft); color: var(--danger); }
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}
.badge.off { background: var(--danger-soft); color: var(--danger); }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.card.pad, .pad { padding: 18px; }
.card h2 { margin-bottom: 4px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.form-card { padding: 18px; }
.form-card h2 { margin-bottom: 14px; }
.page-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 4px 0 16px; }
.empty { text-align: center; padding: 64px 16px; }

/* ---------- Auth ---------- */
.auth { min-height: 80vh; display: grid; place-items: center; }
.auth-card {
  width: 100%; max-width: 380px; padding: 28px 24px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
}
.auth-card { text-align: center; }
.auth-card form { text-align: left; }
.auth-card h1 { margin: 10px 0 4px; font-size: 1.1rem; font-weight: 600; letter-spacing: .04em; color: var(--text-2); }
.auth-card > p { margin: 0 0 18px; }

/* ---------- Dashboard ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.seg { display: inline-flex; padding: 4px; gap: 2px; background: var(--surface-2); border-radius: 12px; }
.seg a { padding: 8px 16px; border-radius: 9px; color: var(--text-2); font-weight: 550; }
.seg a.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.picker { display: flex; align-items: center; gap: 6px; }
.picker input, .picker select { width: auto; min-width: 150px; }

.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.tile-label { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-weight: 550; font-size: .9rem; }
.tile-value { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; margin: 6px 0 10px; }
.tile-value.neg, td.neg { color: var(--danger); }
.tile-meta { display: grid; grid-template-columns: repeat(3, auto); justify-content: space-between; gap: 4px 12px; margin: 0; font-size: .82rem; }
.tile-meta div { display: grid; }
.tile-meta dt { color: var(--text-3); }
.tile-meta dd { margin: 0; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.tile-net { background: var(--accent-soft); border-color: transparent; }
.key { width: 10px; height: 10px; border-radius: 3px; background: var(--c); flex: none; display: inline-block; }

.charts { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 980px) { .charts { grid-template-columns: 3fr 2fr; } .charts > :only-child { grid-column: 1 / -1; } }
.chart-card { margin: 0; padding: 16px 16px 10px; }
.chart-card figcaption { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.legend { display: flex; gap: 14px; list-style: none; margin: 0; padding: 0; font-size: .85rem; color: var(--text-2); }
.legend li { display: flex; align-items: center; gap: 6px; }
.chart-box { position: relative; height: 280px; }
.charts + .card { margin-top: 16px; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td { padding: 10px 18px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 600; background: var(--surface); position: sticky; top: 0; }
table.data tbody th { font-weight: 550; }
table.data .num { text-align: right; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tr.now { background: var(--accent-soft); }
table.data tr.future { color: var(--text-3); }
table.data tfoot th, table.data tfoot td { font-weight: 700; border-bottom: 0; border-top: 2px solid var(--line); }
.dow { font-size: .8rem; }

/* ---------- Users ---------- */
table.users td { white-space: normal; vertical-align: top; }
table.users tr.disabled { opacity: .6; }
td.actions { display: flex; gap: 6px; justify-content: flex-end; }
td.actions form { margin: 0; }

/* ---------- Logs ---------- */
.filters { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; padding: 14px 18px; }
.filters label { min-width: 180px; }
.filters .count { margin-left: auto; padding-bottom: 10px; }
.log { list-style: none; margin: 0; padding: 0; }
.log li { display: grid; grid-template-columns: 110px 1fr auto; gap: 14px; padding: 12px 18px; border-bottom: 1px solid var(--line); align-items: start; }
.log li:last-child { border-bottom: 0; }
.log li.warn { box-shadow: inset 3px 0 0 var(--danger); }
.log time { font-size: .85rem; }
.log .ip { font-size: .8rem; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; }
.facts { margin: 12px 0 0; display: grid; gap: 10px; }
.facts div { display: grid; grid-template-columns: 90px 1fr; gap: 10px; }
.facts dt { color: var(--text-3); }
.facts dd { margin: 0; font-weight: 550; }

/* ---------- Phone ---------- */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; padding-bottom: 0; }
  .brand-name { font-size: .95rem; }
  .who { margin-left: auto; }
  .who-name { display: none; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .wrap { padding: 14px 12px 40px; }
  h1 { font-size: 1.15rem; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .seg { display: flex; }
  .seg a { flex: 1; text-align: center; padding: 9px 4px; }
  .picker input, .picker select { flex: 1; min-width: 0; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tile { padding: 12px; }
  .tile-value { font-size: 1.3rem; margin: 4px 0 8px; }
  .tile-meta { grid-template-columns: 1fr; gap: 3px; }
  .tile-meta div { display: flex; justify-content: space-between; gap: 6px; }
  .chart-box { height: 230px; }
  table.data th, table.data td { padding: 9px 12px; }
  .grid2 { grid-template-columns: 1fr; }
  .filters label { min-width: 0; flex: 1; }
  .filters .count { width: 100%; margin: 0; padding: 0; }
  .log li { grid-template-columns: 80px 1fr; }
  .log .ip { grid-column: 2; }

  /* users table becomes cards */
  table.users thead { display: none; }
  table.users, table.users tbody, table.users tr, table.users td { display: block; width: 100%; }
  table.users tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  table.users td { border: 0; padding: 3px 0; }
  table.users td[data-label]::before { content: attr(data-label); display: inline-block; width: 92px; color: var(--text-3); font-size: .85rem; }
  table.users td[data-label="User"]::before { display: none; }
  table.users td.actions { display: flex; justify-content: flex-start; padding-top: 10px; }
}
@media (max-width: 380px) { .tiles { grid-template-columns: 1fr; } }

/* keep the date column visible while scrolling the table sideways */
table.data tbody th, table.data thead th:first-child, table.data tfoot th { position: sticky; left: 0; background: var(--surface); z-index: 1; }
table.data thead th:first-child { z-index: 2; }
table.data tr.now th { background: var(--accent-soft); }
table.users tbody th { position: static; }

/* ---------- Status & settings ---------- */
.status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.updated { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--series-3); box-shadow: 0 0 0 3px color-mix(in srgb, var(--series-3) 25%, transparent); }
.sub { margin: 4px 0 0; font-size: .9rem; }
.settings { max-width: 760px; }
.hint { margin: 2px 0 14px; font-size: .9rem; }
.flow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; font-size: .85rem; font-weight: 600; }
.flow span { padding: 6px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.flow i { font-style: normal; color: var(--text-3); }
.advanced summary { cursor: pointer; list-style: none; display: grid; gap: 2px; }
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary h2::after { content: " ▸"; color: var(--text-3); }
.advanced[open] summary h2::after { content: " ▾"; }
.advanced[open] summary { margin-bottom: 14px; }
.advanced summary .muted { font-size: .85rem; }
.sticky-actions { position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); }
table.data tbody tr:hover th { background: var(--surface-2); }

.debug summary { cursor: pointer; }
.debug .facts div { grid-template-columns: 70px 1fr; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .85rem; word-break: break-all; }

/* ---------- Detail lists ---------- */
.tile { display: flex; flex-direction: column; }
.tile-link { margin-top: auto; padding-top: 10px; font-size: .85rem; font-weight: 600; }
.cell-link { color: inherit; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.cell-link:hover { color: var(--accent); text-decoration-color: currentColor; }
.back { display: inline-block; margin-bottom: 8px; font-weight: 600; font-size: .9rem; }
.range { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; padding: 14px 18px; }
.range label { min-width: 150px; }
.range .quick { display: flex; gap: 6px; flex-wrap: wrap; }
.search { max-width: 320px; }
@media (max-width: 760px) {
  .range label { flex: 1; min-width: 0; }
  .range .quick { width: 100%; }
  .range .quick .btn { flex: 1; }
  .range > .btn { width: 100%; }
  .card-head { flex-wrap: wrap; }
  .search { max-width: none; }
}

.demo-banner { background: #fff4d6; color: #6b4b00; border-bottom: 1px solid #f0d58a; padding: 9px 16px; text-align: center; font-size: .9rem; }
.demo-banner a { color: inherit; text-decoration: underline; margin-left: 6px; font-weight: 600; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .demo-banner { background: #3a2f12; color: #f3d98f; border-color: #5a4a1e; } }
.small { font-size: .82rem; font-weight: 400; } code { font-family: ui-monospace, Consolas, monospace; font-size: .85em; }

/* ---------- Settings: sources ---------- */
.source-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.pill { font-size: .8rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.pill.ok { background: var(--ok-soft); color: var(--ok-ink); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.query { margin-top: 14px; }
.query summary { cursor: pointer; font-weight: 600; font-size: .9rem; color: var(--accent); }
.query textarea { width: 100%; margin: 10px 0 8px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); color: var(--text); font: .8rem/1.5 ui-monospace, Consolas, monospace; resize: vertical; }
.debug-facts { margin: 0 0 14px; }
.debug-facts div { grid-template-columns: 60px 1fr; }
.alert:not(.alert-ok):not(.alert-err) { background: var(--surface-2); color: var(--text-2); }

.secret { -webkit-text-security: disc; text-security: disc; }

/* ---------- Compare with last year ---------- */
.compare-btn { gap: 8px; }
.compare-btn .tick { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid var(--text-3); font-size: .75rem; line-height: 1; }
.compare-btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.compare-btn.on .tick { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tile-compare { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); font-size: .82rem; }
.cmp-line { display: flex; align-items: baseline; gap: 6px; }
.cmp-detail { margin-top: 3px; line-height: 1.5; }
.cmp-detail strong { color: var(--text-2); font-weight: 600; }
.chg { font-weight: 700; white-space: nowrap; font-size: .85rem; }
.chg.good { color: var(--ok-ink); }
.chg.bad { color: var(--danger); }
.chg.flat { color: var(--text-3); }
.tile-compare .chg { font-size: .95rem; }
td.ly { color: var(--text-3); }
.key.prev { opacity: .4; }
@media (max-width: 760px) { .compare-btn { width: 100%; } }

.cmp-years { display: flex; flex-wrap: wrap; gap: 2px 16px; margin: 4px 0 0; }
.cmp-years div { display: flex; gap: 6px; align-items: baseline; }
.cmp-years dt { color: var(--text-3); }
.cmp-years dd { margin: 0; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.legend { flex-wrap: wrap; justify-content: flex-end; gap: 6px 14px; }
.legend li { white-space: nowrap; }

.tiles { grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr)); }
.tile { min-width: 0; }
@media (max-width: 760px) {
  .tiles { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .cmp-years { flex-direction: column; }
}
@media (min-width: 980px) { .charts.many { grid-template-columns: 1fr 1fr; } }
