:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --ink: #16202c;
  --ink-2: #4a5666;
  --muted: #7a8595;
  --line: #dde2e9;
  --brand: #16325c;
  --brand-ink: #ffffff;
  --accent: #e8900c;
  --accent-soft: #fdf1dd;
  --good: #1f8a4c;
  --bad: #c2372b;
  --warn-soft: #fff4e0;
  --info-soft: #e8f0fb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --surface: #171e27; --surface-2: #1f2833; --ink: #e8edf3; --ink-2: #b4bfcc;
    --muted: #8793a2; --line: #2b3542; --brand: #8fb3ec; --brand-ink: #0f141b; --accent: #f3a632;
    --accent-soft: #3a2c14; --good: #4cc27f; --bad: #ff7a6b; --warn-soft: #33290f; --info-soft: #172a45;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141b; --surface: #171e27; --surface-2: #1f2833; --ink: #e8edf3; --ink-2: #b4bfcc;
  --muted: #8793a2; --line: #2b3542; --brand: #8fb3ec; --brand-ink: #0f141b; --accent: #f3a632;
  --accent-soft: #3a2c14; --good: #4cc27f; --bad: #ff7a6b; --warn-soft: #33290f; --info-soft: #172a45;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.6 "IBM Plex Sans Thai", "Sarabun", "Leelawadee UI", Tahoma, sans-serif;
}
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; text-wrap: balance; }
h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.good { color: var(--good); } .bad { color: var(--bad); }

/* ---------- header ---------- */
#site-header { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.nav { display: flex; align-items: center; gap: 16px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-size: 1.2rem; }
.brand .logo {
  display: grid; place-items: center; height: 36px; padding: 0 10px; border-radius: 8px;
  background: linear-gradient(135deg, #1e88e5, #0d5bb5); color: #fff; border: 2px solid #fff;
  box-shadow: 0 0 0 2px #1e88e5; font-weight: 700; font-size: .95rem; letter-spacing: .08em;
}
.brand b { color: #1e88e5; }
.nav nav { margin-left: auto; display: flex; gap: 4px; }
.nav nav a { text-decoration: none; color: var(--ink-2); padding: 8px 14px; border-radius: 8px; }
.nav nav a:hover { background: var(--surface-2); }
.nav nav a.on { background: var(--brand); color: var(--brand-ink); }
.menu-btn { display: none; margin-left: auto; background: none; border: 1px solid var(--line); color: var(--ink); border-radius: 8px; padding: 4px 10px; font-size: 1.2rem; }
@media (max-width: 720px) {
  .menu-btn { display: block; }
  .nav { flex-wrap: wrap; }
  .nav nav { display: none; width: 100%; flex-direction: column; padding-bottom: 10px; }
  .nav nav.open { display: flex; }
}

/* ---------- hero ---------- */
.hero { background: var(--brand); color: var(--brand-ink); padding: 48px 0 40px; }
.hero p { max-width: 62ch; opacity: .9; font-size: 1.05rem; }
.hero .eyebrow { color: var(--accent); font-weight: 600; letter-spacing: .02em; margin-bottom: .4em; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .hero { background: #14243b; color: var(--ink); } }
:root[data-theme="dark"] .hero { background: #14243b; color: var(--ink); }
.cta { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 16px; border-radius: 8px; font: inherit; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1b1203; font-weight: 600; }
.btn.small { padding: 4px 10px; font-size: .9rem; }

/* ---------- layout ---------- */
main { padding: 28px 0 48px; }
section { margin-bottom: 32px; }
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.g2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
@media (max-width: 400px) { .g2, .g3 { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card h3 { margin-bottom: .3em; }
.kpi .label { color: var(--muted); font-size: .9rem; }
.kpi .value { font-size: 1.7rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--ink-2); font-size: .88rem; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.section-head p { margin: 0; }

/* ---------- bars ---------- */
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 230px) 1fr auto; gap: 10px; align-items: center; font-size: .92rem; }
.bar-track { background: var(--surface-2); border-radius: 6px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--brand); border-radius: 6px; }
.bar-fill.pt { background: var(--accent); }
@media (max-width: 560px) { .bar-row { grid-template-columns: 1fr auto; } .bar-track { grid-column: 1 / -1; order: 3; } }
.legend { display: flex; gap: 16px; font-size: .88rem; color: var(--ink-2); flex-wrap: wrap; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 6px; background: var(--brand); }
.legend i.pt { background: var(--accent); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; }
th { background: var(--surface-2); font-weight: 600; color: var(--ink-2); white-space: nowrap; position: sticky; top: 0; }
tbody tr:hover { background: var(--surface-2); }
tfoot td { font-weight: 600; background: var(--surface-2); }
.scroll-y { max-height: 520px; }
.tag { display: inline-block; font-size: .78rem; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.tag.pt { background: var(--accent-soft); color: var(--ink); }
.tag.user { background: var(--info-soft); color: var(--ink); }

/* ---------- forms ---------- */
.form { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: end; }
label { display: grid; gap: 4px; font-size: .88rem; color: var(--ink-2); }
input, select { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; min-width: 0; }
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
td input { padding: 4px 8px; width: 110px; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 20px; scrollbar-width: thin; }
.tabs button { font: inherit; background: none; border: none; border-bottom: 3px solid transparent; padding: 10px 14px; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------- notes ---------- */
.note { border-radius: var(--radius); padding: 12px 16px; border: 1px solid var(--line); }
.note.warn { background: var(--warn-soft); }
.note.info { background: var(--info-soft); }
.note b { display: block; }
.formula { font-family: ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 2px 8px; border-radius: 6px; font-size: .9em; }

/* ---------- route path ---------- */
.path { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.path .stop { background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 12px; }
.path .leg { color: var(--muted); font-size: .85rem; }
.stops { display: grid; gap: 8px; }
.stop-row { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; }
.stop-row .n { width: 26px; height: 26px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: .85rem; }

/* ---------- invoice ---------- */
.invoice { background: #fff; color: #111; border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; }
.invoice table { font-size: .9rem; }
.invoice th { background: #f1f3f6; color: #333; position: static; }
.invoice td, .invoice th { border: 1px solid #ccd; }
.invoice .head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.invoice .title { text-align: center; font-size: 1.3rem; font-weight: 700; margin: 8px 0 14px; }
.invoice .sign { display: flex; justify-content: space-around; margin-top: 40px; text-align: center; gap: 20px; flex-wrap: wrap; }

@media print {
  #site-header, #site-footer, .no-print, .tabs { display: none !important; }
  body { background: #fff; }
  main { padding: 0; }
  .invoice { border: none; padding: 0; }
  [role=tabpanel] > :not(.print-area) { display: none; }
}

/* ---------- footer ---------- */
#site-footer { border-top: 1px solid var(--line); background: var(--surface); padding: 20px 0; font-size: .9rem; }
.foot { display: grid; gap: 4px; }

.cover { position: relative; margin: 0 0 28px; border-radius: var(--radius); overflow: hidden; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line), var(--shadow); }
.cover img { display: block; width: 100%; height: auto; }
.cover figcaption { position: absolute; right: 12px; bottom: 10px; background: rgba(255,255,255,.92); color: #0d47a1; font-size: .85rem; font-weight: 600; padding: 3px 12px; border-radius: 999px; }
@media (max-width: 560px) { .cover figcaption { position: static; border-radius: 0; text-align: center; } }
.cover.photo { margin-bottom: 12px; }
.cover.photo img { aspect-ratio: 16 / 7; object-fit: cover; object-position: center 55%; }
.cover-overlay {
  position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 14px; padding: 22px;
  background: linear-gradient(90deg, rgba(13, 71, 161, .88) 0%, rgba(30, 136, 229, .45) 45%, rgba(255, 255, 255, 0) 75%),
              linear-gradient(0deg, rgba(13, 71, 161, .55), rgba(13, 71, 161, 0) 45%);
  color: #fff;
}
.logo.big { display: grid; place-items: center; height: 56px; padding: 0 16px; border-radius: 12px; background: #fff; color: #1565c0; font-weight: 800; font-size: 1.4rem; letter-spacing: .1em; }
.cover-title { font-size: clamp(1.3rem, 3.5vw, 2.1rem); font-weight: 700; line-height: 1.2; text-shadow: 0 1px 6px rgba(0, 0, 0, .3); }
.cover-sub { opacity: .95; }
@media (max-width: 560px) { .cover.photo img { aspect-ratio: 4 / 3; } .cover-overlay { padding: 14px; } .logo.big { display: none; } }
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.gallery figure { margin: 0; border-radius: var(--radius); overflow: hidden; position: relative; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line); background: #1565c0; }
.gallery img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.gallery figcaption { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 10px 6px; color: #fff; font-weight: 600; font-size: .9rem;
  background: linear-gradient(0deg, rgba(13, 71, 161, .9), rgba(13, 71, 161, 0)); }
@media (max-width: 560px) { .gallery { grid-template-columns: 1fr 1fr; } .gallery figure:first-child { grid-column: 1 / -1; } }
.credit { font-size: .78rem; color: var(--muted); margin: 8px 0 28px; }
.company-hero { display: grid; grid-template-columns: 1.3fr 1fr; gap: 24px; align-items: center; }
@media (max-width: 800px) { .company-hero { grid-template-columns: 1fr; } }
dl.info { display: grid; grid-template-columns: max-content minmax(0, 1fr); overflow-wrap: anywhere; gap: 8px 16px; margin: 0; }
dl.info dt { color: var(--muted); }
dl.info dd { margin: 0; }
.plates { display: flex; flex-wrap: wrap; gap: 8px; }
.plate { border: 2px solid var(--ink); border-radius: 6px; padding: 2px 10px; font-weight: 600; background: var(--surface); font-variant-numeric: tabular-nums; }
