/* ============ Bunchee Tax — Design System ============ */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@300;400;500;600;700&family=Noto+Sans+Mono:wght@400;500;600&display=swap');

:root {
  /* Brand — refined deep emerald (default theme; overridden by theme switcher) */
  --primary:        oklch(0.53 0.108 165);
  --primary-dark:   oklch(0.45 0.10 166);
  --primary-press:  oklch(0.39 0.092 167);
  --primary-tint:   oklch(0.965 0.028 168);
  --primary-tint2:  oklch(0.925 0.05 168);
  --on-primary:     #ffffff;

  /* Neutrals (cool-warm balanced) */
  --bg:        oklch(0.978 0.005 160);
  --surface:   #ffffff;
  --surface-2: oklch(0.984 0.005 165);
  --ink:       oklch(0.24 0.012 165);
  --ink-2:     oklch(0.44 0.012 165);
  --ink-3:     oklch(0.60 0.010 165);
  --line:      oklch(0.91 0.006 165);
  --line-2:    oklch(0.95 0.005 165);

  /* Status */
  --ok:      oklch(0.55 0.10 162);
  --ok-bg:   oklch(0.95 0.035 162);
  --warn:    oklch(0.62 0.13 75);
  --warn-bg: oklch(0.95 0.05 80);
  --danger:  oklch(0.56 0.16 27);
  --danger-bg: oklch(0.95 0.04 27);
  --info:    oklch(0.55 0.11 250);
  --info-bg: oklch(0.95 0.035 250);

  --radius:   12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(20,40,30,.05), 0 1px 1px rgba(20,40,30,.03);
  --shadow:    0 2px 6px rgba(20,40,30,.06), 0 6px 18px rgba(20,40,30,.05);
  --shadow-lg: 0 12px 40px rgba(20,40,30,.14);
  --mono: 'Noto Sans Mono', ui-monospace, monospace;
  --sans: 'Noto Sans Thai', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-weight: 400;
}
#root { height: 100%; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: inherit; text-decoration: none; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ============ App shell ============ */
.app { display: flex; min-height: 100%; }
.sidebar {
  width: 248px; flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 18px 18px 14px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  background: var(--primary); color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 19px; box-shadow: var(--shadow-sm);
}
.brand-name { font-weight: 700; font-size: 15.5px; line-height: 1.15; }
.brand-sub { font-size: 11.5px; color: var(--ink-3); }

.entity-switch {
  margin: 4px 14px 10px; padding: 4px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 10px; display: flex; gap: 3px;
}
.entity-switch button {
  flex: 1; padding: 7px 4px; border-radius: 7px; font-size: 12.5px; font-weight: 600;
  color: var(--ink-3); transition: .15s;
}
.entity-switch button.on { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }

.nav { padding: 4px 12px; overflow-y: auto; flex: 1; }
.nav-group-label { font-size: 11px; font-weight: 600; color: var(--ink-3); letter-spacing: .04em; padding: 14px 10px 5px; text-transform: uppercase; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: 9px;
  color: var(--ink-2); font-weight: 500; font-size: 14px; width: 100%; text-align: left;
  transition: .13s; position: relative; margin-bottom: 1px;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.on { background: var(--primary-tint); color: var(--primary-dark); font-weight: 600; }
.nav-item .ic { width: 19px; height: 19px; flex-shrink: 0; opacity: .85; }
.nav-item.on .ic { opacity: 1; }
.nav-badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 5px; }
.nav-badge.amber { background: var(--warn); }

.sidebar-foot { padding: 10px 12px; border-top: 1px solid var(--line); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 7px 9px; border-radius: 10px; width: 100%; transition: .13s; }
.user-chip:hover { background: var(--surface-2); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary-tint2); color: var(--primary-dark); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.user-chip .nm { font-size: 13px; font-weight: 600; line-height: 1.2; }
.user-chip .rl { font-size: 11px; color: var(--ink-3); }

/* main */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 62px; background: rgba(255,255,255,.82); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line); display: flex; align-items: center;
  gap: 14px; padding: 0 26px; position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 18px; font-weight: 700; white-space: nowrap; }
.card-head { display: flex; align-items: center; gap: 12px; padding: 15px 20px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.card-head h3 { font-size: 15px; font-weight: 700; white-space: nowrap; }
.topbar .crumb { font-size: 12.5px; color: var(--ink-3); }
.period-pill {
  margin-left: auto; display: flex; align-items: center; gap: 8px; padding: 7px 13px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  font-size: 13px; font-weight: 600; box-shadow: var(--shadow-sm);
}
.content { padding: 24px 26px 60px; max-width: 1320px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .pt { font-size: 22px; font-weight: 700; }
.page-head .ps { font-size: 13.5px; color: var(--ink-2); margin-top: 3px; }
.page-head .spacer { flex: 1; }

/* ============ primitives ============ */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 18px 20px; }
.card-head .sub { font-size: 12px; color: var(--ink-3); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border-radius: 9px; font-weight: 600; font-size: 14px;
  transition: .14s; white-space: nowrap; border: 1px solid transparent;
}
.btn .ic { width: 17px; height: 17px; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { background: var(--primary-press); }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--ink-3); }
.btn-soft { background: var(--primary-tint); color: var(--primary-dark); }
.btn-soft:hover { background: var(--primary-tint2); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { filter: brightness(.97); }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.5; white-space: nowrap; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.muted { background: var(--surface-2); color: var(--ink-3); border: 1px solid var(--line); }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 500; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); }

/* form */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 11.5px; color: var(--ink-3); }
.input, .select, textarea.input {
  padding: 9px 12px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 9px; font-size: 14px; transition: .13s; width: 100%; outline: none;
}
.input:focus, .select:focus, textarea.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-tint2); }
.input.right { text-align: right; font-variant-numeric: tabular-nums; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7672' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

/* table */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
table.tbl th { text-align: left; font-size: 11.5px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .02em; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; background: var(--surface-2); }
table.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tbody tr { transition: .1s; }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl td.r, table.tbl th.r { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl td.c, table.tbl th.c { text-align: center; }
.row-link { cursor: pointer; }

/* sticky action column — keeps แก้ไข/ลบ buttons visible on wide tables */
table.tbl td.sticky-act, table.tbl th.sticky-act, table.tbl tfoot td.sticky-act {
  position: sticky; right: 0; box-shadow: -8px 0 8px -8px rgba(20,40,30,.22);
}
table.tbl td.sticky-act { background: var(--surface); z-index: 1; }
table.tbl th.sticky-act { background: var(--surface-2); z-index: 3; }
table.tbl tbody tr:hover td.sticky-act { background: var(--surface-2); }
table.tbl tfoot td.sticky-act { background: var(--surface-2); }

/* stat */
.stat { padding: 16px 18px; }
.stat .lbl { font-size: 12.5px; color: var(--ink-2); font-weight: 500; display: flex; align-items: center; gap: 7px; }
.stat .val { font-size: 26px; font-weight: 700; margin-top: 7px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat .val .unit { font-size: 14px; font-weight: 500; color: var(--ink-3); margin-left: 3px; }
.stat .delta { font-size: 12px; font-weight: 600; margin-top: 6px; display: inline-flex; align-items: center; gap: 4px; }
.stat .delta.up { color: var(--ok); }
.stat .delta.down { color: var(--danger); }
.stat-ic { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; }

.grid { display: grid; gap: 16px; }
.divider { height: 1px; background: var(--line-2); margin: 14px 0; }

/* progress / bars */
.bar-track { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--primary); }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(22,33,28,.42); backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 100; padding: 20px; animation: fade .15s ease; }
.modal { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; max-height: 90vh; overflow: hidden; display: flex; flex-direction: column; animation: pop .18s cubic-bezier(.2,.8,.3,1); }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--line-2); }
.modal-head h3 { font-size: 17px; font-weight: 700; flex: 1; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--line-2); display: flex; gap: 10px; justify-content: flex-end; background: var(--surface-2); }
.x-btn { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; color: var(--ink-3); }
.x-btn:hover { background: var(--surface-2); color: var(--ink); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }

/* note / callout */
.callout { display: flex; gap: 11px; padding: 13px 15px; border-radius: var(--radius-sm); font-size: 13px; line-height: 1.55; }
.callout.info { background: var(--info-bg); color: oklch(0.4 0.09 250); }
.callout.warn { background: var(--warn-bg); color: oklch(0.42 0.1 65); }
.callout .ic { width: 19px; height: 19px; flex-shrink: 0; margin-top: 1px; }

/* segmented */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { padding: 6px 13px; border-radius: 6px; font-size: 13px; font-weight: 600; color: var(--ink-3); transition: .13s; white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }

/* mobile */
.mobile-top { display: none; }
.bottom-nav { display: none; }
.menu-btn { display: none; }

@media (max-width: 880px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .25s cubic-bezier(.2,.8,.3,1); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .scrim { position: fixed; inset: 0; background: rgba(20,30,25,.4); z-index: 25; }
  .menu-btn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 9px; }
  .menu-btn:hover { background: var(--surface-2); }
  .content { padding: 16px 14px 90px; }
  .topbar { padding: 0 14px; height: 56px; }
  .topbar h1 { font-size: 16px; }
  .bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: rgba(255,255,255,.92); backdrop-filter: blur(12px); border-top: 1px solid var(--line); z-index: 40; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .bottom-nav button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 5px 8px; border-radius: 9px; color: var(--ink-3); font-size: 10.5px; font-weight: 600; flex: 1; }
  .bottom-nav button.on { color: var(--primary); }
  .bottom-nav .ic { width: 22px; height: 22px; }
  .page-head .pt { font-size: 19px; }
}
@media (min-width: 881px) { .scrim { display: none; } }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; border: 2px solid var(--surface); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }
