:root {
  --bg: #f5f7fa; --surface: #ffffff; --surface-2: #f0f3f7; --border: #dfe4ea; --text: #1b2430; --muted: #66727f;
  --accent: #1f6feb; --accent-ink: #ffffff; --accent-soft: #e6effd;
  --ok: #1a7f37; --ok-soft: #dcf3e3; --warn: #9a6700; --warn-soft: #fbf0d3; --bad: #cf222e; --bad-soft: #fde3e4; --idle: #8c959f; --idle-soft: #eef0f2;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif; font-size: 14px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141a; --surface: #161c24; --surface-2: #1c242e; --border: #2a3441; --text: #e6edf3; --muted: #8d99a6;
    --accent: #4c8dff; --accent-ink: #0b1220; --accent-soft: #19283f;
    --ok: #3fb950; --ok-soft: #12301b; --warn: #d29922; --warn-soft: #33270b; --bad: #f85149; --bad-soft: #3b1618; --idle: #8b949e; --idle-soft: #232a33;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141a; --surface: #161c24; --surface-2: #1c242e; --border: #2a3441; --text: #e6edf3; --muted: #8d99a6;
  --accent: #4c8dff; --accent-ink: #0b1220; --accent-soft: #19283f;
  --ok: #3fb950; --ok-soft: #12301b; --warn: #d29922; --warn-soft: #33270b; --bad: #f85149; --bad-soft: #3b1618; --idle: #8b949e; --idle-soft: #232a33;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 600; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 16px 0 8px; font-weight: 600; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; }
.spacer { flex: 1; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* auth */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.auth-card .brand { margin-bottom: 20px; }
.auth-card h1 { margin-bottom: 14px; }

.brand { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.brand img { width: 30px; height: 30px; }

/* layout */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 220px; flex: none; background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { padding: 4px 8px 18px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); margin-bottom: 2px; }
.sidebar nav a:hover { background: var(--surface-2); text-decoration: none; }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar nav .nav-ico { width: 18px; text-align: center; opacity: .85; }
.sidebar-foot { margin-top: auto; padding: 8px; font-size: 12px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar .menu-btn { display: none; }
.view { padding: 24px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .spacer { min-width: 8px; }
.user { display: flex; align-items: center; gap: 10px; }

/* controls */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: 7px 12px; font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn.icon { padding: 6px 9px; }
.btn.wide { width: 100%; justify-content: center; padding: 10px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
label { display: block; margin-bottom: 12px; font-weight: 500; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0 14px 8px 0; font-weight: 400; }
input, select, textarea { display: block; width: 100%; margin-top: 5px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; }
textarea { min-height: 90px; resize: vertical; font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; }
input[type=checkbox], input[type=radio] { display: inline-block; width: auto; margin: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.hint { font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 4px; }
.form-error { color: var(--bad); min-height: 1em; margin: 4px 0 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
.grid6 { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0 10px; }
select.compact { display: inline-block; width: auto; margin: 0; padding: 6px 8px; }

/* cards, tables */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head h2 { margin: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 26px; font-weight: 600; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12.5px; color: var(--muted); }
.kpi.bad .value { color: var(--bad); }
.bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar.warn > i { background: var(--warn); } .bar.bad > i { background: var(--bad); }

/* status */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--idle-soft); color: var(--idle); 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.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }

/* chart */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 8px; }
.chart .col { flex: 1; display: flex; flex-direction: column-reverse; min-width: 0; height: 100%; position: relative; }
.chart .seg { width: 100%; }
.chart .seg.ok { background: var(--ok); } .chart .seg.warn { background: var(--warn); } .chart .seg.bad { background: var(--bad); }
.chart .col .seg:first-child { border-radius: 0 0 3px 3px; }
.chart-x { display: flex; gap: 6px; margin-top: 6px; }
.chart-x span { flex: 1; text-align: center; font-size: 11px; color: var(--muted); min-width: 0; overflow: hidden; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.legend .ok { background: var(--ok); } .legend .warn { background: var(--warn); } .legend .bad { background: var(--bad); }

/* tabs, crumbs, browser */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--accent); border-color: var(--accent); font-weight: 600; text-decoration: none; }
.crumbs { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 10px 18px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.crumbs a, .crumbs span { font-size: 13px; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.secret { background: var(--surface-2); border: 1px dashed var(--border); border-radius: 8px; padding: 10px 12px; overflow-wrap: anywhere; margin: 6px 0 12px; }
.note { background: var(--accent-soft); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }
.note.warn { background: var(--warn-soft); }

/* modal, toast */
.modal { position: fixed; inset: 0; background: rgba(10,15,25,.45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 20; overflow-y: auto; }
.modal-card { background: var(--surface); border-radius: 14px; width: 100%; max-width: 640px; padding: 22px; box-shadow: 0 12px 40px rgba(0,0,0,.25); border: 1px solid var(--border); }
.modal-card.wide { max-width: 860px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 30; max-width: calc(100% - 32px); box-shadow: var(--shadow); }
.toast.error { background: var(--bad); color: #fff; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px 4px; margin: 0 0 14px; }
legend { padding: 0 6px; font-weight: 600; }

@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid3, .grid6 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .sidebar { position: fixed; left: -240px; z-index: 15; transition: left .2s; box-shadow: var(--shadow); }
  .sidebar.open { left: 0; }
  .topbar .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .view { padding: 16px; }
  .grid2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .kv dt { margin-top: 6px; }
  th, td { padding: 8px 10px; }
  .hide-sm { display: none; }
}
