:root {
  --paper: #f6f0e6;
  --surface: #fffaf1;
  --ink: #251b14;
  --muted: #74695d;
  --line: #ddd0bf;
  --primary: #0f766e;
  --primary-strong: #0b5751;
  --selected: #00a693;
  --sand: #ead8bd;
  --danger: #ad2f2f;
  --shadow: 0 18px 45px rgba(55, 39, 22, 0.12);
  font-family: Avenir Next, Avenir, Segoe UI, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 0%, rgba(196, 122, 58, 0.18), transparent 32rem),
    linear-gradient(180deg, #fbf4e9 0%, var(--paper) 45%, #efe3d1 100%);
  min-height: 100vh;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
.app-header {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: flex-start;
  padding: max(18px, env(safe-area-inset-top)) 18px 12px;
}
.app-header h1 { margin: 2px 0 4px; font-size: clamp(26px, 8vw, 54px); line-height: .95; letter-spacing: -.055em; }
.app-header p { margin: 0; max-width: 760px; }
.eyebrow { margin: 0 0 6px; color: var(--primary-strong); font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.muted { color: var(--muted); }
.notice { margin: 0 18px 12px; padding: 12px 14px; border: 1px solid #e2b45f; border-radius: 14px; background: #fff2c8; color: #5e4210; }
.tabs { position: sticky; top: 0; z-index: 500; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 8px 18px; background: rgba(246, 240, 230, .9); backdrop-filter: blur(14px); }
.tabs button, .ghost-button, .primary-button, .secondary-button, .danger-button {
  border: 1px solid var(--line); border-radius: 999px; padding: 11px 15px; background: rgba(255, 250, 241, .78); color: var(--ink); font-weight: 800;
}
.tabs button.is-active, .primary-button { border-color: var(--primary); background: var(--primary); color: white; }
.secondary-button { border-color: var(--primary); color: var(--primary-strong); background: #e6f2ef; }
.danger-button { border-color: #e7b7b7; color: var(--danger); background: #fff2f0; padding: 8px 11px; }
.danger-panel { border-color: #e7b7b7; background: #fff7f4; }
.danger-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
main { padding: 0 18px 32px; }
.planner-layout { display: grid; gap: 16px; }
.map-panel { position: relative; display: grid; gap: 10px; }
.map { height: min(52vh, 500px); min-height: 320px; border: 1px solid var(--line); border-radius: 26px; overflow: hidden; background: #d8ded1; box-shadow: var(--shadow); }
.route-card, .panel { background: rgba(255, 250, 241, .9); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.route-card { padding: 14px; }
.route-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.route-summary div { padding: 10px; border-radius: 16px; background: #f1e3cf; }
.route-summary strong { display: block; font-size: 18px; }
.route-summary span { display: block; color: var(--muted); font-size: 12px; }
.stage-workspace { display: grid; gap: 14px; align-content: start; }
.stage-rail { display: flex; gap: 10px; overflow-x: auto; padding: 2px 0 4px; scroll-snap-type: x mandatory; }
.stage-chip { flex: 0 0 210px; display: grid; grid-template-columns: 34px 1fr; gap: 2px 10px; text-align: left; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 20px; background: rgba(255,250,241,.84); scroll-snap-align: start; }
.stage-chip span { grid-row: span 2; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--sand); font-weight: 900; }
.stage-chip strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage-chip small { color: var(--muted); }
.stage-chip.is-selected { border-color: var(--selected); background: #e4f6f2; box-shadow: 0 0 0 3px rgba(0,166,147,.14) inset; }
.stage-chip.is-selected span { background: var(--selected); color: #fff; }
.panel { padding: 18px; }
.panel h2, .panel h3 { margin: 0 0 10px; letter-spacing: -.03em; }
.selected-panel { border-color: rgba(0,166,147,.42); box-shadow: 0 18px 45px rgba(0, 92, 82, 0.14); }
.split-banner { padding: 12px 14px; border-radius: 16px; background: #dff8f3; border: 1px solid rgba(0,166,147,.35); color: #07544c; font-weight: 850; }
.stage-form strong { color: var(--ink); }
.stage-panel { display: grid; gap: 16px; }
.stage-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.stage-heading h2 { font-size: clamp(24px, 7vw, 40px); line-height: 1; }
.mini-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mini-metrics span { padding: 10px; border-radius: 14px; background: #f1e3cf; color: var(--muted); }
.mini-metrics strong { color: var(--ink); }
.stack-form, .stage-form, .config-layout { display: grid; gap: 14px; }
.config-layout { max-width: 980px; margin: 0 auto; }
label { display: grid; gap: 7px; color: var(--muted); font-weight: 750; }
input, textarea, select {
  width: 100%; border: 1px solid var(--line); border-radius: 15px; padding: 12px 13px; color: var(--ink); background: #fffdf8; outline: none;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, textarea:focus, select:focus, button:focus-visible { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(15, 118, 110, .16); outline: none; }
.split-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.details-card { border: 1px solid var(--line); border-radius: 18px; padding: 12px; background: #fff6e8; }
.details-card summary { cursor: pointer; font-weight: 900; }
.details-card label { margin-top: 12px; }
.sticky-actions { position: sticky; bottom: 0; display: flex; gap: 8px; padding: 10px 0 0; background: linear-gradient(180deg, transparent, var(--surface) 26%); flex-wrap: wrap; }
.upload-form { display: grid; grid-template-columns: 1fr; gap: 10px; }
.attachment-grid { display: grid; gap: 10px; margin-top: 14px; }
.attachment-card { display: grid; grid-template-columns: 84px 1fr auto; gap: 12px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 18px; background: #fffdf8; }
.attachment-card img, .file-tile { width: 84px; height: 64px; object-fit: cover; border-radius: 12px; background: var(--sand); display: grid; place-items: center; color: var(--muted); font-size: 12px; font-weight: 900; }
.attachment-card strong, .attachment-card small { display: block; }
.stage-table { display: grid; gap: 8px; }
.stage-row { display: grid; grid-template-columns: 38px 1fr; gap: 2px 10px; text-align: left; width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 16px; background: #fffdf8; }
.stage-row span { grid-row: span 2; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--sand); font-weight: 900; }
.stage-row small { color: var(--muted); }
.stage-row.is-selected { border-color: var(--selected); background: #e4f6f2; }
.stage-row.is-selected span { background: var(--selected); color: #fff; }
.empty-state p { max-width: 580px; color: var(--muted); }
.toast { position: fixed; left: 18px; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 1000; padding: 13px 15px; border-radius: 16px; background: var(--ink); color: white; box-shadow: var(--shadow); }
.toast.is-error { background: var(--danger); }
.stage-marker { background: transparent; border: 0; }
.stage-marker span { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 999px; background: var(--primary); color: #fff; border: 3px solid #fffaf1; font-weight: 900; box-shadow: 0 8px 20px rgba(0,0,0,.22); }
.stage-marker.is-selected span { width: 38px; height: 38px; background: var(--selected); border-width: 4px; box-shadow: 0 0 0 5px rgba(0,166,147,.2), 0 12px 24px rgba(0,0,0,.26); }
.full-route-line { filter: drop-shadow(0 1px 2px rgba(75,47,36,.32)); }
.full-route-shadow { filter: blur(.2px); }
.selected-stage-line { filter: drop-shadow(0 0 7px rgba(0,166,147,.78)); }
@media (min-width: 960px) {
  .app-header { padding: 28px 32px 14px; }
  .tabs { max-width: 560px; margin-left: 14px; border-radius: 999px; }
  main { padding: 0 32px 42px; }
  .planner-layout { grid-template-columns: minmax(420px, .95fr) minmax(420px, 1.05fr); align-items: start; }
  .map-panel { position: sticky; top: 74px; }
  .map { height: calc(100vh - 285px); min-height: 470px; }
  .stage-rail { flex-wrap: wrap; overflow: visible; }
  .stage-chip { flex-basis: calc(50% - 5px); }
  .upload-form { grid-template-columns: 1fr 1fr auto; align-items: end; }
}
@media (max-width: 620px) {
  .app-header { align-items: stretch; flex-direction: column; }
  .route-summary { grid-template-columns: repeat(2, 1fr); }
  .map { height: 42vh; min-height: 290px; border-radius: 20px; }
  .split-fields, .mini-metrics { grid-template-columns: 1fr; }
  .attachment-card { grid-template-columns: 74px 1fr; }
  .attachment-card .danger-button { grid-column: 1 / -1; }
  .sticky-actions button { flex: 1 1 100%; }
}
