:root {
  --bg: #f4f6fb; --panel: #ffffff; --text: #18223a; --muted: #6b7690; --line: #e3e8f2;
  --nav: #142142; --nav-text: #c6cfe6; --nav-active: #2f6bff; --accent: #2f6bff; --accent-soft: #e8efff;
  --ok: #17a35b; --warn: #d98a00; --err: #d93a3a; --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: flex; min-height: 100vh; }
.sidebar { width: 230px; flex: none; background: var(--nav); color: var(--nav-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { padding: 18px 20px; font-weight: 700; font-size: 18px; color: #fff; letter-spacing: .3px; }
.brand span { color: #7aa2ff; }
.brand { display: flex; align-items: center; gap: 9px; }
.brand img { border-radius: 7px; flex: none; }
.who { padding: 0 20px 14px; font-size: 12px; color: #8f9bbb; border-bottom: 1px solid rgba(255,255,255,.08); }
.who b { display: block; color: #e2e8f8; font-size: 13px; font-weight: 600; }
.nav-group { padding: 12px 12px 4px; }
.nav-group-title { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: #7d89a8; padding: 4px 8px; }
.nav a { display: block; padding: 7px 10px; border-radius: 7px; color: var(--nav-text); font-size: 13.5px; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: var(--nav-active); color: #fff; }
.nav a .soon { float: right; font-size: 10px; background: rgba(255,255,255,.12); border-radius: 4px; padding: 1px 5px; margin-top: 2px; }
.sidebar-foot { margin-top: auto; padding: 12px; border-top: 1px solid rgba(255,255,255,.08); }

.main { flex: 1; min-width: 0; padding: 20px 22px 32px; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.topbar h1 { font-size: 22px; margin: 0; font-weight: 650; }
.topbar .spacer { flex: 1; }
.burger { display: none; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 8px; padding: 7px 14px; font: inherit; cursor: pointer; }
.btn:hover { border-color: #c5cee0; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #255de6; }
.btn.danger { color: var(--err); border-color: #f1c6c6; }
.btn.small { padding: 4px 10px; font-size: 12.5px; }

input[type=text], input[type=password], input[type=search], input[type=number], textarea, select {
  font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; color: var(--text); width: 100%;
}
textarea { min-height: 90px; font-family: Consolas, monospace; font-size: 12px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 220px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type=search] { max-width: 320px; }
.toolbar .info { color: var(--muted); font-size: 12.5px; }

/* Таблицы: помещаются по ширине страницы — текст переносится, числа и даты не переносятся,
   заголовок выровнен так же, как значения в колонке. */
.table-wrap { overflow-y: auto; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; max-height: calc(100vh - 250px); }
table.data { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.data th, table.data td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.data td { white-space: normal; overflow-wrap: break-word; }
table.data th { position: sticky; top: 0; background: #f7f9fd; font-weight: 600; color: #46516b; cursor: pointer; user-select: none; z-index: 1;
  white-space: normal; line-height: 1.25; vertical-align: bottom; font-size: 12px; }
table.data th.sorted::after { content: " ▲"; font-size: 10px; }
table.data th.sorted.desc::after { content: " ▼"; }
table.data th.num, table.data td.num { text-align: right; }
table.data td.num { white-space: nowrap; font-variant-numeric: tabular-nums; overflow-wrap: normal; }
table.data td.nw { white-space: nowrap; overflow-wrap: normal; }
table.data td.wrap { min-width: 150px; }
table.data td.wrap .clip { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
table.data tbody tr:hover { background: #f8faff; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; background: var(--accent-soft); color: #2a4fb8; font-size: 12px; }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 10px; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; border: 1px solid; }
.alert.success { background: #ebf8f1; border-color: #bfe8d1; color: #11683c; }
.alert.error { background: #fdf0f0; border-color: #f3c9c9; color: #9b2424; }
.alert.info { background: var(--accent-soft); border-color: #cbd9ff; color: #284aa8; }
.alert.warning { background: #fff7e6; border-color: #f5dca6; color: #855400; }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.tile { display: block; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; color: var(--text); }
.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile .g { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.tile .t { font-weight: 600; margin-top: 4px; }

table.list { border-collapse: collapse; width: 100%; }
table.list th, table.list td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; }
table.list th { color: var(--muted); font-weight: 600; font-size: 12.5px; }

.perm-group { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
.perm-group > .hd { padding: 9px 14px; background: #f7f9fd; font-weight: 600; border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; }
.perm-sec { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.perm-sec:last-child { border-bottom: 0; }
.perm-sec .head { display: flex; align-items: center; gap: 10px; }
.perm-sec .head label { font-weight: 600; }
.perm-sec .details { margin: 8px 0 0 26px; display: none; }
.perm-sec.on .details { display: block; }
.chips { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 4px; }
.chips label { font-size: 13px; white-space: nowrap; }
.sub-title { font-size: 11.5px; color: var(--muted); margin-top: 6px; }

.city-list { max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; columns: 3 200px; }
.city-list label { display: block; font-size: 13px; padding: 2px 0; break-inside: avoid; }
.selected-offices { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.selected-offices .tag { background: var(--accent-soft); border-radius: 6px; padding: 3px 8px; font-size: 12.5px; }
.selected-offices .tag button { border: 0; background: none; cursor: pointer; color: var(--muted); }
.search-results { border: 1px solid var(--line); border-radius: 8px; max-height: 220px; overflow-y: auto; display: none; }
.search-results div { padding: 6px 10px; cursor: pointer; font-size: 13px; }
.search-results div:hover { background: var(--accent-soft); }

.filters { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; padding: 12px 14px; }
.filters label.field { margin: 0; min-width: 170px; flex: 0 1 auto; }
.filters select { min-width: 240px; }

/* общая таблица: панель фильтров, раскрытие строк */
.grid-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.grid-bar input[type=search] { max-width: 300px; flex: 1 1 220px; }
.grid-bar select { width: auto; max-width: 240px; padding: 6px 8px; font-size: 13px; color: var(--muted); }
.grid-bar select.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.grid-bar .info { color: var(--muted); font-size: 12.5px; margin-left: auto; }
.g-cols { position: relative; }
.g-colmenu { display: none; position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 12px 30px rgba(20,33,66,.15); padding: 8px 12px; min-width: 240px; max-height: 60vh; overflow-y: auto; }
.g-colmenu.open { display: block; }
.g-colmenu label { display: block; font-size: 13px; padding: 3px 0; white-space: nowrap; }
.g-colmenu .btn { margin-top: 6px; }
table.data th.num { text-align: right; }
table.data td a { font-weight: 600; }
table.data .xcol { width: 30px; padding: 4px 6px; text-align: center; }
.xbtn { border: 1px solid var(--line); background: #fff; border-radius: 6px; width: 24px; height: 24px; cursor: pointer; color: var(--accent); line-height: 1; }
tr.open > td { background: #f3f7ff; }
tr.xrow > td { background: #f8faff; padding: 6px 10px 12px 36px; white-space: normal; }
.xbox { border: 1px solid var(--line); border-radius: 8px; background: #fff; overflow-y: auto; overflow-x: hidden; max-height: 420px; }
.xbox table.data { table-layout: auto; }
.xtitle { font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 10px 4px; text-transform: uppercase; letter-spacing: .4px; }
table.data.sub { font-size: 12.5px; }
table.data.sub th { position: static; background: #fbfcfe; cursor: default; }
td.acts { white-space: nowrap; }

/* карточка объекта */
.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px 20px; }
.kv .k { font-size: 12px; color: var(--muted); }
.kv .v { font-weight: 600; word-break: break-word; }

.act-dlg { border: 1px solid var(--line); border-radius: 12px; padding: 20px; width: min(520px, 94vw); box-shadow: 0 20px 60px rgba(20,33,66,.25); }
.act-dlg::backdrop { background: rgba(20,33,66,.35); }
.act-dlg h2 { font-size: 17px; }
.act-dlg select[size] { height: auto; }

.login-box { max-width: 360px; margin: 12vh auto; }
.loader { padding: 40px; text-align: center; color: var(--muted); }
.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.status-dot.ok { background: var(--ok); } .status-dot.err { background: var(--err); } .status-dot.none { background: #b8c0d2; }

@media (max-width: 900px) {
  .sidebar { position: fixed; left: -280px; z-index: 20; transition: left .2s; }
  .sidebar.open { left: 0; }
  .burger { display: inline-flex; }
  .main { padding: 14px 16px 30px; }
}
