:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f9fafb; --border: #e7e9ee; --border-strong: #d6d9e0;
  --text: #0f172a; --text-2: #334155; --muted: #6b7280; --faint: #9aa1ad;
  --accent: #4f46e5; --accent-soft: #eef0ff; --accent-text: #4338ca;
  --ok: #16a34a; --ok-soft: #e8f7ee; --warn: #c2700a; --warn-soft: #fff5e6; --crit: #dc2626; --crit-soft: #fdecec;
  --idle: #6b7280; --idle-soft: #f1f2f4;
  --bar: #c7cbf7; --bar-strong: #4f46e5;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --shadow-lg: 0 20px 50px rgba(16,24,40,.18);
  --radius: 14px; --radius-sm: 9px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0e13; --surface: #14171e; --surface-2: #181c24; --border: #242936; --border-strong: #303747;
    --text: #e8eaf0; --text-2: #c3c8d4; --muted: #8b93a5; --faint: #646c7e;
    --accent: #8b8ff8; --accent-soft: #1f2140; --accent-text: #aeb1ff;
    --ok: #34d399; --ok-soft: #10261d; --warn: #f5b04c; --warn-soft: #2a2010; --crit: #f87171; --crit-soft: #2c1517;
    --idle: #8b93a5; --idle-soft: #1c2029; --bar: #343a6b; --bar-strong: #8b8ff8;
    --shadow: 0 1px 2px rgba(0,0,0,.3); --shadow-lg: 0 20px 50px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c0e13; --surface: #14171e; --surface-2: #181c24; --border: #242936; --border-strong: #303747;
  --text: #e8eaf0; --text-2: #c3c8d4; --muted: #8b93a5; --faint: #646c7e;
  --accent: #8b8ff8; --accent-soft: #1f2140; --accent-text: #aeb1ff;
  --ok: #34d399; --ok-soft: #10261d; --warn: #f5b04c; --warn-soft: #2a2010; --crit: #f87171; --crit-soft: #2c1517;
  --idle: #8b93a5; --idle-soft: #1c2029; --bar: #343a6b; --bar-strong: #8b8ff8;
  --shadow: 0 1px 2px rgba(0,0,0,.3); --shadow-lg: 0 20px 50px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased; font-feature-settings: "tnum" 1, "cv11" 1;
}
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
a { color: var(--accent-text); text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: var(--text); }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--accent); display: grid; place-items: center; color: #fff; }
.brand-mark svg { stroke-width: 2.6; }
.brand-name { font-weight: 700; font-size: 15px; line-height: 1.1; }
.brand-sub { color: var(--muted); font-size: 12.5px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); }
.nav a.on { background: var(--accent-soft); color: var(--accent-text); }
.nav-badge { margin-left: auto; background: var(--crit); color: #fff; font-size: 11px; font-weight: 700; border-radius: 99px; padding: 0 7px; line-height: 18px; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 8px; font-size: 12px; color: var(--muted); }
.chip-line { display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex-shrink: 0; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.crit { background: var(--crit); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 14px 28px; background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 17px; font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.updated { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.content { padding: 24px 28px 60px; max-width: 1440px; width: 100%; }
.banner { margin: 16px 28px 0; padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13.5px; display: flex; gap: 10px; align-items: center; }
.banner.info { background: var(--accent-soft); color: var(--accent-text); }
.banner.err { background: var(--crit-soft); color: var(--crit); }

.only-mobile { display: none !important; }

/* ---------- controls ---------- */
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); color: var(--text-2); }
.icon-btn:hover { border-color: var(--border-strong); }
.icon-btn.spin svg { animation: spin .9s linear infinite; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; }
.seg button { border: 0; background: none; padding: 5px 11px; border-radius: 6px; color: var(--muted); font-weight: 500; font-size: 13px; white-space: nowrap; }
.seg button.on { background: var(--accent-soft); color: var(--accent-text); }

.btn {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); font-weight: 500; font-size: 13px; white-space: nowrap; color: var(--text-2);
}
.btn:hover { border-color: var(--border-strong); }
.btn svg { width: 15px; height: 15px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.sm { height: 28px; padding: 0 9px; font-size: 12.5px; }
.btn.locked { color: var(--faint); background: var(--surface-2); border-style: dashed; }
.btn.locked:hover { color: var(--muted); }
.btn.locked.primary { background: var(--surface-2); border-color: var(--border-strong); color: var(--muted); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.input, .select {
  height: 34px; padding: 0 11px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); outline: none; min-width: 0;
}
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.sm { height: 30px; font-size: 13px; }

.switch { position: relative; width: 34px; height: 20px; border-radius: 99px; background: var(--border-strong); border: 0; padding: 0; flex-shrink: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch.on { background: var(--ok); }
.switch.on::after { transform: translateX(14px); }
.switch.locked { opacity: .55; }
.switch .lk { position: absolute; right: -14px; top: 2px; width: 12px; height: 12px; color: var(--faint); }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 16px 18px 0; }
.card-h h3 { font-size: 14.5px; font-weight: 600; }
.card-h .sub { color: var(--muted); font-size: 12.5px; }
.card-h .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.card-b { padding: 16px 18px 18px; }
.section-gap { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr); }
.grid { display: grid; gap: 16px; }
.g-kpi { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.g-kpi4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-2 { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); }
.tbl .row .nm { white-space: nowrap; }
.tbl td:first-child .row { min-width: 210px; }
.g-2e { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-cards { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

.kpi { padding: 16px 18px; }
.kpi .l { color: var(--muted); font-size: 12.5px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi .v { font-size: 25px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; line-height: 1.2; }
.kpi .s { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.kpi.crit .v { color: var(--crit); }

.page-h { display: flex; align-items: flex-end; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.page-h h1 { font-size: 22px; font-weight: 700; }
.page-h p { margin: 2px 0 0; color: var(--muted); }
.page-h .right { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warning, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.critical, .badge.crit { background: var(--crit-soft); color: var(--crit); }
.badge.idle { background: var(--idle-soft); color: var(--idle); }
.badge.plain { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge.plain::before { display: none; }
.tag { font-size: 11.5px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; white-space: nowrap; }

/* ---------- alerts list ---------- */
.alert-list { display: flex; flex-direction: column; }
.alert-item { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); align-items: flex-start; }
.alert-item:first-child { border-top: 0; padding-top: 2px; }
.alert-ic { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; }
.alert-ic.critical { background: var(--crit-soft); color: var(--crit); }
.alert-ic.warning { background: var(--warn-soft); color: var(--warn); }
.alert-item .t { font-weight: 600; }
.alert-item .t a { color: var(--text); }
.alert-item .d { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; }
.empty .big { font-size: 15px; color: var(--text-2); font-weight: 600; margin-bottom: 4px; }

/* ---------- client cards ---------- */
.ccard { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; cursor: pointer; transition: border-color .15s, transform .15s; }
.ccard:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.ccard.critical { border-color: color-mix(in srgb, var(--crit) 45%, var(--border)); }
.ccard.warning { border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); }
.ccard-top { display: flex; align-items: flex-start; gap: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex-shrink: 0; background: var(--accent-soft); color: var(--accent-text); overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.ccard .nm { font-weight: 600; line-height: 1.3; }
.ccard .bz { color: var(--muted); font-size: 12px; }
.ccard-mid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mini .l { color: var(--muted); font-size: 11.5px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.mini .v { font-weight: 600; font-size: 15px; }
.ccard-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 12.5px; }

/* ---------- meter ---------- */
.meter { height: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; overflow: hidden; min-width: 60px; }
.meter > i { display: block; height: 100%; border-radius: 99px; background: var(--ok); }
.meter.warning > i { background: var(--warn); } .meter.critical > i { background: var(--crit); }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface); position: sticky; top: 0; }
.tbl th.r, .tbl td.r { text-align: right; }
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--text); }
.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl .nm { font-weight: 550; color: var(--text); }
.tbl .sm { color: var(--muted); font-size: 12px; }
.tbl .acts { display: flex; gap: 6px; justify-content: flex-end; }
.tbl tr.clickable { cursor: pointer; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--border); align-items: center; }
.filters .input { width: 240px; }
.filters .count { margin-left: auto; color: var(--muted); font-size: 12.5px; }

/* ---------- charts ---------- */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart rect { stroke: none; }
.chart text { fill: var(--muted); font-size: 11px; stroke: none; font-family: inherit; }
.chart .grid line { stroke: var(--border); stroke-width: 1; }
.chart rect.b { fill: var(--bar); transition: fill .1s; }
.chart rect.b.last { fill: var(--bar-strong); }
.chart g.col:hover rect.b { fill: var(--bar-strong); }
.chart rect.hit { fill: transparent; }
.spark { width: 100%; height: 34px; display: block; }
.spark path.l { stroke: var(--accent); stroke-width: 1.8; fill: none; }
.spark path.a { fill: var(--accent-soft); stroke: none; }
.chart-tip { position: fixed; pointer-events: none; z-index: 60; background: var(--text); color: var(--bg); font-size: 12px; padding: 6px 9px; border-radius: 7px; white-space: nowrap; box-shadow: var(--shadow-lg); }

/* ---------- detail ---------- */
.detail-h { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.detail-h .avatar { width: 48px; height: 48px; font-size: 16px; border-radius: 13px; }
.detail-h h1 { font-size: 22px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.back:hover { color: var(--text); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 9px 18px; font-size: 13.5px; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 550; text-align: right; }
.asset { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.asset:first-child { border-top: 0; padding-top: 0; }
.asset .ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); overflow: hidden; flex-shrink: 0; }
.asset .ic img { width: 100%; height: 100%; object-fit: cover; }
.asset .info { flex: 1; min-width: 0; }
.asset .info .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asset .info .d { color: var(--muted); font-size: 12.5px; }

/* ---------- actions center ---------- */
.lock-hero { display: flex; gap: 16px; align-items: flex-start; padding: 18px; }
.lock-hero .ic { width: 42px; height: 42px; border-radius: 12px; background: var(--warn-soft); color: var(--warn); display: grid; place-items: center; flex-shrink: 0; }
.lock-hero.open .ic { background: var(--ok-soft); color: var(--ok); }
.lock-hero h3 { font-size: 15.5px; }
.lock-hero p { margin: 4px 0 0; color: var(--muted); max-width: 760px; }
.act-card { padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.act-card .top { display: flex; gap: 12px; align-items: center; }
.act-card .ic { width: 36px; height: 36px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; }
.act-card .t { font-weight: 600; }
.act-card .d { color: var(--muted); font-size: 13px; flex: 1; }

/* ---------- settings ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12.5px; font-weight: 550; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--muted); }
.field .with-unit { display: flex; align-items: center; gap: 8px; }
.field .with-unit .input { flex: 1; }
.field .with-unit span { color: var(--muted); font-size: 13px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; }
.check input { margin-top: 3px; accent-color: var(--accent); }
.status-box { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-sm); font-size: 13.5px; }
.status-box.ok { background: var(--ok-soft); color: var(--ok); }
.status-box.warn { background: var(--warn-soft); color: var(--warn); }
.status-box div { color: var(--text-2); }
.status-box b { color: inherit; }
.log-item { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); font-size: 13px; }
.log-item:first-child { border-top: 0; padding-top: 0; }
.log-item .when { color: var(--muted); white-space: nowrap; min-width: 92px; }
.log-item ul { margin: 4px 0 0; padding-left: 18px; color: var(--muted); }

/* ---------- modal & toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10,12,18,.45); backdrop-filter: blur(3px); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; width: min(520px, 100%); box-shadow: var(--shadow-lg); max-height: calc(100vh - 32px); overflow: auto; animation: pop .16s ease-out; }
.modal-h { display: flex; gap: 12px; align-items: flex-start; padding: 20px 20px 0; }
.modal-h .ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; flex-shrink: 0; background: var(--warn-soft); color: var(--warn); }
.modal-h .ic.accent { background: var(--accent-soft); color: var(--accent-text); }
.modal-h h3 { font-size: 16px; }
.modal-h p { margin: 3px 0 0; color: var(--muted); font-size: 13.5px; }
.modal-b { padding: 16px 20px; }
.modal-b ol { margin: 0; padding-left: 20px; color: var(--text-2); display: grid; gap: 6px; font-size: 13.5px; }
.modal-b code { background: var(--surface-2); border: 1px solid var(--border); padding: 0 5px; border-radius: 5px; font-size: 12.5px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 20px; }
.lock-strip { display: flex; gap: 8px; align-items: center; padding: 9px 12px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); font-size: 13px; margin-bottom: 14px; }
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 70; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-size: 13.5px; box-shadow: var(--shadow-lg); max-width: 360px; animation: pop .16s ease-out; }
.toast.err { background: var(--crit); color: #fff; }

.loading { display: flex; align-items: center; gap: 12px; color: var(--muted); padding: 60px 0; justify-content: center; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid var(--border-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } }

.muted { color: var(--muted); }
.crit-text { color: var(--crit); font-weight: 600; }
.warn-text { color: var(--warn); font-weight: 600; }
.ok-text { color: var(--ok); font-weight: 600; }
.nowrap { white-space: nowrap; }
.row { display: flex; align-items: center; gap: 8px; }

/* ---------- responsive ---------- */
@media (max-width: 1200px) { .g-kpi { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g-kpi4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-2 { grid-template-columns: 1fr; } }
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 250px; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .only-mobile { display: grid !important; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .topbar-right { width: 100%; margin-left: 0; }
  .updated { display: none; }
  .seg { flex: 1; } .seg button { flex: 1; padding: 5px 4px; }
  .content { padding: 18px 16px 50px; }
  .banner { margin: 12px 16px 0; }
  .g-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-2e, .form-grid { grid-template-columns: 1fr; }
  .filters .input { width: 100%; }
  .kpi .v { font-size: 21px; }
}
