:root {
  color-scheme: light dark;
  --bg: #f2efea; --paper: #fbfaf7; --raised: #ffffff; --ink: #1c1b19; --muted: #6d685f; --soft: #e9e4dc; --line: #e1dcd3; --line-strong: #cfc8bd;
  --accent: #1c1b19; --on-accent: #f3f0ea; --caution: #b4372e; --caution-soft: #f6e4e1; --ok: #2f6b45; --ok-soft: #e3efe6; --focus: #1c1b19;
  --serif: Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --radius: 10px; --radius-lg: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121110; --paper: #1a1918; --raised: #1e1d1b; --ink: #f3f0ea; --muted: #9c978e; --soft: #262420; --line: #2e2c29; --line-strong: #45413b;
    --accent: #f3f0ea; --on-accent: #121110; --caution: #ff7b70; --caution-soft: #3a1f1c; --ok: #7fc797; --ok-soft: #1c2c21; --focus: #f3f0ea;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans); font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 400; line-height: 1.2; text-wrap: balance; }
h1 { font-family: var(--serif); font-size: 30px; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 13px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0; }
a { color: inherit; text-underline-offset: 3px; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.caution { color: var(--caution); }

/* Layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--bg); }
.brand { font-family: var(--serif); font-size: 24px; padding: 2px 10px 18px; display: flex; align-items: baseline; gap: 8px; }
.brand small { font-family: var(--sans); font-size: 12px; color: var(--muted); }
.nav-group { margin: 10px 0 4px; padding: 0 10px; font-size: 11px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; border-radius: 8px; text-decoration: none; color: var(--ink); min-height: 34px; }
.nav a:hover { background: var(--soft); }
.nav a[aria-current="page"] { background: var(--paper); box-shadow: inset 0 0 0 1px var(--line); font-weight: 600; }
.nav .count { font-size: 12px; color: var(--muted); }
.who { margin-top: 18px; padding: 12px 10px; border-top: 1px solid var(--line); font-size: 13px; }
.who button { margin-top: 8px; }
main { padding: 28px 36px 64px; max-width: 1240px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin-top: 4px; }
.topbar { display: none; }

/* Controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 7px 14px; border-radius: var(--radius); border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent); font-weight: 600; cursor: pointer; transition: opacity .15s, background-color .15s; white-space: nowrap; }
.btn:hover { opacity: .88; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: var(--paper); color: var(--ink); border-color: var(--line-strong); }
.btn.secondary:hover { background: var(--soft); opacity: 1; }
.btn.ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn.ghost:hover { color: var(--ink); background: var(--soft); }
.btn.danger { background: transparent; color: var(--caution); border-color: var(--line-strong); }
.btn.small { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; align-content: start; }
label .hint { font-weight: 400; color: var(--muted); }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--raised); min-height: 38px; font-size: 15px; font-weight: 400; }
textarea { min-height: 84px; resize: vertical; }
input[type="checkbox"] { width: 18px; height: 18px; min-height: 18px; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.form { display: grid; gap: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar select, .toolbar input { width: auto; min-width: 180px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 9px; padding: 2px; background: var(--paper); }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 13px; min-height: 30px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

/* Surfaces */
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-body { padding: 16px 18px; }
.stack { display: grid; gap: 16px; }
.split { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, 1fr); gap: 16px; align-items: start; }
.kv { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: break-word; min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 14px 16px; text-decoration: none; color: inherit; display: block; }
a.stat:hover { border-color: var(--line-strong); }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 24px; margin-top: 4px; letter-spacing: -0.01em; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 9px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--soft); }
td.num, th.num { text-align: right; white-space: nowrap; }
.route { font-family: var(--serif); font-size: 17px; white-space: nowrap; }
.empty { padding: 40px 18px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-weight: 600; margin-bottom: 4px; }

/* Status */
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line-strong); white-space: nowrap; }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.chip.active::before { background: var(--ink); }
.chip.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); background: var(--ok-soft); }
.chip.ok::before { background: var(--ok); }
.chip.warn { color: var(--caution); border-color: color-mix(in srgb, var(--caution) 35%, transparent); background: var(--caution-soft); }
.chip.warn::before { background: var(--caution); }
.notice { padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--line-strong); background: var(--soft); font-size: 14px; }
.notice.warn { border-color: color-mix(in srgb, var(--caution) 40%, transparent); background: var(--caution-soft); color: var(--caution); }
.countdown { font-variant-numeric: tabular-nums; font-weight: 650; }

/* Booking detail */
.hero { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 16px; }
.hero .route-big { font-family: var(--serif); font-size: 34px; letter-spacing: -0.01em; }
.hero .meta { display: flex; gap: 6px 14px; align-items: center; flex-wrap: wrap; margin-top: 6px; color: var(--muted); font-size: 14px; }
.segment { display: grid; grid-template-columns: 76px 1fr auto; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.segment:last-child { border-bottom: 0; }
.segment .time { font-weight: 650; }
.layover { font-size: 12px; color: var(--muted); padding: 6px 0 6px 88px; border-bottom: 1px dashed var(--line); }
.timeline { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.timeline li { display: grid; grid-template-columns: 112px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { color: var(--muted); font-size: 12px; padding-top: 2px; }
.money-line { display: flex; justify-content: space-between; padding: 4px 0; font-size: 14px; }
.money-line.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; font-weight: 650; font-size: 16px; }
details.drawer { border-top: 1px solid var(--line); }
details.drawer > summary { cursor: pointer; padding: 12px 18px; font-weight: 600; list-style: none; display: flex; justify-content: space-between; }
details.drawer > summary::after { content: "+"; color: var(--muted); }
details.drawer[open] > summary::after { content: "–"; }
details.drawer > .panel-body { padding-top: 0; }
.chat { display: grid; gap: 10px; max-height: 480px; overflow-y: auto; padding: 4px; }
.bubble { max-width: 78%; padding: 9px 12px; border-radius: 12px; background: var(--soft); font-size: 14px; white-space: pre-wrap; }
.bubble.staff { justify-self: end; background: var(--accent); color: var(--on-accent); }
.bubble .by { font-size: 11px; opacity: .7; margin-bottom: 2px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .card { width: 100%; max-width: 380px; }
.login h1 { margin-bottom: 6px; }
.login form { margin-top: 22px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--accent); color: var(--on-accent); padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px); z-index: 10; }
#toast.show { opacity: 1; }
#toast.error { background: var(--caution); color: #fff; }
.skeleton { height: 14px; border-radius: 6px; background: var(--soft); margin: 10px 0; }

@media (max-width: 1180px) {
  .split { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 5; transform: translateX(-102%); transition: transform .2s ease; box-shadow: 0 0 0 100vmax rgba(0,0,0,0); }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 4; }
  .topbar .brand { padding: 0; font-size: 20px; }
  main { padding: 18px 16px 48px; }
  h1 { font-size: 26px; }
  .hero .route-big { font-size: 28px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .segment { grid-template-columns: 64px 1fr; }
  .segment > :last-child { grid-column: 2; }
  .layover { padding-left: 76px; }
  .timeline li { grid-template-columns: 1fr; gap: 0; }
  .toolbar select, .toolbar input { min-width: 0; flex: 1; }
  table.responsive thead { display: none; }
  table.responsive tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  table.responsive td { padding: 0; border: 0; }
  table.responsive td.num { text-align: right; }
  .btn { min-height: 44px; }
  .nav a { min-height: 44px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

fieldset.segment { border: 1px solid var(--line, #2b2825); border-radius: 12px; padding: 12px 14px 14px; margin: 10px 0; }
fieldset.segment legend { padding: 0 6px; color: var(--muted, #a09a8f); }

.side-search { padding: 0 14px 10px; }
.side-search input { width: 100%; }
fieldset.segment { display: block; min-width: 0; }
fieldset.segment .grid3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
fieldset.segment input { width: 100%; min-width: 0; }
@media (max-width: 760px) { fieldset.segment .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
