:root {
  --bg: #f5f6f8; --panel: #fff; --ink: #1c2430; --muted: #66707d; --line: #e2e5ea; --accent: #2f5bd3; --accent-ink: #fff;
  --ok: #1f8a4c; --warn: #b7791f; --bad: #c0392b; --soft: #eef2fb; --radius: 8px;
  --lvl-all: #6b4fd8; --lvl-department: #2f5bd3; --lvl-region: #0f8b8d; --lvl-local: #c46a1a;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 8px; }
h3 { font-size: 14px; margin: 0; }
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 6px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
button:hover { border-color: #c5cad3; background: #fafbfc; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); }
button.small { padding: 3px 8px; font-size: 12px; }
button.icon { padding: 3px 7px; }
button:disabled { opacity: .45; cursor: default; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; color: var(--ink); }
input[type=checkbox], input[type=radio] { padding: 0; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid #9db4f0; outline-offset: 0; }
label { display: block; }
.field { margin-bottom: 12px; }
.field > span, .label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--bad); }

/* layout */
.topbar { height: 52px; background: #111a2b; color: #fff; display: flex; align-items: center; padding: 0 16px; gap: 16px; }
.topbar .brand { font-weight: 700; letter-spacing: .06em; font-size: 16px; }
.topbar .brand span { color: #8fb0ff; }
.topbar a, .topbar button { color: #dfe6f5; background: transparent; border-color: transparent; }
.topbar button:hover { background: rgba(255,255,255,.08); border-color: transparent; }
.shell { display: grid; grid-template-columns: 290px 1fr; height: calc(100vh - 52px); }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); overflow: auto; padding: 12px 8px; }
.main { overflow: auto; padding: 20px 28px 60px; }

/* tree */
.tree ul { list-style: none; margin: 0; padding-left: 14px; }
.tree > ul { padding-left: 0; }
.tree .item { display: flex; align-items: center; gap: 6px; padding: 5px 6px; border-radius: 6px; cursor: pointer; }
.tree .item:hover { background: #f2f4f7; }
.tree .item.sel { background: var(--soft); font-weight: 600; }
.tree .item.locked { color: var(--muted); }
.tree .tog { width: 16px; color: var(--muted); text-align: center; font-size: 10px; flex: none; }
.tree .count { margin-left: auto; font-size: 11px; color: var(--muted); }
.lvl { display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 1px 6px; border-radius: 4px; color: #fff; flex: none; }
.lvl.all { background: var(--lvl-all); } .lvl.department { background: var(--lvl-department); }
.lvl.region { background: var(--lvl-region); } .lvl.local { background: var(--lvl-local); }

/* page */
.crumbs { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.crumbs a { color: var(--muted); }
.head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 600; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.card.dim { opacity: .65; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: #eef0f3; color: #4a5361; font-weight: 600; }
.badge.ok { background: #e3f4ea; color: var(--ok); } .badge.bad { background: #fbe7e5; color: var(--bad); }
.badge.warn { background: #fdf1dc; color: var(--warn); } .badge.accent { background: var(--soft); color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 26px; border: 1px dashed var(--line); border-radius: var(--radius); background: #fbfbfc; }

/* tables */
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.list td { padding: 7px 8px; border-bottom: 1px solid #f0f1f4; vertical-align: middle; }
table.list tr:last-child td { border-bottom: none; }
table.list tr.hidden td { opacity: .5; text-decoration: line-through; }
.thumb { width: 64px; height: 36px; object-fit: cover; border-radius: 4px; background: #e9ecf1; display: flex; align-items: center; justify-content: center; font-size: 16px; color: var(--muted); overflow: hidden; }
img.thumb { display: block; }

/* media grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(190px, 100%), 1fr)); gap: 12px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.tile.pick { cursor: pointer; }
.tile.pick:hover { border-color: var(--accent); }
.tile .pv { height: 110px; background: #e9ecf1; display: flex; align-items: center; justify-content: center; font-size: 30px; color: var(--muted); }
.tile .pv img { width: 100%; height: 100%; object-fit: cover; }
.tile .meta { padding: 8px 10px; flex: 1; overflow-wrap: anywhere; }
.tile .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .acts {
  padding: 0 10px 10px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(76px, 100%), 1fr));
  gap: 6px;
}
.tile .acts > * { min-width: 0; min-height: 28px; white-space: normal; overflow-wrap: anywhere; }
.tile .acts .btn { display: grid; place-items: center; padding: 3px 8px; text-align: center; }
.drop { border: 2px dashed #c9d2e3; border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); margin-bottom: 14px; background: #fafbfe; }
.drop.over { border-color: var(--accent); background: var(--soft); }
.progress { height: 6px; background: #e9ecf1; border-radius: 3px; overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* dialog */
dialog { border: none; border-radius: 10px; padding: 0; width: min(640px, 94vw); box-shadow: 0 20px 60px rgba(10, 20, 40, .25); }
dialog.wide { width: min(980px, 96vw); }
dialog::backdrop { background: rgba(15, 23, 32, .45); }
.dlg-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.dlg-body { padding: 16px 18px; max-height: 70vh; overflow: auto; }
.dlg-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
.sched { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: #fbfbfc; }
.days { display: flex; gap: 4px; flex-wrap: wrap; }
.days label { display: inline-flex; align-items: center; gap: 3px; border: 1px solid var(--line); border-radius: 6px; padding: 3px 7px; background: #fff; cursor: pointer; font-size: 12px; }
.days label.on { background: var(--soft); border-color: #b7c7f1; }
.windows .row { margin-bottom: 6px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.four { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }

/* login */
.login { max-width: 360px; margin: 12vh auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; }
.login h1 { margin-bottom: 18px; }
.login input { width: 100%; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast { background: #1c2430; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 420px; }
.toast.bad { background: var(--bad); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #b8bec8; margin-right: 6px; }
.dot.on { background: var(--ok); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 4px 12px; font-size: 13px; }
.kv div:nth-child(odd) { color: var(--muted); }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .split { grid-template-columns: 1fr; } }

/* dashboard */
.stats { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 12px; }
.stat { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat:hover { background: #fafbfc; }
.stat.sel { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.stat-value { font-size: 28px; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 12px; margin-top: 4px; font-weight: 600; }
.stat.ok .stat-value { color: var(--ok); }
.stat.bad .stat-value { color: var(--bad); }
.stat.warn .stat-value { color: var(--warn); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f7f9fc; }

.tree-tools { display: flex; gap: 6px; padding: 0 6px 10px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.tree-tools button { flex: 1; }
