/* TaxFlow — design system + screens */

/* ===== Tokens (Light, Clean preset) ===== */
:root {
  --accent:        #2563eb;
  --accent-soft:   #2563eb1f;
  --accent-tint:   #2563eb0a;
  --on-accent:     #ffffff;

  --bg:            #fbfaf7;
  --bg-2:          #f5f3ee;
  --surface:       #ffffff;
  --surface-2:     #faf9f6;
  --sidebar:       #f4f2ed;

  --text:          #15171c;
  --text-2:        #3b4250;
  --text-3:        #6b7280;
  --text-dim:      #98a0ac;

  --line:          #e7e3da;
  --line-soft:     #efece4;

  --ok:            #16a34a;
  --ok-soft:       #16a34a18;
  --amber:         #d97706;
  --amber-soft:    #d9770618;
  --danger:        #dc2626;
  --danger-soft:   #dc262618;

  --r-lg: 14px;
  --r-md: 10px;
  --r-sm: 6px;

  --shadow-sm: 0 1px 2px rgba(20, 22, 30, 0.05);
  --shadow-md: 0 6px 24px -8px rgba(20, 22, 30, 0.10), 0 2px 6px -2px rgba(20, 22, 30, 0.05);
  --shadow-lg: 0 24px 48px -16px rgba(20, 22, 30, 0.14), 0 4px 12px -4px rgba(20, 22, 30, 0.06);

  --side-w: 248px;
  --topbar-h: 64px;

  --row-py: 14px;
  --row-fs: 14px;
  --row-line: 1.45;
}

/* density variants */
[data-density="compact"]     { --row-py: 9px;  --row-fs: 13px; }
[data-density="comfortable"] { --row-py: 14px; --row-fs: 14px; }
[data-density="spacious"]    { --row-py: 20px; --row-fs: 15px; }

/* preset: fintech (cooler, more graphical) */
[data-preset="fintech"] {
  --bg:        #f5f7fb;
  --bg-2:      #ebeff5;
  --surface:   #ffffff;
  --surface-2: #f8fafd;
  --sidebar:   #0b1220;
  --line:      #e3e8ef;
  --line-soft: #eef1f6;
  --text:      #0c111b;
  --text-2:    #2a3242;
  --text-3:    #5a6478;
  --shadow-md: 0 6px 24px -6px rgba(12, 17, 27, 0.10), 0 2px 6px -2px rgba(12, 17, 27, 0.06);
}
[data-preset="fintech"] .side {
  background: var(--sidebar);
  color: #cbd4e3;
  border-right: 1px solid #131a2e;
}
[data-preset="fintech"] .brand-name { color: #fff; }
[data-preset="fintech"] .brand-sub  { color: #7a8597; }
[data-preset="fintech"] .nav-item   { color: #cbd4e3; }
[data-preset="fintech"] .nav-item:hover     { background: #131a2e; color: #fff; }
[data-preset="fintech"] .nav-item.is-active { background: linear-gradient(180deg, #131a2e, #0e1426); color: #fff; }
[data-preset="fintech"] .theme-toggle { background: #131a2e; color: #cbd4e3; border-color: #1a2238; }
[data-preset="fintech"] .side-user-name { color: #fff; }

/* preset: soft (more rounded, pastel) */
[data-preset="soft"] {
  --bg:        #f7f4f0;
  --bg-2:      #eee9e0;
  --surface:   #ffffff;
  --surface-2: #fbf8f3;
  --sidebar:   #efeae0;
  --line:      #e7dfd1;
  --line-soft: #f0e9da;
  --r-lg:      18px;
  --r-md:      14px;
}

/* ===== Dark theme ===== */
[data-theme="dark"] {
  --bg:        #0a0d14;
  --bg-2:      #0e1320;
  --surface:   #111726;
  --surface-2: #0c1220;
  --sidebar:   #0a0e1a;

  --text:      #e7ecf3;
  --text-2:    #c4cbd7;
  --text-3:    #8b94a5;
  --text-dim:  #5a6478;

  --line:      #1c2436;
  --line-soft: #161d2c;

  --accent-soft: color-mix(in oklab, var(--accent) 22%, transparent);
  --accent-tint: color-mix(in oklab, var(--accent) 8%, transparent);

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 8px 32px -10px rgba(0,0,0,0.55), 0 2px 8px -2px rgba(0,0,0,0.35);
  --shadow-lg: 0 28px 56px -16px rgba(0,0,0,0.65), 0 6px 18px -4px rgba(0,0,0,0.4);
}

/* ===== Reset & base ===== */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: "IBM Plex Sans Thai", "Sora", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 220ms ease, color 220ms ease;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
#root { height: 100%; }

.tabnum { font-variant-numeric: tabular-nums; }
.mono   { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 13px; }

/* baht-aware number rendering — prefix kept in Thai font, digits in display font */
.num { display: inline-flex; align-items: baseline; gap: 0.18em; }
.num-pfx { font-family: "IBM Plex Sans Thai", sans-serif; font-weight: 600; opacity: 0.9; }
.num-v   { font-variant-numeric: tabular-nums; }
.num-sfx { font-family: "IBM Plex Sans Thai", sans-serif; font-size: 0.6em; color: var(--text-3); margin-left: 0.2em; }

/* ===== App shell ===== */
.app {
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  height: 100vh;
  overflow: hidden;
}
.main {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}
.scroll-wrap {
  flex: 1; overflow-y: auto;
  padding: 28px 36px 80px;
}
.page {
  animation: pageIn 280ms cubic-bezier(.2,.7,.2,1) both;
}
@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* scrollbar */
.scroll-wrap::-webkit-scrollbar      { width: 10px; }
.scroll-wrap::-webkit-scrollbar-track{ background: transparent; }
.scroll-wrap::-webkit-scrollbar-thumb{ background: var(--line); border-radius: 10px; }
.scroll-wrap::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ===== Sidebar ===== */
.side {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 20px 14px;
  transition: background-color 220ms ease, border-color 220ms ease;
}
.brand {
  display: flex; gap: 12px; align-items: center;
  padding: 6px 10px 18px;
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  box-shadow: 0 4px 14px -4px var(--accent-soft);
}
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; }
.brand-sub  { font-size: 10.5px; color: var(--text-3); letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap; }

.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.nav-group { display: flex; flex-direction: column; gap: 2px; padding: 8px 0; }
.nav-group + .nav-group { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; }
.nav-section {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 4px 12px 6px;
}
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  background: transparent; border: 0;
  text-align: left;
  border-radius: var(--r-md);
  font-size: 14px; font-weight: 500;
  color: var(--text-2);
  transition: background-color 160ms ease, color 160ms ease, transform 160ms;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.is-active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.nav-pill {
  position: absolute; right: 10px; width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.nav-ic  { display: inline-flex; }
.nav-lb  { flex: 1; }

.side-foot { margin-top: auto; padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.theme-toggle {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px 6px 6px; border-radius: 100px;
  background: var(--surface); border: 1px solid var(--line);
  transition: all 160ms;
}
.theme-toggle:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.tt-knob {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent);
  transition: transform 280ms cubic-bezier(.4,1.4,.5,1);
}
.tt-knob.is-dark { background: #0f172a; color: #fde68a; transform: rotate(360deg); }
.tt-lb { font-size: 13px; font-weight: 500; color: var(--text-2); }

.side-user {
  display: flex; align-items: center; gap: 10px;
  padding: 10px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--line);
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), color-mix(in oklab, var(--accent) 50%, var(--text)));
  color: var(--on-accent);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
}
.side-user-name { font-size: 13px; font-weight: 600; }
.side-user-mail { font-size: 11px; color: var(--text-3); }

/* ===== Topbar ===== */
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center;
  gap: 20px;
  padding: 0 36px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in oklab, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 50;
}
.topbar-l { min-width: 200px; }
.topbar-title { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; }
.topbar-sub   { font-size: 12px; color: var(--text-3); margin-top: 1px; }
.topbar-r { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.topbar-search {
  flex: 1; max-width: 480px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  height: 38px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  color: var(--text-3);
  transition: border-color 160ms, box-shadow 160ms;
}
.topbar-search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.topbar-search input {
  flex: 1; border: 0; background: transparent; outline: none;
  font-size: 13.5px; color: var(--text);
}
.topbar-search input::placeholder { color: var(--text-dim); }

/* ===== Buttons / IconBtn ===== */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  font-size: 13.5px; font-weight: 500;
  transition: transform 120ms, background-color 160ms, box-shadow 160ms, color 160ms, border-color 160ms;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: var(--accent); color: var(--on-accent);
  box-shadow: 0 6px 16px -8px var(--accent-soft), 0 1px 0 rgba(255,255,255,0.2) inset;
}
.btn-primary:hover { box-shadow: 0 10px 24px -10px var(--accent-soft), 0 1px 0 rgba(255,255,255,0.2) inset; }
.btn-ghost {
  background: var(--surface); color: var(--text-2);
  border-color: var(--line);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-dim); background: var(--surface-2); }
.btn-default {
  background: var(--surface-2); color: var(--text-2); border-color: var(--line);
}

.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  background: transparent; border: 1px solid transparent;
  color: var(--text-3);
  transition: all 140ms;
}
.icon-btn:hover { background: var(--surface); color: var(--text); border-color: var(--line); }

.x-btn {
  width: 26px; height: 26px;
  border-radius: var(--r-sm);
  background: transparent; border: 0;
  display: grid; place-items: center;
  color: var(--text-3);
  transition: all 140ms;
}
.x-btn:hover { background: var(--bg-2); color: var(--text); }

/* ===== Layout helpers ===== */
.page { display: flex; flex-direction: column; gap: 20px; max-width: 1440px; }
.row  { display: flex; }
.row-wrap { display: flex; flex-wrap: wrap; gap: 12px; }
.row-jb { justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.ai-c { align-items: center; }
.mt-12 { margin-top: 12px; }
.dim { color: var(--text-dim); }
.strong { font-weight: 600; }
.accent { color: var(--accent); }
.ellip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r { text-align: right; }
.c { text-align: center; }
.amber { color: var(--amber); }
.ok { color: var(--ok); }

/* ===== Card ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  transition: background-color 220ms ease, border-color 220ms ease, box-shadow 220ms ease;
}
.card.no-pad { padding: 0; overflow: hidden; }
.card.no-pad .tbl-scroll { overflow-x: auto; }
.card.no-pad .tbl-scroll::-webkit-scrollbar { height: 8px; }
.card.no-pad .tbl-scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
.card-h {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  margin-bottom: 16px;
}
.card.no-pad .card-h { padding: 18px 22px 14px; margin-bottom: 0; }
.card-eyebrow { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); margin-bottom: 4px; }
.card-title { font-size: 16px; font-weight: 700; margin: 0; letter-spacing: -0.01em; white-space: nowrap; }
.card-title.big { font-size: 24px; }
.card-sub { font-size: 12.5px; color: var(--text-3); margin-top: 4px; }

.glow-card {
  position: relative; overflow: hidden;
}
.glow-card::before {
  content: ""; position: absolute; inset: -2px; pointer-events: none;
  background: radial-gradient(600px 200px at 80% -10%, var(--accent-tint), transparent 60%);
}

/* ===== Seg toggle (dashboard tabs) ===== */
.seg {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 100px;
  position: relative;
}
.seg-i {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent; border: 0;
  padding: 7px 14px;
  border-radius: 100px;
  font-size: 13.5px; color: var(--text-3);
  transition: color 160ms, background 160ms;
  white-space: nowrap;
}
.seg-i:hover { color: var(--text); }
.seg-i.is-on { background: var(--accent); color: var(--on-accent); }
.seg-dim { color: inherit; opacity: 0.6; font-size: 12px; }
.seg-r { margin-left: 12px; padding-left: 12px; font-size: 12px; color: var(--text-3); border-left: 1px solid var(--line); display: none; }
@media (min-width: 1100px) { .seg-r { display: inline; } }

.seg-inline {
  display: inline-flex; gap: 4px;
  padding: 4px; margin: 4px 0 8px;
  background: var(--bg-2); border-radius: 100px;
}
.seg-inline .seg-i { padding: 6px 14px; }

/* ===== Dashboard grid ===== */
.dash-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 22px;
}
@media (max-width: 1100px) { .dash-grid { grid-template-columns: 1fr; } }

.dash-chart { min-height: 320px; padding-right: 4px; }
.dash-stats { display: flex; flex-direction: column; gap: 12px; }

/* Stat card */
.stat {
  position: relative;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 16px 16px 14px;
  transition: transform 180ms cubic-bezier(.2,.7,.2,1), box-shadow 180ms, border-color 180ms, background 180ms;
  cursor: pointer;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--text-dim); }
.stat-h { display: flex; align-items: center; justify-content: space-between; }
.stat-lb { font-size: 12.5px; color: var(--text-3); }
.stat-ic {
  width: 30px; height: 30px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--surface); color: var(--text-3);
  border: 1px solid var(--line);
}
.stat-v { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -0.01em; }
.stat-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; }
.stat-cap { font-size: 12px; color: var(--text-3); }
.stat-delta {
  display: inline-flex; align-items: center; gap: 2px;
  font-size: 11px; font-weight: 600;
  padding: 2px 7px;
  border-radius: 100px;
  font-variant-numeric: tabular-nums;
}
.delta-up   { background: var(--ok-soft);     color: var(--ok); }
.delta-down { background: var(--danger-soft); color: var(--danger); }
.delta-flat { background: var(--bg-2);         color: var(--text-3); }
.stat-cta {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 12px; padding: 6px 10px;
  background: var(--accent-soft); color: var(--accent);
  border: 0; border-radius: var(--r-sm);
  font-size: 12.5px; font-weight: 500;
}
.stat-cta:hover { filter: brightness(0.92); }
.stat-accent { background: linear-gradient(180deg, var(--accent-tint), transparent); border-color: var(--accent-soft); }
.stat-accent .stat-ic { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.stat-warn .stat-ic { color: var(--amber); background: var(--amber-soft); border-color: transparent; }
.stat-ok   .stat-ic { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.stat-ok   .stat-v  { color: var(--ok); }
.stat-muted .stat-v { color: var(--text-3); }

/* ===== Table ===== */
.tbl { display: flex; flex-direction: column; overflow-x: auto; }
.tbl::-webkit-scrollbar { height: 8px; }
.tbl::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
.thead, .trow { display: grid; gap: 12px; padding: var(--row-py) 22px; align-items: center; font-size: var(--row-fs); }
.thead {
  background: var(--surface-2);
  font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-3);
  font-weight: 600;
  padding-top: 12px; padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 1;
}
.trow {
  border-bottom: 1px solid var(--line-soft);
  transition: background 140ms;
}
.trow:hover { background: var(--accent-tint); }
.trow:last-child { border-bottom: 0; }

.row-7  { grid-template-columns: 100px 1.5fr 100px 110px 110px 130px 80px; min-width: 980px; }
.row-7s { grid-template-columns: 100px 120px 1.4fr 110px 110px 130px 90px; min-width: 980px; }
.row-purch {
  grid-template-columns: 130px minmax(120px, 1fr) minmax(120px, 1.2fr) 88px 78px 88px 46px 88px;
  min-width: 0;
}

.row-purch > * {
  min-width: 0;
}

.page-purchases .thead,
.page-purchases .trow {
  gap: 8px;
  padding-left: 14px;
  padding-right: 14px;
  font-size: 12.5px;
}

.page-purchases .icon-btn {
  width: 26px;
  height: 26px;
}
.row-sup   { grid-template-columns: 50px 1fr 200px 90px; min-width: 600px; }
.row-aud   { grid-template-columns: 150px 130px 140px 120px 200px 1fr; min-width: 1000px; }
.row-trash { grid-template-columns: 160px 100px 1fr 130px 1.5fr 100px; min-width: 900px; }

.row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.row-actions.reveal { opacity: 0; transition: opacity 160ms; }
.trow:hover .row-actions.reveal { opacity: 1; }
.trow:focus-within .row-actions.reveal { opacity: 1; }

/* date divider row inside table */
.date-divider {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 22px;
  background: var(--surface-2);
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  font-size: 12px; color: var(--text-3);
  font-weight: 500;
  position: sticky; top: 41px; z-index: 1; /* under thead */
}
.date-divider-lb { font-size: 12.5px; color: var(--text-2); font-weight: 600; white-space: nowrap; }
.date-divider-rt { display: inline-flex; align-items: center; gap: 12px; font-size: 12.5px; white-space: nowrap; }
.date-divider + .trow { border-top: 0; }

.t-pri { font-weight: 500; }
.t-sec { font-size: 12px; color: var(--text-3); margin-top: 1px; }

.empty-row {
  padding: 32px 22px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}

.check-ok {
  display: inline-grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--ok-soft); color: var(--ok);
}

/* Stagger animation for table rows */
.stagger { animation: rowIn 360ms cubic-bezier(.2,.7,.2,1) both; }
@keyframes rowIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== Badge ===== */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 11.5px; font-weight: 600;
  letter-spacing: 0.01em;
}
.tone-ok      { background: var(--ok-soft);     color: var(--ok); }
.tone-amber   { background: var(--amber-soft);  color: var(--amber); }
.tone-danger  { background: var(--danger-soft); color: var(--danger); }
.tone-neutral { background: var(--bg-2);         color: var(--text-3); }

/* ===== Chart ===== */
.chart-wrap { position: relative; }
.chart { width: 100%; height: 100%; display: block; }
.ax-l  { font-size: 11px; fill: var(--text-3); font-family: inherit; }
.ch-pt { opacity: 0; transition: opacity 220ms ease; }
.ch-pt.is-hov { opacity: 1; }
.chart-tip {
  position: absolute; transform: translate(-50%, calc(-100% - 16px));
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 6px 10px;
  font-size: 12px; box-shadow: var(--shadow-md);
  pointer-events: none;
  white-space: nowrap;
}
.chart-tip-lb { color: var(--text-3); font-size: 11px; }
.chart-tip-v  { color: var(--text); font-weight: 600; }
.spark { display: block; }

/* ===== KPI ===== */
.kpi-row {
  display: grid; gap: 12px;
  grid-template-columns: repeat(4, 1fr);
}
@media (max-width: 900px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px 16px;
  transition: transform 160ms, box-shadow 160ms;
}
.kpi:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.kpi-lb { font-size: 12px; color: var(--text-3); }
.kpi-v  { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -0.01em; display: flex; align-items: baseline; gap: 6px; }
.kpi-u  { font-size: 13px; color: var(--text-3); font-weight: 500; }
.kpi-accent .kpi-v { color: var(--accent); }

/* ===== P&L ===== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.pl-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 22px 24px;
  position: relative; overflow: hidden;
  transition: transform 180ms, box-shadow 220ms;
}
.pl-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.pl-loss { background: linear-gradient(180deg, color-mix(in oklab, var(--danger) 8%, var(--surface)), var(--surface) 60%); border-color: color-mix(in oklab, var(--danger) 20%, var(--line)); }
.pl-gain { background: linear-gradient(180deg, color-mix(in oklab, var(--ok) 8%, var(--surface)), var(--surface) 60%); border-color: color-mix(in oklab, var(--ok) 20%, var(--line)); }
.pl-lb { font-size: 13px; color: var(--text-3); }
.pl-row { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.pl-v  { font-size: 38px; font-weight: 700; letter-spacing: -0.02em; }
.pl-loss .pl-v { color: var(--danger); }
.pl-gain .pl-v { color: var(--ok); }
.pl-arrow { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--line); }
.pl-loss .pl-arrow { color: var(--danger); }
.pl-gain .pl-arrow { color: var(--ok); }
.pl-cap { font-size: 13px; color: var(--text-3); margin-top: 4px; }
.pl-spark { margin-top: 12px; opacity: 0.7; }

.kv-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0;
  border-top: 1px dashed var(--line-soft);
}
.kv-row:first-of-type { border-top: 0; }
.kv-l { color: var(--text-2); font-size: 14px; }
.kv-r { font-size: 14px; }
.kv-r.big { font-size: 18px; font-weight: 700; }
.kv-n { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }
.kv-total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 16px; }
.kv-row.ok .kv-r { color: var(--ok); }

.vat-summary {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px;
  padding: 4px 0 0;
}
@media (max-width: 900px) { .vat-summary { grid-template-columns: 1fr; } }
.vs-cell { text-align: center; padding: 16px; background: var(--surface-2); border-radius: var(--r-md); border: 1px solid var(--line); }
.vs-lb { font-size: 13px; color: var(--text-3); }
.vs-v  { font-size: 30px; font-weight: 700; margin-top: 8px; letter-spacing: -0.01em; }
.vs-v.amber { color: var(--amber); }
.vs-v.ok    { color: var(--ok); }
.vs-cap { font-size: 12px; color: var(--text-3); margin-top: 4px; }

/* ===== VAT hero card ===== */
.hero-card {
  background: linear-gradient(135deg, color-mix(in oklab, var(--ok) 10%, var(--surface)) 0%, var(--surface) 70%);
  border: 1px solid color-mix(in oklab, var(--ok) 25%, var(--line));
  border-radius: var(--r-lg);
  padding: 26px 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  position: relative; overflow: hidden;
}
.hero-card::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(400px 200px at 20% 100%, color-mix(in oklab, var(--ok) 14%, transparent), transparent 70%);
}
.hero-l { display: flex; align-items: flex-start; gap: 18px; }
.hero-ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--ok); color: white; flex-shrink: 0; }
.hero-lb { font-size: 14px; color: var(--text-2); font-weight: 500; }
.hero-v  { font-size: 44px; font-weight: 800; letter-spacing: -0.02em; color: var(--ok); margin: 2px 0; }
.hero-cap { font-size: 13px; color: var(--text-3); }
.hero-r { position: relative; }
.ring { position: relative; width: 120px; height: 120px; }
.ring-c {
  position: absolute; inset: 0; display: grid; place-items: center;
  flex-direction: column; text-align: center;
}
.ring-n { font-size: 28px; font-weight: 800; line-height: 1; }
.ring-l { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.ring-anim { animation: ringDraw 1200ms cubic-bezier(.2,.7,.2,1) both; }
@keyframes ringDraw { from { stroke-dashoffset: 301.6; } }

/* ===== Empty state ===== */
.empty {
  text-align: center; padding: 64px 32px;
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--r-lg);
}
.empty-ic { display: inline-grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; background: var(--bg-2); color: var(--text-3); margin-bottom: 16px; }
.empty-t  { font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.empty-m  { font-size: 13.5px; color: var(--text-3); margin-bottom: 18px; }

/* ===== Period bar (chips + month) ===== */
.period-bar {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 100px;
  box-shadow: var(--shadow-sm);
}
.period-bar .mp-btn {
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 7px 12px;
}
.period-bar .mp-btn:hover { background: var(--bg-2); border-radius: 100px; }
.chip {
  background: transparent; border: 0;
  padding: 7px 14px;
  font-size: 13px; font-weight: 500;
  color: var(--text-3);
  border-radius: 100px;
  transition: background 140ms, color 140ms;
  white-space: nowrap;
}
.chip:hover { color: var(--text); background: var(--bg-2); }
.chip.is-on { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.chip-sep {
  width: 1px; height: 18px;
  background: var(--line);
  margin: 0 4px;
}

/* ===== Month picker ===== */
.mp { position: relative; }
.mp-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  font-size: 13.5px; font-weight: 500; color: var(--text);
  transition: border-color 160ms, box-shadow 160ms;
  white-space: nowrap;
}
.mp-btn:hover { border-color: var(--text-dim); }
.mp-pop {
  position: absolute; right: 0; top: 100%; margin-top: 6px; z-index: 60;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 12px;
  width: 260px;
  animation: pop 180ms cubic-bezier(.2,.7,.2,1);
}
@keyframes pop {
  from { opacity: 0; transform: scale(.96) translateY(-4px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.mp-yr {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 4px 8px;
}
.mp-yr button { background: transparent; border: 0; width: 28px; height: 28px; border-radius: var(--r-sm); color: var(--text-2); }
.mp-yr button:hover { background: var(--bg-2); }
.mp-yr span { font-weight: 600; font-size: 14px; }
.mp-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.mp-cell { padding: 8px 0; border-radius: var(--r-sm); background: transparent; border: 0; font-size: 12.5px; color: var(--text-2); transition: background 140ms, color 140ms; }
.mp-cell:hover { background: var(--bg-2); }
.mp-cell.is-on { background: var(--accent); color: var(--on-accent); font-weight: 600; }

/* ===== Modal ===== */
.modal-bd {
  position: fixed; inset: 0; z-index: 200;
  background: color-mix(in oklab, var(--text) 35%, transparent);
  backdrop-filter: blur(6px);
  display: grid; place-items: center;
  padding: 24px;
  animation: fade 160ms ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  max-width: 100%; max-height: 90vh; display: flex; flex-direction: column;
  animation: modalIn 220ms cubic-bezier(.2,.7,.2,1);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-h {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--line);
}
.modal-t { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.modal-b { padding: 20px 22px; overflow-y: auto; }
.modal-f { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

/* form */
.form-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field-full { grid-column: 1 / -1; }
.field-l { font-size: 12px; color: var(--text-3); font-weight: 500; display: flex; gap: 6px; align-items: center; justify-content: space-between; min-height: 18px; }
.field input, .field select {
  height: 38px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  font-size: 14px; color: var(--text); outline: none;
  transition: border-color 140ms, box-shadow 140ms;
}
.field input:focus, .field select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft);
}
.field input:disabled, .field select:disabled { background: var(--bg-2); color: var(--text-3); cursor: not-allowed; }
.form-total {
  padding: 12px 14px; background: var(--accent-tint); color: var(--accent);
  border-radius: var(--r-md); font-size: 18px; font-weight: 700; text-align: right;
}
.chk { display: flex; align-items: center; gap: 8px; color: var(--text-2); user-select: none; }
.chk input { width: 16px; height: 16px; accent-color: var(--accent); }

.req { color: var(--danger); font-weight: 700; }

.link-btn {
  background: transparent; border: 0;
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--accent); font-size: 12px; font-weight: 600;
  padding: 2px 6px; border-radius: var(--r-sm);
  margin-left: auto;
  transition: background 140ms;
  white-space: nowrap;
}
.link-btn:hover { background: var(--accent-tint); }

/* Money group — three currency fields stacked together */
.money-group {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px 16px;
}
.money-h { font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 10px; }
.money-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.money-row .field-l { font-size: 11.5px; }

/* Number input with up/down stepper */
.num-input {
  position: relative;
  display: flex; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  transition: border-color 140ms, box-shadow 140ms;
}
.num-input.is-highlight { border-color: color-mix(in oklab, var(--accent) 30%, var(--line)); background: var(--accent-tint); }
.num-input.is-disabled  { background: var(--bg-2); }
.num-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.num-input input {
  flex: 1; height: 38px; padding: 0 4px 0 12px;
  background: transparent; border: 0; outline: none;
  font-size: 15px; font-variant-numeric: tabular-nums;
  text-align: right; color: var(--text); width: 100%;
}
.num-input.is-highlight input { color: var(--accent); font-weight: 700; }
.num-input input:disabled { color: var(--text-3); }
.num-input-step { display: flex; flex-direction: column; padding-right: 4px; }
.num-input-step button {
  background: transparent; border: 0;
  width: 16px; height: 18px; padding: 0;
  font-size: 9px; color: var(--text-3); cursor: pointer; line-height: 1;
}
.num-input-step button:hover:not(:disabled) { color: var(--text); }
.num-input-step button:disabled { opacity: 0.3; cursor: not-allowed; }

/* Credit-eligible callout */
.credit-box {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px;
  background: linear-gradient(180deg, var(--amber-soft), transparent);
  border: 1px solid color-mix(in oklab, var(--amber) 30%, var(--line));
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background 160ms, border-color 160ms;
}
.credit-box.is-on { background: color-mix(in oklab, var(--ok) 8%, var(--surface)); border-color: color-mix(in oklab, var(--ok) 35%, var(--line)); }
.credit-box input { width: 18px; height: 18px; accent-color: var(--accent); margin-top: 1px; flex-shrink: 0; }
.credit-t { font-size: 14px; font-weight: 600; color: var(--text); }
.credit-s { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.credit-box.is-on .credit-t::after { content: " ✓"; color: var(--ok); }

/* File drop zone */
.file-drop {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1.5px dashed var(--line);
  border-radius: var(--r-md);
  color: var(--text-3);
  font-size: 13px;
  cursor: pointer;
  transition: all 160ms;
}
.file-drop:hover, .file-drop.is-drag { border-color: var(--accent); background: var(--accent-tint); color: var(--accent); }
.file-drop.is-on { border-style: solid; border-color: color-mix(in oklab, var(--ok) 35%, var(--line)); color: var(--text); background: color-mix(in oklab, var(--ok) 5%, var(--surface)); }
.file-drop .x-btn { margin-left: auto; }
.attach-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-view { font-size: 12px; font-weight: 600; color: var(--accent); text-decoration: none; padding: 2px 8px; border-radius: 4px; background: var(--accent-tint); flex-shrink: 0; }
.attach-view:hover { text-decoration: underline; }

/* row-sales table */
.row-sales { grid-template-columns: 100px 120px 1.4fr 110px 110px 130px 100px; min-width: 980px; }

/* avatar small */
.avatar-sm {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: white;
  flex-shrink: 0;
}

/* hint */
.hint { font-size: 11.5px; color: var(--text-3); margin-top: 6px; }

/* ===== Toast ===== */
.toast-host {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  z-index: 300; pointer-events: none;
}
.toast {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 100px;
  font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toastIn 240ms cubic-bezier(.2,.7,.2,1);
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.toast-ic { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--ok-soft); color: var(--ok); }
.toast-err .toast-ic { background: var(--danger-soft); color: var(--danger); }

/* ===== Tweaks panel adjustments ===== */
[data-tweaks-panel] { font-family: inherit !important; }

/* Boot screen — shown while bootstrapping data from /api/bootstrap */
.boot-screen {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--bg, #fafafa); color: var(--fg, #0f172a);
  font-family: "IBM Plex Sans Thai", system-ui, sans-serif;
}
.boot-card {
  text-align: center; padding: 32px 40px; min-width: 320px;
  background: var(--surface, #fff);
  border: 1px solid var(--line, #e5e7eb);
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(15,23,42,.06);
}
.boot-logo {
  font-family: "Sora", "IBM Plex Sans Thai", sans-serif;
  font-weight: 700; font-size: 22px; letter-spacing: -0.01em;
  color: var(--accent, #2563eb); margin-bottom: 10px;
}
.boot-msg { font-size: 14px; color: var(--muted, #64748b); }
.boot-msg.boot-err { color: #b91c1c; font-weight: 500; }
.boot-sub { margin-top: 8px; font-size: 12px; color: var(--muted, #64748b); max-width: 360px; word-break: break-word; }
.boot-btn {
  margin-top: 16px; padding: 8px 16px; border-radius: 8px; border: 0;
  background: var(--accent, #2563eb); color: #fff; font-size: 13px; cursor: pointer;
}
