:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #1e3a8a;
  --brand-2: #2563eb;
  --btn: #2563eb;
  --warn-bg: #fef9c3;
  --warn-line: #facc15;
  --warn-text: #713f12;
  --danger: #dc2626;
  --ok: #16a34a;
  --chip: #eef2ff;
  --input: #ffffff;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --card: #171d24;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --line: #2a323c;
    --brand: #93c5fd;
    --brand-2: #60a5fa;
    --warn-bg: #3a3212;
    --warn-line: #a16207;
    --warn-text: #fde68a;
    --chip: #1e2633;
    --input: #0f1419;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--brand-2); text-decoration: none; }
h1 { font-size: 20px; margin: 0 0 12px; }
h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* 상단바 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); font-size: 17px; white-space: nowrap; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a.on { background: var(--chip); color: var(--brand); }
.who { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* 하단 탭바(모바일) */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: none; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { flex: 1; text-align: center; padding: 8px 0 7px; color: var(--muted); font-size: 12px; }
.tabbar a .ic { display: block; font-size: 19px; line-height: 1.2; }
.tabbar a.on { color: var(--brand); font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 20px; }

@media (max-width: 720px) {
  .nav, .who { display: none; }
  .topbar { padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); }
  .tabbar:not([hidden]) { display: flex; }
  main { padding: 14px 16px 90px; }
}

/* 카드·버튼 */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 8px 14px; border-radius: 10px; font: inherit; font-weight: 500; cursor: pointer; min-height: 38px;
}
.btn:hover { border-color: var(--brand-2); }
.btn.primary { background: var(--btn); border-color: var(--btn); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.big { width: 100%; min-height: 48px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: default; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--chip); color: var(--brand); }
.badge.gray { color: var(--muted); }
.badge.red { background: #fee2e2; color: #b91c1c; }
.badge.green { background: #dcfce7; color: #15803d; }
.badge.yellow { background: var(--warn-bg); color: var(--warn-text); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; margin-right: 4px; }

/* 폼 */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 12px; }
.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.f.wide { grid-column: 1 / -1; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--input);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 38px; width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { width: auto; min-height: auto; }
.paste { min-height: 220px; font-size: 14px; }

/* 경고 */
.warns { background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-text); border-radius: 10px; padding: 8px 12px; margin: 8px 0 12px; font-size: 14px; }
.warns ul { margin: 0; padding-left: 18px; }
.err { color: var(--danger); }

/* 기사 추천 */
.rec { margin-top: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip { border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; background: var(--card); cursor: pointer; text-align: left; font: inherit; color: var(--text); }
.chip small { display: block; color: var(--muted); font-size: 12px; }
.chip.on { border-color: var(--brand-2); background: var(--chip); box-shadow: inset 0 0 0 1px var(--brand-2); }
.chip.busy { opacity: .55; }

/* 상세 */
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
@media (max-width: 480px) { .kv { grid-template-columns: 86px 1fr; } }
pre.raw { white-space: pre-wrap; word-break: break-word; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font: 13px/1.5 ui-monospace, "D2Coding", monospace; margin: 6px 0 0; }
details > summary { cursor: pointer; color: var(--brand-2); font-weight: 500; padding: 4px 0; }
.hist { border-left: 3px solid var(--line); padding: 4px 0 4px 12px; margin: 8px 0; }
.hist.old { opacity: .6; }
.hist del { color: var(--muted); }
.hist ins { text-decoration: none; font-weight: 700; }
.canceled { text-decoration: line-through; opacity: .6; }

/* 내 배차 목록 */
.trip { display: block; color: var(--text); }
.trip .when { font-size: 17px; font-weight: 700; }
.trip .what { margin-top: 2px; }
.trip.today { border-color: var(--brand-2); }
.daysep { margin: 18px 0 8px; font-weight: 700; color: var(--muted); font-size: 14px; }

/* 표 */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
.tablewrap { overflow-x: auto; }
td input, td select { min-height: 32px; padding: 4px 6px; }

/* 캘린더 */
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
#cal { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.fc { --fc-border-color: var(--line); --fc-page-bg-color: var(--card); --fc-neutral-bg-color: var(--bg); --fc-list-event-hover-bg-color: var(--chip); --fc-today-bg-color: rgba(37,99,235,.08); }
.fc .fc-toolbar-title { font-size: 18px; }
.fc a.fc-col-header-cell-cushion, .fc a.fc-daygrid-day-number, .fc a.fc-list-day-text, .fc a.fc-list-day-side-text { color: var(--text); }
.fc .fc-daygrid-block-event .fc-event-time { font-weight: 700; }
.fc-event { cursor: pointer; }
.fc .fc-button { padding: 4px 10px; font-size: 13px; }
.fc-event.is-canceled { opacity: .45; text-decoration: line-through; }
.fc-event.is-mine { box-shadow: 0 0 0 2px var(--text); }
.fc-event.is-est { background-image: repeating-linear-gradient(135deg, transparent 0 6px, rgba(255,255,255,.18) 6px 12px); }
.fc .fc-list-event.is-canceled { text-decoration: line-through; opacity: .5; }
@media (max-width: 720px) {
  #cal { padding: 6px; }
  .fc .fc-toolbar { flex-wrap: wrap; gap: 6px; }
  .fc .fc-toolbar-title { font-size: 16px; }
}

/* 로그인 */
.login { max-width: 360px; margin: 10vh auto; }
.login h1 { text-align: center; margin-bottom: 20px; }
.login .f { margin-bottom: 10px; }

/* 토스트 */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 50;
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: 90vw;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.toast.bad { background: var(--danger); }

.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--brand-2); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

.itemhead { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.itemhead select { width: auto; }
.stack > * + * { margin-top: 10px; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; }
@media (max-width: 720px) { .sticky-actions { bottom: 58px; } }
