/* Accunting — Stripe-style UI */
:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --border: #e3e8ee;
  --border-strong: #d5dbe1;
  --text: #30313d;
  --text-soft: #687385;
  /* Overridden per-request from Settings → branding colour, see accent_style_tag() */
  --accent: #4f6ef7;
  --accent-hover: #4661d9;
  --accent-soft: #f1f3fe;
  --ok: #217005;
  --ok-bg: #e2f2e6;
  --warn: #a3590a;
  --warn-bg: #f6ecd8;
  --bad: #b3063d;
  --bad-bg: #f7e6ea;
  --info: #0055bc;
  --info-bg: #e3eaf6;
  --neutral-bg: #ebeef1;
  --shadow-rgb: 48, 49, 61;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(var(--shadow-rgb), .06), 0 1px 2px rgba(var(--shadow-rgb), .04);
  --shadow-hover: 0 2px 6px rgba(var(--shadow-rgb), .1);
  --ring: 0 0 0 3px rgba(79, 110, 247, .28);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171c; --surface: #1d2027; --border: #2b2f39; --border-strong: #3c414d;
    --text: #e8eaf0; --text-soft: #9198a8;
    --ok: #4fd88a; --ok-bg: #17301f;
    --warn: #f5b855; --warn-bg: #3a2c11;
    --bad: #f77c8c; --bad-bg: #3a1b22;
    --info: #7cb0fb; --info-bg: #182840;
    --neutral-bg: #262a33;
    --shadow-rgb: 0, 0, 0;
  }
}
:root[data-theme="dark"] {
  --bg: #15171c; --surface: #1d2027; --border: #2b2f39; --border-strong: #3c414d;
  --text: #e8eaf0; --text-soft: #9198a8;
  --ok: #4fd88a; --ok-bg: #17301f;
  --warn: #f5b855; --warn-bg: #3a2c11;
  --bad: #f77c8c; --bad-bg: #3a1b22;
  --info: #7cb0fb; --info-bg: #182840;
  --neutral-bg: #262a33;
  --shadow-rgb: 0, 0, 0;
}
:root[data-theme="light"] {
  --bg: #f6f8fb; --surface: #ffffff; --border: #e3e8ee; --border-strong: #d5dbe1;
  --text: #30313d; --text-soft: #687385;
  --ok: #217005; --ok-bg: #e2f2e6;
  --warn: #a3590a; --warn-bg: #f6ecd8;
  --bad: #b3063d; --bad-bg: #f7e6ea;
  --info: #0055bc; --info-bg: #e3eaf6;
  --neutral-bg: #ebeef1;
  --shadow-rgb: 48, 49, 61;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0; padding: 20px 12px;
  display: flex; flex-direction: column; gap: 1px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
}
.brand { padding: 6px 7px 18px; }
.brand-logo { height: 40px; width: auto; vertical-align: middle; }
.logo-for-dark { display: none; }
@media (prefers-color-scheme: dark) {
  .logo-for-light { display: none; }
  .logo-for-dark { display: inline-block; }
}
:root[data-theme="dark"] .logo-for-light { display: none; }
:root[data-theme="dark"] .logo-for-dark { display: inline-block; }
:root[data-theme="light"] .logo-for-light { display: inline-block; }
:root[data-theme="light"] .logo-for-dark { display: none; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 12px; border-radius: var(--radius-sm);
  color: var(--text-soft); font-weight: 500; font-size: .95rem;
  transition: background .1s ease, color .1s ease;
}
.nav-link:hover { color: var(--text); background: var(--bg); }
.nav-link.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.nav-link .ic { width: 18px; text-align: center; font-size: .95rem; opacity: .8; }
.nav-sep { margin: 14px 12px 5px; font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .8px; color: var(--text-soft); }
.main { flex: 1; padding: 24px 32px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.topbar h1 { font-size: 1.45rem; font-weight: 700; letter-spacing: -0.3px; }
.topbar .sub { color: var(--text-soft); font-size: .9rem; margin-top: 3px; }
.top-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 22px; margin-bottom: 20px;
}
a.card:hover { box-shadow: var(--shadow-hover); border-color: var(--border-strong); color: inherit; }
.card.inset { background: var(--bg); box-shadow: none; }
.card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 14px; letter-spacing: -0.1px; }
.grid { display: grid; gap: 20px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 1100px) { .grid.cols-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .grid.cols-3 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 760px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 16px; }
}

.stat { padding: 16px 18px; }
.stat .label { font-size: .82rem; font-weight: 500; color: var(--text-soft); }
.stat .value { font-size: 1.5rem; font-weight: 700; margin-top: 6px; letter-spacing: -0.4px; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: .8rem; color: var(--text-soft); margin-top: 5px; }
.stat.ok .value { color: var(--ok); }
.stat.bad .value { color: var(--bad); }
.stat.warn .value { color: var(--warn); }
.stat.accent .value { color: var(--accent); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--border-strong); cursor: pointer; font: inherit;
  font-weight: 600; font-size: .9rem;
  color: var(--text); background: var(--surface);
  padding: 7px 14px; border-radius: var(--radius-sm);
  box-shadow: 0 1px 1px rgba(var(--shadow-rgb), .08);
  transition: all .1s ease;
}
.btn:hover { box-shadow: var(--shadow-hover); color: var(--text); }
.btn:active { box-shadow: none; }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn.primary {
  color: #fff; background: var(--accent); border-color: var(--accent);
  box-shadow: 0 1px 1px rgba(var(--shadow-rgb), .12), inset 0 1px 0 rgba(255, 255, 255, .12);
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: .82rem; }
.btn.ghost { border-color: transparent; box-shadow: none; background: transparent; color: var(--text-soft); }
.btn.ghost:hover { color: var(--text); background: var(--neutral-bg); }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* ---------- Forms ---------- */
label.f { display: block; margin-bottom: 13px; }
label.f .l, .f-l { display: block; font-size: .82rem; font-weight: 600; color: var(--text); margin-bottom: 5px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=file], input[type=url], input[type=color], select, textarea {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 1px rgba(var(--shadow-rgb), .06);
  padding: 7px 10px;
}
input[type=color] { padding: 3px 5px; height: 36px; }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23687385' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px;
}
.form-row { display: grid; gap: 0 16px; grid-template-columns: repeat(2, minmax(0,1fr)); }
.form-row.three { grid-template-columns: repeat(3, minmax(0,1fr)); }
@media (max-width: 700px) { .form-row, .form-row.three { grid-template-columns: 1fr; } }
.check { display: flex; align-items: center; gap: 9px; margin-bottom: 13px; font-weight: 500; font-size: .92rem; }
.check input { width: auto; accent-color: var(--accent); box-shadow: none; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
table.t th {
  text-align: left; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-soft); padding: 8px 10px; border-bottom: 1px solid var(--border);
}
table.t td { padding: 10px; border-bottom: 1px solid var(--border); font-size: .92rem; vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr.clickable { cursor: pointer; }
table.t tr.clickable:hover td { background: var(--bg); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--text-soft); padding: 40px 20px; }
.empty .big { font-size: 2rem; margin-bottom: 10px; opacity: .7; }

/* ---------- Badges & flash ---------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: .74rem; font-weight: 600; letter-spacing: .1px;
  background: var(--neutral-bg); color: var(--text-soft);
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--neutral-bg); color: var(--text-soft); }
.flashes { margin-bottom: 18px; }
.flash {
  padding: 11px 16px; border-radius: var(--radius-sm); margin-bottom: 8px;
  font-weight: 500; font-size: .92rem;
  background: var(--surface); border: 1px solid var(--border); border-left-width: 4px;
  box-shadow: var(--shadow);
}
.flash.ok { border-left-color: var(--ok); color: var(--ok); }
.flash.error { border-left-color: var(--bad); color: var(--bad); }
.flash.info { border-left-color: var(--info); color: var(--info); }

/* ---------- Auth screens ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--bg); }
.auth-card { width: 100%; max-width: 400px; padding: 34px 34px 30px; position: relative; overflow: hidden; }
.auth-card::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
}
.auth-card .brand { text-align: center; padding: 6px 0 2px; }
.auth-card .brand-logo { height: 34px; }
.auth-card .tag { text-align: center; color: var(--text-soft); margin-bottom: 24px; font-size: .92rem; }

/* ---------- Misc ---------- */
.muted { color: var(--text-soft); }
.small { font-size: .85rem; }
.right { text-align: right; }
.mt { margin-top: 16px; } .mb0 { margin-bottom: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.pill-tabs { display: inline-flex; gap: 4px; padding: 3px; border-radius: var(--radius-sm); background: var(--neutral-bg); }
.pill-tabs a { padding: 5px 12px; border-radius: 5px; font-weight: 600; font-size: .85rem; color: var(--text-soft); }
.pill-tabs a:hover { color: var(--text); }
.pill-tabs a.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(var(--shadow-rgb), .12); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700;
}
.progress { height: 8px; border-radius: 999px; background: var(--neutral-bg); overflow: hidden; }
.progress > div { height: 100%; border-radius: 999px; background: var(--accent); }
.chart-bars { display: flex; align-items: flex-end; gap: 10px; height: 180px; padding: 10px 4px 0; }
.chart-bars .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; min-width: 0; }
.chart-bars .bars { display: flex; gap: 4px; align-items: flex-end; height: 140px; width: 100%; justify-content: center; }
.chart-bars .bar { width: 45%; max-width: 24px; border-radius: 3px 3px 0 0; min-height: 2px; }
.chart-bars .bar.in { background: var(--accent); }
.chart-bars .bar.out { background: var(--bad); }
.chart-bars .lbl { font-size: .72rem; color: var(--text-soft); white-space: nowrap; }
.legend { display: flex; gap: 16px; font-size: .82rem; color: var(--text-soft); }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.itembox { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); padding: 12px 14px; margin-bottom: 10px; }
.tpl-pick { display: flex; gap: 12px; flex-wrap: wrap; }
.tpl-pick label { cursor: pointer; text-align: center; }
.tpl-pick input { display: none; }
.tpl-pick .swatch {
  width: 84px; height: 106px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); box-shadow: var(--shadow);
  padding: 8px; display: flex; flex-direction: column; gap: 4px; background: #fff;
}
.tpl-pick label:hover .swatch { box-shadow: var(--shadow-hover); }
.tpl-pick input:checked + .swatch { border-color: var(--accent); box-shadow: var(--ring); }
.tpl-pick .name { font-size: .78rem; font-weight: 600; margin-top: 6px; color: var(--text-soft); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 18px; font-size: .92rem; }
.kv dt { color: var(--text-soft); font-weight: 500; }
.kv dd { text-align: right; font-variant-numeric: tabular-nums; }
/* Stripe-style settings sections */
.settings-layout { display: flex; gap: 24px; align-items: flex-start; }
.settings-nav { width: 200px; flex-shrink: 0; padding: 10px; position: sticky; top: 20px; }
.settings-nav a {
  display: block; padding: 7px 12px; border-radius: var(--radius-sm);
  color: var(--text-soft); font-weight: 500; font-size: .93rem;
}
.settings-nav a:hover { color: var(--text); background: var(--bg); }
.settings-nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.settings-content { flex: 1; min-width: 0; }
@media (max-width: 860px) {
  .settings-layout { flex-direction: column; }
  .settings-nav { width: 100%; position: static; display: flex; flex-wrap: wrap; gap: 4px; }
}

code.k {
  background: var(--neutral-bg); border: 1px solid var(--border);
  border-radius: 5px; padding: 2px 7px; font-size: .84em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text);
}
