:root {
  color-scheme: light;
  --ink: #172d36;
  --muted: #526771;
  --line: #dce6e8;
  --paper: #fff;
  --surface: #f2f6f7;
  --accent: #12634f;
  --accent-soft: #e5f3ed;
  --danger: #a12734;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--surface);
  color: var(--ink);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid #308878; outline-offset: 3px; }

.topbar { background: #142e36; color: var(--paper); }
.topbar-inner {
  margin: auto;
  max-width: 1320px;
  padding: 0 clamp(18px, 4vw, 52px);
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 48px;
}
.brand { display: inline-flex; align-items: center; gap: 11px; color: #fff; font-size: 1.1rem; font-weight: 720; }
.brand-mark { display: flex; gap: 3px; align-items: end; padding: 7px; border-radius: 8px; background: #c5efdc; }
.brand-mark i { width: 4px; height: 8px; border-radius: 2px; background: #1c5849; }
.brand-mark i:nth-child(2) { height: 12px; }
.brand-mark i:nth-child(3) { height: 16px; }

.shell { margin: auto; max-width: 1320px; padding: clamp(26px, 5vw, 56px) clamp(18px, 4vw, 52px); }
.shell:has(.planner) { max-width: 1640px; }
.page-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 18px; margin: 0 0 25px; }
.planner-heading { margin-bottom: 16px; }
h1 { margin: 0; font-size: clamp(1.75rem, 3.3vw, 2.65rem); letter-spacing: -.045em; line-height: 1.12; }
h2 { font-size: 1.12rem; margin: 0; letter-spacing: -.02em; }
p { line-height: 1.55; }
.page-heading p { color: var(--muted); margin: 9px 0 0; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 3px 14px #22394206; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; border-radius: 8px; border: 1px solid transparent; padding: 9px 14px; font-size: .94rem; font-weight: 650; white-space: nowrap; }
.button:hover { text-decoration: none; }
.primary { background: var(--accent); color: #fff; }
.primary:hover { background: #0c4d3d; }
.secondary { background: #fff; border-color: #c8d8da; color: #233e48; }
.secondary:hover { background: #edf4f5; }
.danger { color: var(--danger); border-color: #e4bbc0; background: #fff; }
.danger:hover { background: #fff0f2; }

.filters { display: flex; align-items: end; justify-content: space-between; gap: 18px; flex-wrap: wrap; padding: 20px 24px; border-bottom: 1px solid var(--line); }
.plan-views, .day-tabs { display: flex; gap: 4px; overflow-x: auto; align-items: stretch; }
.plan-views { margin-bottom: 12px; }
.plan-views a, .day-tabs a { padding: 10px 13px; white-space: nowrap; color: var(--muted); font-size: .9rem; font-weight: 650; }
.plan-views a { border-radius: 7px; }
.plan-views .selected { background: var(--accent); color: #fff; }
.day-tabs { padding: 6px 10px 0; border-bottom: 1px solid var(--line); background: #f6f9fa; border-radius: 14px 14px 0 0; }
.day-tabs a { border-bottom: 3px solid transparent; }
.day-tabs .selected { color: var(--accent); border-color: var(--accent); }
.day-tabs time { display: block; margin-top: 2px; font-size: .8rem; font-weight: 500; }
.filter-form { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; }
.filter-form [type="search"] { width: min(100%, 260px); }
label { display: block; font-size: .9rem; font-weight: 650; }
input, textarea { display: block; width: 100%; margin-top: 6px; min-height: 42px; padding: 9px 11px; border: 1px solid #c5d5d8; color: var(--ink); background: #fff; border-radius: 8px; font-weight: 400; }
textarea { resize: vertical; }
.list-heading { padding: 17px 24px; display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.list-heading span { color: var(--muted); font-size: .9rem; }
.table-scroll { overflow-x: auto; }
.sheet { width: 100%; min-width: 1060px; border-collapse: collapse; text-align: left; font-size: .9rem; }
.sheet th, .sheet td { padding: 9px 10px; vertical-align: top; overflow-wrap: anywhere; border: 1px solid var(--line); }
.sheet th:first-child, .sheet td:first-child { border-left: 0; }
.sheet th:last-child, .sheet td:last-child { border-right: 0; }
.sheet th { background: #d5eef2; color: #234752; white-space: nowrap; }
.personal-plan .sheet th { background: #d9ead3; color: #2a4434; }
.sheet tr:last-child td { border-bottom: 0; }
.sheet tbody tr:hover { background: #f7fbfa; }
.sheet-origin, .sheet-destination { min-width: 140px; }
.sheet-comment { min-width: 110px; white-space: pre-wrap; }
.planner .sheet :is(th, td) { padding-inline: 7px; }
.planner .sheet-origin, .planner .sheet-destination { min-width: 120px; }
.planner .sheet-comment { min-width: 104px; }
.planner .sheet-phone { min-width: 106px; }
.planner .sheet-invoice { min-width: 88px; }
.planner .sheet-pickup, .planner .sheet-delivery { min-width: 108px; }
.sheet-delivery_date, .sheet-time { white-space: nowrap; }
.row-actions { display: grid; justify-items: start; gap: 5px; white-space: nowrap; font-weight: 650; }
.row-button { border: 0; padding: 0; background: transparent; color: var(--accent); font: inherit; }
.row-button:hover { text-decoration: underline; }
.row-delete { color: var(--danger); }
.route-panel { padding: clamp(16px, 3vw, 24px); margin-bottom: 14px; }
.route-panel h2 { margin-bottom: 12px; }
.route-controls { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; margin: 0 0 14px; }
.route-controls[hidden] { display: none; }
.route-controls select {
  display: block; width: 100%; max-width: min(52ch, 78vw); min-height: 42px; margin-top: 6px; padding: 8px;
  border: 1px solid #c5d5d8; border-radius: 8px; background: var(--paper); color: var(--ink); font: inherit;
}
.route-list, .route-stops { list-style: none; padding: 0; }
.route-list li { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.route-list a, .route-panel summary { font-weight: 650; }
.route-table { min-width: 760px; }
.ledger-table { min-width: 860px; }
.review-list { margin: 0; padding-left: 18px; }
.archive-meta { display: block; margin-top: 3px; color: var(--muted); font-size: .9em; white-space: pre-wrap; }
.waybill-candidates { min-width: 760px; }
.waybill-pick, .route-point-pick { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.waybill-pick input, .route-point-pick input { width: 16px; height: 16px; min-height: 0; margin: 0; accent-color: var(--accent); }
.route-points-scroll { max-height: min(55vh, 36rem); overflow: auto; }
.route-points-scroll th { position: sticky; top: 0; z-index: 1; }
.route-order-list { list-style: none; padding: 0; }
.route-order-list li {
  display: grid; grid-template-columns: 2em minmax(0, 1fr) auto; gap: 8px;
  align-items: start; padding: 8px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere;
}
.route-order-list select { min-height: 36px; font: inherit; }
.route-order-list input[type="number"] { width: 4.5rem; min-height: 36px; }
.waybill-save { margin-top: 16px; }
.directory-columns { display: grid; grid-template-columns: minmax(190px, .65fr) minmax(0, 1fr); gap: 14px; }
.directory-list { margin: 0; padding-left: 20px; overflow-wrap: anywhere; }
.directory-list li + li { margin-top: 8px; }
.directory-controls { margin: 16px 0 0; }
.directory-columns select {
  display: block; width: 100%; min-height: 42px; margin-top: 6px; padding: 8px;
  border: 1px solid #c5d5d8; border-radius: 8px; background: var(--paper); color: var(--ink); font: inherit;
}
@media (max-width: 720px) {
  .directory-columns { grid-template-columns: 1fr; }
}
.waybill-print { max-width: 920px; margin: auto; padding: clamp(18px, 4vw, 42px); overflow-wrap: anywhere; }
.waybill-toolbar { display: flex; flex-wrap: wrap; gap: 8px 18px; max-width: 920px; margin: 0 auto 16px; }
.waybill-toolbar > :not(a) { flex-basis: 100%; }
.waybill-toolbar p { margin: 0; color: var(--muted); }
.waybill-heading { text-align: center; }
.waybill-heading p { margin: 0 0 10px; }
.waybill-director { text-align: right; }
.waybill-firm strong { font-size: 1.15em; }
.waybill-draft-label { color: var(--muted); font-weight: 650; }
.waybill-print h1 { font-size: clamp(1.45rem, 3vw, 2rem); }
.waybill-print dl { display: grid; grid-template-columns: minmax(110px, 180px) 1fr; gap: 8px 12px; }
.waybill-print dd { margin: 0; }
.waybill-print table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.waybill-print td, .waybill-print th { width: 33.3%; padding: 9px; border: 1px solid var(--line); text-align: left; vertical-align: top; }
.waybill-print th { text-align: center; }

@media print {
  @page waybill { size: A4 portrait; margin: 12mm; }
  :root:has(.waybill-print) { background: #fff; }
  body:has(.waybill-print) { page: waybill; min-height: 0; color: #000; background: #fff; }
  body:has(.waybill-print) .topbar, .waybill-toolbar { display: none; }
  .shell:has(.waybill-print) { padding: 0; }
  .waybill-print { max-width: none; margin: 0; border: 0; padding: 0; box-shadow: none; font: 10pt/1.35 Arial, sans-serif; }
  .waybill-print h1 { font-size: 16pt; letter-spacing: normal; }
  .waybill-print dl { grid-template-columns: 53mm 1fr; }
  .waybill-print dt { text-align: right; }
  .waybill-print table { width: calc(100% - 1px); border: 1px solid #000; line-height: 1.25; }
  .waybill-print th, .waybill-print td { width: auto; border-color: #000; padding: 2mm; }
  .waybill-print thead { display: table-header-group; }
  .waybill-print tr { break-inside: avoid; }
}
.route-table tbody th { background: var(--paper); font-size: inherit; }
.reschedule summary { cursor: pointer; white-space: nowrap; }
.reschedule[open] { min-width: 190px; }
.reschedule .route-controls { margin: 8px 0 0; }
.reschedule + .reschedule { margin-top: 8px; }
.cancelled-requests { margin-top: 14px; }
.stop-header { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 16px; }
.stop-header h2 { margin: 0; }
.stop-address { font-size: 1.12rem; font-weight: 650; overflow-wrap: anywhere; }
.stop-address-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 14px; }
.driver-refresh {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; flex-wrap: wrap;
  gap: 6px 12px; padding: 8px 0; margin-bottom: 12px; background: var(--surface);
}
.driver-refresh .notice { flex-basis: 100%; margin: 0; }
.driver-checked { flex-basis: 100%; margin: 0; color: var(--muted); font-size: .88rem; }
.driver-refresh .notice:empty, [data-route-next]:empty { display: none; }
[data-route-stop], #driver-removed-stops { scroll-margin-block-start: var(--route-stop-offset, 12rem); }
.stop-result { color: var(--muted); font-size: .9rem; }
.stop-result.done { color: var(--accent); }
.stop-result.partial { color: #805c13; }
.stop-result.cancelled { color: var(--danger); }
.stop-details { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); gap: 12px; }
.stop-details dt { color: var(--muted); font-size: .85rem; }
.stop-details dd { margin: 4px 0 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.stop-address-row .button, .driver-refresh .button { min-height: 44px; }
.stop-details a[href^="tel:"] { display: inline-flex; align-items: center; min-height: 44px; }
.actual-form { border-top: 1px solid var(--line); padding-top: 14px; }
.empty { padding: 45px 18px 54px; text-align: center; border-top: 1px solid var(--line); }
.empty-icon { display: grid; place-items: center; margin: 0 auto 14px; width: 42px; height: 42px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 1.5rem; }
.empty p { margin: 7px 0 0; color: var(--muted); }

.notice { margin: 0 0 18px; padding: 10px 14px; color: #134d3f; background: var(--accent-soft); border-radius: 8px; }
.notice.error { background: #fff0f2; color: var(--danger); }
.back-link { display: inline-block; margin-bottom: 12px; font-weight: 650; }
.editor { max-width: 960px; padding: clamp(16px, 3vw, 30px); }
.editor-actions, .form-actions, .confirm-actions { display: flex; flex-wrap: wrap; gap: 8px; }
fieldset { border: 0; margin: 0 0 26px; padding: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 12px; font-size: 1.18rem; font-weight: 700; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.request-details section + section { border-top: 1px solid var(--line); margin-top: 22px; padding-top: 22px; }
.request-details h2 { font-size: 1.18rem; }
.request-details dl { margin: 12px 0 0; }
.request-details dt { color: var(--muted); font-size: .9rem; }
.request-details dd { margin: 4px 0 0; overflow-wrap: anywhere; white-space: pre-wrap; }
label[for="comment"] { grid-column: 1 / -1; }
.required, .field-error { color: var(--danger); }
.field-error { display: block; margin-top: 6px; font-weight: 500; }
[aria-invalid="true"] { border-color: var(--danger); }
.form-actions { border-top: 1px solid var(--line); padding-top: 18px; }
.confirm { max-width: 670px; padding: 24px; }
.confirm p:first-child { margin-top: 0; }
.confirm h1 { margin-bottom: 20px; font-size: 1.55rem; }

@media (max-width: 540px) {
  .topbar-inner { gap: 22px; }
  .filters, .list-heading { padding-inline: 14px; }
  .filter-form { width: 100%; }
  .filter-form label { flex: 1 1 125px; }
  .field-grid { grid-template-columns: 1fr; }
}

.account { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: .9rem; }
.account a { color: #eaf8f3; overflow-wrap: anywhere; }
.account button { padding: 6px 10px; color: #eaf8f3; border: 1px solid #71948f; background: transparent; border-radius: 6px; }
.topbar-inner { gap: 14px; }
.login-panel { max-width: 420px; margin: 24px auto; padding: clamp(20px, 5vw, 35px); }
.login-panel h1 { margin-bottom: 22px; font-size: 1.85rem; }
.login-panel form { display: grid; gap: 16px; }
.login-panel .button { justify-self: start; }
.week-nav { display: flex; gap: 6px; flex-wrap: wrap; }
.planner-filters { display: flex; flex-wrap: wrap; gap: 12px; }
.week-nav .button { font-size: .88rem; min-height: 36px; }
.list-heading { flex-wrap: wrap; }
.list-heading h2 { margin-bottom: 4px; }
.plan-day { border-top: 1px solid var(--line); }
.day-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 12px 24px; background: #f6f9fa; }
.day-heading h3 { margin: 0; font-size: .98rem; }
.day-heading time { margin-left: 5px; color: var(--muted); font-size: .88rem; font-weight: 500; }
.day-heading a { font-size: .9rem; font-weight: 650; }
.today .day-heading { background: var(--accent-soft); }
.day-empty { margin: 0; padding: 9px 24px; color: var(--muted); font-size: .9rem; }
.map-lookup { padding: 14px 16px; margin: -10px 0 24px; border: 1px solid var(--line); border-radius: 10px; background: #f6f9fa; }
.map-lookup p { margin: 0 0 10px; }
.map-lookup .map-status { margin: 10px 0 0; color: var(--accent); }
.map-lookup .map-credit { margin: 8px 0 0; font-size: .83rem; color: var(--muted); }
.map-results { margin: 14px 0 0; }
.map-results legend { margin-bottom: 5px; font-size: .95rem; }
.map-choice { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; padding: 8px 0; }
.map-choice label { display: flex; align-items: start; gap: 8px; font-weight: 500; }
.map-choice input { width: 16px; height: 16px; min-height: 0; margin: 1px 0 0; accent-color: var(--accent); flex: 0 0 auto; }
.map-choice a { font-size: .88rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
