:root {
  --bg: #f3f5f8; --panel: #fff; --ink: #1b2430; --muted: #6b7686; --line: #dfe4ea;
  --brand: #0a6fa8; --brand-ink: #fff; --ok: #1a7f4b; --warn: #b26a00; --bad: #c0392b; --side: #0c3550;
  --gold: #c99a2e; --gold-soft: #f4e7c3;
  --portrait-login: .22;   /* прозрачность портрета на странице входа */
  --portrait-work: .07;    /* прозрачность портрета в рабочей области */
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg) url(brand/ornament-gold.svg) 0 0 / 120px 120px fixed; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 0 0 10px; }

.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--side); color: #cfd8e3; padding: 16px 0; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.logo { font-size: 18px; font-weight: 700; color: #fff; padding: 0 18px 14px; }
.logo small { display: block; font-size: 11px; font-weight: 400; color: #8fa3bb; }
.side a { display: flex; justify-content: space-between; padding: 9px 18px; color: #cfd8e3; }
.side a:hover { background: #1b3556; text-decoration: none; }
.side a.on { background: var(--brand); color: #fff; }
.side .who { margin-top: auto; padding: 12px 18px; font-size: 12px; border-top: 1px solid #24405f; }
.side .who button { margin-top: 8px; }
.badge { background: var(--bad); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; }
.main { padding: 22px 26px; min-width: 0; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.cols { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 1000px) { .cols, .grid2 { grid-template-columns: 1fr; } .layout { grid-template-columns: 1fr; } .side { position: static; height: auto; } }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
input, select, textarea { width: 100%; padding: 7px 9px; border: 1px solid #c5ccd6; border-radius: 6px; font: inherit; background: #fff; color: var(--ink); }
input[type=checkbox] { width: auto; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc3ee; border-color: var(--brand); }
.field { flex: 1 1 180px; margin-bottom: 10px; }
button, .btn { padding: 7px 14px; border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink); border-radius: 6px; font: inherit; cursor: pointer; display: inline-block; }
button:hover, .btn:hover { filter: brightness(1.1); text-decoration: none; }
button.ghost, .btn.ghost { background: #fff; color: var(--brand); }
button.danger { background: var(--bad); border-color: var(--bad); }
button.small { padding: 3px 9px; font-size: 12px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover { background: #f1f6fc; }
.tablewrap { overflow-x: auto; }

.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: #e8edf3; color: #3c4858; white-space: nowrap; }
.tag.ok { background: #dff3e7; color: var(--ok); }
.tag.warn { background: #fdeed3; color: var(--warn); }
.tag.bad { background: #fbe0dc; color: var(--bad); }
.tag.info { background: #dceafa; color: var(--brand); }
.muted { color: var(--muted); }
.pre { white-space: pre-wrap; }
.error { color: var(--bad); margin: 8px 0; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.tile b { display: block; font-size: 24px; }
.tile span { color: var(--muted); font-size: 12px; }
.tile em { font-style: normal; color: var(--muted); font-size: 13px; margin-left: 6px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 14px; border-left: 2px solid var(--line); margin-left: 4px; }
.timeline li.escalation, .timeline li.emergency { border-color: var(--bad); }
.timeline small { color: var(--muted); display: block; }

.callbar { background: #fff6dd; border: 1px solid #f0cf7a; border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.alert { background: #fbe0dc; border: 1px solid #efb1a9; border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; }

.login { max-width: 360px; margin: 12vh auto; }
.login h1 { text-align: center; }
details summary { cursor: pointer; color: var(--brand); margin-bottom: 8px; }

.tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--line); margin: -6px 0 16px; }
.tabs a { padding: 7px 12px; border: 1px solid var(--line); border-bottom: none; border-radius: 8px 8px 0 0; background: #e9edf2; color: var(--ink); font-size: 13px; white-space: nowrap; }
.tabs a:hover { text-decoration: none; background: #f4f6f9; }
.tabs a.on { background: var(--panel); border-color: var(--brand); border-bottom: 2px solid var(--panel); margin-bottom: -1px; font-weight: 600; }
.tabs .x { margin-left: 8px; color: var(--muted); font-weight: 400; padding: 0 3px; border-radius: 3px; }
.tabs .x:hover { background: #d5dbe3; color: var(--bad); }
.map { height: 340px; border-radius: 6px; border: 1px solid var(--line); z-index: 0; }
.mapsearch { position: relative; margin-bottom: 8px; }
.mapres { position: absolute; z-index: 1000; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid #c5ccd6; border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.12); max-height: 240px; overflow: auto; }
.mapres div { padding: 7px 10px; cursor: pointer; border-bottom: 1px solid var(--line); }
.mapres div:hover { background: #f1f6fc; }
.checks { gap: 22px; margin-bottom: 10px; }
.checks label { font-size: 14px; color: var(--ink); display: flex; gap: 6px; align-items: center; margin: 0; }
.comment { background: #eef7f0; border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; }
.comment small { color: var(--muted); display: block; }
tr.sel { background: #e3eefb; }

/* ---------- Оформление: орнаменты и портрет ---------- */
.side { background: linear-gradient(180deg, #0c3550 0%, #0a4a6e 100%); position: sticky; }
.side::before { content: ""; position: absolute; inset: 0; background: url(brand/ornament-light.svg) 0 0 / 120px 120px; pointer-events: none; }
.side > * { position: relative; }
.logo { padding-bottom: 12px; margin-bottom: 8px; color: #fff; }
.logo::after { content: ""; display: block; height: 24px; margin: 12px -18px 0; background: url(brand/ornament-band.svg) 0 0 / 60px 24px repeat-x; }
.logo small { color: #cfe3ee; }
.side a.on { background: rgba(255,255,255,.14); box-shadow: inset 4px 0 0 var(--gold); }
.side a:hover { background: rgba(255,255,255,.08); }
.side .who { border-top-color: rgba(255,255,255,.18); }
.main { position: relative; }
h1 { padding-bottom: 8px; border-bottom: 2px solid var(--gold-soft); }
.panel, .tile { background: rgba(255,255,255,.94); }
.tabs a.on { border-color: var(--gold); }
button, .btn { border-color: var(--brand); background: var(--brand); }

/* портрет в рабочей области: правый нижний угол, под содержимым, не мешает щелчкам */
.portrait-work { position: fixed; right: 0; bottom: 0; width: min(34vw, 460px); height: min(70vh, 620px); background: url(brand/portrait.png) right bottom / contain no-repeat; opacity: var(--portrait-work); pointer-events: none; z-index: 0; }
.layout > .main > *:not(.portrait-work) { position: relative; z-index: 1; }
.side .muted { color: #b9d2e0; }

/* страница входа */
.loginpage { min-height: 100vh; display: grid; place-items: center; position: relative; overflow: hidden; background: linear-gradient(135deg, #0c3550 0%, #0a6fa8 60%, #1389b8 100%); }
.loginpage::before { content: ""; position: absolute; inset: 0; background: url(brand/ornament-login.svg) 0 0 / 120px 120px; }
.loginpage .portrait { position: absolute; right: 4vw; bottom: 0; width: min(44vw, 620px); height: 92vh; background: url(brand/portrait.png) right bottom / contain no-repeat; opacity: var(--portrait-login); pointer-events: none; }
.loginpage .login { position: relative; margin: 0; width: min(380px, 92vw); max-width: none; background: rgba(255,255,255,.96); border: none; border-top: 4px solid var(--gold); box-shadow: 0 18px 50px rgba(0,0,0,.28); padding: 26px 26px 22px; }
.loginpage .login h1 { border: none; padding: 0; font-size: 26px; color: #0c3550; margin-bottom: 14px; }
.loginpage .login::before { content: ""; display: block; height: 24px; margin: -6px 0 14px; background: url(brand/ornament-band.svg) center / 60px 24px repeat-x; filter: saturate(.9) brightness(.8); }
.loginpage .login button { width: 100%; padding: 10px; }
.no-portrait .portrait, .no-portrait .portrait-work { display: none; }
@media (max-width: 800px) { .loginpage .portrait, .portrait-work { display: none; } }

/* линии поддержки */
.tag.line1 { background: #dceafa; color: #0a5a8c; }
.tag.line2 { background: #e6e0f7; color: #5a3ea6; }
.tag.line3 { background: #fbe9c8; color: #8a5a00; border: 1px solid #e9c97a; }
.timeline li.line { border-color: #8a6fd1; }

/* лицензия и соглашение */
.licfoot { margin-top: 10px; font-size: 11px; color: #b9d2e0; }
.modal { position: fixed; inset: 0; z-index: 5000; background: rgba(8, 30, 46, .72); display: grid; place-items: center; padding: 20px; }
.modalbox { background: #fff; border-radius: 10px; border-top: 4px solid var(--gold); width: min(820px, 100%); max-height: 92vh; display: flex; flex-direction: column; padding: 22px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.eulatext { overflow: auto; max-height: 52vh; border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; background: #fafbfc; font-size: 13px; line-height: 1.5; }
.panel .eulatext { max-height: 420px; }

/* фото и видео в карточке */
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; }
.thumb { position: relative; }
.thumb img { display: block; height: 120px; max-width: 220px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.thumb .nothumb { display: grid; place-items: center; text-align: center; width: 140px; height: 120px; padding: 6px; border: 1px dashed #b9c2cd; border-radius: 6px; font-size: 12px; color: var(--muted); overflow: hidden; word-break: break-all; }
.thumb.video { flex: 1 1 100%; }
.thumb.video video { display: block; max-width: 100%; max-height: 320px; border-radius: 6px; background: #000; }
.filedel { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; padding: 0; line-height: 18px; border-radius: 50%; border: 1px solid #fff; background: rgba(192, 57, 43, .92); color: #fff; font-size: 15px; opacity: 0; transition: opacity .15s; }
.thumb:hover .filedel, .filedel:focus { opacity: 1; }

/* ---------- Меню: более жирный шрифт ---------- */
.logo { font-size: 20px; font-weight: 800; }
.logo small { font-weight: 500; }
.side a { font-size: 15px; font-weight: 600; }
.side a.on { font-weight: 800; }
.side .who { font-weight: 600; }
.themebtn { margin-top: 8px; margin-left: 6px; }

/* ---------- Тёмная тема: включается кнопкой в меню, выбор запоминается в браузере ---------- */
html[data-theme="dark"] {
  --bg: #0f1722; --panel: #182330; --ink: #e6edf5; --muted: #a3b3c6; --line: #2a3a4c;
  --brand: #e2b04a; --brand-ink: #1b1405; --ok: #aeeac6; --warn: #ffdc8f; --bad: #ffc4bc; --side: #0a1119;
  --gold: #e2b04a; --gold-soft: #4a3a12;
  --portrait-login: .16; --portrait-work: .05;
  color-scheme: dark;
}
html[data-theme="dark"] body { background: var(--bg); }                       /* без узора на фоне: ночью меньше ряби */
html[data-theme="dark"] a { color: #f0c56a; }
html[data-theme="dark"] .side { background: #0a1119; border-right: 1px solid #1e2b3a; }
html[data-theme="dark"] .side::before { background-image: url(brand/ornament-login.svg); opacity: .6; }
html[data-theme="dark"] .side a { color: #d5dfea; }
html[data-theme="dark"] .side a.on { background: #1a2736; color: #fff; }
html[data-theme="dark"] .side .muted, html[data-theme="dark"] .licfoot, html[data-theme="dark"] .logo small { color: #9fb0c3; }
html[data-theme="dark"] .panel, html[data-theme="dark"] .tile { background: var(--panel); }
html[data-theme="dark"] input, html[data-theme="dark"] select, html[data-theme="dark"] textarea { background: #0f1722; border-color: #3a4d63; color: var(--ink); }
html[data-theme="dark"] input:focus, html[data-theme="dark"] select:focus, html[data-theme="dark"] textarea:focus { outline-color: #8a6a22; }
html[data-theme="dark"] input::placeholder, html[data-theme="dark"] textarea::placeholder { color: #8395aa; }
html[data-theme="dark"] button.ghost, html[data-theme="dark"] .btn.ghost { background: transparent; color: #f0c56a; }
html[data-theme="dark"] button.danger { background: #b23a2e; border-color: #b23a2e; color: #fff; }
html[data-theme="dark"] .badge { background: #c0392b; color: #fff; }
html[data-theme="dark"] tr.click:hover, html[data-theme="dark"] .mapres div:hover { background: #1f2e3f; }
html[data-theme="dark"] tr.sel { background: #22344a; }
html[data-theme="dark"] .tag { background: #2a3a4c; color: #d5dfea; }
html[data-theme="dark"] .tag.ok { background: #163d2a; color: #aeeac6; }
html[data-theme="dark"] .tag.warn { background: #4a3a12; color: #ffdc8f; }
html[data-theme="dark"] .tag.bad { background: #4f201b; color: #ffc4bc; }
html[data-theme="dark"] .tag.info, html[data-theme="dark"] .tag.line1 { background: #17365a; color: #c4e0ff; }
html[data-theme="dark"] .tag.line2 { background: #35295e; color: #dcd0ff; }
html[data-theme="dark"] .tag.line3 { background: #4a3a12; color: #ffdc8f; border-color: #7a6220; }
html[data-theme="dark"] .callbar { background: #3a2f12; border-color: #7a6220; }
html[data-theme="dark"] .alert { background: #4f201b; border-color: #8c3a31; }
html[data-theme="dark"] .error { color: #ffb4aa; }
html[data-theme="dark"] .tabs a { background: #131d29; }
html[data-theme="dark"] .tabs a:hover { background: #1c2937; }
html[data-theme="dark"] .tabs a.on { background: var(--panel); border-color: var(--gold); border-bottom-color: var(--panel); }
html[data-theme="dark"] .tabs .x:hover { background: #2a3a4c; }
html[data-theme="dark"] .mapres { background: var(--panel); border-color: #3a4d63; }
html[data-theme="dark"] .comment { background: #16302a; }
html[data-theme="dark"] .timeline li.line { border-color: #8a6fd1; }
html[data-theme="dark"] .modalbox { background: var(--panel); }
html[data-theme="dark"] .eulatext { background: #0f1722; }
html[data-theme="dark"] .thumb img { border-color: #3a4d63; }
html[data-theme="dark"] .thumb .nothumb { border-color: #4a5d73; }
html[data-theme="dark"] h1 { border-bottom-color: #3a3113; }
html[data-theme="dark"] .loginpage { background: linear-gradient(135deg, #070c12 0%, #0f1c2a 60%, #152a3d 100%); }
html[data-theme="dark"] .loginpage .login { background: var(--panel); }
html[data-theme="dark"] .loginpage .login h1 { color: #fff; }
html[data-theme="dark"] .leaflet-tile-pane { filter: brightness(.72) contrast(1.08) saturate(.8); }   /* карта не слепит на тёмном фоне */
html[data-theme="dark"] .leaflet-container { background: #1a2532; }
html[data-theme="dark"] .leaflet-bar a, html[data-theme="dark"] .leaflet-control-attribution { background: #182330; color: #d5dfea; border-color: #3a4d63; }

.tag.archive { background: #e9e5dc; color: #5b5142; }
html[data-theme="dark"] .tag.archive { background: #3a352b; color: #e2d8c3; }

/* ---------- Дашборд: графики ---------- */
.viz-root { --viz-series: #2a78d6; --viz-other: #9aa3ad; --viz-grid: #e6e9ee; --viz-axis: #c3c9d1; --viz-ink2: #566273; --viz-surface: #ffffff;
  --h0: #eef1f5; --h1: #cde2fb; --h2: #9ec5f4; --h3: #6da7ec; --h4: #3987e5; --h5: #256abf; --h6: #184f95; --h7: #0d366b; }
html[data-theme="dark"] .viz-root { --viz-series: #3987e5; --viz-other: #6f7d8e; --viz-grid: #26364a; --viz-axis: #3a4d63; --viz-ink2: #a3b3c6; --viz-surface: #182330;
  --h0: #1f2d3d; --h1: #0d366b; --h2: #184f95; --h3: #256abf; --h4: #3987e5; --h5: #6da7ec; --h6: #9ec5f4; --h7: #cde2fb; }
.viz-root .tiles { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.tile span { display: block; margin-bottom: 4px; }
.tile b { font-size: 26px; line-height: 1.15; }
.tile small { display: block; margin-top: 4px; font-size: 12px; color: var(--muted); }
.viz-card h2 { margin-bottom: 2px; }
.viz-sub { font-size: 12px; margin-bottom: 12px; }
.viz-grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 16px; }
.viz-grid2 .panel { margin-bottom: 16px; min-width: 0; }
.viz-root svg { display: block; max-width: 100%; }
.viz-grid { stroke: var(--viz-grid); stroke-width: 1; }
.viz-axis { stroke: var(--viz-axis); stroke-width: 1; }
.viz-lab { font-size: 11px; fill: var(--viz-ink2); }
.viz-val { font-size: 12px; font-weight: 600; fill: var(--ink); }
.viz-line { fill: none; stroke: var(--viz-series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz-area { fill: var(--viz-series); opacity: .1; }
.viz-dot { fill: var(--viz-series); stroke: var(--viz-surface); stroke-width: 2; }
.viz-cross { stroke: var(--viz-axis); stroke-width: 1; }
.viz-row { display: grid; grid-template-columns: minmax(120px, 38%) 1fr 64px; gap: 10px; align-items: center; padding: 5px 0; border-radius: 4px; outline: none; }
.viz-row:hover, .viz-row:focus { background: rgba(127, 140, 160, .12); }
.viz-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viz-track { height: 16px; }
.viz-bar { height: 16px; background: var(--viz-series); border-radius: 0 4px 4px 0; }
.viz-bar.other { background: var(--viz-other); }
.viz-num { font-size: 13px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.viz-heat { display: grid; grid-template-columns: 28px repeat(24, minmax(0, 1fr)); gap: 2px; align-items: center; max-width: 980px; }
.viz-hh, .viz-hd { font-size: 11px; color: var(--viz-ink2); }
.viz-hh { text-align: left; }
.viz-cell { height: 22px; border-radius: 3px; outline: none; }
.viz-heat .viz-cell:hover, .viz-heat .viz-cell:focus { box-shadow: 0 0 0 2px var(--viz-surface), 0 0 0 3px var(--ink); }
.viz-cell.h0 { background: var(--h0); } .viz-cell.h1 { background: var(--h1); } .viz-cell.h2 { background: var(--h2); } .viz-cell.h3 { background: var(--h3); }
.viz-cell.h4 { background: var(--h4); } .viz-cell.h5 { background: var(--h5); } .viz-cell.h6 { background: var(--h6); } .viz-cell.h7 { background: var(--h7); }
.viz-legend { display: flex; align-items: center; gap: 3px; margin-top: 10px; font-size: 11px; color: var(--viz-ink2); }
.viz-legend .viz-cell { display: inline-block; width: 18px; height: 12px; }
.viz-legend span { margin: 0 5px; }
.viz-table { margin-top: 10px; }
.viz-table td, .viz-table th { padding: 4px 8px; font-size: 12px; font-variant-numeric: tabular-nums; }
.viztip { position: fixed; z-index: 6000; pointer-events: none; background: #1b2430; color: #fff; border-radius: 6px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 18px rgba(0,0,0,.28); max-width: 320px; }
html[data-theme="dark"] .viztip { background: #e6edf5; color: #10202f; }
.viztip-t { opacity: .8; margin-bottom: 4px; }
.viztip-r { display: flex; align-items: baseline; gap: 6px; }
.viztip-r b { font-size: 14px; font-variant-numeric: tabular-nums; }
.viztip-r span { opacity: .8; }
.viztip-k { display: inline-block; width: 12px; height: 2px; background: #5b9ff0; align-self: center; }
.seg { display: inline-flex; border: 1px solid #c5ccd6; border-radius: 6px; overflow: hidden; }
.seg button { border: none; border-right: 1px solid #c5ccd6; border-radius: 0; background: var(--panel); color: var(--ink); padding: 7px 12px; }
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--brand); color: var(--brand-ink); }
html[data-theme="dark"] .seg, html[data-theme="dark"] .seg button { border-color: #3a4d63; }
