:root {
  --bg: #0d1117;
  --surface: #151b23;
  --surface-2: #1b222c;
  --line: #303944;
  --text: #e7edf3;
  --muted: #95a2af;
  --accent: #38bdf8;
  --accent-dark: #075985;
  --success: #46c37b;
  --warning: #f0b84b;
  --danger: #ef6464;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); font-family: Inter, "Segoe UI", Arial, sans-serif; font-size: 14px; letter-spacing: 0; }
button, input { font: inherit; letter-spacing: 0; }
button { border: 0; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: 21px; }
h2 { margin-bottom: 4px; font-size: 20px; }
h3 { margin: 0; font-size: 16px; }
.muted { color: var(--muted); }
.success-text { color: var(--success) !important; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #0b0f14; }
.login-panel { width: min(400px, 100%); display: grid; gap: 18px; padding: 32px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.brand-mark { width: 48px; height: 48px; display: grid; place-items: center; background: var(--accent); color: #03141c; font-weight: 800; border-radius: 6px; }
.brand-mark.small { width: 32px; height: 32px; font-size: 12px; }
label { display: grid; gap: 7px; color: #c5d0da; font-weight: 600; }
input { min-width: 0; height: 40px; padding: 0 12px; color: var(--text); background: #0f141b; border: 1px solid var(--line); border-radius: 5px; outline: none; }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(56,189,248,.14); }

.primary, .secondary, .danger, .ghost { min-height: 38px; padding: 0 15px; border-radius: 5px; font-weight: 700; }
.primary { color: #04151d; background: var(--accent); }
.primary:hover { background: #70d4fb; }
.secondary { color: var(--text); background: var(--surface-2); border: 1px solid var(--line); }
.secondary:hover { border-color: #596775; }
.danger { color: white; background: #b93645; }
.ghost { padding: 0 8px; color: var(--muted); background: transparent; }
.ghost:hover { color: white; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 20px 14px; background: #10151c; border-right: 1px solid var(--line); }
.brand-row { display: flex; align-items: center; gap: 11px; padding: 0 8px 24px; font-size: 16px; }
nav { display: grid; gap: 5px; }
.nav-item { height: 40px; padding: 0 12px; text-align: left; color: var(--muted); background: transparent; border-radius: 5px; }
.nav-item:hover { color: white; background: var(--surface); }
.nav-item.active { color: white; background: var(--surface-2); border-left: 3px solid var(--accent); }
.sidebar-footer { margin-top: auto; display: flex; align-items: center; justify-content: space-between; padding: 14px 8px 0; border-top: 1px solid var(--line); color: var(--muted); }
.workspace { min-width: 0; }
.topbar { min-height: 78px; display: flex; align-items: center; justify-content: space-between; padding: 16px 28px; border-bottom: 1px solid var(--line); background: rgba(13,17,23,.94); }
.topbar p { margin-bottom: 0; }
.status-indicator { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.status-indicator span { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px rgba(70,195,123,.12); }
#devicesView, #auditView { padding: 24px 28px 40px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.stats article { min-height: 90px; padding: 18px 20px; background: var(--surface); border-right: 1px solid var(--line); }
.stats article:last-child { border-right: 0; }
.stats span { display: block; color: var(--muted); margin-bottom: 8px; }
.stats strong { font-size: 26px; font-variant-numeric: tabular-nums; }
.toolbar { display: flex; gap: 10px; margin: 20px 0 12px; }
.toolbar input { width: min(420px, 100%); margin-right: auto; }
.audit-toolbar { justify-content: space-between; align-items: center; margin-top: 0; }
.table-wrap { position: relative; overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { height: 52px; padding: 0 14px; text-align: left; border-bottom: 1px solid var(--line); }
th { height: 42px; color: var(--muted); background: #11171f; font-size: 12px; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255,255,255,.018); }
.cell-title { display: block; color: var(--text); font-weight: 650; }
.cell-sub { display: block; max-width: 240px; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; }
.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); font-size: 12px; }
.badge.online { color: #8ee3ad; border-color: #286343; background: #122a1d; }
.badge.offline { color: #f1c46c; border-color: #664d23; background: #291f10; }
.badge.disabled { color: #f38a91; border-color: #69333a; background: #2b1519; }
.actions { display: flex; gap: 6px; }
.actions button { min-height: 30px; padding: 0 9px; }
.empty { padding: 50px; text-align: center; color: var(--muted); }
.form-error { min-height: 18px; margin-bottom: 0; color: var(--danger); }

dialog { width: min(520px, calc(100% - 30px)); padding: 0; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 22px 80px rgba(0,0,0,.6); }
dialog::backdrop { background: rgba(3,6,10,.72); }
dialog form, dialog section { display: grid; gap: 18px; padding: 22px; }
dialog header, dialog footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
dialog footer { justify-content: flex-end; }
.icon-close { width: 32px; height: 32px; padding: 0; color: var(--muted); background: transparent; font-size: 18px; }
.icon-close:hover { color: white; }
.secret-value { display: flex; gap: 8px; }
.secret-value code { min-width: 0; flex: 1; padding: 12px; overflow-wrap: anywhere; color: #9ee6ff; background: #0b1118; border: 1px solid var(--line); border-radius: 5px; font-size: 18px; }
.countdown { color: var(--warning); font-variant-numeric: tabular-nums; }
.toast { position: fixed; right: 22px; bottom: 22px; max-width: 360px; padding: 12px 16px; color: white; background: #26313d; border: 1px solid #536171; border-radius: 5px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: .18s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; width: 100%; height: auto; flex-direction: row; align-items: center; padding: 10px 14px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand-row { padding: 0; margin-right: 18px; }
  nav { display: flex; }
  .nav-item { width: auto; }
  .sidebar-footer { margin: 0 0 0 auto; padding: 0 0 0 12px; border: 0; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stats article:nth-child(2) { border-right: 0; }
  .stats article:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 580px) {
  .brand-row strong, .sidebar-footer span, .status-indicator { display: none; }
  .topbar { padding: 14px 16px; }
  #devicesView, #auditView { padding: 16px; }
  .toolbar { flex-wrap: wrap; }
  .toolbar input { width: 100%; flex-basis: 100%; }
  .stats article { min-height: 76px; padding: 14px; }
  .stats strong { font-size: 22px; }
}
