:root {
  --bg: #f4f7f5;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --text: #14201a;
  --muted: #64736b;
  --line: #dfe7e2;
  --primary: #166534;
  --primary-strong: #14532d;
  --primary-soft: #dcfce7;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --warning: #a15c07;
  --warning-soft: #fff4d6;
  --info: #175cd3;
  --info-soft: #e8f1ff;
  --shadow: 0 16px 40px rgba(20, 32, 26, .08);
  --radius: 18px;
  --radius-sm: 12px;
  --sidebar-width: 248px;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }

.splash-screen,
.setup-screen,
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.splash-screen { align-content: center; text-align: center; }
.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: inline-grid;
  place-items: center;
  font-weight: 900;
  letter-spacing: -.04em;
  color: white;
  background: linear-gradient(145deg, #15803d, #14532d);
  box-shadow: 0 12px 28px rgba(22, 101, 52, .28);
}
.brand-lockup { display: flex; gap: 12px; align-items: center; }
.brand-lockup strong { display: block; font-size: 18px; }
.brand-lockup span { color: var(--muted); font-size: 12px; }

.auth-shell,
.setup-card {
  width: min(980px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.auth-shell { display: grid; grid-template-columns: 1.05fr .95fr; }
.auth-hero {
  padding: 54px;
  background:
    radial-gradient(circle at top right, rgba(134, 239, 172, .55), transparent 38%),
    linear-gradient(145deg, #14532d, #166534 64%, #15803d);
  color: white;
  min-height: 610px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.auth-hero .brand-mark { background: white; color: var(--primary); box-shadow: none; }
.auth-hero h1 { font-size: clamp(38px, 6vw, 62px); line-height: .98; letter-spacing: -.055em; margin: 44px 0 18px; }
.auth-hero p { max-width: 430px; color: rgba(255,255,255,.78); font-size: 17px; line-height: 1.6; }
.hero-points { display: grid; gap: 12px; }
.hero-point { display: flex; gap: 10px; align-items: center; color: rgba(255,255,255,.9); }
.hero-point::before { content: "✓"; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.15); }
.auth-panel { padding: 46px; align-self: center; }
.auth-panel h2 { margin: 0 0 8px; font-size: 30px; letter-spacing: -.035em; }
.auth-panel > p { margin: 0 0 28px; color: var(--muted); }
.auth-tabs { display: flex; padding: 4px; background: var(--surface-soft); border-radius: 12px; margin-bottom: 24px; }
.auth-tab { flex: 1; border: 0; border-radius: 9px; padding: 10px; color: var(--muted); background: transparent; font-weight: 700; }
.auth-tab.active { color: var(--primary); background: white; box-shadow: 0 2px 8px rgba(0,0,0,.06); }

.setup-card { max-width: 720px; padding: 42px; }
.setup-card h1 { margin: 18px 0 8px; }
.setup-card code { background: #eef2ef; padding: 2px 6px; border-radius: 6px; }
.setup-steps { margin: 26px 0; display: grid; gap: 14px; }
.setup-step { display: grid; grid-template-columns: 34px 1fr; gap: 12px; align-items: start; }
.step-number { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: var(--primary); background: var(--primary-soft); font-weight: 800; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: grid; gap: 7px; }
.field-full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 750; color: #324139; }
.field small { color: var(--muted); line-height: 1.45; }
.input,
.select,
.textarea {
  width: 100%;
  border: 1px solid #cfd9d3;
  border-radius: 12px;
  background: white;
  color: var(--text);
  padding: 12px 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.textarea { min-height: 94px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: #46a66c; box-shadow: 0 0 0 4px rgba(34, 197, 94, .12); }
.input[disabled], .select[disabled] { background: #f1f4f2; color: #88938d; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-weight: 800;
  text-decoration: none;
  transition: transform .15s, background .15s, border-color .15s, opacity .15s;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { cursor: not-allowed; opacity: .55; transform: none; }
.btn-primary { color: white; background: var(--primary); }
.btn-primary:hover { background: var(--primary-strong); }
.btn-secondary { color: var(--text); background: white; border-color: var(--line); }
.btn-soft { color: var(--primary); background: var(--primary-soft); }
.btn-danger { color: white; background: var(--danger); }
.btn-danger-soft { color: var(--danger); background: var(--danger-soft); }
.btn-block { width: 100%; }
.btn-lg { min-height: 52px; font-size: 16px; border-radius: 14px; }
.btn-sm { min-height: 34px; padding: 7px 11px; border-radius: 9px; font-size: 13px; }
.link-button { border: 0; background: transparent; color: var(--primary); padding: 4px; font-weight: 750; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions-end { justify-content: flex-end; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-width) 1fr; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  background: #10231a;
  color: white;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  z-index: 30;
}
.sidebar .brand-lockup span { color: rgba(255,255,255,.55); }
.sidebar-nav { margin-top: 34px; display: grid; gap: 7px; }
.nav-button {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  padding: 10px 12px;
  color: rgba(255,255,255,.72);
  background: transparent;
  text-align: left;
  font-weight: 700;
}
.nav-button:hover, .nav-button.active { color: white; background: rgba(255,255,255,.1); }
.nav-icon { width: 24px; text-align: center; font-size: 17px; }
.sidebar-footer { margin-top: auto; padding-top: 20px; border-top: 1px solid rgba(255,255,255,.1); }
.user-summary { display: grid; grid-template-columns: 38px 1fr; gap: 10px; align-items: center; margin-bottom: 14px; }
.avatar { width: 38px; height: 38px; border-radius: 12px; background: rgba(134, 239, 172, .18); color: #bbf7d0; display: grid; place-items: center; font-weight: 900; }
.user-summary strong { display: block; font-size: 13px; }
.user-summary span { display: block; color: rgba(255,255,255,.52); font-size: 12px; margin-top: 2px; }

.main { grid-column: 2; min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 30px;
  border-bottom: 1px solid rgba(223, 231, 226, .9);
  background: rgba(244, 247, 245, .9);
  backdrop-filter: blur(14px);
}
.topbar h1 { margin: 0; font-size: 22px; letter-spacing: -.03em; }
.topbar p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.content { padding: 28px 30px 90px; max-width: 1500px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; margin-bottom: 24px; }
.page-head h2 { margin: 0 0 6px; font-size: 28px; letter-spacing: -.04em; }
.page-head p { margin: 0; color: var(--muted); }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card, .card {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(20, 32, 26, .04);
}
.stat-card { padding: 18px; }
.stat-card .stat-top { display: flex; justify-content: space-between; gap: 10px; align-items: center; color: var(--muted); font-size: 13px; }
.stat-icon { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; background: var(--surface-soft); }
.stat-card strong { display: block; margin-top: 15px; font-size: 30px; letter-spacing: -.05em; }
.stat-card small { display: block; color: var(--muted); margin-top: 4px; }
.card { padding: 20px; }
.card + .card { margin-top: 18px; }
.card-head { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 18px; }
.card-head h3 { margin: 0; font-size: 18px; letter-spacing: -.025em; }
.card-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(320px, .8fr); gap: 18px; }
.grid-equal { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th { background: #f7faf8; color: var(--muted); font-size: 12px; text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 14px; border-bottom: 1px solid #edf1ee; font-size: 14px; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.table-primary { font-weight: 800; }
.table-secondary { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.empty-state { padding: 42px 20px; text-align: center; border: 1px dashed #cbd8d0; border-radius: 14px; color: var(--muted); }
.empty-icon { font-size: 34px; margin-bottom: 12px; }

.status { display: inline-flex; align-items: center; gap: 6px; min-height: 26px; padding: 4px 9px; border-radius: 999px; font-size: 11px; font-weight: 850; white-space: nowrap; }
.status-draft, .status-pending { color: #475467; background: #f2f4f7; }
.status-ready, .status-assigned { color: #175cd3; background: #eaf2ff; }
.status-started, .status-in_route, .status-next_delivery { color: #93370d; background: #fff0c7; }
.status-delivered, .status-completed { color: #067647; background: #dcfae6; }
.status-not_delivered, .status-cancelled { color: #b42318; background: #fee4e2; }
.status-rescheduled { color: #6941c6; background: #f0eaff; }

.progress { height: 9px; border-radius: 999px; overflow: hidden; background: #e8eeea; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #22c55e, #15803d); }
.progress-row { display: flex; align-items: center; gap: 10px; }
.progress-row .progress { flex: 1; }
.progress-row strong { font-size: 12px; min-width: 40px; text-align: right; }

.route-card-list { display: grid; gap: 12px; }
.route-card { border: 1px solid var(--line); border-radius: 15px; padding: 16px; background: white; transition: border-color .15s, transform .15s; }
.route-card:hover { border-color: #9ec7ac; transform: translateY(-1px); }
.route-card-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.route-card h3 { margin: 0 0 5px; font-size: 16px; }
.route-card p { margin: 0; color: var(--muted); font-size: 13px; }
.route-metrics { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 15px; color: var(--muted); font-size: 12px; }
.route-metrics strong { color: var(--text); }

.map { width: 100%; min-height: 430px; border-radius: 15px; overflow: hidden; background: #e9efeb; border: 1px solid var(--line); }
.route-marker-wrapper { background: transparent; border: 0; }
.route-marker { width: 34px; height: 34px; border: 3px solid white; border-radius: 50% 50% 50% 8px; transform: rotate(-45deg); display: grid; place-items: center; color: white; font-size: 12px; font-weight: 900; box-shadow: 0 5px 14px rgba(0,0,0,.22); background: #64748b; }
.route-marker span { transform: rotate(45deg); display: block; }
.marker-origin { background: #111827; }
.marker-pending { background: #2563eb; }
.marker-next { background: #f59e0b; }
.marker-delivered { background: #16a34a; }
.marker-problem { background: #dc2626; }

.stop-list { display: grid; gap: 11px; }
.stop-card { display: grid; grid-template-columns: 42px 1fr auto; gap: 13px; align-items: start; border: 1px solid var(--line); border-radius: 15px; padding: 14px; background: white; }
.stop-card.next { border-color: #f4b740; box-shadow: 0 0 0 3px rgba(245, 158, 11, .12); }
.stop-number { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; color: var(--primary); background: var(--primary-soft); font-weight: 900; }
.stop-card h4 { margin: 0 0 5px; font-size: 15px; }
.stop-card p { margin: 3px 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.stop-meta { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 9px; color: var(--muted); font-size: 11px; }
.stop-actions { display: grid; gap: 7px; min-width: 126px; }

.route-form-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; align-items: start; }
.sticky-card { position: sticky; top: 90px; }
.delivery-editor { display: grid; gap: 12px; }
.delivery-row { border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: #fbfdfb; }
.delivery-row-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.delivery-row-head strong { font-size: 14px; }
.summary-list { display: grid; gap: 12px; }
.summary-item { display: flex; justify-content: space-between; gap: 14px; color: var(--muted); font-size: 13px; }
.summary-item strong { color: var(--text); }
.notice { padding: 13px 14px; border-radius: 12px; color: #694a05; background: var(--warning-soft); font-size: 13px; line-height: 1.5; }
.notice-info { color: #164c94; background: var(--info-soft); }
.notice-danger { color: var(--danger); background: var(--danger-soft); }

.driver-shell { min-height: 100vh; max-width: 760px; margin: 0 auto; background: var(--bg); padding-bottom: 92px; }
.driver-header { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 17px; background: rgba(244,247,245,.94); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.driver-header .brand-mark { width: 40px; height: 40px; border-radius: 12px; font-size: 13px; }
.driver-content { padding: 18px 14px; }
.driver-hero { padding: 20px; color: white; background: linear-gradient(145deg, #14532d, #15803d); border-radius: 20px; box-shadow: 0 14px 36px rgba(20,83,45,.22); }
.driver-hero h1 { margin: 0 0 6px; font-size: 24px; letter-spacing: -.04em; }
.driver-hero p { margin: 0; color: rgba(255,255,255,.72); }
.driver-hero .route-metrics { color: rgba(255,255,255,.67); margin: 20px 0; }
.driver-hero .route-metrics strong { color: white; }
.driver-progress { margin-top: 16px; }
.driver-progress .progress { background: rgba(255,255,255,.2); }
.driver-progress .progress > span { background: #bbf7d0; }
.driver-section-title { display: flex; justify-content: space-between; align-items: center; margin: 22px 2px 11px; }
.driver-section-title h2 { margin: 0; font-size: 18px; }
.driver-stop { border: 1px solid var(--line); border-radius: 18px; background: white; padding: 17px; margin-bottom: 12px; box-shadow: 0 5px 20px rgba(20,32,26,.035); }
.driver-stop.next { border: 2px solid #f5b333; }
.driver-stop.completed { opacity: .72; }
.driver-stop-top { display: flex; gap: 12px; align-items: flex-start; }
.driver-stop .stop-number { flex: 0 0 auto; }
.driver-stop h3 { margin: 1px 0 4px; font-size: 17px; }
.driver-stop p { margin: 4px 0; color: var(--muted); line-height: 1.45; }
.driver-stop-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 16px; }
.driver-stop-actions .btn:first-child { grid-column: 1 / -1; }
.mobile-nav { position: fixed; inset: auto 0 0; z-index: 25; max-width: 760px; margin: auto; display: grid; grid-template-columns: repeat(3,1fr); padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.96); backdrop-filter: blur(14px); border-top: 1px solid var(--line); }
.mobile-nav button { border: 0; background: transparent; padding: 7px; color: var(--muted); font-size: 11px; font-weight: 750; }
.mobile-nav button span { display: block; font-size: 20px; margin-bottom: 3px; }
.mobile-nav button.active { color: var(--primary); }

.modal-backdrop { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 18px; background: rgba(10, 21, 15, .58); backdrop-filter: blur(3px); }
.modal-card { position: relative; width: min(520px, 100%); max-height: min(88vh, 900px); overflow-y: auto; border-radius: 20px; background: white; padding: 24px; box-shadow: 0 28px 80px rgba(0,0,0,.28); }
.modal-wide { width: min(920px, 100%); }
.modal-close { position: absolute; top: 12px; right: 12px; width: 34px; height: 34px; border: 0; border-radius: 10px; background: #f1f4f2; font-size: 22px; }
.modal-card h2 { margin: 0 38px 7px 0; letter-spacing: -.035em; }
.modal-card > p { margin: 0 0 20px; color: var(--muted); }

.toast-region { position: fixed; top: 18px; right: 18px; z-index: 2000; display: grid; gap: 10px; width: min(380px, calc(100vw - 36px)); }
.toast { transform: translateY(-10px); opacity: 0; padding: 13px 15px; color: white; background: #25332c; border-radius: 12px; box-shadow: 0 14px 35px rgba(0,0,0,.18); transition: opacity .2s, transform .2s; font-weight: 700; font-size: 13px; }
.toast-visible { transform: translateY(0); opacity: 1; }
.toast-error { background: #9f1d16; }
.toast-warning { background: #8a4c04; }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: white; border-radius: 50%; animation: spin .7s linear infinite; }
.btn-secondary .spinner { border-color: rgba(20,32,26,.2); border-top-color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .route-form-layout { grid-template-columns: 1fr; }
  .sticky-card { position: static; }
}

@media (max-width: 820px) {
  .auth-shell { grid-template-columns: 1fr; max-width: 560px; }
  .auth-hero { display: none; }
  .app-shell { display: block; }
  .sidebar { display: none; }
  .main { grid-column: auto; }
  .content { padding: 20px 14px 82px; }
  .topbar { padding: 11px 14px; }
  .page-head { align-items: stretch; flex-direction: column; }
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
  .field-full { grid-column: auto; }
  .grid-equal { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .auth-panel, .setup-card { padding: 28px 20px; }
  .auth-shell, .setup-card { border-radius: 20px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-card strong { font-size: 25px; }
  .card { padding: 16px; border-radius: 16px; }
  .map { min-height: 330px; }
  .stop-card { grid-template-columns: 38px 1fr; }
  .stop-actions { grid-column: 1 / -1; grid-template-columns: 1fr 1fr; }
  .driver-stop-actions { grid-template-columns: 1fr; }
  .driver-stop-actions .btn:first-child { grid-column: auto; }
  .modal-card { padding: 22px 17px; border-radius: 18px; }
}
