:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #eceef2;
  --line: #d9dde3;
  --ink: #161a1f;
  --ink-2: #4a525c;
  --ink-3: #7a838e;
  --accent: #c98a00;          /* 차선 노랑 */
  --accent-ink: #1b1400;
  --accent-soft: #fff2cc;
  --rec: #d6312b;             /* 로깅 중 */
  --ok: #1f8a4c;
  --warn: #b86e00;
  --bad: #c62f2f;
  --b1: #138f86;              /* 속도대 저 · 중 · 고 */
  --b2: #d08a00;
  --b3: #b2357d;
  --idle: #8a939e;
  --shadow: 0 1px 2px rgba(20, 26, 33, .08), 0 4px 16px rgba(20, 26, 33, .06);
  --r: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1317;
    --panel: #171c22;
    --panel-2: #20262e;
    --line: #2c343e;
    --ink: #e8ebef;
    --ink-2: #b2bac4;
    --ink-3: #7f8994;
    --accent: #f2b705;
    --accent-ink: #1b1400;
    --accent-soft: #3a2f0a;
    --rec: #ff4d43;
    --ok: #3fbf74;
    --warn: #f0a020;
    --bad: #ff5c5c;
    --b1: #2cc2b6;
    --b2: #f2b705;
    --b3: #e05aa8;
    --idle: #6b7580;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1317;
  --panel: #171c22;
  --panel-2: #20262e;
  --line: #2c343e;
  --ink: #e8ebef;
  --ink-2: #b2bac4;
  --ink-3: #7f8994;
  --accent: #f2b705;
  --accent-ink: #1b1400;
  --accent-soft: #3a2f0a;
  --rec: #ff4d43;
  --ok: #3fbf74;
  --warn: #f0a020;
  --bad: #ff5c5c;
  --b1: #2cc2b6;
  --b2: #f2b705;
  --b3: #e05aa8;
  --idle: #6b7580;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 "Pretendard Variable", Pretendard, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.num, td.n, .tab { font-variant-numeric: tabular-nums; }
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
h2 { font-size: 17px; font-weight: 700; }
h3 { font-size: 14px; font-weight: 700; color: var(--ink-2); }

/* 상단 */
header.top {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px; height: 52px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: -.01em; white-space: nowrap; }
.brand .mark {
  width: 22px; height: 22px; border-radius: 6px; background: var(--ink);
  display: grid; place-items: center;
}
.brand .mark i { display: block; width: 3px; height: 14px; background: repeating-linear-gradient(var(--accent) 0 4px, transparent 4px 7px); }
nav.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs a {
  padding: 7px 11px; border-radius: 8px; text-decoration: none; color: var(--ink-2);
  white-space: nowrap; font-weight: 600; font-size: 14px;
}
nav.tabs a.on { background: var(--panel-2); color: var(--ink); }
nav.tabs a.rec { color: var(--rec); }
.who { font-size: 13px; color: var(--ink-3); white-space: nowrap; }
.who button { margin-left: 6px; }

@media (max-width: 560px) {
  header.top { gap: 8px; padding: 0 10px; }
  .brand .label, .who a { display: none; }
}
main { padding: 16px; max-width: 1200px; margin: 0 auto; display: grid; gap: 16px; }
main.full { max-width: none; padding: 0; gap: 0; }
.page { display: contents; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.card > h2 + * { margin-top: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: grid; gap: 10px; }
.grid2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.muted { color: var(--ink-3); font-size: 13px; }
.small { font-size: 13px; }
.sp { flex: 1; }

/* 입력 */
input[type=text], input[type=password], input[type=number], input[type=date], input:not([type]), select, textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  min-height: 40px; width: 100%;
}
textarea { min-height: 70px; resize: vertical; }
label.f { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); font-weight: 600; }
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink);
  border-radius: 8px; padding: 8px 14px; min-height: 40px; font-weight: 650; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.04); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.pri { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.rec { background: var(--rec); border-color: var(--rec); color: #fff; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, var(--line)); background: transparent; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 12px; min-height: 36px;
  font-weight: 600; cursor: pointer; color: var(--ink-2);
}
.seg button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chips button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--panel-2); color: var(--ink-2); white-space: nowrap; }
.pill.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.pill.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pill.bad { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.pill.rec { background: var(--rec); color: #fff; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

/* 표 */
.tw { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; word-break: keep-all; }
table.nowrap td { white-space: nowrap; }
th { font-size: 12px; color: var(--ink-3); font-weight: 700; white-space: nowrap; }
td.n, th.n { text-align: right; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--panel-2); }
.bar { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; min-width: 80px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar.over > i { background: var(--bad); }

/* 지도 */
.map { height: 420px; border-radius: var(--r); overflow: hidden; border: 1px solid var(--line); background: var(--panel-2); isolation: isolate; }
.split { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.4fr) minmax(300px, 1fr); align-items: start; }
@media (max-width: 860px) { .split { grid-template-columns: 1fr; } }
.pin-wrap { background: none; border: 0; }
.pin-wrap .pin { transform: translate(-50%, -50%); }
.pin { position: relative; transform: translate(0, 0); }
.pin::before {
  content: ""; display: block; width: 14px; height: 14px; border-radius: 50%;
  background: var(--pin); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}
.pin > span {
  position: absolute; left: 12px; top: -4px; white-space: nowrap; font-size: 12px; font-weight: 700;
  background: rgba(17, 22, 28, .82); color: #fff; padding: 1px 6px; border-radius: 6px; pointer-events: none;
}
.pin.me::before { width: 18px; height: 18px; background: #2f7cf6; border-width: 3px; box-shadow: 0 0 0 6px rgba(47, 124, 246, .25); }
.pin.wp::before { width: 12px; height: 12px; border-radius: 3px; }
.pin.ev::before { width: 10px; height: 10px; }

/* 주행 기록 화면 */
.drive { display: grid; grid-template-rows: auto minmax(220px, 42vh) auto; min-height: calc(100dvh - 52px); }
.drive .map { height: auto; border-radius: 0; border-left: 0; border-right: 0; }
.dstat {
  position: sticky; top: 52px; z-index: 30;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line);
  border-bottom: 1px solid var(--line);
}
.dstat > div { background: var(--panel); padding: 8px 10px; min-width: 0; }
.dstat b { display: block; font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dstat small { font-size: 11px; color: var(--ink-3); font-weight: 700; letter-spacing: .02em; }
.dpanel { padding: 12px 16px 28px; display: grid; gap: 14px; max-width: 900px; width: 100%; margin: 0 auto; }
.logbtn { width: 100%; min-height: 64px; font-size: 20px; border-radius: 14px; }
.logbtn.rec { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--rec) 25%, transparent); } }
@media (prefers-reduced-motion: reduce) { .logbtn.rec { animation: none; } }
.marks { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.marks .btn { min-height: 48px; }
.sect { display: grid; gap: 8px; }
.sect > h3 { display: flex; align-items: center; gap: 8px; }
.recbadge { display: inline-flex; align-items: center; gap: 6px; color: var(--rec); font-weight: 800; }
.recbadge .dot { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .2; } }
@media (prefers-reduced-motion: reduce) { .recbadge .dot { animation: none; } }

/* 로그인 */
.login { max-width: 360px; margin: 12vh auto; }
.login .brand { font-size: 20px; margin-bottom: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 1000;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 650;
  box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}
.toast.err { background: var(--bad); color: #fff; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); padding: 16px; width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }

.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }

.list { display: grid; gap: 0; }
.li { padding: 10px 2px; border-bottom: 1px solid var(--line); display: grid; gap: 3px; cursor: pointer; }
.li:hover { background: var(--panel-2); }
.li.on { background: var(--accent-soft); }
.li .t { font-weight: 700; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

@media print {
  header.top, .noprint { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border-color: #999; break-inside: avoid; }
}

/* 코스 편집 */
.maphint {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 500;
  background: rgba(17, 22, 28, .85); color: #fff; font-size: 12px; font-weight: 600;
  padding: 5px 10px; border-radius: 8px; max-width: calc(100% - 20px); text-align: center; pointer-events: none;
}
.wplist { display: grid; gap: 6px; max-height: 340px; overflow-y: auto; }
.wp { display: flex; align-items: center; gap: 4px; }
.wp input { min-height: 34px; padding: 4px 8px; flex: 1; min-width: 0; }
.wp .btn.sm { padding: 4px 7px; }
.wpn {
  flex: none; width: 26px; height: 26px; border-radius: 50%; color: #fff; font-size: 12px; font-weight: 800;
  display: grid; place-items: center;
}
