/* ══════════════════════════════════════════════════════════════
   2PROVI TOOLS — Design System v2
   ใช้ร่วมกันทุกหน้า: index / irr / fna / savings
   Light + Dark · Responsive · PWA (standalone, safe-area)
   ══════════════════════════════════════════════════════════════ */

/* ── 1. TOKENS ─────────────────────────────────────────────── */
:root {
  /* Dark เป็นค่าเริ่มต้น */
  --bg:          #070b16;
  --bg-2:        #0b1120;
  --surface:     #0f1728;
  --surface-2:   #151f36;
  --surface-3:   #1d2a47;
  --border:      #223350;
  --border-2:    #31456b;

  --text:        #eaf1fb;
  --text-2:      #9fb2cf;
  --text-3:      #6d80a1;

  --green:       #10b981;
  --green-soft:  #6ee7b7;
  --amber:       #f59e0b;
  --amber-soft:  #fcd34d;
  --red:         #f87171;
  --red-strong:  #ef4444;

  /* accent เปลี่ยนตามหน้าผ่าน [data-accent] */
  --accent:      #4b8cf7;
  --accent-2:    #22d3ee;
  --accent-soft: #a8c8ff;
  --accent-tint: rgba(75,140,247,.14);
  --accent-line: rgba(75,140,247,.34);
  --accent-glow: rgba(75,140,247,.28);
  --on-accent:   #ffffff;

  --font:  'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono:  'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --r-xs: 7px;
  --r-sm: 10px;
  --r:    14px;
  --r-lg: 20px;
  --r-xl: 26px;

  --sh-1: 0 1px 2px rgba(0,0,0,.30);
  --sh-2: 0 2px 6px rgba(0,0,0,.28), 0 10px 30px rgba(0,0,0,.28);
  --sh-3: 0 20px 56px rgba(0,0,0,.46);
  --shadow: var(--sh-2);
  --shadow-lg: var(--sh-3);
  --ring: 0 0 0 3px var(--accent-tint);

  --maxw: 1160px;
  --topbar-h: 60px;
  --ease: cubic-bezier(.22,1,.36,1);

  /* ระยะเผื่อขอบจอโค้ง/แถบล่าง เวลาเปิดเป็นแอป (PWA standalone) */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  color-scheme: dark;
}

:root[data-accent="violet"] {
  --accent: #a07bfa; --accent-2: #f472b6; --accent-soft: #d6c6ff;
  --accent-tint: rgba(160,123,250,.15); --accent-line: rgba(160,123,250,.36);
  --accent-glow: rgba(160,123,250,.3);
}
:root[data-accent="green"] {
  --accent: #2dd4a0; --accent-2: #22d3ee; --accent-soft: #9af5d4;
  --accent-tint: rgba(45,212,160,.14); --accent-line: rgba(45,212,160,.34);
  --accent-glow: rgba(45,212,160,.28);
  --on-accent: #04231a;
}
:root[data-accent="amber"] {
  --accent: #f59e0b; --accent-2: #fb7185; --accent-soft: #fcd34d;
  --accent-tint: rgba(245,158,11,.14); --accent-line: rgba(245,158,11,.36);
  --on-accent: #1a1206;
}

/* ── Light theme ── */
:root[data-theme="light"] {
  --bg:          #f2f5fa;
  --bg-2:        #ffffff;
  --surface:     #ffffff;
  --surface-2:   #f5f8fd;
  --surface-3:   #e8eef8;
  --border:      #dde5f0;
  --border-2:    #c3d0e2;

  --text:        #0c1526;
  --text-2:      #47586f;
  --text-3:      #74869e;

  --green:       #059669;
  --green-soft:  #047857;
  --amber:       #b45309;
  --amber-soft:  #92400e;
  --red:         #dc2626;
  --red-strong:  #b91c1c;

  --sh-1: 0 1px 2px rgba(15,34,66,.06);
  --sh-2: 0 1px 2px rgba(15,34,66,.05), 0 10px 28px rgba(15,34,66,.08);
  --sh-3: 0 24px 56px rgba(15,34,66,.16);
  color-scheme: light;
}
/* โหมดสว่าง: สีเน้นต้องเข้มพอจะอ่านออกบนพื้นขาว */
:root[data-theme="light"][data-accent="blue"],
:root[data-theme="light"]:not([data-accent])    { --accent: #2563eb; --accent-soft: #1d4ed8; --accent-tint: rgba(37,99,235,.10); --accent-line: rgba(37,99,235,.28); }
:root[data-theme="light"][data-accent="violet"] { --accent: #7c3aed; --accent-soft: #6d28d9; --accent-tint: rgba(124,58,237,.10); --accent-line: rgba(124,58,237,.28); }
:root[data-theme="light"][data-accent="green"]  { --accent: #059669; --accent-soft: #047857; --accent-tint: rgba(5,150,105,.10); --accent-line: rgba(5,150,105,.28); --on-accent: #ffffff; }
:root[data-theme="light"][data-accent="amber"]  { --accent: #d97706; --accent-soft: #b45309; --accent-tint: rgba(217,119,6,.10); --accent-line: rgba(217,119,6,.28); }

/* ── 2. RESET / BASE ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── การเลื่อนหน้า ──
   ตัวเลื่อนของหน้าต้องเป็น <html> เท่านั้น ห้ามให้ <body> กลายเป็น
   scroll container เด็ดขาด เพราะถ้า body มี overflow-x: hidden
   เบราว์เซอร์จะบังคับ overflow-y เป็น auto ทำให้ body เป็นตัวเลื่อนซ้อน
   ผลคือ (1) ล้อเมาส์เหนือการ์ด/พาเนลจะเลื่อนหน้าไม่ได้ และ
        (2) แถบเมนูบน position:sticky จะไม่ติดขอบจอ
   จึงย้ายการตัด scroll แนวนอนมาไว้ที่ <html> แทน */
html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  overflow-x: hidden;
  overflow-y: scroll;              /* มีแถบเลื่อนเสมอ กันหน้ากระตุกตอนเนื้อหาสั้น/ยาว */
  -webkit-overflow-scrolling: touch;
  scroll-padding-top: calc(var(--topbar-h) + var(--safe-t) + 12px);
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  font-size: 15px;
  min-height: 100vh;
  min-height: 100dvh;
  /* ห้ามใส่ overflow หรือ overscroll-behavior ที่ body — ดูหมายเหตุด้านบน */
  padding-bottom: calc(56px + var(--safe-b));
  -webkit-font-smoothing: antialiased;
}
/* แสงเรืองอ่อนๆ ด้านบน — ทำให้หน้าดูมีมิติโดยไม่รบกวนการอ่าน */
body::before {
  content: ''; position: fixed; inset: 0 0 auto 0; height: 480px; z-index: -1;
  background:
    radial-gradient(ellipse 70% 100% at 22% 0%, var(--accent-tint), transparent 62%),
    radial-gradient(ellipse 62% 100% at 82% 0%, rgba(34,211,238,.10), transparent 62%);
  pointer-events: none;
}

button, a, input, select, textarea, label { touch-action: manipulation; }
button, input, select, textarea { font-family: inherit; font-size: 100%; color: inherit; }
img, svg { max-width: 100%; height: auto; display: block; }
a { color: var(--accent-soft); }
::selection { background: var(--accent); color: var(--on-accent); }

:where(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px;
}

* { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; }
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-2); border-radius: 99px;
  border: 3px solid transparent; background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--accent); background-clip: content-box; }

.wrap {
  width: 100%; max-width: var(--maxw); margin: 0 auto;
  padding-inline: max(18px, var(--safe-l)) max(18px, var(--safe-r));
}
.wrap-narrow { max-width: 800px; }

/* ── 3. TOP BAR + NAV ──────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 60;
  padding-top: var(--safe-t);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid transparent;
  transition: border-color .25s, background .25s;
}
.topbar.is-stuck { border-bottom-color: var(--border); background: color-mix(in srgb, var(--bg) 94%, transparent); }
@supports not (backdrop-filter: blur(4px)) { .topbar { background: var(--bg); } }

.topbar-inner {
  max-width: var(--maxw); margin: 0 auto; min-height: var(--topbar-h);
  padding-inline: max(18px, var(--safe-l)) max(18px, var(--safe-r));
  display: flex; align-items: center; gap: 14px;
}
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: inherit; min-width: 0; }
.brand-mark {
  width: 38px; height: 38px; flex: 0 0 38px; border-radius: 12px;
  display: grid; place-items: center; font-size: 15px; font-weight: 800; letter-spacing: -.02em;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  color: var(--on-accent);
  box-shadow: 0 4px 16px var(--accent-glow);
}
.brand-text { min-width: 0; }
.brand-name { font-weight: 800; font-size: 15px; line-height: 1.25; white-space: nowrap; letter-spacing: -.01em; }
.brand-sub { font-size: 11.5px; color: var(--text-3); line-height: 1.3; white-space: nowrap; }

.nav { display: flex; gap: 3px; margin-left: auto; align-items: center; }
.nav a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 14px; border-radius: 99px; text-decoration: none;
  font-size: 14px; font-weight: 600; color: var(--text-2);
  border: 1px solid transparent; white-space: nowrap;
  transition: background .2s, color .2s, border-color .2s;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { color: var(--accent-soft); background: var(--accent-tint); border-color: var(--accent-line); }

.theme-toggle {
  width: 40px; height: 40px; flex: 0 0 40px; border-radius: 99px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border);
  display: grid; place-items: center; font-size: 16px; line-height: 1;
  transition: border-color .2s, transform .3s var(--ease), background .2s;
}
.theme-toggle:hover { border-color: var(--accent); transform: rotate(-25deg) scale(1.06); }

/* บนมือถือ ซ่อนเมนูบน แล้วใช้แถบล่างแทน (แบบแอป) */
@media (max-width: 760px) {
  .topbar-inner { min-height: 54px; gap: 10px; }
  .nav { display: none; }
  .brand-sub { display: none; }
  .theme-toggle { margin-left: auto; }
  body { padding-bottom: calc(76px + var(--safe-b)); }
}

/* ── 3b. BOTTOM NAV (มือถือ) ───────────────────────────────── */
.botnav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
  padding: 6px max(8px, var(--safe-l)) calc(6px + var(--safe-b)) max(8px, var(--safe-r));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
}
@supports not (backdrop-filter: blur(4px)) { .botnav { background: var(--bg); } }
.botnav-inner { display: flex; max-width: 560px; margin: 0 auto; }
.botnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 7px 4px 5px; text-decoration: none; border-radius: var(--r-sm);
  color: var(--text-3); font-size: 11px; font-weight: 600; line-height: 1.3;
  transition: color .2s, background .2s;
}
.botnav a .ic { font-size: 19px; line-height: 1.15; }
.botnav a:active { background: var(--surface-2); }
.botnav a[aria-current="page"] { color: var(--accent); }
.botnav a[aria-current="page"] .ic { transform: translateY(-1px); }
@media (max-width: 760px) { .botnav { display: block; } }
@media print { .botnav { display: none !important; } }

/* ── 4. PAGE HEADER ────────────────────────────────────────── */
.page-head { padding: 32px 0 4px; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--accent-tint); border: 1px solid var(--accent-line);
  color: var(--accent-soft); border-radius: 99px; padding: 5px 15px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .08em; margin-bottom: 14px;
}
.eyebrow::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}
h1.page-title {
  font-size: clamp(25px, 4.4vw, 36px); font-weight: 800; line-height: 1.2;
  letter-spacing: -.022em; margin-bottom: 8px;
}
.page-sub { color: var(--text-2); font-size: clamp(13.5px, 2.4vw, 15.5px); max-width: 64ch; }

.agent-bar {
  display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-top: 16px; padding: 9px 16px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--border);
  text-decoration: none; color: inherit; font-size: 13px; box-shadow: var(--sh-1);
  transition: border-color .2s, transform .2s var(--ease);
}
.agent-bar:hover { border-color: var(--accent); transform: translateY(-1px); }
.agent-bar strong { color: var(--text); }
.agent-bar span { color: var(--text-2); }

/* ── 5. CARD / PANEL ───────────────────────────────────────── */
.grid { display: grid; gap: 18px; }
.stack > * + * { margin-top: 16px; }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--sh-2);
}
.panel-head {
  display: flex; align-items: center; gap: 12px;
  padding: 15px 22px; border-bottom: 1px solid var(--border);
  background: linear-gradient(100deg, var(--accent-tint), transparent 58%);
}
.panel-head .ico {
  width: 34px; height: 34px; flex: 0 0 34px; border-radius: 10px;
  display: grid; place-items: center; font-size: 16px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.panel-head h2 { font-size: 17px; font-weight: 700; letter-spacing: -.01em; line-height: 1.35; }
.panel-head .sub { font-size: 12px; color: var(--text-3); font-weight: 400; line-height: 1.4; }
.panel-body { padding: 22px; }
@media (max-width: 560px) { .panel-body { padding: 16px; } .panel-head { padding: 13px 16px; } }

hr.sep { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ── 6. FORM ───────────────────────────────────────────────── */
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.field-grid.two { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.field.span-all { grid-column: 1 / -1; }
.field > label, .field-label {
  display: block; font-size: 12.5px; font-weight: 700; color: var(--text-2);
  letter-spacing: .015em; margin-bottom: 7px;
}
.field .help { font-size: 11.5px; color: var(--text-3); margin-top: 6px; line-height: 1.5; }

.input-wrap { position: relative; display: block; }
.input, input[type="text"].input, input[type="number"].input, select.input, textarea.input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.4;
  transition: border-color .18s, box-shadow .18s, background .18s;
  -webkit-appearance: none; appearance: none;
}
textarea.input { font-family: var(--font); resize: vertical; min-height: 66px; }
select.input {
  cursor: pointer; padding-right: 40px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
                    linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 20px) 55%, calc(100% - 14px) 55%;
  background-size: 6px 6px, 6px 6px; background-repeat: no-repeat;
}
.input-wrap:has(.unit) .input { padding-right: 52px; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); background: var(--surface); }
.input::placeholder { color: var(--text-3); opacity: 1; }
.input[readonly], .input:disabled { color: var(--accent-soft); background: var(--surface-3); cursor: default; }
.input.is-error { border-color: var(--red); box-shadow: 0 0 0 3px rgba(248,113,113,.14); }
input[type=number].input { -moz-appearance: textfield; }
input[type=number].input::-webkit-outer-spin-button,
input[type=number].input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.unit {
  position: absolute; right: 13px; top: 50%; transform: translateY(-50%);
  font-size: 11px; font-weight: 700; color: var(--text-3); pointer-events: none;
  transition: color .18s;
}
.input:focus + .unit { color: var(--accent); }

.slider { margin-top: 11px; }
input[type=range] {
  width: 100%; height: 6px; -webkit-appearance: none; appearance: none;
  background: var(--surface-3); border-radius: 99px; outline: none; cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--surface);
  box-shadow: 0 2px 8px var(--accent-glow); cursor: grab;
}
input[type=range]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%; background: var(--accent);
  border: 3px solid var(--surface); box-shadow: 0 2px 8px var(--accent-glow); cursor: grab;
}
.slider-ticks { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--text-3); margin-top: 6px; }

/* ── 7. BUTTONS ────────────────────────────────────────────── */
.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px; border-radius: var(--r-sm); border: 1px solid var(--border-2);
  background: var(--surface-2); color: var(--text);
  font-family: var(--font); font-size: 14.5px; font-weight: 600; cursor: pointer;
  transition: background .2s, border-color .2s, transform .12s var(--ease), box-shadow .2s, opacity .2s;
  min-height: 44px; text-decoration: none; -webkit-tap-highlight-color: transparent;
}
.btn:hover { border-color: var(--accent); background: var(--surface-3); }
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  border-color: transparent; color: var(--on-accent); font-weight: 700;
  box-shadow: 0 4px 16px var(--accent-glow);
}
.btn-primary:hover { background: linear-gradient(140deg, var(--accent), var(--accent-2)); filter: brightness(1.08); box-shadow: 0 8px 26px var(--accent-glow); }

.btn-lg { padding: 17px 28px; font-size: 17px; border-radius: var(--r); min-height: 58px; width: 100%; }
.btn-sm { padding: 7px 13px; font-size: 12.5px; min-height: 34px; border-radius: var(--r-xs); }
.btn-warn { background: var(--amber); border-color: transparent; color: #1a1206; font-weight: 700; }
.btn-warn:hover { background: var(--amber-soft); color: #1a1206; filter: none; }
.btn-danger { background: rgba(220,38,38,.13); border-color: rgba(220,38,38,.4); color: var(--red); }
.btn-danger:hover { background: rgba(220,38,38,.22); border-color: var(--red); color: var(--red); }
.btn-dashed { background: var(--accent-tint); border: 1px dashed var(--accent-line); color: var(--accent-soft); }
.btn-dashed:hover { background: var(--accent-tint); filter: brightness(1.2); }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-row.end { justify-content: flex-end; }
@media (max-width: 540px) { .btn-row .btn { flex: 1 1 100%; } }

/* ── 8. RESULT / KPI ───────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.kpi {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r); padding: 16px 17px 16px 20px; position: relative;
  transition: border-color .2s, transform .2s var(--ease);
}
.kpi:hover { border-color: var(--border-2); }
.kpi::after {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--accent); border-radius: var(--r) 0 0 var(--r);
}
.kpi.accent-green::after { background: var(--green); }
.kpi.accent-amber::after { background: var(--amber); }
.kpi.accent-violet::after { background: #a78bfa; }
.kpi-label { font-size: 11.5px; font-weight: 700; color: var(--text-2); letter-spacing: .03em; margin-bottom: 7px; line-height: 1.45; }
.kpi-value {
  font-family: var(--mono); font-size: clamp(18px, 3vw, 23px); font-weight: 700;
  color: var(--accent-soft); line-height: 1.25; overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}
.kpi-value.pos { color: var(--green); }
.kpi-value.neg { color: var(--red); }
.kpi-value.warn { color: var(--amber); }
.kpi-unit { font-family: var(--font); font-size: .6em; font-weight: 600; color: var(--text-3); margin-left: 5px; white-space: nowrap; }
.kpi-note { font-size: 10.5px; color: var(--text-3); margin-top: 6px; line-height: 1.45; }

.hero-result {
  background:
    radial-gradient(ellipse 70% 130% at 0% 0%, var(--accent-tint), transparent 70%),
    linear-gradient(135deg, var(--surface-2), var(--surface-3));
  border: 1px solid var(--accent-line); border-radius: var(--r-lg);
  padding: 24px 26px; position: relative; overflow: hidden;
}
.hero-result::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 4px; background: linear-gradient(180deg, var(--accent), var(--accent-2)); }
.hero-label { font-size: 13px; color: var(--text-2); margin-bottom: 5px; }
.hero-value {
  font-family: var(--mono); font-size: clamp(27px, 6vw, 40px); font-weight: 800;
  color: var(--accent-soft); line-height: 1.14; overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}
.hero-value.neg { color: var(--red); }
.hero-note { font-size: 12px; color: var(--text-3); margin-top: 7px; }

.callout {
  display: flex; gap: 11px; align-items: flex-start;
  background: var(--accent-tint); border: 1px solid var(--accent-line);
  border-radius: var(--r); padding: 12px 16px; font-size: 13px; color: var(--text-2); line-height: 1.6;
}
.callout .ic { color: var(--accent); flex-shrink: 0; }
.callout.warn { background: rgba(245,158,11,.1); border-color: rgba(245,158,11,.32); }
.callout.warn .ic { color: var(--amber); }

.save-box {
  background: linear-gradient(120deg, rgba(16,185,129,.11), rgba(16,185,129,.04));
  border: 1px solid rgba(16,185,129,.3);
  border-radius: var(--r); padding: 15px 17px;
}
.save-box .field-label { color: var(--green-soft); }

/* ── 9. TABLE ──────────────────────────────────────────────── */
.table-wrap { border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; background: var(--surface); }
.table-scroll { overflow-x: auto; overflow-y: auto; max-height: 560px; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 480px; }
table.data thead th {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface-3); color: var(--text);
  padding: 12px 14px; text-align: right; white-space: nowrap;
  font-size: 11.5px; font-weight: 700; letter-spacing: .04em;
  border-bottom: 1px solid var(--border-2);
}
table.data thead th:first-child { text-align: left; }
table.data tbody td {
  padding: 10px 14px; text-align: right; font-family: var(--mono); font-size: 12.5px;
  border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums;
}
table.data tbody td:first-child { text-align: left; color: var(--text-2); font-family: var(--font); white-space: nowrap; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background .15s; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data tr.row-total td { background: var(--accent-tint); font-weight: 700; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.zero { color: var(--text-3); }
.scroll-hint { font-size: 11.5px; color: var(--text-3); margin-top: 9px; line-height: 1.55; }

/* ── 10. TABS ──────────────────────────────────────────────── */
.tabs {
  display: flex; gap: 4px; padding: 5px; margin-bottom: 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  overflow-x: auto; scrollbar-width: none; box-shadow: var(--sh-1);
  scroll-snap-type: x proximity;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; min-width: 106px; padding: 11px 14px; border: none; cursor: pointer;
  background: transparent; color: var(--text-2); border-radius: var(--r-sm);
  font-size: 13.5px; font-weight: 600; text-align: center; white-space: nowrap;
  transition: background .2s, color .2s, box-shadow .2s; min-height: 46px;
  scroll-snap-align: center; -webkit-tap-highlight-color: transparent;
}
.tab .ic { display: block; font-size: 17px; margin-bottom: 1px; }
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab[aria-selected="true"] {
  background: var(--accent-tint); color: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent-line);
}
.tabpanel { display: none; }
.tabpanel.is-active { display: block; animation: fade .28s var(--ease); }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.steps { display: flex; gap: 7px; justify-content: center; margin-bottom: 16px; }
.step-dot { width: 8px; height: 8px; border-radius: 99px; background: var(--border-2); transition: all .3s var(--ease); }
.step-dot.is-done { background: var(--green); }
.step-dot.is-active { background: var(--accent); width: 24px; }

/* ── 11. TOAST + MODAL (แทน alert/confirm ที่ถูกบล็อกใน iframe) ── */
.toast-host {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%);
  z-index: 9999; display: flex; flex-direction: column; gap: 8px;
  align-items: center; pointer-events: none; width: min(92vw, 470px);
}
@media (max-width: 760px) { .toast-host { bottom: calc(86px + var(--safe-b)); } }
.toast {
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border-2); border-left: 4px solid var(--accent);
  border-radius: var(--r); padding: 13px 18px; font-size: 14px;
  box-shadow: var(--sh-3); animation: toastIn .26s var(--ease);
  max-width: 100%; text-align: center; white-space: pre-line; line-height: 1.55;
}
.toast.is-error { border-left-color: var(--red); }
.toast.is-ok { border-left-color: var(--green); }
.toast.is-out { animation: toastOut .25s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(16px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(10px); } }

.modal-host {
  position: fixed; inset: 0; z-index: 9998; display: grid; place-items: center;
  background: rgba(3,7,18,.7); padding: 20px; animation: fade .2s ease;
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}
.modal {
  background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--r-lg);
  padding: 24px; width: min(94vw, 430px); box-shadow: var(--sh-3);
  animation: modalIn .28s var(--ease);
}
@keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }
.modal p { margin-bottom: 20px; white-space: pre-line; line-height: 1.65; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

.pdf-modal {
  background: var(--surface); border-radius: var(--r-lg); padding: 14px;
  width: min(96vw, 960px); height: min(90vh, 920px);
  display: flex; flex-direction: column; gap: 10px; box-shadow: var(--sh-3);
}
.pdf-modal iframe { flex: 1; border: none; border-radius: var(--r-sm); background: #fff; }
.pdf-modal-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.pdf-modal-bar .name { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── 11b. PWA — ป้ายติดตั้ง / ออฟไลน์ / อัปเดต ─────────────── */
.install-card {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + var(--safe-b)); z-index: 9990;
  width: min(94vw, 440px);
  display: flex; align-items: center; gap: 13px;
  background: var(--surface); border: 1px solid var(--accent-line);
  border-radius: var(--r-lg); padding: 14px 16px; box-shadow: var(--sh-3);
  animation: toastIn .3s var(--ease);
}
@media (max-width: 760px) { .install-card { bottom: calc(84px + var(--safe-b)); } }
.install-card .ic {
  width: 42px; height: 42px; flex: 0 0 42px; border-radius: 12px; display: grid; place-items: center;
  font-size: 21px; background: linear-gradient(140deg, var(--accent), var(--accent-2)); color: var(--on-accent);
}
.install-card .tx { flex: 1; min-width: 0; }
.install-card .tx b { display: block; font-size: 14px; }
.install-card .tx span { font-size: 12px; color: var(--text-3); line-height: 1.45; display: block; }
.install-card .btn { padding: 9px 15px; min-height: 38px; font-size: 13.5px; flex-shrink: 0; }
.install-card .x {
  background: none; border: none; color: var(--text-3); cursor: pointer;
  font-size: 17px; padding: 4px 6px; line-height: 1; flex-shrink: 0;
}
.install-card .x:hover { color: var(--text); }

.offline-bar {
  position: fixed; left: 0; right: 0; top: 0; z-index: 9995;
  padding: calc(7px + var(--safe-t)) 14px 7px;
  background: var(--amber); color: #1a1206;
  font-size: 12.5px; font-weight: 700; text-align: center;
  animation: toastIn .25s var(--ease);
}
body.is-offline { --topbar-offset: 34px; }

@media print {
  .install-card, .offline-bar { display: none !important; }
}

/* ── 12. FOOTER ────────────────────────────────────────────── */
.site-footer {
  margin-top: 46px; padding: 26px 0 10px; border-top: 1px solid var(--border);
  color: var(--text-3); font-size: 13px;
}
.site-footer .wrap { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: space-between; }
.site-footer a { color: var(--accent-soft); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.footer-links { display: flex; gap: 16px; flex-wrap: wrap; }

/* ── 13. UTIL ──────────────────────────────────────────────── */
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }
.center { text-align: center; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 26px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.chip {
  display: inline-block; background: var(--surface-3); border: 1px solid var(--border);
  border-radius: 99px; padding: 2px 10px; font-size: 11.5px; color: var(--text-2);
}

/* ── 14. PRINT + PDF EXPORT MODE ───────────────────────────
   .exporting-pdf ถูกใส่ที่ <body> ชั่วคราวก่อน html2canvas จับภาพ
   (html2canvas อ่านสไตล์บนจอ ไม่อ่าน @media print) ── */
@media print {
  .topbar, .site-footer, .no-print, .toast-host, .modal-host { display: none !important; }
  body { background: #fff !important; color: #000 !important; padding: 0 !important; }
  body::before { display: none !important; }
  .panel, .kpi, .hero-result, .table-wrap { break-inside: avoid; box-shadow: none !important; }
  table.data { break-inside: auto; }
  table.data tr { break-inside: avoid; break-after: auto; }
  .table-scroll { max-height: none !important; overflow: visible !important; }
  .tabpanel { display: block !important; }
  @page { margin: 12mm; }
}

body.exporting-pdf { background: #fff !important; color: #111 !important; }
body.exporting-pdf::before { display: none !important; }
body.exporting-pdf .topbar,
body.exporting-pdf .botnav,
body.exporting-pdf .site-footer,
body.exporting-pdf .no-print,
body.exporting-pdf .install-card,
body.exporting-pdf .offline-bar,
body.exporting-pdf .toast-host { display: none !important; }
body.exporting-pdf .panel { background: #fff !important; border: 1px solid #cbd5e1 !important; box-shadow: none !important; }
body.exporting-pdf .panel-head { background: #eef2f7 !important; border-bottom: 1px solid #cbd5e1 !important; }
body.exporting-pdf .panel-head h2,
body.exporting-pdf h1.page-title,
body.exporting-pdf .brand-name { color: #0f172a !important; -webkit-text-fill-color: #0f172a !important; background: none !important; }
body.exporting-pdf .kpi, body.exporting-pdf .hero-result, body.exporting-pdf .save-box,
body.exporting-pdf .callout, body.exporting-pdf .table-wrap { background: #f8fafc !important; border-color: #cbd5e1 !important; }
body.exporting-pdf .kpi-value, body.exporting-pdf .hero-value { color: #1d4ed8 !important; -webkit-text-fill-color: #1d4ed8 !important; }
body.exporting-pdf .kpi-label, body.exporting-pdf .hero-label,
body.exporting-pdf .page-sub, body.exporting-pdf .field > label,
body.exporting-pdf .field-label, body.exporting-pdf .muted { color: #334155 !important; }
body.exporting-pdf table.data thead th { background: #1e40af !important; color: #fff !important; }
body.exporting-pdf table.data tbody td { color: #111 !important; border-bottom: 1px solid #e2e8f0 !important; }
body.exporting-pdf .pos { color: #047857 !important; }
body.exporting-pdf .neg { color: #b91c1c !important; }
body.exporting-pdf .zero { color: #64748b !important; }
body.exporting-pdf .table-scroll { max-height: none !important; overflow: visible !important; }
body.exporting-pdf .tabpanel { display: block !important; }
body.exporting-pdf .tabs { display: none !important; }
body.exporting-pdf .pdf-only { display: block !important; }
.pdf-only { display: none; }

span[data-pdf-replica] {
  display: inline-flex; align-items: center; box-sizing: border-box;
  background: #f1f5f9; border: 1px solid #cbd5e1; color: #0f172a;
  overflow: hidden; white-space: nowrap; vertical-align: middle;
}

/* ── 3c. ลิงก์กลับเว็บหลัก / ทีมตัวแทน ─────────────────────────
   เครื่องมือชุดนี้อยู่คนละโฟลเดอร์กับเว็บหลัก เดิมมีแค่ปุ่ม Home เล็ก ๆ
   ที่ปนอยู่กับเมนูสลับเครื่องมือ และบนมือถือ .nav ถูกซ่อนทั้งแถว
   ทำให้ไม่มีทางกลับ 2provi.com เลย จึงแยกสองลิงก์นี้เป็นกลุ่มของตัวเอง
   คั่นด้วยเส้น และเพิ่มเข้าไปในแถบล่างของมือถือด้วย */
.nav-site {
  color: var(--text) !important;
  background: var(--surface-2);
  border-color: var(--border) !important;
}
.nav-site:hover { border-color: var(--accent) !important; background: var(--accent-tint); }
.nav-sep {
  width: 1px; height: 22px; flex: 0 0 1px;
  background: var(--border); margin-inline: 5px;
}

/* แถบล่างของมือถือมี 6 ช่องแล้ว บีบระยะให้พอดีจอแคบ */
@media (max-width: 400px) {
  .botnav a { padding: 7px 2px 5px; font-size: 10.5px; gap: 1px; }
  .botnav a .ic { font-size: 17px; }
}
@media (max-width: 340px) {
  .botnav a { font-size: 9.8px; }
  .botnav a .ic { font-size: 16px; }
}

/* ── โลโก้ 2ProviGroup บนแถบหัวของเครื่องคำนวณ ──
   .brand-mark เดิมเป็นไล่เฉดตาม accent ของแต่ละหน้า ซึ่งจะโผล่ตามมุม
   โปร่งของไฟล์โลโก้ จึงเอาพื้นออก */
.brand-mark{
  background: none;
  border-radius: 50%;
  padding: 0;
  overflow: hidden;
  box-shadow: 0 6px 18px -8px rgba(0,0,0,.6);
}
.brand-mark img { width: 100%; height: 100%; display: block; object-fit: contain; }
