:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --ink: #1b2233;
  --muted: #687186;
  --line: #e2e6ee;
  --accent: #2f5bd3;
  --accent-ink: #ffffff;
  --accent-soft: #e8eefc;
  --good: #0f7a4a;
  --good-soft: #e3f4ea;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 4px 16px rgba(20, 30, 60, .05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f131b;
    --surface: #171c27;
    --surface-2: #1d2331;
    --ink: #e7eaf1;
    --muted: #98a1b5;
    --line: #2a3142;
    --accent: #7d9cf5;
    --accent-ink: #0f131b;
    --accent-soft: #222d4a;
    --good: #5fd39a;
    --good-soft: #15301f;
    --warn: #f0b85a;
    --warn-soft: #33270f;
    --bad: #f3897e;
    --bad-soft: #3a1a17;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 "IBM Plex Sans Thai", -apple-system, "Segoe UI", Tahoma, sans-serif;
}
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0; }
.muted { color: var(--muted); margin: 2px 0 0; }
button, input, select { font: inherit; color: inherit; }

/* ── ปุ่ม ── */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13.5px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .55; cursor: progress; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: 13.5px; }
.icon-btn { background: none; border: 0; font-size: 18px; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); }

/* ── login ── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px 24px; box-shadow: var(--shadow); display: grid; gap: 14px;
}
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.plane { color: var(--accent); font-size: 20px; }

/* ── layout ── */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.top-actions { display: flex; gap: 6px; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 20px 16px 48px; }
.head-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin: 8px 0 18px; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 16px; }

.banner { border-radius: 12px; padding: 10px 14px; margin-bottom: 10px; font-size: 14px; border: 1px solid transparent; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.info { background: var(--accent-soft); color: var(--ink); }

/* ── การ์ด ── */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0;
}
.card.paused { opacity: .72; }
.card-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.card-title { font-weight: 600; font-size: 16px; line-height: 1.35; word-break: break-word; }
.route { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.chip {
  display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }

.price-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.price { font-size: 28px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.price.good { color: var(--good); }
.price-sub { font-size: 13px; color: var(--muted); }
.spark { width: 132px; height: 40px; flex-shrink: 0; }
.spark .line { fill: none; stroke: var(--accent); stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; }
.spark .ceil { stroke: var(--good); stroke-width: 1; stroke-dasharray: 3 3; }
.spark .dot { fill: var(--accent); }

.meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--muted); }
.err { font-size: 13px; color: var(--bad); background: var(--bad-soft); padding: 6px 10px; border-radius: 8px; word-break: break-word; }

details.offers summary { cursor: pointer; font-size: 13.5px; color: var(--accent); list-style: none; }
details.offers summary::-webkit-details-marker { display: none; }
details.offers summary::before { content: "▸ "; }
details.offers[open] summary::before { content: "▾ "; }
.offer-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.offer {
  display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; padding: 8px 10px;
  border-radius: 10px; background: var(--surface-2); font-size: 13.5px;
}
.offer b { font-variant-numeric: tabular-nums; }
.offer a { color: var(--accent); text-decoration: none; grid-column: 2; }
.offer a:hover { text-decoration: underline; }

.card-actions { display: flex; gap: 6px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 12px; margin-top: auto; }
.card-actions .spacer { flex: 1; }

.empty {
  grid-column: 1 / -1; text-align: center; padding: 48px 16px; color: var(--muted);
  border: 1.5px dashed var(--line); border-radius: var(--radius);
}

/* ── log ── */
.log { margin-top: 36px; }
.log h2 { margin-bottom: 10px; }
.notif-list { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.notif-list li { display: flex; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); font-size: 13.5px; align-items: baseline; }
.notif-list li:first-child { border-top: 0; }
.notif-list time { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; min-width: 92px; }
.notif-list .subj { flex: 1; min-width: 0; word-break: break-word; }
.notif-list .empty-row { color: var(--muted); }

/* ── dialog ── */
.dialog {
  border: 0; padding: 0; border-radius: 16px; width: min(640px, calc(100vw - 24px));
  max-height: calc(100vh - 32px); background: var(--surface); color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.dialog.small { width: min(460px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(10, 15, 30, .45); }
.dialog > form, .dialog > div { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dlg-body { padding: 8px 20px 16px; overflow-y: auto; overflow-x: hidden; }
.dlg-body fieldset, .row > *, .stack > * { min-width: 0; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); }

fieldset { border: 0; padding: 0; margin: 14px 0 0; display: grid; gap: 12px; }
legend { font-weight: 600; font-size: 14px; margin-bottom: 8px; padding: 0; }
label { display: grid; gap: 5px; font-size: 13.5px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); align-self: end; padding-bottom: 9px; }
input:not([type=checkbox]):not([type=radio]), select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); min-height: 40px;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.stack { display: grid; gap: 8px; align-content: start; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .row { grid-template-columns: 1fr; } label.check { padding-bottom: 0; } }
.label-row { display: flex; justify-content: space-between; font-size: 13.5px; color: var(--muted); margin-bottom: 6px; gap: 8px; flex-wrap: wrap; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips label {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border: 1px solid var(--line);
  border-radius: 99px; cursor: pointer; color: var(--ink); font-size: 13.5px; user-select: none;
}
.chips label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); }
.chips input { margin: 0; accent-color: var(--accent); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; padding: 3px; width: fit-content; }
.seg label { display: flex; align-items: center; gap: 6px; padding: 5px 14px; border-radius: 8px; cursor: pointer; color: var(--ink); }
.seg label:has(input:checked) { background: var(--accent-soft); }
.seg input { accent-color: var(--accent); margin: 0; }

.hint { font-size: 13px; color: var(--muted); margin: 14px 0 0; }
.hint.flush { margin: 0; }
.error { color: var(--bad); background: var(--bad-soft); padding: 8px 12px; border-radius: 10px; font-size: 14px; margin: 10px 0 0; }

h3.sub { font-size: 14px; margin: 16px 0 0; }
h3.sub:first-child { margin-top: 8px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 14px; margin: 12px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: 13px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
