/* ══════════════ 화물 혼적 경로 — 디자인 시스템 ══════════════
 * 밝은 세이지 그라데이션 + 딥 틸 그린 브랜드 컬러.
 * 토큰 기반: 라이트가 기본, 시스템 다크 + 수동 토글(data-theme) 모두 지원.
 */
:root {
  --bg-top: #e9f2ec;
  --bg-bottom: #f8fbf9;
  --card: #ffffff;
  --card-sub: #f2f7f4;
  --line: #dde8e1;
  --ink: #1d3229;
  --ink-dim: #64796e;
  --brand: #1e6b5a;
  --brand-deep: #175648;
  --brand-soft: #e3f0ea;
  --amber: #b26a10;
  --amber-soft: #fbf0dd;
  --green: #2e8b57;
  --green-soft: #e4f2e9;
  --red: #c73e3e;
  --red-soft: #fbe9e9;
  --shadow: 0 1px 2px rgba(29, 50, 41, .05), 0 10px 30px rgba(29, 50, 41, .07);
  --shadow-btn: 0 6px 18px rgba(30, 107, 90, .28);
  --on-brand: #ffffff;
  --radius: 18px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg-top: #101a15;
    --bg-bottom: #0c130f;
    --card: #16221c;
    --card-sub: #1c2b23;
    --line: #27382f;
    --ink: #e6efe9;
    --ink-dim: #8fa598;
    --brand: #4fb597;
    --brand-deep: #3d9a7f;
    --brand-soft: #1b3a30;
    --amber: #e3a24f;
    --amber-soft: #34281a;
    --green: #5fc98d;
    --green-soft: #1a3324;
    --red: #e57373;
    --red-soft: #3a2020;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
    --shadow-btn: 0 6px 18px rgba(0, 0, 0, .4);
    --on-brand: #07130e;
  }
}
:root[data-theme="light"] {
  --bg-top: #e9f2ec; --bg-bottom: #f8fbf9; --card: #ffffff; --card-sub: #f2f7f4;
  --line: #dde8e1; --ink: #1d3229; --ink-dim: #64796e;
  --brand: #1e6b5a; --brand-deep: #175648; --brand-soft: #e3f0ea;
  --amber: #b26a10; --amber-soft: #fbf0dd;
  --green: #2e8b57; --green-soft: #e4f2e9;
  --red: #c73e3e; --red-soft: #fbe9e9;
  --shadow: 0 1px 2px rgba(29, 50, 41, .05), 0 10px 30px rgba(29, 50, 41, .07);
  --shadow-btn: 0 6px 18px rgba(30, 107, 90, .28);
  --on-brand: #ffffff;
}
:root[data-theme="dark"] {
  --bg-top: #101a15; --bg-bottom: #0c130f; --card: #16221c; --card-sub: #1c2b23;
  --line: #27382f; --ink: #e6efe9; --ink-dim: #8fa598;
  --brand: #4fb597; --brand-deep: #3d9a7f; --brand-soft: #1b3a30;
  --amber: #e3a24f; --amber-soft: #34281a;
  --green: #5fc98d; --green-soft: #1a3324;
  --red: #e57373; --red-soft: #3a2020;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
  --shadow-btn: 0 6px 18px rgba(0, 0, 0, .4);
  --on-brand: #07130e;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
/* 한글은 낱말 단위로만 줄바꿈 (글자 한 자씩 쪼개지지 않게) */
body { word-break: keep-all; }

body {
  font-family: "Pretendard Variable", "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", -apple-system, sans-serif;
  background: linear-gradient(175deg, var(--bg-top) 0%, var(--bg-bottom) 420px);
  background-attachment: fixed;
  color: var(--ink);
  font-size: 16px;   /* 고정 큰 글씨 — 고령·저시력 배려, 줌 방식 사용 안 함 */
  line-height: 1.6;
  padding-bottom: 40px;
  transition: background .3s, color .3s;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ── 헤더 (슬림) ── */
.app-header { padding: 18px 16px 12px; }
.header-inner {
  max-width: 640px; margin: 0 auto;
  display: flex; align-items: center; gap: 11px;
}
.logo {
  width: 44px; height: 44px; flex-shrink: 0;
  background: linear-gradient(140deg, var(--brand), var(--brand-deep));
  border-radius: 13px;
  display: flex; align-items: center; justify-content: center;
  font-size: 23px;
  box-shadow: var(--shadow-btn);
}
.header-text { flex: 1; min-width: 0; }
h1 { font-size: 19px; font-weight: 800; letter-spacing: -0.03em; color: var(--ink); }
.tagline { font-size: 12.5px; color: var(--ink-dim); letter-spacing: -0.01em; margin-top: 1px; }
.theme-toggle {
  width: 40px; height: 40px; flex-shrink: 0;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); color: var(--ink);
  font-size: 17px; cursor: pointer;
  box-shadow: var(--shadow);
}

/* ── 탭 (세그먼트 필) ── */
.tabs {
  position: sticky; top: 10px; z-index: 500;
  display: flex; gap: 4px;
  max-width: 640px; margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px;
  box-shadow: var(--shadow);
  margin-left: max(14px, calc((100% - 640px) / 2));
  margin-right: max(14px, calc((100% - 640px) / 2));
}
.tab {
  flex: 1; min-width: 0; padding: 9px 2px;
  background: none; border: none; border-radius: 999px;
  color: var(--ink-dim);
  font-size: 13.5px; font-weight: 700; font-family: inherit;
  letter-spacing: -0.02em;
  cursor: pointer;
  white-space: nowrap; overflow: hidden;
  transition: background .2s, color .2s;
}
.tab.active { color: var(--on-brand); background: linear-gradient(140deg, var(--brand), var(--brand-deep)); }

/* ── 레이아웃 ── */
.container { max-width: 640px; margin: 0 auto; padding: 14px 14px 30px; }
.panel { display: none; }
.panel.active { display: block; animation: rise .35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.hidden { display: none !important; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card.highlight { border-color: var(--brand); }
/* 제목은 '라벨'처럼 조용하게 — 내용과 버튼이 돋보이도록 위계 정리 */
.card-title { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 11px; color: var(--ink-dim); }
.card-title.accent { color: var(--brand); font-size: 16px; }
.hint { font-size: 12.5px; color: var(--ink-dim); font-weight: 500; }
.center-card { text-align: center; padding: 40px 16px; color: var(--ink-dim); }
.big-emoji { font-size: 46px; margin-bottom: 10px; }

/* ── 입력 ── */
.input {
  width: 100%;
  background: var(--card-sub);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  font-size: 16px;
  padding: 12px 13px;
  outline: none;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); background: var(--card); }
.input::placeholder { color: var(--ink-dim); opacity: .7; }
.textarea { resize: vertical; min-height: 76px; }
select.input { appearance: none; }

/* iOS가 시간 입력칸을 자체 크기로 그려 select와 높이가 어긋나는 것 방지 */
input[type="time"].input, select.input {
  -webkit-appearance: none;
  appearance: none;
  height: 47px;
  padding-top: 0;
  padding-bottom: 0;
}
input[type="time"].input::-webkit-date-and-time-value { text-align: left; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { font-size: 13.5px; color: var(--ink-dim); font-weight: 700; letter-spacing: -0.01em; }

.row { display: flex; align-items: center; }
.row.gap { gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.space-between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.top8 { margin-top: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.center { text-align: center; }
.full { width: 100%; }

/* ── 버튼 ── */
.btn {
  border: none; border-radius: 13px;
  font-size: 15.5px; font-weight: 700; letter-spacing: -0.02em;
  padding: 12px 16px;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
  display: inline-block; text-align: center; text-decoration: none;  /* <a>로 만든 버튼도 블록처럼 */
  transition: filter .15s, transform .06s, box-shadow .15s;
}
.btn:active { transform: scale(0.98); }
.btn:focus-visible, .tab:focus-visible, .input:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn.primary {
  background: linear-gradient(140deg, var(--brand), var(--brand-deep));
  color: var(--on-brand);
  box-shadow: var(--shadow-btn);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.secondary { background: var(--brand-soft); color: var(--brand); }
.btn.secondary:hover { filter: brightness(0.97); }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); color: var(--ink-dim); }
.btn.danger { background: linear-gradient(140deg, #d64545, #b93333); color: #fff; box-shadow: 0 6px 18px rgba(199, 62, 62, .25); }
.btn.big { width: 100%; font-size: 17px; font-weight: 800; padding: 16px; margin-bottom: 12px; border-radius: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── 배송지 리스트 (블록 레이아웃: 주소·정보를 카드 전체 폭으로) ── */
.stop-list { list-style: none; margin-top: 12px; }
.stop-item {
  display: block;
  background: var(--card-sub);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 13px;
  margin-bottom: 8px;
  font-size: 15px;
  animation: rise .25s ease both;
}
/* 윗줄: 아이콘 + 상차/하차·날짜 배지(왼쪽), ✕(오른쪽) */
.si-head { display: flex; align-items: center; gap: 6px 7px; flex-wrap: wrap; }
.si-head .si-icon { font-size: 18px; line-height: 1; flex-shrink: 0; }
.si-head .si-del { margin-left: auto; }
/* 주소·본문: 전체 폭 */
.si-text { font-weight: 700; font-size: 15.5px; line-height: 1.4; margin-top: 6px; }
.stop-item .label { min-width: 0; white-space: normal; font-weight: 600; line-height: 1.4; }
.stop-item .sub { display: block; font-size: 13.5px; font-weight: 400; color: var(--ink-dim); white-space: normal; line-height: 1.65; margin-top: 4px; }
/* 상차=주황 / 하차=초록 색 띠 */
.stop-item.load { border-left-width: 6px; border-left-color: var(--amber); }
.stop-item.unload { border-left-width: 6px; border-left-color: var(--green); }
.stop-item.error { border-color: var(--red); background: var(--red-soft); }

.badge {
  font-size: 13px; font-weight: 800;
  min-height: 32px; padding: 5px 12px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; cursor: pointer; font-family: inherit;
  white-space: nowrap; letter-spacing: -0.01em; flex-shrink: 0;
}
.badge.load { background: var(--amber-soft); color: var(--amber); }
.badge.unload { background: var(--green-soft); color: var(--green); }
.badge.final { background: var(--brand-soft); color: var(--brand); }

.icon-btn {
  background: none; border: none; color: var(--ink-dim);
  font-size: 18px; cursor: pointer;
  min-width: 40px; min-height: 40px; display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.icon-btn:hover { color: var(--red); }

.geo-status { font-size: 14px; color: var(--ink-dim); margin-top: 7px; min-height: 1em; }
.geo-status.ok { color: var(--green); font-weight: 600; }
.geo-status.err { color: var(--red); font-weight: 600; }
.geo-status.center { text-align: center; margin-bottom: 14px; }

/* ── 결과 ── */
.totals { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.total-chip {
  flex: 1; min-width: 92px;
  background: var(--card-sub);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 12px 8px;
  text-align: center;
}
.total-chip .v {
  font-size: 18px; font-weight: 800; color: var(--brand);
  letter-spacing: -0.02em; font-variant-numeric: tabular-nums;
}
.total-chip .k { font-size: 13px; color: var(--ink-dim); font-weight: 600; }

.visit-list { list-style: none; }
.visit-item {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 11px 2px;
  border-bottom: 1px dashed var(--line);
}
.visit-item:last-child { border-bottom: none; }
.visit-num {
  flex-shrink: 0;
  width: 27px; height: 27px; border-radius: 50%;
  background: var(--brand); color: #fff;
  font-size: 13px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  margin-top: 2px;
}
.visit-num.origin { background: var(--ink-dim); }
.visit-num.done { background: var(--green); }
.visit-body { flex: 1; min-width: 0; }
.visit-name { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.visit-meta { font-size: 14px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.visit-leg { font-size: 13.5px; color: var(--brand); font-weight: 600; font-variant-numeric: tabular-nums; }
.visit-actions { display: flex; gap: 6px; flex-shrink: 0; flex-direction: column; align-items: flex-end; }
.mini-btn {
  font-size: 14px; font-weight: 700;
  min-height: 40px; padding: 9px 13px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none;
  background: var(--brand-soft); color: var(--brand);
  cursor: pointer; font-family: inherit;
  white-space: nowrap;
}
.mini-btn.done { background: var(--green-soft); color: var(--green); }

/* ── 지도 ── */
#map {
  height: 320px;
  border-radius: 13px;
  background: var(--card-sub);
  z-index: 1;
}
.map-marker {
  background: var(--brand); color: #fff;
  border-radius: 50%;
  width: 36px !important; height: 36px !important;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 800;
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
}
.map-marker.origin { background: #5b6b62; }

/* ── 내비 버튼 (서비스 브랜드 컬러 유지) ── */
.navi-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.navi-btn {
  border: none; border-radius: 14px;
  padding: 16px 6px; min-height: 58px;
  font-size: 15px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.35;
  cursor: pointer; font-family: inherit;
  text-align: center; text-decoration: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff;
  box-shadow: var(--shadow);
  transition: filter .15s, transform .06s;
}
.navi-btn:active { transform: scale(0.97); }
.navi-btn.tmap { background: #2657e0; }
.navi-btn.kakao { background: #fee500; color: #191919; }
.navi-btn.naver { background: #03c75a; }
.navi-sub { font-size: 12px; font-weight: 700; opacity: .82; margin-top: 2px; }
.fine-print { font-size: 13px; color: var(--ink-dim); margin-top: 9px; line-height: 1.55; }

/* ── AI 추천 ── */
.ai-tips { list-style: none; }
.ai-tips li {
  padding: 9px 0 9px 27px;
  position: relative;
  font-size: 15px;
  border-bottom: 1px dashed var(--line);
}
.ai-tips li:last-child { border-bottom: none; }
.ai-tips li::before { content: attr(data-icon); position: absolute; left: 0; }

/* ── 운행 ── */
.timer {
  font-size: 21px; font-weight: 800; color: var(--brand);
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
}

/* ── 기록 ── */
.history-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 17px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.history-item summary {
  cursor: pointer; font-weight: 700; font-size: 14px;
  list-style: none; display: flex; justify-content: space-between; gap: 8px;
  letter-spacing: -0.01em;
}
.history-item summary::-webkit-details-marker { display: none; }
.history-date { color: var(--ink-dim); font-weight: 500; font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.history-detail { margin-top: 10px; font-size: 13px; color: var(--ink-dim); }
.history-detail b { color: var(--ink); }

/* ── 결과 표 ── */
.result-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.result-table td { padding: 8px 4px; border-bottom: 1px dashed var(--line); }
.result-table td:first-child { color: var(--ink-dim); }
.result-table td:last-child { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.result-table tr:last-child td { border-bottom: none; }

.verdict {
  font-size: 15.5px; font-weight: 800; text-align: center;
  padding: 12px; border-radius: 12px; margin-bottom: 12px;
  letter-spacing: -0.01em;
}
.verdict.ok { background: var(--green-soft); color: var(--green); }
.verdict.warn { background: var(--amber-soft); color: var(--amber); }
.verdict.bad { background: var(--red-soft); color: var(--red); }

.gauge { height: 10px; background: var(--card-sub); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; margin: 6px 0 14px; }
.gauge > div { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--green), var(--amber), var(--red)); background-size: 300px 100%; }

/* ── 토스트 ── */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg-bottom);
  padding: 12px 22px; border-radius: 999px;
  font-size: 14px; font-weight: 700; letter-spacing: -0.01em;
  z-index: 1000;
  pointer-events: none; /* 토스트가 아래 버튼 터치를 막지 않도록 */
  box-shadow: 0 8px 28px rgba(0, 0, 0, .3);
  max-width: 90vw; text-align: center;
  animation: rise .25s ease both;
}

.app-footer {
  max-width: 640px; margin: 0 auto; padding: 8px 16px 30px;
  font-size: 11px; color: var(--ink-dim); text-align: center; opacity: .8;
}

/* 다크모드에서 지도 타일을 살짝 어둡게 (수동 라이트 지정 시 제외) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-tile { filter: brightness(.78) contrast(1.08) saturate(.92); }
}
:root[data-theme="dark"] .leaflet-tile { filter: brightness(.78) contrast(1.08) saturate(.92); }
:root[data-theme="light"] .leaflet-tile { filter: none; }

@media (max-width: 480px) {
  .grid3 { grid-template-columns: 1fr 1fr; }
  .tab { font-size: 12.5px; }
  h1 { font-size: 20px; }
}

/* ── 특이사항·일정·문자 요약 표시 ── */
.stop-item .sub { white-space: normal; }        /* 특이사항이 여러 줄로 보이도록 */
.stop-item .sub .note,
.visit-meta.note { color: var(--amber); font-weight: 600; }
.badge.sched { background: var(--brand-soft); color: var(--brand); }
.sms-meta {
  margin-top: 8px; padding: 8px 12px; border-radius: 10px;
  background: var(--brand-soft); font-size: 12.5px; line-height: 1.55;
}

/* ── 적재함 배치도 ── */
.cargo-diagram { margin-top: 12px; }
.cargo-diagram svg { width: 100%; height: auto; display: block; }
.diagram-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 12px; color: var(--ink-dim); }
.diagram-key { display: inline-flex; align-items: center; gap: 5px; }
.diagram-key i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex: none; }
.diagram-cap { font-size: 12px; font-weight: 700; color: var(--ink-dim); margin: 12px 0 4px; }
.stop-divider { padding: 10px 4px 4px; font-size: 12px; font-weight: 700; color: var(--ink-dim); border-top: 1px dashed var(--line); margin-top: 8px; list-style: none; }
.stop-item.future { opacity: .72; }

/* ── 일정 미리 선택 칩 ── */
.sched-picker { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.sched-picker .field-label { margin-right: 2px; }
.chip {
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink-dim);
  border-radius: 999px; padding: 6px 12px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.chip.active { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.badge.inline { padding: 2px 8px; font-size: 11px; }
.chip.kind { flex: 1; padding: 12px 8px; font-size: 14.5px; text-align: center; border-radius: 12px; }

/* ── 밝게/어둡게 전환 버튼: 아이콘 + 글자 ── */
.theme-toggle {
  width: auto; padding: 0 13px;
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 13px; font-weight: 700; letter-spacing: -0.02em;
  white-space: nowrap;
}

/* ── 홈 화면 설치 카드 ── */
.install-card { border-color: var(--brand); }

/* ── 적재 방법(화물별) 한눈에 ── */
.pack-list { margin-top: 12px; }
.pack-item { padding: 11px 0; border-bottom: 1px dashed var(--line); }
.pack-item:last-child { border-bottom: none; }
.pack-name { font-weight: 700; font-size: 14.5px; margin-bottom: 7px; }
.pack-how { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.pack-how + .pack-how { margin-top: 6px; }
.pack-chip {
  display: inline-flex; align-items: center; gap: 2px;
  background: var(--card-sub); border: 1px solid var(--line);
  border-radius: 8px; padding: 4px 9px; font-size: 13.5px; color: var(--ink);
  white-space: nowrap;
}
.pack-chip b { font-weight: 800; font-size: 15px; }
.pack-chip.bad { background: var(--red-soft); border-color: var(--red); color: var(--red); font-weight: 700; }
.pack-mode {
  display: inline-flex; align-items: center;
  background: var(--brand-soft); color: var(--brand);
  font-weight: 800; font-size: 13.5px; padding: 4px 10px; border-radius: 8px; white-space: nowrap;
}
.pack-mode.laid { background: var(--amber-soft); color: var(--amber); }
