:root {
  color-scheme: dark;
  --bg: #0d0f12;
  --panel: #15181d;
  --panel-2: #1b1f25;
  --panel-3: #22272e;
  --text: #f5f7fa;
  --muted: #9ca6b4;
  --line: #2a3039;
  --line-strong: #3a424d;
  --accent: #f0f3f6;
  --accent-ink: #101215;
  --red: #ff5252;
  --red-dark: #5b1f23;
  --red-soft: rgba(255, 82, 82, .12);
  --amber: #ffc857;
  --amber-soft: rgba(255, 200, 87, .14);
  --green: #67d391;
  --green-soft: rgba(103, 211, 145, .12);
  --shadow: 0 16px 50px rgba(0,0,0,.25);
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { min-width: 320px; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }

.topbar {
  height: 68px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between;
  padding: 0 clamp(16px, 4vw, 44px); position: sticky; top: 0; z-index: 20; background: rgba(13,15,18,.92); backdrop-filter: blur(16px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; background: var(--text); color: var(--bg); display: grid; place-items: center; font-weight: 850; font-size: 18px; }
.brand-title { font-weight: 760; letter-spacing: -.02em; }
.brand-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.file-badge { max-width: 48vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 8px 11px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 12px; }

.app-shell { width: min(1680px, 100%); margin: 0 auto; padding: clamp(18px, 3vw, 36px); }
.hidden { display: none !important; }

.upload-view { min-height: calc(100vh - 140px); display: grid; place-items: center; }
.upload-card { width: min(620px, 100%); text-align: center; padding: clamp(26px, 5vw, 48px); border: 1px solid var(--line); border-radius: 22px; background: linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,.01)); box-shadow: var(--shadow); }
.upload-card h1 { margin: 18px 0 8px; font-size: clamp(26px, 4vw, 36px); letter-spacing: -.04em; }
.upload-card p { color: var(--muted); line-height: 1.6; margin: 0 auto 24px; max-width: 500px; }
.upload-icon { width: 58px; height: 58px; margin: auto; border: 1px solid var(--line-strong); border-radius: 16px; display: grid; place-items: center; background: var(--panel); }
.upload-icon svg { width: 28px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.drop-zone { display: grid; gap: 6px; border: 1px dashed #555f6d; border-radius: 16px; padding: 34px 20px; background: rgba(255,255,255,.02); cursor: pointer; transition: .18s ease; }
.drop-zone:hover, .drop-zone.dragging { border-color: #a7b0bc; background: rgba(255,255,255,.05); transform: translateY(-1px); }
.drop-zone input { display: none; }
.drop-title { font-weight: 700; }
.drop-sub, .upload-note { color: var(--muted); font-size: 13px; }
.upload-note { margin-top: 16px; line-height: 1.5; }

.workspace { display: grid; gap: 18px; }
.control-rail { display: flex; justify-content: space-between; align-items: end; gap: 16px; }
.selectors { display: flex; gap: 10px; flex-wrap: wrap; flex: 1; }
label { color: var(--muted); font-size: 12px; font-weight: 620; }
select, textarea, input[type="text"], input[type="time"] { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; outline: none; }
select { display: block; min-width: 160px; margin-top: 6px; padding: 10px 34px 10px 11px; }
select:focus, textarea:focus, input:focus { border-color: #717b89; box-shadow: 0 0 0 3px rgba(255,255,255,.04); }

.module-tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); }
.module-tab { border: 0; background: transparent; padding: 12px 16px; color: var(--muted); cursor: pointer; position: relative; font-weight: 700; }
.module-tab.active { color: var(--text); }
.module-tab.active::after { content: ""; position: absolute; left: 14px; right: 14px; bottom: -1px; height: 2px; background: var(--text); border-radius: 2px 2px 0 0; }

.module { display: grid; gap: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0,0,0,.1); }
.overview-grid { display: grid; grid-template-columns: minmax(280px, 1.5fr) repeat(3, minmax(150px, .6fr)); gap: 12px; }
.route-card, .metric-card { padding: 18px 20px; min-height: 116px; }
.eyebrow { text-transform: uppercase; letter-spacing: .11em; font-size: 10px; color: var(--muted); font-weight: 800; }
.route-title { font-size: 27px; font-weight: 820; margin-top: 9px; letter-spacing: -.035em; }
.route-places { color: #d7dde5; margin-top: 4px; }
.subtle { color: var(--muted); font-size: 13px; line-height: 1.5; }
.metric-label { color: var(--muted); font-size: 12px; font-weight: 650; }
.metric-value { font-size: 30px; font-weight: 800; margin-top: 9px; letter-spacing: -.035em; }
.metric-sub { margin-top: 2px; font-size: 11px; color: var(--muted); }
.danger-text { color: #ff7474; }

.planner-grid { display: grid; grid-template-columns: minmax(250px, 330px) minmax(0, 1fr); gap: 14px; align-items: start; }
.cut-card { padding: 18px; position: sticky; top: 86px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.section-heading h2 { margin: 3px 0 0; font-size: 18px; letter-spacing: -.02em; }
.cut-card textarea { width: 100%; resize: vertical; min-height: 90px; padding: 11px; margin: 12px 0 10px; line-height: 1.45; }
.divider { height: 1px; background: var(--line); margin: 18px 0; }
.mini-title { color: var(--muted); font-size: 11px; text-transform: uppercase; font-weight: 800; letter-spacing: .08em; margin-bottom: 10px; }
.duty-chips { display: flex; flex-wrap: wrap; gap: 7px; max-height: 220px; overflow: auto; }
.duty-chip { border: 1px solid var(--line); background: var(--panel-2); color: #dbe1e9; border-radius: 999px; padding: 7px 10px; cursor: pointer; font-size: 12px; }
.duty-chip.selected { background: var(--red-soft); border-color: rgba(255,82,82,.45); color: #ff8d8d; }

.btn { border: 1px solid var(--line); border-radius: 10px; padding: 9px 13px; cursor: pointer; font-weight: 730; background: var(--panel-2); }
.btn:hover { filter: brightness(1.08); }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.secondary { background: #2a3038; }
.btn.ghost { background: transparent; color: #d7dde5; }
.btn.full { width: 100%; }
.text-btn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px; font-size: 12px; }
.text-btn:hover { color: var(--text); }

.table-card { overflow: hidden; }
.table-heading { padding: 17px 18px 10px; }
.table-scroll { overflow: auto; }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12px; }
.data-table th { position: sticky; top: 0; z-index: 2; background: #1b1f25; color: #aeb7c4; text-align: left; font-size: 10px; letter-spacing: .035em; text-transform: uppercase; padding: 10px 12px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
.data-table td { padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table tbody tr:hover td { background: rgba(255,255,255,.02); }
.data-table tr.dropped td { background: var(--red-soft); border-bottom-color: rgba(255,82,82,.17); }
.data-table tr.dropped:hover td { background: rgba(255,82,82,.16); }
.status { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 4px 8px; font-size: 10px; font-weight: 800; }
.status.operated { color: #91e4ae; background: var(--green-soft); }
.status.dropped { color: #ff8b8b; background: rgba(255,82,82,.16); }
.exception { color: var(--amber); font-weight: 750; }
.hw-bad { color: #ff8989; font-weight: 760; }
.alert-summary { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.alert-chip { padding: 5px 8px; border-radius: 999px; font-size: 10px; font-weight: 780; background: var(--amber-soft); color: #ffd77d; }
.alert-chip.danger { background: var(--red-soft); color: #ff8686; }
.summary-card { overflow: hidden; }
.summary-card .section-heading { padding: 16px 18px 8px; }
.empty-state { padding: 20px 18px 24px; color: var(--muted); font-size: 13px; }
.compact td, .compact th { padding-top: 8px; padding-bottom: 8px; }

.survey-toolbar { padding: 18px; display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.survey-toolbar h2 { margin: 3px 0 3px; }
.survey-toolbar p { margin: 0; }
.survey-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.toggle { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border: 1px solid var(--line); padding: 8px 10px; border-radius: 10px; color: #d8dee6; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle span { width: 28px; height: 16px; background: #3b424c; border-radius: 999px; position: relative; transition: .15s; }
.toggle span::after { content: ""; position: absolute; width: 12px; height: 12px; top: 2px; left: 2px; border-radius: 50%; background: white; transition: .15s; }
.toggle input:checked + span { background: #67727f; }
.toggle input:checked + span::after { transform: translateX(12px); }
.survey-stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat-pill { display: flex; gap: 8px; align-items: baseline; padding: 8px 11px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 11px; color: var(--muted); }
.stat-pill strong { color: var(--text); }
.survey-table-card { overflow: hidden; }
.survey-scroll { max-height: calc(100vh - 250px); min-height: 420px; }
.survey-table th:first-child, .survey-table td:first-child { position: sticky; left: 0; z-index: 3; background: var(--panel); }
.survey-table th:first-child { background: #1b1f25; }
.survey-table tr.dropped td:first-child { background: #2a171a; }
.cell-input { width: 100%; min-width: 105px; padding: 7px 8px; color: var(--text); }
.remark-input { min-width: 220px; }
.time-entry { display: flex; align-items: center; gap: 5px; }
.time-entry input { min-width: 112px; padding: 7px 8px; }
.now-btn { padding: 7px 8px; border-radius: 8px; border: 1px solid var(--line); background: #252a31; cursor: pointer; color: #d9dfe7; font-size: 10px; font-weight: 800; }
.now-btn:hover { background: #303640; }
input:disabled { opacity: .45; cursor: not-allowed; }

.alert { border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-top: 14px; text-align: left; }
.alert.error { background: rgba(255,82,82,.1); color: #ff9696; border: 1px solid rgba(255,82,82,.28); }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: #eceff3; color: #111418; padding: 10px 14px; border-radius: 10px; font-size: 12px; font-weight: 720; box-shadow: var(--shadow); transition: .2s; z-index: 99; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1050px) {
  .overview-grid { grid-template-columns: repeat(3, 1fr); }
  .route-card { grid-column: 1 / -1; }
  .planner-grid { grid-template-columns: 1fr; }
  .cut-card { position: static; }
  .duty-chips { max-height: none; }
  .survey-toolbar { align-items: flex-start; flex-direction: column; }
  .survey-actions { justify-content: flex-start; }
}

@media (max-width: 700px) {
  .topbar { height: 62px; padding: 0 14px; }
  .brand-sub { display: none; }
  .file-badge { display: none; }
  .app-shell { padding: 14px; }
  .control-rail { align-items: stretch; flex-direction: column; }
  .selectors { display: grid; grid-template-columns: 1fr 1fr; }
  .selectors label:last-child { grid-column: 1 / -1; }
  select { min-width: 0; width: 100%; }
  .overview-grid { grid-template-columns: 1fr 1fr; }
  .route-card { grid-column: 1 / -1; }
  .metric-card:last-child { grid-column: 1 / -1; }
  .survey-actions { width: 100%; }
  .survey-actions .btn { flex: 1; }
  .toggle { width: 100%; }
  .route-title { font-size: 23px; }
}

/* All-issues overview */
.global-issues-card { overflow: hidden; }
.global-issues-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; padding: 18px 18px 10px; }
.global-issues-head h2 { margin: 3px 0 4px; font-size: 20px; letter-spacing: -.025em; }
.global-issues-head p { margin: 0; max-width: 820px; }
.issue-metrics { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 18px 14px; }
.issue-metric { min-width: 120px; display: flex; align-items: baseline; justify-content: space-between; gap: 14px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
.issue-metric span { color: var(--muted); font-size: 11px; }
.issue-metric strong { font-size: 18px; }
.compact-empty { padding-top: 6px; }
.clickable-row { cursor: pointer; }
.clickable-row:hover td { background: rgba(255,255,255,.045) !important; }
.open-link { color: #dfe5ec; font-weight: 760; text-align: right; }

/* Partial-duty cuts */
.partial-cut-info { margin-top: 10px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.duty-chip.partial { background: var(--amber-soft); border-color: rgba(255,200,87,.45); color: #ffd77d; }
.trip-cut-btn { border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; cursor: pointer; font-size: 10px; font-weight: 800; white-space: nowrap; }
.trip-cut-btn.cut { background: #252a31; color: #dbe1e9; }
.trip-cut-btn.restore { background: rgba(255,82,82,.14); color: #ff9696; border-color: rgba(255,82,82,.3); }
.trip-cut-btn:hover { filter: brightness(1.1); }
@keyframes issueFocusPulse {
  0%, 100% { box-shadow: inset 0 0 0 0 rgba(255,200,87,0); }
  30%, 70% { box-shadow: inset 0 0 0 2px rgba(255,200,87,.95); }
}
