/* Журнал выездов — внутренний диспетчерский инструмент.
   Палитра: paper #F3F4F2, ink #1A2126, slate #22303A, green #146B49, line #DDE1DD */
:root {
  --paper: #F3F4F2;
  --panel: #FFFFFF;
  --ink: #1A2126;
  --muted: #5C6660;
  --slate: #22303A;
  --topbar-bg: var(--slate);
  --green: #146B49;
  --green-dark: #0E5237;
  --line: #DDE1DD;
  --border: #B9C0BA;
  --error: #A8320A;
  --error-bg: #FBEDE7;
  --ok-bg: #E8F2ED;
  --warn-bg: #FBF3E1;
  --warn-ink: #8A5A00;
  --hover-bg: #FAFBFA;
  --hcell-empty: #EBEDEA;
  --hcell-1: #BEE2CF;
  --hcell-2: #7FC79E;
  --hcell-3: #3D9F6B;
  --hcell-1-ink: #0E3E2B;
  --ao-no-bg: #EEF0EE;
  --mono: ui-monospace, "Cascadia Mono", "Consolas", "Liberation Mono", monospace;
  color-scheme: light;
}

/* Тёмная тема: применяется через data-theme="dark" на <html>, который
   выставляет static/js/theme.js — вручную или по системной настройке
   (если пользователь не переключал тему сам, режим "auto"). */
[data-theme="dark"] {
  --paper: #14181A;
  --panel: #1C2225;
  --ink: #E7EAE8;
  --muted: #93A19A;
  --slate: #0E1518;
  --topbar-bg: #1B2529;
  --green: #2FAE80;
  --green-dark: #22916A;
  --line: #313A3C;
  --border: #445055;
  --error: #E2734A;
  --error-bg: #3A2118;
  --ok-bg: #163329;
  --warn-bg: #3A3014;
  --warn-ink: #E0B54A;
  --hover-bg: #202829;
  --hcell-empty: #262E30;
  --hcell-1: #1D4635;
  --hcell-2: #226B4C;
  --hcell-3: #2C9268;
  --hcell-1-ink: #B9E9CE;
  --ao-no-bg: #262E30;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}

h1 { font-size: 1.45rem; margin: 0 0 .35rem; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-family: var(--mono); font-size: .95em; }

.narrow { max-width: 760px; margin: 0 auto; padding: 0 16px; }
.wide { max-width: 1160px; margin: 0 auto; padding: 0 16px; }
main { padding-bottom: 56px; }

/* Шапка */
.topbar { background: var(--topbar-bg); color: #E9EDEF; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; min-height: 52px; gap: 16px; }
.brand { color: #fff; text-decoration: none; font-weight: 700; letter-spacing: .01em; }
.topnav { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.topnav a { color: #C6D0D6; text-decoration: none; }
.topnav a:hover, .topnav a:focus-visible { color: #fff; text-decoration: underline; }
.topnav .who { color: #93A3AC; font-size: .9rem; }
.topnav form { margin: 0; }
.linkbtn { background: none; border: 0; color: #C6D0D6; cursor: pointer; font: inherit; padding: 0; }
.linkbtn:hover { color: #fff; text-decoration: underline; }

.theme-toggle { font-size: 1.05rem; line-height: 1; padding: 2px 4px !important; }
.theme-toggle:hover { text-decoration: none !important; }
.theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-dark { display: inline; }

/* Сообщения */
.flash { border: 1px solid var(--line); border-left: 4px solid var(--green); background: var(--ok-bg); padding: 10px 14px; margin: 16px 0 0; }
.flash.error { border-left-color: var(--error); background: var(--error-bg); }

/* Талон фиксации выезда — главный элемент */
.ticket {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 6px solid var(--green);
  padding: 20px 22px 22px;
  margin-top: 24px;
}
.visit-form { margin-top: 14px; }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row .field { flex: 1 1 180px; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
input[type="text"], input[type="password"], input[type="date"], select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 1px;
}
.field-error { color: var(--error); font-size: .85rem; margin-top: 4px; }

button.primary, a.button {
  display: inline-block;
  background: var(--green);
  color: #fff;
  border: 0;
  border-radius: 2px;
  padding: 11px 22px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
button.primary:hover { background: var(--green-dark); }
a.button { background: var(--slate); }
a.button:hover { filter: brightness(1.2); }
a.button.ghost { background: transparent; border: 1px solid var(--slate); color: var(--slate); }
a.button.ghost:hover { background: var(--slate); color: #fff; }
.small-btn { padding: 8px 14px; font-size: .85rem; }

/* Списки сущностей на дашборде */
.entity-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-top: 14px; }
.entity-panel { margin-top: 0; display: flex; flex-direction: column; max-height: 480px; }
.entity-head { display: flex; align-items: baseline; justify-content: space-between; }
.entity-search { display: flex; gap: 6px; margin: 8px 0 4px; }
.entity-search input[type="text"] { flex: 1; padding: 7px 10px; font-size: .9rem; }
.entity-list { list-style: none; margin: 6px 0 0; padding: 0; overflow-y: auto; }
.entity-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 2px;
  border-bottom: 1px solid var(--line);
}
.entity-list li:last-child { border-bottom: none; }
.entity-list a { color: var(--ink); text-decoration: none; font-weight: 500; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entity-list a:hover { color: var(--green-dark); text-decoration: underline; }

/* Детальная страница: контакты, тепловая карта */
.eyebrow { margin: 0 0 2px; }
.contact-line { color: var(--muted); font-size: .92rem; margin: 4px 0 0; }
.contact-line a { color: var(--green-dark); }

.heatmap-panel { overflow-x: auto; }
.heatmap-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 6px; }
.heatmap-head h2 { font-size: 1rem; font-weight: 600; margin: 0; }
.heatmap-legend { display: flex; align-items: center; gap: 5px; margin-bottom: 22px; }
.legend-cell { width: 22px; height: 22px; }

.months-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 28px 24px;
}
.month-block { min-width: 0; }
.month-title { display: flex; align-items: baseline; justify-content: space-between; font-weight: 600; margin-bottom: 8px; font-size: .95rem; }
.weekday-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 4px; }
.weekday-row span { text-align: center; font-size: .72rem; color: var(--muted); }
.month-week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 4px; }
.day-cell {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--hcell-empty);
}
.day-cell-empty { background: transparent; }
.level-1 { background: var(--hcell-1); color: var(--hcell-1-ink); }
.level-2 { background: var(--hcell-2); color: var(--hcell-1-ink); }
.level-3 { background: var(--hcell-3); color: #fff; }
.level-4 { background: var(--green-dark); color: #fff; }

.year-tabs { display: flex; flex-direction: row; flex-wrap: wrap; gap: 4px; }
.year-tab { padding: 7px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-radius: 2px; font-size: .9rem; }
.year-tab:hover { background: var(--hover-bg); }
.year-tab.active { background: var(--slate); color: #fff; }

/* Журнал / реестр */
.journal { margin-top: 32px; }
.journal-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
table.registry { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); margin-top: 10px; }
.registry th {
  text-align: left;
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 2px solid var(--slate);
  padding: 9px 12px;
}
.registry td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.registry tbody tr:hover { background: var(--hover-bg); }

.status { display: inline-block; padding: 2px 9px; border-radius: 2px; font-size: .82rem; font-weight: 600; }
.status-done { background: var(--ok-bg); color: var(--green-dark); }
.status-partial { background: var(--warn-bg); color: var(--warn-ink); }
.status-not_done { background: var(--error-bg); color: var(--error); }

.ao-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 2px;
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
}
.ao-yes { background: var(--ok-bg); color: var(--green-dark); }
.ao-no { background: var(--ao-no-bg); color: var(--muted); }

/* Значок у статуса, если к выезду есть пояснение (видно при наведении) */
.has-note {
  display: inline-block;
  width: 13px;
  height: 13px;
  line-height: 13px;
  text-align: center;
  border-radius: 50%;
  font-size: .68rem;
  font-weight: 700;
  border: 1px solid currentColor;
  opacity: .7;
  margin-left: 2px;
  cursor: help;
}
.status { cursor: default; }
.status[title] { cursor: help; }

/* Ссылки внутри таблиц-реестров */
.registry a { color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--line); }
.registry a:hover { color: var(--green-dark); border-bottom-color: var(--green); }

.svc-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 2px;
  font-size: .82rem;
  font-weight: 600;
  font-family: var(--mono);
}
.svc-ok { background: var(--ok-bg); color: var(--green-dark); }
.svc-warn { background: var(--warn-bg); color: var(--warn-ink); }
.svc-late { background: var(--error-bg); color: var(--error); }

.add-center { margin-top: 12px; }
.add-center summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.add-center summary:hover { color: var(--ink); }
.add-center-form { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.add-center-form input { padding: 8px 10px; }

/* Вход */
.login-box { max-width: 380px; margin: 9vh auto 0; background: var(--panel); border: 1px solid var(--line); border-top: 6px solid var(--slate); padding: 26px 26px 20px; }
.login-box label { margin-top: 12px; }
.login-box button { width: 100%; margin-top: 18px; }

/* Дашборд */
.dash-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-top: 24px; }
.filters { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.filters label { margin: 0; }
.filters input, .filters select { width: auto; padding: 8px 10px; }
.stat-strip { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); padding: 12px 18px; display: flex; align-items: baseline; gap: 10px; color: var(--muted); }
.num.big { font-size: 1.7rem; color: var(--ink); font-weight: 600; }
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.panel { background: var(--panel); border: 1px solid var(--line); padding: 16px 18px; margin-top: 14px; }
.charts .panel { margin-top: 0; }
.span2 { grid-column: 1 / -1; }
.chart-wrap { position: relative; height: 260px; }
.chart-wrap.tall { height: 340px; }

@media (max-width: 800px) {
  .charts { grid-template-columns: 1fr; }
  .entity-grid { grid-template-columns: 1fr; }
  .dash-head { flex-direction: column; align-items: stretch; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
