:root {
  color-scheme: light;
  --ink: #172121;
  --muted: #667171;
  --line: #dde4e1;
  --paper: #f5f7f6;
  --surface: #ffffff;
  --brand: #ff5b2d;
  --brand-dark: #da3d12;
  --brand-soft: #fff0e9;
  --success: #138a5b;
  --warning: #b26a00;
  --danger: #c83f49;
  --shadow: 0 16px 44px rgba(28, 42, 39, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top, #fff0e9, var(--paper) 48%); }
.login-card { width: min(440px, 100%); padding: 28px; border: 1px solid var(--line); border-radius: 24px; background: white; box-shadow: var(--shadow); }
.login-card h2 { font-size: 1.8rem; }
.login-form { margin: 22px 0 14px; }
.demo-logins { display: flex; flex-wrap: wrap; gap: 7px; }
.user-area { display: flex; align-items: center; gap: 14px; text-align: right; }
.user-area span { display: block; margin-top: 2px; }

.topbar {
  max-width: 1180px;
  margin: 0 auto;
  padding: 34px 24px 20px;
  display: flex;
  justify-content: space-between;
  align-items: end;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(2.2rem, 6vw, 4rem); letter-spacing: -0.08em; line-height: .85; }
h1 span { color: var(--brand); }
h2 { margin-bottom: 6px; font-size: 1.35rem; }
h3 { margin-bottom: 4px; font-size: 1rem; }
.eyebrow { margin-bottom: 8px; font-size: .72rem; font-weight: 800; letter-spacing: .15em; color: var(--brand-dark); }
.muted { color: var(--muted); }
.small { font-size: .82rem; }

.live { display: flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 700; }
.live i { display: block; width: 9px; height: 9px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 5px rgba(19, 138, 91, .12); }

.tabs { max-width: 1180px; margin: 0 auto 22px; padding: 0 24px; display: flex; gap: 8px; }
.tab, button.ghost {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 750;
}
.tab.active { background: var(--ink); border-color: var(--ink); color: white; }

.manager-nav {
  position: sticky;
  top: 8px;
  z-index: 500;
  display: flex;
  gap: 7px;
  overflow-x: auto;
  margin-bottom: 18px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(245, 247, 246, .94);
  backdrop-filter: blur(12px);
}
.manager-nav-button { flex: 0 0 auto; min-height: 40px; padding: 8px 13px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); font-weight: 800; }
.manager-nav-button.active { background: var(--ink); color: white; }
.manager-panel { display: none; }
.manager-panel.active { display: block; }

main { max-width: 1180px; margin: 0 auto; padding: 0 24px 72px; }
.panel { display: none; }
.panel.active { display: block; }
.layout { display: grid; grid-template-columns: 1.05fr .95fr; gap: 18px; }
.surface { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 22px; box-shadow: var(--shadow); margin-bottom: 18px; }
.hero-surface { min-height: 420px; }
.section-heading { display: flex; justify-content: space-between; align-items: start; gap: 16px; margin-bottom: 18px; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--ink); color: white; border-radius: 18px; padding: 18px; }
.stat span { color: #bdc9c6; font-size: .78rem; font-weight: 700; }
.stat strong { display: block; margin-top: 8px; font-size: 1.9rem; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.management-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.management-records { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.finance-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.compact-form { display: grid; align-content: start; gap: 10px; padding: 16px; border: 1px solid var(--line); border-radius: 15px; }
.filter-form { background: #fafcfb; }
.compact-form h3 { margin-bottom: 3px; }
.spaced { margin-top: 16px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: .8rem; font-weight: 750; }
input, select, textarea { width: 100%; min-height: 43px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 11px; background: white; color: var(--ink); }
textarea { resize: vertical; line-height: 1.45; }
.check-row { display: flex; align-items: center; gap: 9px; min-height: 38px; color: var(--ink); }
.check-row input { width: 18px; min-height: 18px; height: 18px; accent-color: var(--brand); }
.wide { grid-column: 1 / -1; }

button.primary, button.secondary, button.danger {
  border: 0;
  border-radius: 12px;
  min-height: 43px;
  padding: 10px 15px;
  font-weight: 800;
}
button.map-pick { border: 1px dashed var(--brand); border-radius: 12px; min-height: 43px; padding: 10px 13px; background: #fff8f4; color: var(--brand-dark); font-weight: 800; }
button.map-pick.active { background: var(--brand); color: white; }
button.primary { background: var(--brand); color: white; }
button.primary:hover { background: var(--brand-dark); }
button.secondary { background: var(--brand-soft); color: var(--brand-dark); }
button.danger { background: #fff0f1; color: var(--danger); }
button:disabled { opacity: .45; cursor: not-allowed; }

.stack { display: grid; gap: 10px; }
.item { border: 1px solid var(--line); border-radius: 15px; padding: 15px; }
.item-top { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.item-meta { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.tag { display: inline-flex; align-items: center; min-height: 26px; padding: 4px 9px; border-radius: 999px; background: #edf1ef; color: #42504d; font-size: .72rem; font-weight: 800; }
.tag.brand { background: var(--brand-soft); color: var(--brand-dark); }
.tag.success { background: #e8f7f0; color: var(--success); }
.tag.warning { background: #fff4dc; color: var(--warning); }
.tag.danger { background: #fff0f1; color: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 13px; }
.actions.no-margin { margin-top: 0; }
.amount { font-size: 1.3rem; font-weight: 850; }
.empty { padding: 34px 10px; text-align: center; color: var(--muted); }
.compact-list { max-height: 600px; overflow: auto; padding-right: 4px; }
.compact-item { padding: 12px; }
.cancel-note { margin: 11px 0 0; padding: 9px 11px; border-radius: 9px; background: #fff0f1; color: var(--danger); }
.callout { margin-top: 14px; padding: 12px; border-left: 4px solid var(--warning); border-radius: 8px; background: #fff8e8; color: #74500f; }
.order-contents { margin-top: 11px; padding: 11px 12px; border-radius: 11px; background: #f7f9f8; color: var(--ink); }
.order-contents strong { display: block; margin-bottom: 6px; font-size: .78rem; }
.order-contents ul { margin: 0; padding-left: 19px; color: var(--muted); font-size: .82rem; }
.order-contents p { margin: 7px 0 0; color: var(--muted); font-size: .82rem; }
.courier-profile { border-color: #ffc1ad; box-shadow: 0 0 0 3px var(--brand-soft), var(--shadow); }
.profile-heading { align-items: center; }
.profile-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.profile-section { min-width: 0; padding: 15px; border: 1px solid var(--line); border-radius: 15px; background: #fafcfb; }
.profile-wide { grid-column: 1 / -1; }
.performance-list { display: grid; gap: 12px; }
.performance-card { padding: 17px; border: 1px solid var(--line); border-radius: 17px; background: #fff; }
.performance-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 13px; }
.performance-card-head p { margin-bottom: 0; }
.performance-head-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.performance-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; }
.performance-metric { min-width: 0; padding: 11px 12px; border-radius: 12px; background: #f3f6f5; }
.performance-metric span { display: block; min-height: 30px; color: var(--muted); font-size: .7rem; font-weight: 800; line-height: 1.25; text-transform: uppercase; }
.performance-metric strong { display: block; margin-top: 5px; overflow-wrap: anywhere; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.performance-metric.highlight { background: #e8f7f0; color: var(--success); }
.performance-metric.warning { background: #fff4dc; color: var(--warning); }
.period-toolbar { display: grid; grid-template-columns: minmax(150px, .6fr) minmax(190px, .8fr) 1fr; align-items: end; gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: 15px; background: #fafcfb; }
.period-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 7px; }
.period-actions button { min-height: 43px; }
.period-card { background: linear-gradient(180deg, #fff, #fcfdfc); }
.period-total { flex: 0 0 auto; text-align: right; }
.period-total strong { display: block; color: var(--brand-dark); font-size: 2rem; line-height: 1; font-variant-numeric: tabular-nums; }
.period-total span { display: block; margin-top: 5px; color: var(--muted); font-size: .72rem; font-weight: 800; }
.period-summary { margin-bottom: 10px; }
.daily-breakdown { display: grid; grid-template-columns: repeat(7, minmax(100px, 1fr)); gap: 7px; overflow-x: auto; padding: 2px 0 5px; }
.daily-breakdown.single-day { grid-template-columns: minmax(220px, 1fr); }
.daily-cell { min-width: 100px; padding: 10px; border: 1px solid var(--line); border-radius: 11px; background: #fafcfb; }
.daily-cell span, .daily-cell small { display: block; color: var(--muted); font-size: .68rem; }
.daily-cell strong { display: block; margin: 7px 0 4px; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.daily-cell.has-delivery { border-color: #a7ddc5; background: #eef9f3; }
.modal-open { overflow: hidden; }
.modal-backdrop { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; padding: 20px; background: rgba(23, 33, 33, .58); backdrop-filter: blur(4px); }
.modal-card { width: min(520px, 100%); padding: 24px; border: 1px solid var(--line); border-radius: 20px; background: white; box-shadow: 0 24px 80px rgba(0, 0, 0, .24); }
.wide-modal { width: min(720px, 100%); }
.modal-form { margin-top: 18px; padding: 0; border: 0; }
.assignment-history { margin-top: 12px; border: 1px solid var(--line); border-radius: 11px; background: #fafcfb; }
.assignment-history summary { cursor: pointer; padding: 10px 12px; color: var(--muted); font-size: .78rem; font-weight: 800; }
.history-row { display: grid; gap: 3px; padding: 9px 12px; border-top: 1px solid var(--line); font-size: .76rem; }
.history-row span { color: var(--muted); }
.route-order { margin-top: 12px; border-left: 5px solid #4c82d4; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 760px; }
.data-table.account-table { min-width: 520px; }
.data-table th, .data-table td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; font-size: .82rem; }
.data-table th { color: var(--muted); font-size: .7rem; letter-spacing: .04em; text-transform: uppercase; }
.data-table tbody tr:hover { background: #fafcfb; }
.data-table .numeric { text-align: right; font-variant-numeric: tabular-nums; }
.success-text { color: var(--success); font-weight: 800; }

.event-item { display: grid; grid-template-columns: auto 1fr; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.event-item:last-child { border-bottom: 0; }
.event-item p { margin: 3px 0 0; }
.event-dot { width: 10px; height: 10px; margin-top: 5px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 5px var(--brand-soft); }

.courier-hero { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; padding: 18px; border-radius: 18px; background: var(--ink); color: white; }
.courier-hero .muted { color: #b8c5c1; }
.courier-state { text-align: right; }
.courier-state strong { display: block; font-size: 1.15rem; color: #ffb199; }
.countdown { font-variant-numeric: tabular-nums; }

.map-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
#map-instruction { color: var(--brand-dark); font-size: .88rem; }
#network-map { width: 100%; height: 430px; margin-bottom: 16px; border: 1px solid var(--line); border-radius: 17px; overflow: hidden; background: #dfe8e5; }
#dispatch-map { width: 100%; height: 420px; border: 1px solid var(--line); border-radius: 17px; overflow: hidden; background: #dfe8e5; }
#delivery-picker-map { width: 100%; height: 430px; border: 1px solid var(--line); border-radius: 15px; overflow: hidden; background: #dfe8e5; }
.map-modal { width: min(900px, calc(100vw - 32px)); }
.coordinate-output { display: block; min-height: 38px; padding: 9px 11px; border-radius: 10px; background: #edf1ef; color: var(--muted); font-size: .78rem; }
.coordinate-output.invalid { background: #fff0f1; color: var(--danger); }
.coordinate-output.pending { background: #fff6d9; color: #805700; }
.map-legend { display: flex; gap: 6px; flex-wrap: wrap; }
.legend { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 10px; padding: 5px 9px; border-radius: 999px; background: #edf1ef; color: var(--muted); font-size: .72rem; font-weight: 800; }
.legend::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.legend.zone { color: var(--success); }
.legend.restaurant { color: var(--brand-dark); }
.legend.courier { color: #2457a7; }
.zone-vertex { width: 18px; height: 18px; border: 3px solid var(--brand-dark); border-radius: 50%; background: white; box-shadow: 0 3px 10px rgba(23, 33, 33, .25); }
.record-editing { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

#toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(390px, calc(100vw - 40px));
  padding: 13px 16px;
  border-radius: 13px;
  background: var(--ink);
  color: white;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: .2s ease;
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.error { background: var(--danger); }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .management-grid { grid-template-columns: 1fr; }
  .management-records { grid-template-columns: 1fr; }
  .finance-columns { grid-template-columns: 1fr; }
  .profile-grid { grid-template-columns: 1fr; }
  .profile-wide { grid-column: auto; }
  .period-toolbar { grid-template-columns: 1fr 1fr; }
  .period-actions { grid-column: 1 / -1; justify-content: flex-start; }
}

@media (max-width: 560px) {
  .topbar { padding-top: 24px; }
  .tabs { overflow-x: auto; }
  main { padding-inline: 14px; }
  .topbar, .tabs { padding-inline: 14px; }
  .surface { border-radius: 17px; padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .wide { grid-column: auto; }
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { padding: 14px; }
  .item-top, .section-heading { flex-direction: column; }
  .courier-hero { grid-template-columns: 1fr; }
  .courier-state { text-align: left; }
  .performance-card-head { flex-direction: column; }
  .performance-head-actions { justify-content: flex-start; }
  .period-toolbar { grid-template-columns: 1fr; }
  .period-actions { grid-column: auto; }
  .period-total { text-align: left; }
  #network-map { height: 340px; }
  #dispatch-map { height: 350px; }
  #delivery-picker-map { height: 330px; }
  .map-toolbar, .user-area { align-items: stretch; flex-direction: column; text-align: left; }
}
