/* ОшПЭС Портал — оформление */
:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f7f9fc;
    --border: #e3e8f0;
    --text: #1b2430;
    --text-muted: #6b7684;
    --accent: #1766d6;
    --accent-2: #0ea5a5;
    --accent-soft: #e8f0fe;
    --ok: #16a34a;
    --ok-soft: #dcfce7;
    --warn: #d97706;
    --warn-soft: #fef3c7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .05);
    --radius: 14px;
    --sidebar-w: 248px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0c1118;
        --surface: #141b25;
        --surface-2: #1a2230;
        --border: #263142;
        --text: #e7edf5;
        --text-muted: #8b97a8;
        --accent: #4f8cf0;
        --accent-2: #2dd4bf;
        --accent-soft: #15233c;
        --ok: #4ade80;
        --ok-soft: #10281a;
        --warn: #fbbf24;
        --warn-soft: #2a2010;
        --danger: #f87171;
        --danger-soft: #2a1414;
        --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 12px 30px rgba(0, 0, 0, .35);
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Каркас ---- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 20px; }
.brand .logo {
    width: 40px; height: 40px; border-radius: 11px; flex: 0 0 40px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    display: grid; place-items: center; color: #fff;
}
.brand .logo svg { width: 22px; height: 22px; }
.brand .title { font-weight: 700; font-size: 16px; line-height: 1.15; }
.brand .subtitle { font-size: 12px; color: var(--text-muted); }

.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.nav a {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: 10px; color: var(--text);
    font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav a svg { width: 19px; height: 19px; opacity: .8; }
.nav .group-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--text-muted); padding: 16px 12px 6px; font-weight: 600;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 28px; border-bottom: 1px solid var(--border);
    background: var(--surface); position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 700; }
.topbar .crumbs { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.pes-chip {
    display: inline-flex; align-items: center; gap: 8px;
    background: var(--accent-soft); color: var(--accent);
    padding: 7px 14px; border-radius: 999px; font-weight: 600; font-size: 13px;
}
.pes-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-2); }

/* Переключатель ПЭС (сегментированный контрол) */
.pes-switch {
    display: inline-flex; gap: 4px; padding: 4px;
    background: var(--accent-soft); border-radius: 999px;
}
.pes-opt {
    padding: 6px 14px; border-radius: 999px; font-weight: 600; font-size: 13px;
    color: var(--accent); text-decoration: none; white-space: nowrap;
    transition: background .15s, color .15s;
}
.pes-opt:hover { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.pes-opt.active { background: var(--accent); color: #fff; }

.content { padding: 26px 28px 48px; }

/* ---- Карточки / сетки ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; }
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.card.pad { padding: 20px; }
.section { margin-top: 28px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.section-head h2 { font-size: 16px; margin: 0; font-weight: 700; }
.section-head .hint { font-size: 12px; color: var(--text-muted); }

.stat { padding: 18px 20px; }
.stat .label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 30px; font-weight: 800; margin-top: 8px; letter-spacing: -.02em; }
.stat .unit { font-size: 14px; font-weight: 600; color: var(--text-muted); margin-left: 4px; }
.stat .icon {
    width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
    background: var(--accent-soft); color: var(--accent); float: right;
}
.stat .icon svg { width: 20px; height: 20px; }
.stat.teal .icon { background: color-mix(in srgb, var(--accent-2) 18%, transparent); color: var(--accent-2); }

/* ---- Полосчатые диаграммы ---- */
.barlist { display: flex; flex-direction: column; gap: 11px; }
.barlist .row { display: grid; grid-template-columns: 90px 1fr 110px; align-items: center; gap: 12px; }
.barlist .row .k { font-size: 13px; color: var(--text-muted); text-align: right; font-variant-numeric: tabular-nums; }
.barlist .row .v { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--text-muted); }
.bar { height: 22px; background: var(--surface-2); border-radius: 7px; overflow: hidden; }
.bar > span {
    display: block; height: 100%; border-radius: 7px;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    min-width: 2px;
}

.balance-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.balance-item { padding: 16px; border-radius: 12px; background: var(--surface-2); }
.balance-item .n { font-size: 24px; font-weight: 800; }
.balance-item .l { font-size: 13px; color: var(--text-muted); margin-top: 3px; }
.balance-item .pct { font-size: 12px; color: var(--accent); font-weight: 600; }

/* ---- Таблицы ---- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table.data { width: 100%; border-collapse: collapse; background: var(--surface); font-size: 14px; }
table.data th, table.data td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th {
    background: var(--surface-2); font-weight: 600; font-size: 12.5px;
    color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; position: sticky; top: 0;
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr:last-child td { border-bottom: none; }

/* ---- Значки статусов / типов ---- */
.badge {
    display: inline-block; padding: 3px 10px; border-radius: 999px;
    font-size: 12px; font-weight: 600; line-height: 1.6;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.muted { background: var(--surface-2); color: var(--text-muted); }
.badge.type-tp { background: var(--accent-soft); color: var(--accent); }
.badge.type-ps { background: var(--warn-soft); color: var(--warn); }
.badge.type-sh { background: color-mix(in srgb, var(--accent-2) 16%, transparent); color: var(--accent-2); }
.badge.type-feeder { background: var(--ok-soft); color: var(--ok); }

/* ---- Дерево сети ---- */
.tree { font-size: 14px; }
.tree details { margin: 2px 0; }
.tree summary {
    cursor: pointer; padding: 8px 10px; border-radius: 9px; list-style: none;
    display: flex; align-items: center; gap: 9px;
}
.tree summary::-webkit-details-marker { display: none; }
.tree summary:hover { background: var(--surface-2); }
.tree summary .caret { transition: transform .15s; color: var(--text-muted); flex: 0 0 auto; }
.tree details[open] > summary .caret { transform: rotate(90deg); }
.tree .node-name { font-weight: 500; }
.tree .node-meta { color: var(--text-muted); font-size: 12.5px; margin-left: auto; }
.tree .children { margin-left: 20px; border-left: 1.5px dashed var(--border); padding-left: 12px; }
.tree .leaf { display: flex; align-items: center; gap: 9px; padding: 6px 10px; border-radius: 8px; }
.tree .leaf:hover { background: var(--surface-2); }
.tn { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 9px; }
.tn.ps { background: var(--warn); }
.tn.sh { background: var(--accent-2); }
.tn.feeder { background: var(--ok); }
.tn.tp { background: var(--accent); }

/* ---- Формы / кнопки ---- */
.field { display: inline-flex; gap: 10px; align-items: center; }
input[type="text"], input[type="search"], select {
    background: var(--surface); border: 1px solid var(--border); color: var(--text);
    padding: 10px 14px; border-radius: 10px; font-size: 14px; font-family: inherit; min-width: 220px;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.btn {
    background: var(--accent); color: #fff; border: none; padding: 10px 18px;
    border-radius: 10px; font-weight: 600; font-size: 14px; cursor: pointer; font-family: inherit;
}
.btn:hover { filter: brightness(1.06); text-decoration: none; }
.btn.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); }

.tabs { display: flex; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; }
.tabs a {
    padding: 9px 16px; border-radius: 10px; font-weight: 600; font-size: 14px;
    color: var(--text-muted); background: var(--surface); border: 1px solid var(--border);
}
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.empty { text-align: center; color: var(--text-muted); padding: 50px 20px; }
.empty svg { width: 46px; height: 46px; opacity: .4; margin-bottom: 10px; }

/* ---- Карточка объекта ---- */
.prop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.prop { padding: 14px 16px; border-radius: 11px; background: var(--surface-2); }
.prop .pk { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.prop .pv { font-size: 15px; font-weight: 600; margin-top: 4px; word-break: break-word; }
.prop.calc { background: var(--accent-soft); }

.muted { color: var(--text-muted); }
.right { text-align: right; }

@media (max-width: 860px) {
    .sidebar { position: fixed; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
    .sidebar.open { transform: none; }
    .content, .topbar { padding-left: 16px; padding-right: 16px; }
}
