/* День — по умолчанию */
:root,
[data-theme="day"] {
  --bg: #eef1f6;
  --surface: #ffffff;
  --border: #c8d3e0;
  --text: #1a2332;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --first: #16a34a;
  --control: #d97706;
  --table-head: #e2e8f2;
  --row-hover: rgba(37, 99, 235, 0.06);
  --row-border: rgba(148, 163, 184, 0.35);
  --chip-active-bg: rgba(37, 99, 235, 0.12);
  --chip-active-text: #1d4ed8;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --error-text: #b91c1c;
  --col-admin: rgba(22, 163, 74, 0.07);
  --col-coord: rgba(37, 99, 235, 0.07);
  --col-dev: rgba(202, 138, 4, 0.08);
  --col-speed: rgba(124, 58, 237, 0.07);
  --pass-first-bg: rgba(22, 163, 74, 0.1);
  --pass-first-border: rgba(22, 163, 74, 0.35);
  --pass-control-bg: rgba(217, 119, 6, 0.1);
  --pass-control-border: rgba(217, 119, 6, 0.35);
  --section-bg: rgba(37, 99, 235, 0.06);
}

[data-theme="night"] {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4f;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --first: #22c55e;
  --control: #f59e0b;
  --table-head: #243044;
  --row-hover: rgba(59, 130, 246, 0.06);
  --row-border: rgba(45, 58, 79, 0.4);
  --chip-active-bg: rgba(59, 130, 246, 0.22);
  --chip-active-text: #93c5fd;
  --error-bg: #451a1a;
  --error-border: #7f1d1d;
  --error-text: #fca5a5;
  --col-admin: rgba(34, 197, 94, 0.04);
  --col-coord: rgba(59, 130, 246, 0.04);
  --col-dev: rgba(234, 179, 8, 0.04);
  --col-speed: rgba(168, 85, 247, 0.06);
  --pass-first-bg: rgba(34, 197, 94, 0.15);
  --pass-first-border: rgba(34, 197, 94, 0.3);
  --pass-control-bg: rgba(245, 158, 11, 0.15);
  --pass-control-border: rgba(245, 158, 11, 0.3);
  --section-bg: rgba(59, 130, 246, 0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  transition: background 0.2s, color 0.2s;
}
header {
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
header h1 { font-size: 1.25rem; font-weight: 600; }
header p { color: var(--muted); font-size: 0.85rem; margin-top: 0.2rem; }

.main-tabs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.main-tab {
  padding: 0.5rem 1.1rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
}
.main-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.km-toggle {
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
}
.theme-toggle {
  padding: 0.45rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s, color 0.15s;
}
.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--text);
}

main { padding: 1rem 1.5rem 2rem; max-width: 100%; }

.split-view {
  display: grid;
  grid-template-columns: 1fr 4px 1fr;
  gap: 0;
  min-height: 70vh;
}
.pass-divider {
  background: var(--border);
  border-radius: 2px;
}
.pass-column {
  padding: 0 0.75rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.pass-title {
  font-size: 1rem;
  font-weight: 600;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  text-align: center;
}
.pass-title.first {
  background: var(--pass-first-bg);
  color: var(--first);
  border: 1px solid var(--pass-first-border);
}
.pass-title.control {
  background: var(--pass-control-bg);
  color: var(--control);
  border: 1px solid var(--pass-control-border);
}

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  text-align: center;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.2s, padding 0.2s;
}
.upload-zone.compact { padding: 0.75rem; }
.upload-zone.compact p { display: none; }
.upload-zone:hover, .upload-zone.dragover { border-color: var(--accent); }

.btn {
  padding: 0.45rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  margin-top: 0.5rem;
}
.btn:hover { background: var(--accent-hover); }

.progress-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin: 0.75rem 0;
  text-align: center;
}
.progress-panel.hidden { display: none; }
.progress-ring {
  width: 80px; height: 80px;
  margin: 0 auto 0.5rem;
  position: relative;
}
.progress-ring svg { transform: rotate(-90deg); width: 80px; height: 80px; }
.progress-ring circle.bg { fill: none; stroke: var(--border); stroke-width: 8; }
.progress-ring circle.fg {
  fill: none; stroke: var(--accent); stroke-width: 8;
  stroke-linecap: round; stroke-dasharray: 283; stroke-dashoffset: 283;
  transition: stroke-dashoffset 0.4s;
}
.progress-pct {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; font-weight: 700;
}
.progress-msg { color: var(--muted); font-size: 0.8rem; }
.progress-bar-wrap {
  height: 4px; background: var(--border); border-radius: 2px;
  margin-top: 0.5rem; overflow: hidden;
}
.progress-bar-fill {
  height: 100%; background: var(--accent); width: 0%;
  transition: width 0.4s;
}

.pass-data { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.pass-data.hidden { display: none; }
.meta { color: var(--muted); font-size: 0.8rem; margin: 0.4rem 0; }
.type-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.5rem; }
.chip {
  background: var(--surface); border: 1px solid var(--border);
  padding: 0.15rem 0.45rem; border-radius: 999px; font-size: 0.72rem;
  cursor: pointer; color: inherit; font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.chip:hover { border-color: var(--accent); }
.chip.active {
  background: var(--chip-active-bg);
  border-color: var(--accent);
  color: var(--chip-active-text);
}

.table-wrap {
  flex: 1; overflow: auto;
  border: 1px solid var(--border); border-radius: 8px;
  max-height: 55vh;
  background: var(--surface);
}
table {
  width: 100%; border-collapse: collapse;
  font-size: 0.78rem; white-space: nowrap;
}
th {
  position: sticky; top: 0; background: var(--table-head);
  padding: 0.4rem 0.5rem; text-align: center;
  font-weight: 600; border-bottom: 1px solid var(--border);
  color: var(--text);
}
td {
  padding: 0.3rem 0.5rem; text-align: center;
  border-bottom: 1px solid var(--row-border);
}
tr:hover td { background: var(--row-hover); }
.col-admin { background: var(--col-admin); }
.col-coord { background: var(--col-coord); }
.col-dev { background: var(--col-dev); }
.col-speed { background: var(--col-speed); }

tr.section-row td {
  text-align: left;
  font-weight: 600;
  font-size: 0.82rem;
  padding: 0.55rem 0.75rem;
  background: var(--section-bg, rgba(37, 99, 235, 0.08));
  border-top: 2px solid var(--accent);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  white-space: normal;
}

.hidden { display: none !important; }
.error {
  background: var(--error-bg); border: 1px solid var(--error-border);
  color: var(--error-text); padding: 0.75rem; border-radius: 8px; margin-bottom: 1rem;
}
.muted { color: var(--muted); text-align: center; padding: 1rem; }

.compare-controls {
  display: flex; gap: 0.75rem; align-items: center; margin: 1rem 0;
}
.compare-controls select,
.report-header select {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); padding: 0.45rem 0.75rem; border-radius: 6px;
}
.report-header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.report-form-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
}
.report-header .btn {
  margin-top: 0;
}
.report-header .btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.report-table-wrap {
  max-width: 100%;
  max-height: none;
}
.report-table .section-row td {
  text-align: left;
  white-space: normal;
}
.report-table .report-subtotal td {
  font-weight: 600;
  background: var(--table-head);
  border-top: 1px solid var(--border);
}
.report-table th,
.report-table td {
  padding: 0.55rem 1rem;
}
.report-table .report-type {
  font-weight: 600;
  text-align: left;
}
.report-table .report-repeated {
  color: #f87171;
  font-weight: 600;
}
.report-table tfoot .report-total td {
  font-weight: 700;
  border-top: 2px solid var(--border);
  background: var(--table-head);
}
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.6rem; margin: 1rem 0;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.75rem; text-align: center;
}
.stat-card .label { color: var(--muted); font-size: 0.75rem; }
.stat-card .value { font-size: 1.3rem; font-weight: 700; margin-top: 0.15rem; }
.section-title {
  font-size: 0.95rem; margin: 1.25rem 0 0.5rem;
  padding-left: 0.5rem; border-left: 3px solid var(--accent);
}

@media (max-width: 900px) {
  .split-view { grid-template-columns: 1fr; }
  .pass-divider { display: none; }
  .km-toggle { margin-left: 0; }
}

/* Отладка */
.debug-col { display: none; }
[data-debug="1"] .debug-col { display: table-cell; }
.col-path { font-weight: 600; color: var(--accent); white-space: nowrap; }
.raw-cell {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.72rem;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}
.debug-markers {
  margin: 0.75rem 0;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 8px;
  font-size: 0.82rem;
}
.debug-markers summary {
  cursor: pointer;
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.debug-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}
.debug-table th,
.debug-table td {
  border: 1px solid var(--row-border);
  padding: 0.25rem 0.5rem;
  text-align: left;
}
.debug-table th { background: var(--table-head); }
.muted { color: var(--muted); }
