/* ==========================================================================
   발권창구 — fintech (Toss-inspired) redesign
   Light/dark theme via [data-theme] on <html>. Tokens mirror DESIGN.md.
   ========================================================================== */

:root,
:root[data-theme="light"] {
  --desk: #E9ECEF;
  --page: #F2F4F6;
  --card: #FFFFFF;
  --sheet: #FFFFFF;
  --fill: #F1F3F5;
  --border: #EBEEF1;
  --track: #E5E8EB;
  --ink: #191F28;
  --ink2: #4E5968;
  --ink3: #6B7684;
  --ink4: #98A0AB;
  --primary: #3182F6;
  --primary-dim: #1B64DA;
  --primary-weak: #E8F1FE;
  --primary-glow: rgba(49, 130, 246, .30);
  --danger: #F04452;
  --ok: #15C47E;
  --ember: #FF6B00;
  --ember-weak: rgba(255, 107, 0, .12);
  --shadow: 0 1px 2px rgba(0, 27, 55, .04), 0 6px 20px rgba(0, 27, 55, .06);
  --logbg: #111418;
  --logink: #E5E8EB;
  --scrim: rgba(10, 15, 25, .42);
  --kor-grad: linear-gradient(135deg, #3182F6, #69A7FF);
  --srt-grad: linear-gradient(135deg, #F04452, #FF7E88);
  --kor-shadow: rgba(49, 130, 246, .4);
  --srt-shadow: rgba(240, 68, 82, .4);
  --kor-tint: #3182F6;
  --srt-tint: #F04452;
  --chip-time-bg: #E8F1FE;
  --chip-time-ink: #1B64DA;
  --chip-pax-bg: #E4F7EF;
  --chip-pax-ink: #0E9E64;
}

:root[data-theme="dark"] {
  --desk: #0A0B0D;
  --page: #101215;
  --card: #1B1E24;
  --sheet: #22262E;
  --fill: #23272E;
  --border: rgba(255, 255, 255, .08);
  --track: #333A44;
  --ink: #F3F5F8;
  --ink2: #C4CBD4;
  --ink3: #9AA3AF;
  --ink4: #6C7480;
  --primary: #4A90F7;
  --primary-dim: #3182F6;
  --primary-weak: rgba(74, 144, 247, .16);
  --primary-glow: rgba(49, 130, 246, .34);
  --danger: #FF6B78;
  --ok: #2ED3A0;
  --ember: #FF8A3D;
  --ember-weak: rgba(255, 138, 61, .16);
  --shadow: 0 1px 2px rgba(0, 0, 0, .2), 0 8px 22px rgba(0, 0, 0, .30);
  --logbg: #0C0E11;
  --logink: #D6DBE2;
  --scrim: rgba(0, 0, 0, .55);
  --chip-time-bg: rgba(74, 144, 247, .18);
  --chip-time-ink: #7FB2FB;
  --chip-pax-bg: rgba(46, 211, 160, .16);
  --chip-pax-ink: #52D9AC;
}

:root {
  --f-body: 'Pretendard Variable', system-ui, -apple-system, sans-serif;
  --f-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Consolas, monospace;
}

/* ---------- reset ---------- */

*, *::before, *::after { box-sizing: border-box; -webkit-font-smoothing: antialiased; }
html, body {
  margin: 0; padding: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 16px;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
  transition: background .3s ease;
  /* Native-app feel: pan/scroll stays, double-tap zoom goes.  Pinch is
     handled by the viewport meta + the gesture* blockers in app.js. */
  touch-action: manipulation;
  /* Stop iOS from inflating text on rotate (breaks the fixed layout). */
  -webkit-text-size-adjust: 100%;
}
body {
  min-height: 100dvh;
  padding: max(env(safe-area-inset-top), 0px)
           max(env(safe-area-inset-right), 0px)
           0
           max(env(safe-area-inset-left), 0px);
}
button, input, select { font: inherit; color: inherit; }
button { border: 0; background: transparent; cursor: pointer; padding: 0; }
a { color: inherit; text-decoration: none; }
hr { border: 0; margin: 0; }
::selection { background: var(--primary-weak); color: var(--primary-dim); }

[hidden] { display: none !important; }
.mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

@keyframes pr { 0% { transform: scale(1); opacity: .55; } 100% { transform: scale(2.7); opacity: 0; } }
@keyframes fu { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes sheetup { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes refresh-spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

/* ==========================================================================
   App shell + scroll body + tab bar
   ========================================================================== */

.app-shell {
  position: relative;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
}
.scroll {
  padding: 8px 20px calc(108px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}
.scroll::-webkit-scrollbar { width: 0; height: 0; }

.tab-section { display: flex; flex-direction: column; gap: 16px; }
.tab-section[hidden] { display: none; }
/* The FAB floats over the scroll area and reaches 96+52 = 148px up from the
   bottom, but .scroll only pads 108px — so it landed on the last card's 삭제
   button and toggle. Only the watch tab shows a FAB, so only it pays the
   difference; padding the shared .scroll would leave the other tabs with a
   dead strip. */
#tab-watch { padding-bottom: 56px; }

/* ---------- header ---------- */

.header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 0;
}
.header__name {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -.02em;
  color: var(--ink);
}
.header__sub {
  display: block;
  margin-top: 3px;
  font-family: var(--f-mono);
  font-size: 12px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink4);
}
.header__refresh {
  width: 40px; height: 40px;
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow);
  color: var(--ink3);
  font-size: 19px; line-height: 1;
  transition: transform .1s ease, color .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.header__refresh:active { transform: scale(.94); }
.header__refresh:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
.header__refresh[data-state="loading"] {
  animation: refresh-spin .8s linear infinite;
  pointer-events: none;
  color: var(--primary);
}

/* ---------- pulse ---------- */

.pulse {
  position: relative;
  width: 14px; height: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.pulse::before {
  content: "";
  position: absolute;
  width: 10px; height: 10px;
  border-radius: 999px;
  border: 1.8px solid var(--ember);
  opacity: 0;
}
.pulse::after {
  content: "";
  width: 9px; height: 9px;
  border-radius: 999px;
  background: var(--track);
}
.pulse[data-state="active"]::before { animation: pr 1.8s ease-out infinite; }
.pulse[data-state="active"]::after { background: var(--ember); }

/* ==========================================================================
   Polling hero card
   ========================================================================== */

.hero {
  background: var(--card);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 22px;
  animation: fu .4s ease both;
}
.hero__top { display: flex; align-items: center; justify-content: space-between; }
.hero__status { display: inline-flex; align-items: center; gap: 9px; }
.hero__status-label { font-size: 13px; font-weight: 700; color: var(--ink2); }
.hero__interval {
  font-size: 12px;
  color: var(--ink4);
  letter-spacing: .02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 55%;
  text-align: right;
}
.hero__count { display: flex; align-items: baseline; gap: 10px; margin-top: 16px; }
.hero__count-num {
  font-size: 52px;
  font-weight: 700;
  letter-spacing: -.03em;
  color: var(--ink);
  line-height: 1;
}
.hero__count-suffix { font-size: 14px; font-weight: 600; color: var(--ink3); padding-bottom: 4px; }
.hero__actions { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
.hero__check {
  flex: 1;
  height: 46px;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  box-shadow: 0 6px 16px var(--primary-glow);
  transition: transform .1s ease, background .15s ease;
}
.hero__check:active { transform: scale(.98); }
.hero__check[data-state="running"] { background: var(--primary-dim); opacity: .85; }
.hero__check:disabled { cursor: default; }
.hero__last {
  height: 46px;
  padding: 0 16px;
  border-radius: 14px;
  background: var(--fill);
  display: flex; align-items: center;
  font-size: 12px;
  color: var(--ink3);
  white-space: nowrap;
}

/* ---------- section head ---------- */

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 4px 0;
}
.section-head__label { font-size: 13px; font-weight: 800; color: var(--ink); }
.section-head__count { font-size: 12px; color: var(--ink4); }

/* ==========================================================================
   Watch card (gradient stamp)
   ========================================================================== */

.watches { display: flex; flex-direction: column; gap: 16px; }

.watch {
  position: relative;
  background: var(--card);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 18px 18px 16px;
  overflow: hidden;
  animation: fu .4s ease both;
  transition: opacity .2s ease;
}
.watch[data-active="false"] { opacity: .55; }

.watch__head { display: flex; align-items: center; gap: 12px; }
.watch__stamp {
  width: 46px; height: 46px;
  border-radius: 14px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 15px; font-weight: 800; letter-spacing: -.01em;
}
.watch[data-provider="korail"] .watch__stamp { background: var(--kor-grad); box-shadow: 0 4px 10px var(--kor-shadow); }
.watch[data-provider="srt"]   .watch__stamp { background: var(--srt-grad); box-shadow: 0 4px 10px var(--srt-shadow); }
.watch__headmain { flex: 1; min-width: 0; }
.watch__tags { display: flex; align-items: center; gap: 7px; }
.watch__route {
  margin: 3px 0 0;
  display: flex; align-items: baseline; gap: 8px;
  font-size: 19px; font-weight: 800; letter-spacing: -.01em;
  color: var(--ink);
}
.watch__arrow { font-size: 15px; font-weight: 400; color: var(--ink4); }

.watch__date {
  margin: 14px 0 12px;
  font-size: 30px; font-weight: 700; letter-spacing: -.02em;
  color: var(--ink);
}

.watch__meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.watch__chip {
  font-size: 12px; font-weight: 600;
  padding: 5px 10px;
  border-radius: 9px;
  white-space: nowrap;
}
/* time — blue tint */
.watch__chip--time {
  font-weight: 700;
  color: var(--chip-time-ink);
  background: var(--chip-time-bg);
}
/* passengers — green tint */
.watch__chip--pax {
  font-weight: 600;
  color: var(--chip-pax-ink);
  background: var(--chip-pax-bg);
}
/* train types — neutral fill */
.watch__meta-types { display: contents; }
.watch__meta-types .badge {
  font-size: 12px; font-weight: 700;
  color: var(--ink2);
  background: var(--fill);
  padding: 5px 10px;
  border-radius: 9px;
  white-space: nowrap;
}

.watch__divider { height: 1px; background: var(--border); margin: 0 -18px 12px; }

.watch__foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.watch__last-check {
  font-size: 11px; color: var(--ink4);
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.watch__controls { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.watch__edit, .watch__delete {
  height: 32px; padding: 0 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--ink3);
  font-size: 12px; font-weight: 700;
  transition: color .15s ease, border-color .15s ease;
}
.watch__edit:active, .watch__delete:active { transform: scale(.97); }
.watch__delete { color: var(--ink4); }
.watch__delete:hover { color: var(--danger); border-color: var(--danger); }

/* ---------- badges ---------- */

.badge {
  font-size: 11px; font-weight: 800; letter-spacing: .04em;
  white-space: nowrap;
}
.badge--provider { text-transform: uppercase; }
.watch[data-provider="korail"] .badge--provider { color: var(--kor-tint); }
.watch[data-provider="srt"]   .badge--provider { color: var(--srt-tint); }
.badge--auto-reserve {
  font-size: 10px; font-weight: 800; letter-spacing: .03em;
  color: var(--ember);
  background: var(--ember-weak);
  padding: 2px 7px;
  border-radius: 6px;
}
/* fired + self-disabled — muted, no longer "armed" */
.badge--auto-reserve[data-done] {
  color: var(--ink4);
  background: var(--fill);
}

/* ---------- empty ---------- */

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 20px;
  padding: 56px 0;
  min-height: 40dvh;
}
.empty__rail { display: none; }
.empty__text { font-size: 15px; color: var(--ink3); margin: 0; text-align: center; }

/* ==========================================================================
   Cards (stats / settings)
   ========================================================================== */

.card {
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 20px 18px;
  animation: fu .4s ease both;
}
.card--rows { padding: 6px 18px; }
.card--chart { padding: 20px 18px 16px; }
.card--runs { padding: 8px 18px; }
.card__title { font-size: 14px; font-weight: 800; color: var(--ink); }
.card__tag { font-size: 11px; font-weight: 600; color: var(--ink4); }
.card__desc { font-size: 12px; line-height: 1.5; color: var(--ink3); margin: 5px 0 14px; }
.card__label {
  font-size: 12px; font-weight: 800; letter-spacing: .03em;
  text-transform: uppercase; color: var(--ink4);
  margin-bottom: 16px;
}

/* ---------- stats ---------- */

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat {
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px 16px;
  animation: fu .4s ease both;
}
.stat__num {
  font-family: var(--f-mono);
  font-size: 32px; font-weight: 700; letter-spacing: -.02em;
  color: var(--ink);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stat--primary .stat__num { color: var(--primary); }
.stat--ok .stat__num { color: var(--ok); }
.stat__label {
  font-size: 11px; font-weight: 800; letter-spacing: .03em;
  text-transform: uppercase; color: var(--ink4);
  margin-top: 9px;
}
.stat__sub { font-size: 11px; font-family: var(--f-mono); color: var(--ink3); margin-top: 4px; min-height: 14px; }

/* ---------- chart ---------- */

.stats-chart {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px;
  align-items: end; height: 110px;
}
.stats-bar { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 8px; }
.stats-bar__fill {
  width: 100%; max-width: 26px;
  height: var(--h, 4%); min-height: 3px;
  background: var(--ink4);
  border-radius: 6px 6px 3px 3px;
}
.stats-bar__fill[data-hit="1"] { background: var(--ok); }
.stats-bar[data-today="1"] .stats-bar__fill { background: var(--primary); }
.stats-bar__label { font-size: 10px; font-family: var(--f-mono); font-weight: 500; color: var(--ink4); }
.stats-bar[data-today="1"] .stats-bar__label { font-weight: 700; color: var(--ink); }

/* ---------- runs ---------- */

.run-list { list-style: none; padding: 0; margin: 0; }
.run-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 0;
  border-top: 1px solid var(--border);
  cursor: pointer;
}
.run-row:first-child { border-top: 0; }
.run-row__status { width: 9px; height: 9px; border-radius: 999px; background: var(--ink4); flex-shrink: 0; }
.run-row__status[data-conclusion="success"] { background: var(--ok); }
.run-row__status[data-conclusion="failure"] { background: var(--danger); }
.run-row__status[data-conclusion="cancelled"], .run-row__status[data-conclusion="skipped"] { background: var(--ink4); }
.run-row__status[data-conclusion="in_progress"], .run-row__status[data-conclusion=""] {
  background: var(--ember);
}
.run-row__body { flex: 1; min-width: 0; }
.run-row__time { font-family: var(--f-mono); font-size: 13px; font-weight: 600; color: var(--ink); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.run-row__meta { font-family: var(--f-mono); font-size: 11px; color: var(--ink4); margin: 2px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.run-row__link { color: var(--ink4); font-size: 15px; flex-shrink: 0; padding: 4px; }
.run-row__link:hover { color: var(--ink); }
.run-list--empty { font-size: 12px; color: var(--ink4); font-family: var(--f-mono); padding: 14px 0; }

/* ==========================================================================
   Settings — segmented control, poll inputs, toggle rows
   ========================================================================== */

.seg-track {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  padding: 4px;
  background: var(--fill);
  border-radius: 14px;
}
.seg-opt {
  display: flex; align-items: center; justify-content: center;
  padding: 10px 6px;
  border-radius: 11px;
  font-size: 13px; font-weight: 600;
  color: var(--ink3);
  background: transparent;
  transition: background .15s ease, color .15s ease;
}
.seg-opt[aria-selected="true"] {
  background: var(--card);
  color: var(--ink);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .14);
}

.pm-input { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.pm-input--two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: stretch; }
.pm-input__col { display: flex; flex-direction: column; gap: 6px; }
.pm-input__label {
  font-size: 11px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink4);
  flex-shrink: 0;
}
.pm-input--two .pm-input__label { margin-bottom: 0; }
.pm-input__box {
  flex: 1;
  width: 100%;
  min-width: 0;
  height: 44px;
  border-radius: 12px;
  background: var(--fill);
  border: 1px solid transparent;
  padding: 0 14px;
  font-family: var(--f-mono);
  font-size: 15px; font-weight: 600;
  color: var(--ink);
  outline: none;
  transition: border-color .15s ease;
}
.pm-input__box::placeholder { color: var(--ink4); opacity: .7; }
.pm-input__box:focus { border-color: var(--primary); }
/* iOS renders a time input as "오전 09:00" and gives its shadow DOM an
   intrinsic width that ignores width:100%, so two side by side overflowed the
   card on a 16 Pro Max. Drop the native chrome, let the inner value shrink,
   and tighten the padding. */
.pm-input__box[type="time"] {
  color-scheme: light;
  -webkit-appearance: none;
  appearance: none;
  padding: 0 10px;
  font-size: 14px;
}
.pm-input__box[type="time"]::-webkit-date-and-time-value {
  min-width: 0;
  margin: 0;
  text-align: left;
}
:root[data-theme="dark"] .pm-input__box[type="time"] { color-scheme: dark; }

.toggle-row {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
.toggle-row:last-child { border-bottom: 0; }
.toggle-row__main { flex: 1; min-width: 0; }
.toggle-row__title { font-size: 14px; font-weight: 700; color: var(--ink); }
.toggle-row__desc { font-size: 12px; line-height: 1.45; color: var(--ink3); margin-top: 3px; }

/* ---------- system health ---------- */

.card__title { display: flex; align-items: center; gap: 8px; }
.health__refresh {
  margin-left: auto;
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px;
  background: var(--fill);
  color: var(--ink3);
  font-size: 14px; line-height: 1;
  transition: transform .1s ease, color .15s ease;
}
.health__refresh:active { transform: scale(.92); }
.health__refresh[data-state="loading"] { animation: refresh-spin .8s linear infinite; pointer-events: none; color: var(--primary); }

.health { list-style: none; margin: 0; padding: 0; }
.health__row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 0;
  border-top: 1px solid var(--border);
}
.health__row:first-child { border-top: 0; }
.health__dot {
  width: 9px; height: 9px; border-radius: 999px;
  background: var(--ink4);
  flex-shrink: 0;
}
.health__dot[data-level="ok"]   { background: var(--ok); }
.health__dot[data-level="warn"] { background: var(--ember); }
.health__dot[data-level="bad"]  { background: var(--danger); }
.health__name { font-size: 13px; font-weight: 700; color: var(--ink); flex-shrink: 0; }
.health__detail {
  font-family: var(--f-mono);
  font-size: 11px; color: var(--ink3);
  margin-left: auto; text-align: right;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.health__fails { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.health__fails-label {
  font-size: 11px; font-weight: 800; letter-spacing: .03em;
  text-transform: uppercase; color: var(--ink4);
  margin-bottom: 8px;
}
.health__fails-list { list-style: none; margin: 0; padding: 0; }
.health__fail {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 0;
  font-family: var(--f-mono); font-size: 11px;
  color: var(--ink3);
  cursor: pointer;
}
.health__fail-time { color: var(--ink); font-weight: 600; }
.health__fail-why { margin-left: auto; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- toggle ---------- */

.toggle { display: inline-flex; align-items: center; cursor: pointer; flex-shrink: 0; }
.toggle__input { position: absolute; opacity: 0; pointer-events: none; }
.toggle__track {
  position: relative;
  width: 46px; height: 28px;
  background: var(--track);
  border-radius: 999px;
  transition: background .2s ease;
}
.toggle__thumb {
  position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px;
  background: #fff;
  border-radius: 999px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .22);
  transition: transform .2s ease;
}
.toggle__input:checked + .toggle__track { background: var(--primary); }
.toggle__input:checked + .toggle__track .toggle__thumb { transform: translateX(18px); }
.toggle__input:focus-visible + .toggle__track { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ==========================================================================
   FAB + tab bar
   ========================================================================== */

.fab {
  position: fixed;
  left: 50%;
  transform: translateX(calc(240px - 100% - 20px));
  bottom: calc(96px + env(safe-area-inset-bottom));
  display: inline-flex; align-items: center; gap: 7px;
  height: 52px;
  padding: 0 22px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 15px; font-weight: 800;
  box-shadow: 0 10px 24px var(--primary-glow);
  z-index: 15;
  transition: transform .12s ease, background .15s ease;
}
.fab:active { transform: translateX(calc(240px - 100% - 20px)) scale(.97); }
.fab[hidden] { display: none; }
.fab__plus { font-size: 20px; font-weight: 400; line-height: 1; }
@media (max-width: 480px) {
  .fab { left: auto; right: 20px; transform: none; }
  .fab:active { transform: scale(.97); }
}

.tabbar {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: 0;
  width: 100%; max-width: 480px;
  height: calc(84px + env(safe-area-inset-bottom));
  padding: 8px 12px calc(22px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 16;
}
.tabbar__item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  color: var(--ink4);
  transition: color .15s ease;
}
.tabbar__item[aria-current="page"] { color: var(--primary); }
.tabbar__label { font-size: 10px; font-weight: 800; letter-spacing: .02em; }

/* ==========================================================================
   Bottom sheets (add-watch / log)
   ========================================================================== */

.sheet {
  border: 0; padding: 0; margin: 0;
  background: transparent;
  width: 100%; max-width: 100%;
  max-height: 100dvh;
}
.sheet[open] {
  display: flex; align-items: flex-end; justify-content: center;
  inset: 0;
  width: 100vw; height: 100dvh;
  max-width: none; max-height: none;
}
.sheet::backdrop { background: var(--scrim); backdrop-filter: blur(2px); }
.sheet__form {
  position: relative;
  background: var(--sheet);
  border-radius: 28px 28px 0 0;
  padding: 14px 20px calc(30px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex; flex-direction: column; gap: 16px;
  animation: sheetup .28s cubic-bezier(.2, .7, .2, 1);
}
.sheet__form::before {
  content: "";
  width: 40px; height: 5px;
  border-radius: 999px;
  background: var(--track);
  margin: 2px auto 2px;
}
.sheet__form--logs { max-height: 82dvh; }

.sheet__header {
  display: flex; align-items: center; justify-content: space-between;
  margin: 0;
}
.sheet__title { margin: 0; font-size: 20px; font-weight: 800; color: var(--ink); }
.sheet__filler { display: none; }
.icon-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px;
  background: var(--fill);
  color: var(--ink3);
  font-size: 18px;
}
.icon-btn:hover { color: var(--ink); }
.sheet__form--logs .sheet__header { order: -1; }

/* log modal */
.log-meta { margin: 0; font-size: 11px; font-family: var(--f-mono); letter-spacing: .03em; text-transform: uppercase; color: var(--ink4); }
.log-content {
  margin: 0;
  font-family: var(--f-mono);
  font-size: 11px; line-height: 1.75;
  color: var(--logink);
  background: var(--logbg);
  border-radius: 14px;
  padding: 16px;
  overflow: auto;
  white-space: pre-wrap;
  flex: 1;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

/* ==========================================================================
   Form controls inside add-watch sheet
   ========================================================================== */

.field { display: flex; flex-direction: column; gap: 6px; }
.field__label {
  font-size: 11px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink4);
}
.field__input {
  width: 100%; min-width: 0;
  height: 48px;
  padding: 0 14px;
  background: var(--fill);
  color: var(--ink);
  border: 1px solid transparent;
  border-radius: 14px;
  font-size: 15px; font-weight: 600;
  outline: none;
  transition: border-color .15s ease;
}
.field__input::placeholder { color: var(--ink4); opacity: .7; }
.field__input:focus { border-color: var(--primary); }
.field__input--mono { font-family: var(--f-mono); }
.field__input[type="date"], .field__input[type="time"] {
  color-scheme: light;
  -webkit-appearance: none;
  appearance: none;
}
/* Same iOS intrinsic-width problem as the settings time inputs — the sheet's
   "최저 시간 / 최대 시간" pair sat side by side and overlapped. */
.field__input[type="time"] { padding: 0 10px; font-size: 14px; }
.field__input[type="date"]::-webkit-date-and-time-value,
.field__input[type="time"]::-webkit-date-and-time-value {
  min-width: 0;
  margin: 0;
  text-align: left;
}
:root[data-theme="dark"] .field__input[type="date"],
:root[data-theme="dark"] .field__input[type="time"] { color-scheme: dark; }
.field__input--select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%2398A0AB' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><polyline points='1,1.5 6,6.5 11,1.5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px 8px;
  padding-right: 38px;
  cursor: pointer;
}
.field__input--select option { background: var(--sheet); color: var(--ink); }
.field__input--select:invalid { color: var(--ink4); }

.row { display: grid; gap: 12px; }
.row--2 { grid-template-columns: 1fr 1fr; }
.row--3 { grid-template-columns: 1fr 1fr 1fr; }
.row > * { min-width: 0; }
/* Last resort: if a native control still refuses to shrink, stack instead of
   letting it push out of the card. */
@media (max-width: 380px) {
  .row--2, .pm-input--two { grid-template-columns: 1fr; }
}

/* provider / seat segmented (radio-based) */
.seg {
  border: 0; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 8px;
}
.seg > legend { padding: 0; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink4); }
.seg__track {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  padding: 4px;
  background: var(--fill);
  border-radius: 14px;
}
.seg__opt {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 10px 8px;
  border-radius: 11px;
  font-size: 13px; font-weight: 600;
  color: var(--ink3);
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.seg__opt input { position: absolute; opacity: 0; pointer-events: none; }
.seg__opt:has(input:checked) {
  background: var(--card);
  color: var(--ink);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .14);
}
.seg__opt:has(input[value="korail"]:checked) { background: var(--kor-grad); color: #fff; box-shadow: 0 2px 6px var(--kor-shadow); }
.seg__opt:has(input[value="srt"]:checked) { background: var(--srt-grad); color: #fff; box-shadow: 0 2px 6px var(--srt-shadow); }
.seg__opt:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }

/* train-type chips */
.check-group {
  border: 0; margin: 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: 8px;
}
.check-group legend {
  width: 100%;
  padding: 0; margin-bottom: 2px;
  font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink4);
}
.check-chip {
  display: inline-flex; align-items: center;
  padding: 9px 15px;
  border-radius: 999px;
  background: var(--fill);
  font-size: 13px; font-weight: 600;
  color: var(--ink3);
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.check-chip input { position: absolute; opacity: 0; pointer-events: none; }
.check-chip:has(input:checked) { background: var(--primary); color: #fff; font-weight: 700; }
.check-chip:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }

/* auto-reserve box inside sheet */
.setting-row--inline {
  display: flex; align-items: center; gap: 14px;
  background: var(--fill);
  border-radius: 14px;
  padding: 14px 16px;
}
.setting-row__main { flex: 1; min-width: 0; }
.setting-row__title { font-size: 14px; font-weight: 700; color: var(--ink); }
.setting-row__hint { font-size: 12px; line-height: 1.45; color: var(--ink3); margin-top: 3px; }

.sheet__error, .setup__error {
  margin: 0;
  font-size: 12px; font-family: var(--f-mono);
  color: var(--danger);
}
.sheet__actions { display: flex; gap: 12px; }
.sheet__actions .btn { flex: 1; }
.sheet__actions .btn--ghost { flex: 0 0 auto; padding: 0 20px; }

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 52px;
  padding: 0 24px;
  border-radius: 16px;
  font-size: 16px; font-weight: 800;
  transition: transform .1s ease, background .15s ease;
}
.btn:active { transform: scale(.98); }
.btn--primary { background: var(--primary); color: #fff; box-shadow: 0 8px 20px var(--primary-glow); }
.btn--primary:hover { background: var(--primary-dim); }
.btn--ghost { background: var(--fill); color: var(--ink2); }
.btn--ghost:hover { background: var(--track); }
.btn--sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }

/* Shortcut setup block: description above, copy buttons below. */
.toggle-row--stack { flex-direction: column; align-items: stretch; gap: 10px; }
.copy-row { display: flex; flex-wrap: wrap; gap: 8px; }
.copy-row .btn { flex: 1 1 auto; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  z-index: 40;
  max-width: min(440px, calc(100vw - 32px));
  padding: 13px 16px;
  border-radius: 14px;
  background: rgba(25, 31, 40, .94);
  color: #fff;
  font-size: 13.5px; line-height: 1.5;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .28);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.toast[data-show="1"] { opacity: 1; transform: translate(-50%, 0); }

/* ---------- station picker ---------- */
/* A button that looks like the other fields but opens a searchable sheet —
   scanning an 80-option dropdown on a phone was the slowest step in adding a
   watch. */
.field__input--picker {
  display: flex; align-items: center;
  text-align: left;
  font-weight: 700;
  cursor: pointer;
}
.field__input--picker[data-empty="1"] { color: var(--ink4); font-weight: 600; }
.station-swap {
  align-self: flex-start;
  margin-top: -4px;
  color: var(--ink3);
}
.sheet__form--station { max-height: 88dvh; }
.station-list {
  flex: 1; min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column;
  margin: 0 -4px;
}
.station-group {
  position: sticky; top: 0;
  background: var(--sheet);
  padding: 12px 4px 6px;
  font-size: 11px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink4);
}
.station-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%;
  padding: 13px 12px;
  border-radius: 12px;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.station-row:active { background: var(--fill); }
.station-row__name { font-size: 15px; font-weight: 600; color: var(--ink); }
.station-row__sub { font-size: 12px; color: var(--ink4); flex-shrink: 0; }
.station-row[data-kind="route"] .station-row__name { color: var(--primary); }
.station-empty { padding: 20px 12px; font-size: 13px; color: var(--ink4); text-align: center; }

/* Manual-override banner under the 집에 있음 toggle. */
.mode-note {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-top: -2px; padding: 10px 12px;
  border-radius: 12px;
  background: var(--ember-weak);
}
.mode-note__text { flex: 1 1 180px; font-size: 12.5px; line-height: 1.5; color: var(--ink2); }
.mode-note[hidden] { display: none !important; }

/* ---------- collapsible how-to ---------- */
.guide { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.guide:first-of-type { border-top: 0; }
.guide__summary {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  font-size: 14px; font-weight: 700; color: var(--ink);
  cursor: pointer; list-style: none;
  padding: 6px 0;
  -webkit-tap-highlight-color: transparent;
}
.guide__summary::-webkit-details-marker { display: none; }
.guide__chev { color: var(--ink4); transition: transform .15s ease; }
.guide[open] .guide__chev { transform: rotate(90deg); }
.guide__steps {
  margin: 6px 0 0;
  padding-left: 20px;
  display: flex; flex-direction: column; gap: 10px;
  font-size: 13px; line-height: 1.65; color: var(--ink2);
}
.guide__steps code {
  font-family: var(--f-mono); font-size: 12px;
  background: var(--fill); border-radius: 6px; padding: 2px 6px;
  overflow-wrap: anywhere;
}
.guide__note {
  margin: 10px 0 0;
  font-size: 12.5px; line-height: 1.6; color: var(--ink3);
}
.guide .copy-row { margin-top: 12px; }

/* ==========================================================================
   Setup screen (first run)
   ========================================================================== */

.setup {
  min-height: 100dvh;
  display: flex; flex-direction: column; justify-content: center;
  padding: 74px 24px 40px;
  max-width: 480px; margin: 0 auto;
}
.setup__card { display: flex; flex-direction: column; }
.setup__card::before {
  content: "";
  width: 64px; height: 64px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--primary), #69A7FF);
  box-shadow: 0 10px 24px var(--primary-glow);
  margin-bottom: 24px;
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='30' height='30' viewBox='0 0 24 24' fill='none'><path d='M6 12h12M13 7l5 5-5 5' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/></svg>"),
    linear-gradient(135deg, var(--primary), #69A7FF);
  background-repeat: no-repeat;
  background-position: center;
}
.setup__eyebrow {
  margin: 0 0 8px;
  font-family: var(--f-mono);
  font-size: 11px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink4);
}
.setup__title { margin: 0; font-size: 30px; font-weight: 800; letter-spacing: -.02em; color: var(--ink); }
.setup__lede { margin: 12px 0 24px; font-size: 14px; line-height: 1.6; color: var(--ink3); }
.setup__lede code, .setup__steps code {
  font-family: var(--f-mono); font-size: 13px;
  background: var(--fill); padding: 1px 6px; border-radius: 6px;
}
.setup__steps {
  margin: 0 0 24px; padding-left: 20px;
  font-size: 13px; line-height: 1.5; color: var(--ink3);
  display: flex; flex-direction: column; gap: 6px;
}
.setup__steps strong { color: var(--ink); }
.setup__steps a { color: var(--primary); text-decoration: underline; text-underline-offset: 3px; }
.setup__form { display: flex; flex-direction: column; gap: 14px; }
.setup__form .btn { margin-top: 6px; }

/* ==========================================================================
   Reduced motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
