:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: #17212b;
  background: #edf2f5;
  font-synthesis: none;
  --ink: #17212b;
  --muted: #667581;
  --line: #d6e0e5;
  --line-strong: #c3d0d7;
  --teal: #109fa0;
  --teal-dark: #087e80;
  --teal-pale: #e7f7f6;
  --navy: #071b25;
  --danger: #cf3f4e;
  --surface: #ffffff;
  --shadow: 0 12px 30px rgb(20 42 54 / 8%);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { min-width: 320px; background: #edf2f5; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, select { cursor: pointer; }
[hidden] { display: none !important; }
svg { display: block; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(150deg, #071b25 0 38%, #edf2f5 38%); }
.login-panel { width: min(420px, 100%); display: grid; gap: 18px; padding: 30px; background: #fff; border: 1px solid var(--line); box-shadow: 0 24px 70px rgb(3 19 27 / 20%); border-radius: 8px; }
.login-brand, .brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.login-brand strong, .brand strong { display: block; font-size: 18px; }
.login-brand span span, .brand small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; color: var(--teal); border: 1px solid #3b636c; background: #0b2530; border-radius: 6px; }
.login-panel h1 { margin: 6px 0 3px; font-size: 28px; }
.login-panel p { margin: 0; color: var(--muted); }
label { display: grid; gap: 6px; color: #394854; font-size: 13px; font-weight: 650; }
input, select, textarea { width: 100%; min-height: 40px; padding: 8px 11px; color: var(--ink); background: #fff; border: 1px solid var(--line-strong); border-radius: 5px; outline: none; }
textarea { resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgb(16 159 160 / 11%); }
.ip-line { display: flex; justify-content: space-between; gap: 12px; padding: 11px 12px; color: var(--muted); background: #f3f6f8; border: 1px solid var(--line); border-radius: 5px; }
.ip-line strong { color: var(--ink); }
.form-error { min-height: 18px; color: #b82f3e !important; font-size: 13px; }

.app-header { min-height: 62px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 9px clamp(16px, 3vw, 42px); color: #fff; background: var(--navy); border-bottom: 1px solid #173744; }
.brand small { color: #75d4d0; }
.account { display: flex; align-items: center; gap: 16px; }
.account > span { text-align: right; }
.account strong, .account small { display: block; }
.account strong { font-size: 14px; }
.account small { margin-top: 2px; color: #9db0b9; font-size: 11px; }
.icon-text-button { min-height: 38px; display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px; color: #fff; background: #102c38; border: 1px solid #31505c; border-radius: 5px; }
.icon-text-button:hover { background: #193947; }

main { width: min(1580px, 100%); margin: 0 auto; padding: 22px clamp(12px, 2vw, 30px) 46px; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.page-heading > div:first-child { display: flex; align-items: center; gap: 12px; }
.heading-icon { width: 38px; height: 38px; display: grid; place-items: center; color: var(--teal-dark); background: var(--teal-pale); border: 1px solid #b9dedc; border-radius: 6px; }
.page-heading h1 { margin: 0; font-size: clamp(21px, 2vw, 28px); }
.page-heading p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.heading-actions { display: flex; gap: 9px; }
.button { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 13px; border: 1px solid transparent; border-radius: 5px; font-weight: 700; }
.button-primary { color: #fff; background: var(--teal); border-color: var(--teal); }
.button-primary:hover { background: var(--teal-dark); border-color: var(--teal-dark); }
.button-secondary { color: #233641; background: #fff; border-color: var(--line-strong); }
.button-secondary:hover, .button-quiet:hover { border-color: #9eb0ba; background: #f4f7f8; }
.button-quiet { color: #4c5c66; background: #f7f9fa; border-color: var(--line); }
.button-danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.button-wide { width: 100%; }

.filters { display: grid; grid-template-columns: minmax(260px, 1fr) 180px 190px auto; align-items: end; gap: 9px; padding: 16px 0 10px; }
.filters label:not(.search-field) > span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; }
.search-field { position: relative; display: block; }
.search-field > span { position: absolute; top: 11px; left: 11px; z-index: 1; color: #71828d; }
.search-field input { padding-left: 38px; }
.summary-line { min-height: 28px; display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 12px; }
.summary-line strong { color: var(--ink); }

.data-surface { min-height: 240px; position: relative; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; box-shadow: var(--shadow); }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12px; }
th { position: sticky; top: 0; z-index: 2; padding: 9px 8px; color: #4b5c66; background: #f1f5f7; border-bottom: 1px solid var(--line-strong); text-align: left; white-space: nowrap; }
td { padding: 7px 8px; border-right: 1px solid #e2e9ed; border-bottom: 1px solid #e2e9ed; vertical-align: middle; }
th:last-child, td:last-child { border-right: 0; }
tbody tr:hover td { background: #f6fbfb; }
tbody tr.is-complete td { background: #eff9f2; }
.date-cell { white-space: nowrap; font-weight: 750; }
.person-cell strong { display: block; }
.person-cell small { display: block; margin-top: 2px; color: var(--muted); }
.type-pill, .status-pill { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 999px; white-space: nowrap; font-weight: 750; }
.type-pill { color: #087e80; background: #e5f7f6; }
.status-pill[data-status="Новая"] { color: #8b5b00; background: #fff3ce; }
.status-pill[data-status="В работе"] { color: #1765a3; background: #e3f2ff; }
.status-pill[data-status="Выполнено"] { color: #19703b; background: #dff4e6; }
.houses { max-width: 260px; display: flex; flex-wrap: wrap; gap: 3px; }
.house-chip { min-width: 24px; padding: 2px 5px; text-align: center; background: #f3f6f8; border: 1px solid #dce5e9; border-radius: 3px; }
.comment-cell { max-width: 240px; overflow: hidden; text-overflow: clip; white-space: nowrap; }
.actions { display: flex; justify-content: flex-end; gap: 5px; }
.mini-button { width: 30px; height: 28px; display: grid; place-items: center; padding: 0; color: #36515e; background: #fff; border: 1px solid var(--line-strong); border-radius: 4px; font-weight: 800; }
.mini-button:hover { border-color: var(--teal); color: var(--teal-dark); }
.mini-button.danger:hover { color: #fff; background: var(--danger); border-color: var(--danger); }
.mobile-list { display: none; }
.empty-state { min-height: 260px; display: grid; place-content: center; justify-items: center; gap: 8px; color: var(--muted); text-align: center; }
.empty-state strong { color: var(--ink); font-size: 17px; }
.empty-state p { margin: 0; }

dialog { width: min(720px, calc(100% - 24px)); max-height: calc(100dvh - 32px); padding: 0; overflow: auto; color: var(--ink); background: #fff; border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: 0 30px 90px rgb(5 25 35 / 28%); }
dialog::backdrop { background: rgb(6 21 29 / 55%); backdrop-filter: blur(2px); }
.wide-dialog { width: min(900px, calc(100% - 24px)); }
.modal-form { padding: 20px; }
.modal-form > header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding-bottom: 15px; border-bottom: 1px solid var(--line); }
.modal-form h2 { margin: 0; font-size: 21px; }
.modal-form header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.close-button { width: 34px; height: 34px; display: grid; place-items: center; padding: 0; color: #4f606a; background: #f5f7f8; border: 1px solid var(--line); border-radius: 5px; font-size: 22px; line-height: 1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; padding-top: 17px; }
.span-2 { grid-column: span 2; }
label small { color: var(--muted); font-size: 11px; font-weight: 400; }
.modal-form > footer { display: flex; justify-content: flex-end; gap: 8px; padding-top: 8px; }
.inline-form { display: grid; grid-template-columns: 1.4fr 1fr auto auto; align-items: end; gap: 9px; padding: 17px 0 12px; }
.check-label { min-height: 40px; display: flex; align-items: center; gap: 7px; padding: 0 8px; white-space: nowrap; }
.check-label input { width: 17px; min-height: 17px; margin: 0; accent-color: var(--teal); }
.distributor-list { border-top: 1px solid var(--line); }
.distributor-row { display: grid; grid-template-columns: minmax(170px, 1fr) minmax(140px, .8fr) 90px auto; align-items: center; gap: 10px; min-height: 50px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.distributor-row.is-inactive { opacity: .55; }
.distributor-row small { color: var(--muted); }
.row-actions { display: flex; gap: 5px; justify-content: flex-end; }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 100; max-width: min(390px, calc(100% - 36px)); padding: 11px 14px; color: #fff; background: #18343f; border-radius: 5px; box-shadow: 0 10px 35px rgb(0 0 0 / 20%); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .18s ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.is-error { background: #a72d3a; }

@media (max-width: 900px) {
  .filters { grid-template-columns: minmax(220px, 1fr) 150px 160px auto; }
  .table-wrap { display: none; }
  .mobile-list { display: grid; gap: 6px; padding: 8px; }
  .route-card { display: grid; gap: 7px; padding: 10px; background: #fff; border: 1px solid var(--line); border-left: 4px solid #d8a52d; border-radius: 5px; }
  .route-card[data-status="В работе"] { border-left-color: #2b88ca; }
  .route-card[data-status="Выполнено"] { border-left-color: #36a05d; background: #f3fbf5; }
  .route-card-top, .route-card-bottom, .route-address { display: flex; align-items: center; gap: 7px; }
  .route-card-top { justify-content: space-between; }
  .route-card-top > div, .route-card-bottom > div { display: flex; align-items: center; gap: 6px; min-width: 0; }
  .route-card time { font-weight: 800; white-space: nowrap; }
  .route-card .distributor-name { overflow: hidden; font-weight: 800; text-overflow: clip; white-space: nowrap; }
  .route-address { align-items: flex-start; color: #30434e; }
  .route-address span:last-child { min-width: 0; }
  .route-houses { color: #435661; font-size: 12px; }
  .route-comment { color: var(--muted); font-size: 12px; }
  .route-card-bottom { justify-content: space-between; padding-top: 3px; border-top: 1px solid #e4eaed; }
}

@media (max-width: 680px) {
  .app-header { min-height: 56px; padding: 7px 10px; }
  .brand-mark { width: 36px; height: 36px; }
  .brand strong { font-size: 15px; }
  .account > span { display: none; }
  .icon-text-button span:last-child { display: none; }
  .icon-text-button { width: 38px; justify-content: center; padding: 0; }
  main { padding: 14px 8px 30px; }
  .page-heading { align-items: flex-start; padding: 0 3px 12px; }
  .heading-icon { display: none; }
  .page-heading h1 { font-size: 19px; }
  .page-heading p { font-size: 11px; }
  .heading-actions { gap: 5px; }
  .heading-actions .button { width: 39px; min-height: 38px; padding: 0; }
  .heading-actions .button { font-size: 0; }
  .heading-actions svg { width: 18px; height: 18px; }
  .filters { grid-template-columns: 1fr 1fr; gap: 6px; padding: 10px 0 6px; }
  .search-field { grid-column: span 2; }
  .filters .button { min-height: 40px; }
  .summary-line { padding: 0 3px; }
  .data-surface { border-radius: 5px; }
  .mobile-list { padding: 6px; gap: 4px; }
  .route-card { padding: 8px; gap: 6px; }
  .type-pill, .status-pill { min-height: 22px; padding: 2px 7px; font-size: 11px; }
  dialog { width: calc(100% - 12px); max-height: calc(100dvh - 12px); }
  .modal-form { padding: 14px; }
  .form-grid { grid-template-columns: 1fr; gap: 10px; }
  .span-2 { grid-column: auto; }
  .inline-form { grid-template-columns: 1fr; }
  .check-label { padding: 0; }
  .distributor-row { grid-template-columns: 1fr auto; gap: 4px 8px; }
  .distributor-row > :nth-child(2), .distributor-row > :nth-child(3) { grid-column: 1; }
  .row-actions { grid-column: 2; grid-row: 1 / span 3; }
  .login-view { padding: 12px; }
  .login-panel { padding: 22px 18px; }
}
