:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --text: #1c2330;
  --muted: #6b7484;
  --line: #e2e6ec;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --ok: #2e9e5b;
  --ok-soft: #dff3e7;
  --bad: #d4553f;
  --bad-soft: #fbe5e0;
  --warn: #c98a12;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 16px rgba(20, 30, 50, .06);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b;
    --panel: #1b2029;
    --panel-2: #232a35;
    --text: #e6e9ef;
    --muted: #949cab;
    --line: #2d3542;
    --accent: #5b8ff0;
    --ok: #4cc27f;
    --ok-soft: #1d3a2a;
    --bad: #ec7a65;
    --bad-soft: #43251f;
    --warn: #e0a93a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151b; --panel: #1b2029; --panel-2: #232a35; --text: #e6e9ef; --muted: #949cab; --line: #2d3542;
  --accent: #5b8ff0; --ok: #4cc27f; --ok-soft: #1d3a2a; --bad: #ec7a65; --bad-soft: #43251f; --warn: #e0a93a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

/* ---------- шапка ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px; height: 56px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; white-space: nowrap; }
.brand svg { width: 24px; height: 24px; }
.tabs { display: flex; gap: 4px; }
.tabs a {
  padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 550;
}
.tabs a:hover { background: var(--panel-2); text-decoration: none; color: var(--text); }
.tabs a.on { background: var(--panel-2); color: var(--text); }
.top .spacer { flex: 1; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; white-space: nowrap; color: var(--text);
}
.btn:hover { background: var(--panel-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn svg { width: 16px; height: 16px; }

main { max-width: 1400px; margin: 0 auto; padding: 20px; }

/* ---------- полосы прогресса ---------- */
.bar { height: 8px; border-radius: 99px; background: var(--bad-soft); overflow: hidden; display: flex; }
.bar > i { display: block; height: 100%; background: var(--ok); }
.bar.big { height: 14px; }
.pct-ok { color: var(--ok); font-weight: 600; }
.pct-bad { color: var(--bad); font-weight: 600; }

/* ---------- файлы ---------- */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 17px; margin-bottom: 12px; }
.crumbs a, .crumbs span { padding: 2px 4px; border-radius: 6px; }
.crumbs span.cur { font-weight: 650; }
.crumbs .sep { color: var(--muted); padding: 0; }

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.toolbar .sum { flex: 1 1 320px; min-width: 0; }
.toolbar .sum .bar { margin-top: 6px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; white-space: nowrap; }
.toggle input { width: 16px; height: 16px; accent-color: var(--accent); }
select.btn { padding-right: 8px; }

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 8px 0 10px; font-weight: 600; }

.dirs { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-bottom: 24px; }
.dir {
  display: flex; gap: 12px; align-items: center; padding: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); box-shadow: var(--shadow); min-width: 0;
}
.dir:hover { border-color: var(--accent); text-decoration: none; }
.dir .cover {
  width: 56px; height: 56px; flex: none; border-radius: 8px; background: var(--panel-2) center/cover no-repeat;
  display: grid; place-items: center; color: var(--muted);
}
.dir .cover svg { width: 28px; height: 28px; }
.dir .info { min-width: 0; flex: 1; }
.dir .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dir .meta { font-size: 13px; color: var(--muted); margin: 2px 0 6px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.tile {
  position: relative; display: flex; flex-direction: column; min-width: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; box-shadow: var(--shadow); text-align: left; padding: 0;
}
.tile:hover { border-color: var(--accent); }
.tile .th {
  aspect-ratio: 1; background: var(--panel-2); display: grid; place-items: center; position: relative; overflow: hidden;
}
.tile .th img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .th .ic { display: grid; place-items: center; gap: 4px; color: var(--muted); }
.tile .th .ic svg { width: 40px; height: 40px; }
.tile .th .ic b { font-size: 12px; letter-spacing: .05em; text-transform: uppercase; }
.tile .play {
  position: absolute; inset: auto auto 8px 8px; background: rgba(0,0,0,.6); color: #fff;
  border-radius: 99px; padding: 2px 8px 2px 6px; font-size: 12px; display: flex; align-items: center; gap: 4px;
}
.tile .play svg { width: 12px; height: 12px; }
.tile .cap { padding: 8px 10px; min-width: 0; }
.tile .cap .n { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .cap .s { font-size: 12px; color: var(--muted); }
.tile.lost { cursor: default; }
.tile.lost .th { background: repeating-linear-gradient(135deg, var(--panel-2) 0 10px, var(--bad-soft) 10px 20px); }
.tile.lost .badge {
  position: absolute; top: 8px; left: 8px; font-size: 11px; font-weight: 600;
  background: var(--bad); color: #fff; border-radius: 6px; padding: 1px 6px;
}
.tile.lost .cap .n { color: var(--muted); }

.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- просмотр ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 100; background: #0b0d11; color: #eee;
  display: grid; grid-template-rows: auto 1fr;
}
.viewer[hidden] { display: none; }
.viewer .vbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-width: 0; }
.viewer .vbar .t { flex: 1; min-width: 0; }
.viewer .vbar .t .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.viewer .vbar .t .m { font-size: 12px; color: #aab; }
.viewer .vbtn {
  border: 0; background: rgba(255,255,255,.1); color: #fff; border-radius: 8px; padding: 8px 12px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.viewer .vbtn:hover { background: rgba(255,255,255,.2); text-decoration: none; }
.viewer .vbtn svg { width: 18px; height: 18px; }
.viewer .stage { position: relative; min-height: 0; display: grid; place-items: center; padding: 0 56px 16px; }
.viewer .stage > * { max-width: 100%; max-height: 100%; }
.viewer .stage img { object-fit: contain; width: auto; height: auto; max-height: calc(100vh - 80px); }
.viewer .stage video { width: 100%; height: calc(100vh - 80px); object-fit: contain; background: #000; border-radius: 6px; }
.viewer .stage iframe { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 6px; }
.viewer .stage pre {
  width: min(1000px, 100%); height: 100%; overflow: auto; margin: 0; padding: 16px; border-radius: 8px;
  background: #1a1d23; color: #dde; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-word;
}
.viewer .nav {
  position: absolute; top: 50%; transform: translateY(-50%); border: 0; width: 44px; height: 64px; border-radius: 10px;
  background: rgba(255,255,255,.08); color: #fff; cursor: pointer; display: grid; place-items: center;
}
.viewer .nav:hover { background: rgba(255,255,255,.18); }
.viewer .nav svg { width: 24px; height: 24px; }
.viewer .nav.prev { left: 6px; }
.viewer .nav.next { right: 6px; }
.viewer .msg { text-align: center; max-width: 480px; display: grid; gap: 12px; justify-items: center; color: #ccd; }
.viewer .msg img { max-height: 50vh; border-radius: 8px; }
.viewer .msg svg.big { width: 64px; height: 64px; opacity: .7; }
.spin { width: 36px; height: 36px; border: 3px solid rgba(255,255,255,.2); border-top-color: #fff; border-radius: 50%; animation: sp 1s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

/* ---------- мониторинг ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; min-width: 0;
}
.kpi .l { font-size: 13px; color: var(--muted); }
.kpi .v { font-size: 28px; font-weight: 650; margin: 2px 0; }
.kpi .s { font-size: 13px; color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.off { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.cols { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; margin-top: 16px; }
@media (max-width: 1000px) { .cols { grid-template-columns: minmax(0, 1fr); } }
.card h2 { font-size: 16px; margin: 0 0 12px; }
.card h2 .muted { font-weight: 400; font-size: 13px; }
.overall .row { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-top: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.scroll { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t td.r, table.t th.r { text-align: right; white-space: nowrap; }
table.t tr:last-child td { border-bottom: 0; }
.tree td.name { white-space: nowrap; max-width: 420px; overflow: hidden; text-overflow: ellipsis; }
.tree .tw {
  width: 22px; height: 22px; border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0;
  display: inline-grid; place-items: center; vertical-align: middle; border-radius: 4px;
}
.tree .tw:hover { background: var(--panel-2); }
.tree .tw svg { width: 14px; height: 14px; transition: transform .15s; }
.tree .tw.open svg { transform: rotate(90deg); }
.tree .tw.none { visibility: hidden; }
.tree td.barc { width: 26%; min-width: 130px; }
.barp { display: flex; align-items: center; gap: 8px; }
.barp .bar { flex: 1; }
.barp span { font-size: 13px; color: var(--muted); width: 36px; text-align: right; }

.chart { display: flex; align-items: flex-end; gap: 2px; height: 120px; padding-top: 8px; }
.chart > div { flex: 1; background: var(--ok); border-radius: 3px 3px 0 0; min-height: 1px; position: relative; }
.chart > div.zero { background: var(--line); }
.chart-x { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }
.list { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.list li { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.list li:last-child { border-bottom: 0; }
.list li .p { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li .m { color: var(--muted); white-space: nowrap; font-size: 13px; }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(360px, 100%); display: grid; gap: 12px; }
.login h1 { font-size: 20px; margin: 0 0 4px; display: flex; gap: 8px; align-items: center; }
.login h1 svg { width: 28px; height: 28px; }
.login input {
  font: inherit; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.login .err { color: var(--bad); font-size: 14px; }

@media (max-width: 640px) {
  .top { padding: 0 12px; gap: 8px; }
  .brand span { display: none; }
  main { padding: 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 8px; }
  .tile .cap { padding: 6px 8px; }
  .viewer .stage { padding: 0 0 12px; }
  .viewer .nav { display: none; }
  .viewer .vbtn span { display: none; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 12px; }
  .kpi .v { font-size: 22px; }
}
