:root {
  color-scheme: light;
  --canvas: #f3f6f8;
  --surface: #ffffff;
  --surface-2: #edf1f4;
  --ink: #172433;
  --muted: #657385;
  --line: #d6dee5;
  --accent: #176c78;
  --accent-2: #2f5fb8;
  --accent-ink: #ffffff;
  --signal: #dcebef;
  --ok: #18845b;
  --work: #a86f12;
  --stop: #bd3d49;
  --neutral: #607080;
  --radius: 6px;
  --sidebar: 228px;
  --font-body: "Segoe UI", Arial, sans-serif;
  --font-display: "Segoe UI", Arial, sans-serif;
  --font-data: "SFMono-Regular", Consolas, monospace;
}

html[data-theme="dostavka"] {
  --canvas: #f5f3ef;
  --surface: #fffefd;
  --surface-2: #ece8e1;
  --ink: #202a32;
  --muted: #766e65;
  --line: #d9d3ca;
  --accent: #b83d4c;
  --accent-2: #c98b21;
  --accent-ink: #ffffff;
  --signal: #f1e1e3;
  --radius: 2px;
  --font-display: Georgia, "Times New Roman", serif;
}

html[data-theme="logist"] {
  color-scheme: dark;
  --canvas: #0e1219;
  --surface: #131b26;
  --surface-2: #1a2634;
  --ink: #eef2f6;
  --muted: #91a0b2;
  --line: #29394b;
  --accent: #2c77d1;
  --accent-2: #19a5ca;
  --accent-ink: #ffffff;
  --signal: #16354c;
  --ok: #36c98a;
  --work: #e0b74c;
  --stop: #f05b69;
  --neutral: #8aa0b8;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  letter-spacing: 0;
}
button, input, select { font: inherit; letter-spacing: 0; }
button { color: inherit; }

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  font-weight: 800;
  font-size: 17px;
}

.brand-mark {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border: 2px solid var(--accent);
  color: var(--accent);
}

html[data-theme="vega"] .brand-mark { transform: rotate(45deg); }
html[data-theme="vega"] .brand-mark i {
  position: absolute;
  width: 6px;
  height: 6px;
  background: var(--accent);
}
html[data-theme="vega"] .brand-mark i:nth-child(1) { top: -4px; left: -4px; }
html[data-theme="vega"] .brand-mark i:nth-child(2) { bottom: -4px; right: -4px; }
html[data-theme="vega"] .brand-mark i:nth-child(3) { inset: 12px; }
html[data-theme="vega"] .brand-mark + span { color: var(--accent); }

html[data-theme="dostavka"] .brand-mark {
  border: 0;
  background: var(--accent);
  color: white;
}
html[data-theme="dostavka"] .brand-mark b { font: 700 21px/1 Georgia, serif; }

html[data-theme="logist"] .brand-mark { border-color: var(--accent-2); }
html[data-theme="logist"] .brand-mark i {
  position: absolute;
  left: 6px;
  right: 6px;
  height: 2px;
  background: var(--accent-2);
}
html[data-theme="logist"] .brand-mark i:first-child { transform: translateY(-5px); }
html[data-theme="logist"] .brand-mark i:last-child { transform: translateY(5px); }

.eyebrow, .section-index, label > span, .detail-item > span, .route-summary span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  text-transform: uppercase;
}

.login-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, 1.05fr) minmax(420px, .95fr);
}

.login-identity {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 100vh;
  padding: clamp(32px, 6vw, 84px);
  overflow: hidden;
  background: var(--surface-2);
}

.login-copy { max-width: 620px; }
.login-copy h1 {
  max-width: 760px;
  margin: 14px 0 18px;
  font-family: var(--font-display);
  font-size: clamp(42px, 7vh, 76px);
  line-height: .98;
  letter-spacing: 0;
}
.login-copy p { margin: 0; color: var(--muted); font-size: 18px; }

.identity-line {
  position: absolute;
  right: -120px;
  bottom: 18%;
  width: 68%;
  height: 2px;
  background: var(--accent);
  transform: rotate(-18deg);
  transform-origin: right;
}
html[data-theme="vega"] .identity-line::before,
html[data-theme="vega"] .identity-line::after {
  content: "";
  position: absolute;
  width: 13px;
  height: 13px;
  background: var(--accent-2);
  transform: rotate(45deg);
  top: -6px;
}
html[data-theme="vega"] .identity-line::before { left: 12%; }
html[data-theme="vega"] .identity-line::after { right: 18%; }
html[data-theme="dostavka"] .identity-line {
  right: auto;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 14px;
  transform: none;
  background: repeating-linear-gradient(90deg, var(--accent) 0 34px, transparent 34px 44px);
}
html[data-theme="logist"] .login-identity {
  background-color: var(--surface);
  background-image: radial-gradient(circle at 1px 1px, rgba(25,165,202,.28) 1px, transparent 0);
  background-size: 26px 26px;
}

.login-panel {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 32px;
  background: var(--surface);
}
.login-form { width: min(420px, 100%); }
.login-form h2 { margin: 8px 0 34px; font-size: 28px; }
.login-form label { display: block; margin-top: 18px; }
.login-form input,
.filter-bar input,
.filter-bar select {
  width: 100%;
  height: 44px;
  margin-top: 7px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  background: var(--surface);
  color: var(--ink);
}
.login-form input:focus,
.filter-bar input:focus,
.filter-bar select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent); }
.primary-button {
  width: 100%;
  height: 46px;
  margin-top: 26px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  cursor: pointer;
}
.primary-button:disabled { opacity: .6; cursor: wait; }
.form-error, .load-error { color: var(--stop); font-weight: 700; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  grid-template-rows: 72px minmax(0, 1fr);
}
.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: var(--sidebar) 1fr auto;
  align-items: center;
  min-width: 0;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.topbar-title { padding-left: 26px; }
.topbar-title strong { display: block; margin-top: 3px; font-size: 17px; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.sync-state { color: var(--muted); font-size: 12px; }
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
}
.icon-button:hover { border-color: var(--accent); color: var(--accent); }
.icon-button:disabled { opacity: .35; cursor: default; }
.logout-button {
  height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}
.logout-button:hover { border-color: var(--accent); color: var(--accent); }

.side-rail {
  grid-column: 1;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 26px 14px 18px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.rail-label { margin: 0 12px 12px; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.side-rail nav { display: grid; gap: 4px; }
.rail-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.rail-item.is-active { border-left-color: var(--accent); background: var(--signal); font-weight: 800; }
.rail-item b { font-family: var(--font-data); font-size: 12px; }
.rail-foot { margin-top: auto; padding: 14px 12px 0; border-top: 1px solid var(--line); }
.rail-foot span { display: block; color: var(--muted); font-size: 11px; }
.rail-foot strong { display: block; margin-top: 6px; font-size: 12px; line-height: 1.4; }

.workspace {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  padding: 28px clamp(20px, 3vw, 44px) 40px;
}
.workspace-heading { display: flex; justify-content: space-between; align-items: end; gap: 24px; }
.workspace-heading h1 { margin: 5px 0 0; font-family: var(--font-display); font-size: 30px; line-height: 1.05; }
.summary-strip { display: flex; border: 1px solid var(--line); background: var(--surface); }
.summary-strip div { min-width: 108px; padding: 11px 14px; border-left: 1px solid var(--line); }
.summary-strip div:first-child { border-left: 0; }
.summary-strip span { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; }
.summary-strip strong { display: block; margin-top: 3px; font: 800 18px/1 var(--font-data); }

.filter-bar {
  display: grid;
  grid-template-columns: minmax(240px, 1.5fr) repeat(4, minmax(130px, .7fr)) auto;
  align-items: end;
  gap: 10px;
  margin-top: 24px;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.filter-bar label:empty { display: none; }
.filter-bar input, .filter-bar select { height: 39px; margin-top: 5px; }
.filter-reset { height: 39px; padding: 0 13px; border: 1px solid var(--line); border-radius: var(--radius); background: transparent; cursor: pointer; }
.filter-reset:hover { border-color: var(--accent); color: var(--accent); }

.manifest { margin-top: 14px; border: 1px solid var(--line); background: var(--surface); }
.manifest-head,
.manifest-row {
  display: grid;
  grid-template-columns: minmax(170px, 1.05fr) minmax(230px, 1.45fr) minmax(190px, 1.15fr) 125px 130px 125px;
  gap: 14px;
  align-items: center;
}
.manifest-head {
  min-height: 38px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}
.manifest-row {
  width: 100%;
  min-height: 72px;
  padding: 10px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.manifest-row:last-child { border-bottom: 0; }
.manifest-row:hover { background: color-mix(in srgb, var(--signal) 72%, transparent); }
.manifest-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.manifest-row strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.manifest-row small { display: block; margin-top: 5px; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.request-cell { min-width: 0; border-left: 3px solid var(--accent); padding-left: 11px; }
.row-entity { display: block; margin-top: 4px; color: var(--accent); font-size: 10px; font-weight: 800; }
.route-cell { display: grid; grid-template-columns: minmax(0, 1fr) 20px minmax(0, 1fr); align-items: center; gap: 5px; min-width: 0; }
.route-cell i { color: var(--accent); font-style: normal; text-align: center; }
.route-cell strong {
  overflow: hidden;
  font-size: 13px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rate-cell strong { font-family: var(--font-data); }
.status { display: inline-flex; align-items: center; min-height: 26px; max-width: 100%; padding: 4px 8px; border: 1px solid currentColor; border-radius: 4px; font-size: 11px; line-height: 1.2; }
.status-ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 9%, transparent); }
.status-work { color: var(--work); background: color-mix(in srgb, var(--work) 9%, transparent); }
.status-stop { color: var(--stop); background: color-mix(in srgb, var(--stop) 9%, transparent); }
.status-neutral { color: var(--neutral); background: color-mix(in srgb, var(--neutral) 9%, transparent); }
.manifest-body.is-loading { min-height: 160px; opacity: .45; pointer-events: none; }
.manifest-footer { display: flex; justify-content: space-between; align-items: center; min-height: 54px; padding: 0 14px; border-top: 1px solid var(--line); color: var(--muted); }
.pagination { display: flex; align-items: center; gap: 9px; }
.pagination span { min-width: 24px; text-align: center; font-family: var(--font-data); }
.empty-state { padding: 72px 24px; text-align: center; }
.empty-state h2 { margin: 14px 0 8px; font-size: 20px; }
.empty-state p { margin: 0; color: var(--muted); }
.empty-symbol { display: inline-grid; place-items: center; width: 42px; height: 42px; border: 1px solid var(--accent); color: var(--accent); font-size: 20px; }
.load-error { padding: 32px; }

.application-dialog {
  width: min(920px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}
.application-dialog::backdrop { background: rgba(7, 12, 18, .66); }
.dialog-toolbar { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; min-height: 68px; padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--surface); }
.dialog-toolbar strong { display: block; margin-top: 3px; font-size: 18px; }
.dialog-content { padding: 22px; }
.dialog-loading { padding: 64px 0; color: var(--muted); text-align: center; }
.route-summary { display: grid; grid-template-columns: minmax(0, 1fr) 40px minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 18px; border-left: 4px solid var(--accent); background: var(--surface-2); }
.route-summary > i { color: var(--accent); font-style: normal; font-size: 22px; text-align: center; }
.route-summary strong { display: block; margin-top: 5px; font-size: 18px; }
.route-summary small { display: block; margin-top: 5px; color: var(--muted); }
.detail-section { margin-top: 24px; }
.detail-section h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; }
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.detail-item { min-height: 70px; padding: 12px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.detail-item strong { display: block; margin-top: 7px; line-height: 1.35; overflow-wrap: anywhere; }
.document-row { display: grid; grid-template-columns: minmax(0, 1fr) 80px 90px; gap: 12px; align-items: center; min-height: 50px; padding: 0 12px; border-top: 1px solid var(--line); color: inherit; text-decoration: none; }
.document-row:last-child { border-bottom: 1px solid var(--line); }
.document-row small { color: var(--muted); }
.document-row b { color: var(--accent); text-align: right; }
.no-documents { padding: 18px; border: 1px solid var(--line); color: var(--muted); }

html[data-theme="dostavka"] .app-shell { grid-template-columns: 1fr; grid-template-rows: 72px 54px minmax(0, 1fr); }
html[data-theme="dostavka"] .topbar { grid-column: 1; grid-template-columns: 220px 1fr auto; border-top: 5px solid var(--accent); }
html[data-theme="dostavka"] .side-rail { grid-column: 1; grid-row: 2; flex-direction: row; align-items: center; padding: 6px 22px; border-right: 0; border-bottom: 1px solid var(--line); }
html[data-theme="dostavka"] .side-rail nav { display: flex; gap: 4px; }
html[data-theme="dostavka"] .rail-label, html[data-theme="dostavka"] .rail-foot { display: none; }
html[data-theme="dostavka"] .rail-item { width: auto; min-width: 150px; border-left: 0; border-bottom: 3px solid transparent; border-radius: 0; }
html[data-theme="dostavka"] .rail-item.is-active { border-bottom-color: var(--accent); }
html[data-theme="dostavka"] .workspace { grid-column: 1; grid-row: 3; }
html[data-theme="dostavka"] .workspace-heading h1 { font-size: 34px; font-weight: 500; }
html[data-theme="dostavka"] .request-cell { border-left-color: var(--accent-2); }
html[data-theme="dostavka"] .route-cell i { color: var(--accent-2); }

html[data-theme="logist"] .workspace { background-color: var(--canvas); background-image: radial-gradient(circle at 1px 1px, rgba(25,165,202,.12) 1px, transparent 0); background-size: 30px 30px; }
html[data-theme="logist"] .manifest, html[data-theme="logist"] .filter-bar, html[data-theme="logist"] .summary-strip { backdrop-filter: blur(8px); background: color-mix(in srgb, var(--surface) 94%, transparent); }
html[data-theme="logist"] .manifest-row:nth-child(even) { background: rgba(255,255,255,.012); }

@media (max-width: 1380px) {
  .filter-bar { grid-template-columns: minmax(220px, 1.5fr) repeat(2, minmax(140px, 1fr)); }
  .manifest { overflow-x: auto; }
  .manifest-head, .manifest-row {
    min-width: 916px;
    grid-template-columns: 150px 200px 170px 108px 118px 110px;
    gap: 10px;
  }
  .route-cell strong { font-size: 12px; }
}

@media (max-width: 760px) {
  .login-layout { grid-template-columns: 1fr; }
  .login-identity { min-height: 34vh; padding: 28px 22px; }
  .login-copy h1 { font-size: 40px; }
  .login-copy p { font-size: 15px; }
  .identity-line { bottom: 12%; }
  .login-panel { min-height: 66vh; padding: 34px 22px; }

  .app-shell, html[data-theme="dostavka"] .app-shell { display: block; }
  .topbar, html[data-theme="dostavka"] .topbar { position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: minmax(0, 1fr) auto; min-height: 64px; padding: 0 14px; }
  .topbar-title, .sync-state { display: none; }
  .side-rail, html[data-theme="dostavka"] .side-rail { position: sticky; top: 64px; z-index: 4; display: block; padding: 6px 10px; overflow-x: auto; white-space: nowrap; }
  .side-rail nav, html[data-theme="dostavka"] .side-rail nav { display: flex; }
  .rail-label, .rail-foot { display: none; }
  .rail-item, html[data-theme="dostavka"] .rail-item { width: auto; min-width: 130px; }
  .workspace { padding: 24px 14px 32px; }
  .workspace-heading { display: block; }
  .workspace-heading h1 { font-size: 26px; }
  .summary-strip { margin-top: 18px; width: 100%; }
  .summary-strip div { min-width: 0; flex: 1; padding: 10px; }
  .filter-bar { grid-template-columns: 1fr 1fr; }
  .filter-bar .search-field { grid-column: 1 / -1; }
  .manifest-head { display: none; }
  .manifest { overflow: visible; }
  .manifest-row { min-width: 0; grid-template-columns: 1fr 110px; gap: 10px; min-height: 0; padding: 14px; }
  .request-cell, .route-cell, .carrier-cell { grid-column: 1; }
  .date-cell, .rate-cell, .status-cell { grid-column: 2; }
  .date-cell { grid-row: 1; }
  .rate-cell { grid-row: 2; }
  .status-cell { grid-row: 3; }
  .route-cell { grid-row: 2; }
  .carrier-cell { grid-row: 3; }
  .manifest-row strong { white-space: normal; }
  .route-summary { grid-template-columns: 1fr 22px 1fr; }
  .route-summary > .status { grid-column: 1 / -1; justify-self: start; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 470px) {
  .filter-bar { grid-template-columns: 1fr; }
  .filter-bar .search-field { grid-column: 1; }
  .summary-strip span { font-size: 9px; }
  .summary-strip strong { font-size: 15px; }
  .manifest-row { grid-template-columns: 1fr; }
  .request-cell, .route-cell, .carrier-cell, .date-cell, .rate-cell, .status-cell { grid-column: 1; grid-row: auto; }
  .detail-grid { grid-template-columns: 1fr; }
  .route-summary { grid-template-columns: 1fr; }
  .route-summary > i { transform: rotate(90deg); text-align: left; }
  .document-row { grid-template-columns: 1fr auto; }
  .document-row b { grid-column: 1 / -1; text-align: left; }
}

@media (prefers-reduced-motion: no-preference) {
  .manifest-row, .icon-button, .primary-button { transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease; }
}
