/* CamViewer — спокойный, читаемый интерфейс. Цвета — токены; тёмная тема — по настройке системы. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e2e5ea;
  --border-strong: #cdd2da;
  --text: #1c2430;
  --text-2: #4a5565;
  --muted: #6b7584;
  --accent: #2459d6;
  --accent-soft: #e8eefc;
  --ok: #1d7a46;      --ok-soft: #e4f4ea;
  --warn: #a35b00;    --warn-soft: #fdf0dc;
  --bad: #b42318;     --bad-soft: #fde8e6;
  --off: #5d6672;     --off-soft: #eceef1;
  --unknown: #4b5b75; --unknown-soft: #e8ecf3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 10px;
  --radius-sm: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1318;
    --surface: #171c23;
    --surface-2: #1d232b;
    --border: #2a313b;
    --border-strong: #3a4350;
    --text: #e7eaee;
    --text-2: #b9c0ca;
    --muted: #8d96a3;
    --accent: #7aa2ff;
    --accent-soft: #1f2a44;
    --ok: #4cc283;      --ok-soft: #12291d;
    --warn: #f0a640;    --warn-soft: #2f2412;
    --bad: #ff7b6e;     --bad-soft: #351816;
    --off: #9aa3ae;     --off-soft: #232931;
    --unknown: #9fb0cc; --unknown-soft: #1f2632;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text); font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased; min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; font-weight: 650; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); font-size: .85em; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- раскладка ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1440px; margin: 0 auto; padding: 0 16px; height: 56px;
  display: flex; align-items: center; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand svg { color: var(--accent); }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  padding: 6px 10px; border-radius: var(--radius-sm); color: var(--text-2); white-space: nowrap; font-size: .93rem;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.userbox { display: flex; align-items: center; gap: 10px; font-size: .9rem; color: var(--text-2); white-space: nowrap; }
.userbox form { margin: 0; }
.container { max-width: 1440px; margin: 0 auto; padding: 20px 16px 48px; }
.container.narrow { max-width: 860px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { color: var(--muted); font-size: .92rem; margin-top: 2px; }
.crumbs { font-size: .88rem; color: var(--muted); margin-bottom: 4px; }
.crumbs a { color: var(--muted); }

/* ---------- поверхности ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.section { margin-bottom: 20px; }
.section-title { display: flex; align-items: baseline; gap: 10px; margin: 0 0 10px; }
.section-title h2 { margin: 0; }
.banner {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius);
  margin-bottom: 16px; border: 1px solid; font-size: .93rem;
}
.banner.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 35%, transparent); color: var(--text); }
.banner.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.banner.info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.banner svg { flex: none; margin-top: 2px; }

/* ---------- элементы управления ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-size: .92rem; font-weight: 550;
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { height: 30px; padding: 0 10px; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.icon-btn { width: 36px; padding: 0; }

label { display: block; font-size: .88rem; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], input[type=search], input[type=date],
input[type=time], input[type=url], select, textarea {
  width: 100%; height: 38px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; font-size: .95rem;
}
textarea { height: auto; min-height: 84px; padding: 8px 10px; resize: vertical; }
.field { margin-bottom: 14px; }
.field .hint { font-size: .82rem; color: var(--muted); margin-top: 4px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 16px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; color: var(--text); margin: 0; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
fieldset { border: 0; padding: 0; margin: 0 0 8px; }
legend { font-weight: 650; font-size: 1rem; margin-bottom: 10px; padding: 0; }
.form-error { color: var(--bad); font-size: .9rem; margin-top: 8px; }

.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.segmented button {
  height: 34px; padding: 0 12px; border: 0; background: var(--surface); color: var(--text-2);
  font: inherit; font-size: .88rem; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.segmented button + button { border-left: 1px solid var(--border-strong); }
.segmented button[aria-pressed=true] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
.chip {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2);
  border-radius: 999px; height: 32px; padding: 0 12px; font: inherit; font-size: .86rem; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip[aria-pressed=true] { background: var(--text); color: var(--surface); border-color: var(--text); }
.chip .count { font-variant-numeric: tabular-nums; opacity: .75; }

/* ---------- статусы ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 8px 0 6px; border-radius: 999px;
  font-size: .8rem; font-weight: 650; white-space: nowrap; border: 1px solid transparent;
}
.badge svg { width: 14px; height: 14px; flex: none; }
.lvl-ok { background: var(--ok-soft); color: var(--ok); }
.lvl-warn { background: var(--warn-soft); color: var(--warn); }
.lvl-bad { background: var(--bad-soft); color: var(--bad); }
.lvl-off { background: var(--off-soft); color: var(--off); }
.lvl-unknown { background: var(--unknown-soft); color: var(--unknown); }

/* ---------- главная ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  text-align: left; padding: 14px 16px; cursor: pointer; font: inherit; color: inherit;
  display: flex; flex-direction: column; gap: 2px; border: 1px solid var(--border);
}
.stat:hover { border-color: var(--border-strong); }
.stat[aria-pressed=true] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.stat .label { font-size: .86rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.ok .value { color: var(--ok); }
.stat.problem .value { color: var(--bad); }
.stat .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.stat .dot.lvl-ok { background: var(--ok); }
.stat .dot.lvl-bad { background: var(--bad); }
.stat .dot.lvl-off { background: var(--off); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .search { flex: 1 1 220px; max-width: 360px; position: relative; }
.toolbar .search input { padding-left: 34px; }
.toolbar .search svg { position: absolute; left: 10px; top: 11px; color: var(--muted); }
.toolbar .spacer { flex: 1; }
.office-filter { margin-bottom: 14px; }

.group { margin-bottom: 22px; }
.group-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.group-head h2 { margin: 0; font-size: 1.05rem; }
.group-head .meta { color: var(--muted); font-size: .88rem; }
.group-head .meta .bad { color: var(--bad); font-weight: 600; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.cam-card { overflow: hidden; display: flex; flex-direction: column; }
.cam-card .thumb {
  position: relative; aspect-ratio: 16 / 9; background: var(--surface-2); display: block; overflow: hidden;
  border-bottom: 1px solid var(--border);
}
.cam-card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .noimg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 6px;
  color: var(--muted); font-size: .85rem;
}
.thumb.is-stale img, .viewer.is-stale img { filter: grayscale(.85) brightness(.85); opacity: .7; }
.stale-tag {
  position: absolute; left: 8px; bottom: 8px; right: 8px; display: flex; gap: 6px; align-items: center;
  background: rgba(20, 24, 31, .82); color: #fff; padding: 4px 8px; border-radius: var(--radius-sm); font-size: .8rem; font-weight: 600;
  width: fit-content; max-width: calc(100% - 16px);
}
.cam-card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.cam-card .title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.cam-card .name { font-weight: 650; color: var(--text); overflow-wrap: anywhere; }
.cam-card .meta { font-size: .84rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.cam-card .reason { font-size: .84rem; color: var(--text-2); overflow-wrap: anywhere; }
.cam-card .actions { display: flex; gap: 6px; margin-top: auto; padding-top: 4px; }
.cam-card .actions .btn { flex: 1; }
.cam-card .actions .btn.gear { flex: 0 0 30px; width: 30px; }

.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.list th, table.list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 650; background: var(--surface-2); }
table.list tr:last-child td { border-bottom: 0; }
table.list td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
table.list .actions { white-space: nowrap; text-align: right; }
table.list .mini-thumb { width: 64px; height: 36px; object-fit: cover; border-radius: 4px; background: var(--surface-2); display: block; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }

/* ---------- страница камеры ---------- */
.cam-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.viewer { position: relative; background: #0d1014; border-radius: var(--radius); overflow: hidden; min-height: 200px; display: flex; align-items: center; justify-content: center; }
.viewer img { max-width: 100%; max-height: 78vh; display: block; margin: 0 auto; }
.viewer .noimg { color: #9aa3ae; padding: 60px 16px; text-align: center; }
.viewer-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 0; }
.viewer-bar .when { font-variant-numeric: tabular-nums; font-weight: 600; }
.info-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; font-size: .9rem; margin: 0; }
.info-list dt { color: var(--muted); }
.info-list dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.error-box { background: var(--bad-soft); color: var(--text); border-radius: var(--radius-sm); padding: 10px 12px; font-size: .88rem; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- архив ---------- */
.archive-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.archive-controls input[type=date] { width: auto; }
.hours { display: grid; grid-template-columns: repeat(24, minmax(0, 1fr)); gap: 3px; }
.hour {
  border: 1px solid var(--border); border-radius: 4px; height: 44px; padding: 0; cursor: pointer; position: relative;
  background: var(--surface-2); font: inherit; font-size: .72rem; color: var(--text-2); display: flex; flex-direction: column;
  justify-content: flex-end; overflow: hidden;
}
.hour .fill { position: absolute; left: 0; right: 0; bottom: 0; background: var(--ok); opacity: .28; }
.hour.partial .fill { background: var(--warn); opacity: .35; }
.hour.none { background: repeating-linear-gradient(135deg, var(--bad-soft), var(--bad-soft) 4px, transparent 4px, transparent 8px); }
.hour.future { opacity: .4; cursor: default; background: transparent; }
.hour .lbl { position: relative; padding-bottom: 2px; }
.hour[aria-pressed=true] { outline: 2px solid var(--accent); outline-offset: 1px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; border: 1px solid var(--border); }
.legend .l-full { background: color-mix(in srgb, var(--ok) 30%, var(--surface)); }
.legend .l-part { background: color-mix(in srgb, var(--warn) 35%, var(--surface)); }
.legend .l-none { background: repeating-linear-gradient(135deg, var(--bad-soft), var(--bad-soft) 3px, transparent 3px, transparent 6px); }
.minutes { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; }
.minute {
  border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: var(--surface-2); cursor: pointer;
  padding: 0; font: inherit; color: var(--text-2); text-align: left;
}
.minute img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: var(--surface-2); }
.minute .t { font-size: .74rem; padding: 2px 6px; font-variant-numeric: tabular-nums; display: flex; justify-content: space-between; }
.minute.empty-min { cursor: default; }
.minute.empty-min .ph {
  aspect-ratio: 16/9; display: flex; align-items: center; justify-content: center; font-size: .72rem; color: var(--bad);
  background: repeating-linear-gradient(135deg, var(--bad-soft), var(--bad-soft) 4px, transparent 4px, transparent 8px);
}
.minute[aria-current=true] { outline: 2px solid var(--accent); outline-offset: 1px; }
.frame-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 0; }
.frame-nav input[type=range] { flex: 1 1 200px; accent-color: var(--accent); }
.gap-list { list-style: none; padding: 0; margin: 0; font-size: .88rem; }
.gap-list li { padding: 6px 0; border-bottom: 1px dashed var(--border); display: flex; gap: 8px; align-items: center; }
.gap-list li:last-child { border-bottom: 0; }

/* ---------- прочее ---------- */
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.bar > span { display: block; height: 100%; background: var(--accent); }
.bar.warn > span { background: var(--warn); }
.bar.bad > span { background: var(--bad); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.kpi .v { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .k { font-size: .84rem; color: var(--muted); }
.toast {
  position: fixed; right: 16px; bottom: 16px; z-index: 50; max-width: min(420px, calc(100vw - 32px));
  background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: var(--radius); box-shadow: var(--shadow);
  font-size: .92rem;
}
.toast.bad { background: var(--bad); color: #fff; }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; padding: 28px 24px; }
.test-result { margin-top: 12px; }
.test-result img { max-width: 100%; border-radius: var(--radius-sm); margin-top: 8px; display: block; }
.secret-state { font-size: .82rem; color: var(--ok); font-weight: 600; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
pre.details { white-space: pre-wrap; font-family: var(--mono); font-size: .78rem; margin: 0; color: var(--text-2); max-width: 520px; overflow-wrap: anywhere; }

@media (max-width: 1000px) {
  .cam-layout { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  body { font-size: 15px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat .value { font-size: 1.4rem; }
  .userbox .uname { display: none; }
  .topbar-inner { gap: 8px; }
  .brand span { display: none; }
  .toolbar .search { max-width: none; flex-basis: 100%; }
  .hours { grid-template-columns: repeat(12, minmax(0, 1fr)); }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .cam-card .body { padding: 8px 10px 10px; gap: 4px; }
  .cam-card .title-row { flex-direction: column; gap: 4px; }
  .cam-card .name { font-size: .92rem; }
  .cam-card .meta, .cam-card .reason { font-size: .78rem; }
  .cam-card .actions { display: none; }  /* камеру открывает вся карточка; оттуда до архива одно касание */
  .stale-tag { font-size: .7rem; left: 4px; bottom: 4px; padding: 2px 6px; }
  table.list.responsive thead { display: none; }
  table.list.responsive tr { display: block; border-bottom: 1px solid var(--border); padding: 8px 0; }
  table.list.responsive td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 4px 12px; }
  table.list.responsive td::before { content: attr(data-label); color: var(--muted); font-size: .82rem; }
  table.list.responsive td.actions { justify-content: flex-end; }
  table.list.responsive td.actions::before { content: none; }
}
.spacer { flex: 1; }
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.login-card .btn { width: 100%; height: 40px; }
.audit-nav { margin-top: 12px; }
.brand-logo { border-radius: 5px; display: block; }
.login-title { display: flex; align-items: center; gap: 10px; }
.login-title img { border-radius: 7px; }
.audit-search { position: relative; margin-bottom: 12px; max-width: 520px; }
.audit-search svg { position: absolute; left: 12px; top: 12px; color: var(--muted); }
.audit-search input { padding-left: 36px; height: 40px; }
.audit-filters { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 14px; margin-bottom: 12px; }
.audit-filters .field { margin-bottom: 0; }
.audit-filters .filter-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
.btn[aria-expanded=true] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.count-badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: .72rem; min-width: 18px; height: 18px;
  padding: 0 5px; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }
.active-filters { margin-bottom: 12px; flex-wrap: wrap; }
.active-filters:empty { display: none; }
.active-filters .chip { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.active-filters .chip .x { font-size: 1rem; line-height: 1; opacity: .7; }
.details-list { margin: 0; padding: 0; list-style: none; font-size: .82rem; color: var(--text-2); }
.details-list li { overflow-wrap: anywhere; }
.details-list b { font-weight: 600; color: var(--text); }
@media (max-width: 900px) { .audit-filters { grid-template-columns: 1fr 1fr; } }
