:root {
  --bg: #111315;
  --bg-elev: #171a1d;
  --bg-soft: #1d2126;
  --border: #2a2f36;
  --text: #dfd8c8;
  --muted: #8f98a2;
  --accent: #7fa982;
  --warn: #c79a52;
  --danger: #a63a3a;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

html[data-theme="light"] {
  --bg: #f5f4f0;
  --bg-elev: #ffffff;
  --bg-soft: #eceae3;
  --border: #dad6cc;
  --text: #1c1f22;
  --muted: #666c73;
  --accent: #4c7a52;
  --warn: #a17122;
  --danger: #a63a3a;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.45; }
a { color: inherit; }

.auth-gate { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 360px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px; padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.auth-card h1 { margin: 0; font-size: 20px; font-weight: 600; }

.app-shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { background: var(--bg-elev); border-right: 1px solid var(--border); padding: 16px 12px; display: flex; flex-direction: column; gap: 14px; position: sticky; top: 0; height: 100vh; }
.side-head { display: flex; align-items: center; gap: 10px; padding: 4px 8px; font-weight: 700; font-size: 15px; }
.side-nav { display: flex; flex-direction: column; gap: 4px; }
.nav-btn { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; font: inherit; font-weight: 500; text-align: left; transition: background 0.16s cubic-bezier(0.16,1,0.3,1), color 0.16s; }
.nav-btn:hover { background: var(--bg-soft); color: var(--text); }
.nav-btn.active { background: var(--bg-soft); color: var(--text); font-weight: 600; }
.nav-btn .badge { margin-left: auto; font-family: var(--mono); font-size: 11px; padding: 1px 6px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
.side-links { margin-top: auto; display: flex; flex-direction: column; gap: 4px; border-top: 1px solid var(--border); padding-top: 12px; }
.side-ext { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 7px; text-decoration: none; color: var(--muted); font-size: 13px; }
.side-ext:hover { background: var(--bg-soft); color: var(--text); }
.side-foot { border-top: 1px solid var(--border); padding-top: 10px; }
.user-line { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: var(--muted); padding: 0 4px; }

.main { padding: 20px 26px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.tab-view { display: none; }
.tab-view.active { display: block; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 13px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-elev); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; transition: border-color 0.16s, background 0.16s; }
.btn:hover { background: var(--bg-soft); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #101411; border-color: transparent; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; }
.icon-btn { width: 30px; height: 30px; border-radius: 7px; border: 1px solid var(--border); background: var(--bg); color: var(--muted); cursor: pointer; display: inline-grid; place-items: center; }
.icon-btn:hover { color: var(--text); background: var(--bg-soft); }

.pill { display: inline-flex; align-items: center; gap: 7px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg-elev); font-size: 12px; font-weight: 600; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.pill.ok .dot { background: var(--accent); }
.pill.warn .dot { background: var(--warn); }
.pill.err .dot { background: var(--danger); }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.kpi-k { font-size: 12px; color: var(--muted); }
.kpi-v { font-family: var(--mono); font-size: 22px; font-weight: 700; margin-top: 4px; }
.kpi-s { font-size: 12px; color: var(--muted); margin-top: 2px; }

.split-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2 { margin: 0; font-size: 15px; font-weight: 600; }

.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.input { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font: inherit; padding: 8px 11px; min-width: 0; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; padding: 10px; background: var(--bg-soft); border-radius: 8px; }
.chk { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }

.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; }

.list-box { display: flex; flex-direction: column; gap: 8px; max-height: 400px; overflow-y: auto; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); font-size: 13px; }
.mono-muted { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.alert-err { padding: 9px 12px; border-radius: 8px; border: 1px solid var(--danger); color: #f1b3b3; background: rgba(166,58,58,0.16); font-size: 13px; }
.toast { position: fixed; right: 20px; bottom: 20px; background: var(--bg-elev); border: 1px solid var(--border); padding: 10px 14px; border-radius: 8px; font-size: 13px; z-index: 99; }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { height: auto; position: static; }
}
