:root {
  --ink: #17312d;
  --muted: #687873;
  --forest: #193b36;
  --forest-2: #28564e;
  --lime: #d8f06b;
  --cream: #f5f3ec;
  --card: #fffefa;
  --line: #d9ddd7;
  --blue: #4e7dd1;
  --orange: #f4a261;
  --danger: #bd4a48;
  --shadow: 0 12px 32px rgba(24, 55, 49, .09);
  font-family: "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif;
  color: var(--ink);
  background: var(--cream);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--cream); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(78, 125, 209, .35); outline-offset: 2px; }
.hidden { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 20; height: 68px; padding: 10px max(18px, env(safe-area-inset-left));
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(245, 243, 236, .92); backdrop-filter: blur(14px); border-bottom: 1px solid rgba(25, 59, 54, .08);
}
.brand { border: 0; background: transparent; color: var(--forest); display: flex; align-items: center; gap: 9px; font-size: 1.3rem; font-weight: 800; }
.brand-mark { width: 39px; height: 39px; display: grid; place-items: center; border-radius: 13px; background: var(--forest); color: var(--lime); }
.top-actions { display: flex; gap: 6px; }
.icon-button { min-width: 55px; border: 0; border-radius: 12px; padding: 5px 8px; color: var(--forest); background: transparent; display: grid; gap: 1px; place-items: center; }
.icon-button:hover { background: #e9e9df; }
.icon-button span { font-size: 1.25rem; line-height: 1; }.icon-button small { font-size: .72rem; }

#app { width: min(1120px, 100%); margin: 0 auto; padding: 24px 18px 110px; }
.hero { position: relative; overflow: hidden; min-height: 275px; padding: clamp(28px, 6vw, 64px); border-radius: 32px; color: white; background: var(--forest); box-shadow: var(--shadow); }
.hero::after { content: "฿"; position: absolute; right: -10px; bottom: -115px; color: rgba(216, 240, 107, .12); font-size: 19rem; font-weight: 900; transform: rotate(-12deg); }
.eyebrow { margin: 0 0 10px; color: #b8c9c4; font-size: .84rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.hero h1 { position: relative; z-index: 1; margin: 0; max-width: 650px; font-size: clamp(2rem, 6vw, 4rem); line-height: 1.14; }
.hero p { position: relative; z-index: 1; max-width: 600px; margin: 18px 0 0; color: #d9e4e1; font-size: clamp(1rem, 2vw, 1.2rem); line-height: 1.7; }
.compact-hero { min-height: 0; padding: 28px 34px; }
.compact-hero h1 { font-size: clamp(1.75rem, 4vw, 2.6rem); }
.compact-hero p { margin-top: 2px; color: var(--lime); font-weight: 800; }
.offline-pill { position: relative; z-index: 1; display: inline-flex; align-items: center; gap: 8px; margin-top: 22px; padding: 9px 13px; border: 1px solid rgba(255,255,255,.18); border-radius: 999px; background: rgba(255,255,255,.08); font-size: .84rem; }
.offline-pill::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 0 4px rgba(216,240,107,.13); }

.section-heading { margin: 32px 4px 16px; }.section-heading h2 { margin: 0; font-size: 1.35rem; }.section-heading p { margin: 5px 0 0; color: var(--muted); }
.tool-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.tool-card { position: relative; overflow: hidden; min-height: 220px; padding: 23px; border: 1px solid var(--line); border-radius: 25px; background: var(--card); text-align: left; color: var(--ink); box-shadow: 0 4px 18px rgba(24,55,49,.04); transition: transform .2s, box-shadow .2s; }
.tool-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
.tool-number { color: var(--muted); font-size: .78rem; font-weight: 800; letter-spacing: .06em; }
.tool-icon { width: 54px; height: 54px; margin: 18px 0; display: grid; place-items: center; border-radius: 17px; background: #ecf3dc; color: var(--forest); font-size: 1.7rem; font-weight: 800; }
.tool-card:nth-child(2) .tool-icon { background: #e6eefb; }.tool-card:nth-child(3) .tool-icon { background: #fbeadf; }
.tool-card h3 { margin: 0; font-size: 1.25rem; }.tool-card p { margin: 8px 0 0; color: var(--muted); line-height: 1.55; }
.arrow { position: absolute; right: 20px; top: 20px; width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 50%; display: grid; place-items: center; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin: 0 0 20px; }
.page-head h1 { margin: 2px 0 5px; font-size: clamp(1.75rem, 5vw, 2.7rem); }.page-head p { margin: 0; color: var(--muted); line-height: 1.55; }
.head-actions { display: flex; gap: 8px; flex-shrink: 0; }
.panel { margin-bottom: 18px; padding: clamp(18px, 4vw, 28px); border: 1px solid var(--line); border-radius: 24px; background: var(--card); box-shadow: 0 4px 18px rgba(24,55,49,.035); }
.panel-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; }
.panel-title h2, .panel-title h3 { margin: 0; font-size: 1.15rem; }.panel-title p { margin: 3px 0 0; color: var(--muted); font-size: .9rem; }
.field-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; }
.field { display: grid; gap: 7px; }.field.span-2 { grid-column: span 2; }.field.full { grid-column: 1 / -1; }
.field label { font-weight: 700; font-size: .92rem; }.required::after { content: " *"; color: var(--danger); }.optional { color: var(--muted); font-size: .75rem; font-weight: 500; }
.input-wrap { position: relative; }.input-wrap input, .input-wrap select, .field > select { width: 100%; height: 52px; padding: 0 54px 0 14px; border: 1.5px solid #cfd6d1; border-radius: 14px; color: var(--ink); background: white; font-size: 1rem; }
.input-wrap input:focus, .input-wrap select:focus, .field > select:focus { border-color: var(--forest-2); }.unit { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: .82rem; pointer-events: none; }
input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { appearance: none; -webkit-appearance: none; margin: 0; }
.input-wrap input:disabled { opacity: 1; color: #eef5d5; background: var(--forest); border-color: var(--forest); cursor: not-allowed; }
.input-wrap input:disabled::placeholder { color: #eef5d5; opacity: 1; font-weight: 800; }
.help { color: var(--muted); font-size: .78rem; line-height: 1.4; }.error { color: var(--danger); }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.button { min-height: 46px; padding: 10px 17px; border: 0; border-radius: 14px; font-weight: 800; color: var(--forest); background: #e9ede9; }
.button.primary { color: white; background: var(--forest); }.button.primary:hover { background: var(--forest-2); }.button.accent { color: var(--forest); background: var(--lime); }.button.danger { color: var(--danger); background: #fae9e7; }.button.ghost { border: 1px solid var(--line); background: transparent; }.button.small { min-height: 38px; padding: 7px 12px; font-size: .86rem; }
.button:disabled { opacity: .42; cursor: not-allowed; }
.example-box { margin: 0 0 18px; padding: 15px 17px; border-radius: 16px; background: #f0f4e5; color: #415246; font-size: .87rem; line-height: 1.65; }
.example-box strong { color: var(--forest); }

.result-hero { padding: 22px; border-radius: 20px; color: white; background: var(--forest); }
.result-hero .result-label { color: #b8c9c4; font-size: .9rem; }.result-value { margin-top: 4px; color: var(--lime); font-size: clamp(2rem, 7vw, 3.5rem); font-weight: 900; line-height: 1.2; overflow-wrap: anywhere; }.result-unit { color: #d9e4e1; font-size: 1rem; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }.metric { padding: 15px; border: 1px solid var(--line); border-radius: 16px; background: #fafaf6; }.metric span { display: block; color: var(--muted); font-size: .78rem; }.metric strong { display: block; margin-top: 4px; font-size: 1.06rem; }
.compare-card { position: relative; margin-top: 13px; padding: 18px; border: 1.5px dashed #b8c3bc; border-radius: 18px; background: #fbfbf7; }.compare-card .remove-compare { position: absolute; right: 12px; top: 10px; width: 34px; height: 34px; border: 0; border-radius: 50%; color: var(--danger); background: #fae9e7; font-weight: 900; }
.compare-card h4 { margin: 0 45px 14px 0; }.compare-output { margin-top: 12px; padding: 12px; border-radius: 12px; background: #edf2e1; font-weight: 800; }
.primary-output { margin-top: 18px; border-left: 5px solid var(--forest-2); }
.primary-output strong, .primary-output span { display: block; }.primary-output span { margin-top: 5px; color: var(--muted); font-size: .86rem; font-weight: 600; }

.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; padding: 5px; border-radius: 16px; background: #e9ede9; }.mode-switch button { min-height: 46px; border: 0; border-radius: 12px; color: var(--muted); background: transparent; font-weight: 800; }.mode-switch button.active { color: white; background: var(--forest); box-shadow: 0 4px 10px rgba(25,59,54,.2); }

.chart { min-height: 270px; padding: 18px 10px 4px; display: flex; align-items: flex-end; gap: 15px; overflow-x: auto; border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.bar-group { min-width: 118px; height: 225px; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; text-align: center; }.bar-value { margin-bottom: 6px; font-size: .72rem; font-weight: 800; white-space: nowrap; }.bar { width: 100%; min-height: 2px; padding: 0; border: 0; transition: filter .2s, height .4s; }.bar:hover, .bar:focus-visible { filter: brightness(.9); }.bar.return { background: var(--lime); border-radius: 8px 8px 0 0; }.bar.principal { background: var(--forest-2); }.bar-label { margin-top: 7px; min-height: 32px; color: var(--muted); font-size: .72rem; }
.chart-detail { margin: 4px 0 10px; padding: 10px 13px; border-radius: 12px; color: var(--muted); background: #f1f2ed; font-size: .86rem; font-weight: 700; }.chart-detail.active { color: var(--forest); background: #e5efce; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 13px 0 0; color: var(--muted); font-size: .82rem; }.legend i { display: inline-block; width: 10px; height: 10px; margin-right: 5px; border-radius: 3px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 16px; }table { width: 100%; border-collapse: collapse; min-width: 620px; }th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }th:first-child, td:first-child { text-align: left; }th { color: var(--forest); background: #eef1e9; font-size: .82rem; }td { font-size: .87rem; }tr:last-child td { border-bottom: 0; }

.history-list { display: grid; gap: 12px; }.history-item { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 16px; border: 1px solid var(--line); border-radius: 17px; background: var(--card); }.history-main { flex: 1; min-width: 0; }.history-main strong { display: block; }.history-main p { margin: 4px 0 0; color: var(--muted); font-size: .84rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }.empty { padding: 60px 20px; text-align: center; color: var(--muted); }.empty-icon { display: grid; place-items: center; width: 70px; height: 70px; margin: 0 auto 15px; border-radius: 22px; background: #e9ede9; font-size: 2rem; }
.note { padding: 14px 16px; border-left: 4px solid var(--orange); border-radius: 8px 14px 14px 8px; background: #fff4e9; color: #70523d; font-size: .86rem; line-height: 1.6; }
.toast { position: fixed; left: 50%; bottom: 95px; z-index: 50; max-width: calc(100% - 36px); padding: 11px 18px; border-radius: 999px; color: white; background: var(--ink); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translate(-50%, 15px); transition: .2s; }.toast.show { opacity: 1; transform: translate(-50%, 0); }
.bottom-nav { display: none; }

@media (max-width: 760px) {
  .topbar { height: 62px; }.top-actions .icon-button { min-width: 49px; }
  #app { padding: 17px 14px 104px; }.hero { min-height: 310px; padding: 30px 24px; border-radius: 25px; }.hero.compact-hero { min-height: 0; padding: 25px 24px; }.hero::after { font-size: 15rem; }.compact-hero::after { bottom: -150px; }
  .tool-grid { grid-template-columns: 1fr; }.tool-card { min-height: 180px; }.tool-icon { margin: 14px 0; }
  .field-grid { grid-template-columns: 1fr; }.field.span-2 { grid-column: auto; }
  .page-head { display: block; }.head-actions { margin-top: 14px; }.panel { padding: 18px; border-radius: 20px; }
  .metrics { grid-template-columns: 1fr 1fr; }.metrics .metric:last-child { grid-column: 1 / -1; }
  .bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: calc(72px + env(safe-area-inset-bottom)); padding: 6px 7px env(safe-area-inset-bottom); display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); background: rgba(255,254,250,.96); backdrop-filter: blur(14px); }
  .bottom-nav button { border: 0; border-radius: 12px; color: var(--muted); background: transparent; display: grid; place-items: center; align-content: center; gap: 3px; font-size: .68rem; }.bottom-nav button span { font-size: 1.2rem; }.bottom-nav button.active { color: var(--forest); background: #edf2e1; font-weight: 800; }
  .history-item { align-items: flex-start; }.history-item .button-row { margin: 0; }
}

@media print {
  .topbar, .bottom-nav, .head-actions, .button-row, .remove-compare, .no-print { display: none !important; }
  body, :root { background: white; }#app { width: 100%; padding: 0; }.panel { box-shadow: none; break-inside: avoid; }
  .print-table { break-before: page; page-break-before: always; }
}
