:root {
  --bg: #0f1420;
  --bg-alt: #141b2b;
  --surface: #1a2233;
  --surface-2: #212b40;
  --border: #2a3550;
  --text: #e7ecf7;
  --text-dim: #96a2c0;
  --brand: #4f7cff;
  --brand-2: #7c5cff;
  --ok: #2fbf71;
  --warn: #e6a23c;
  --danger: #e5484d;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(0,0,0,.28);
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: inherit; text-decoration: none; }
.icon { width: 18px; height: 18px; flex: none; }

/* ---------- Auth screens ---------- */
.auth-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 800px at 20% -10%, #1e2a4a 0%, var(--bg) 60%);
}
.auth-card {
  width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 32px; box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 1.25rem; margin: 0 0 4px; }
.auth-card p.sub { color: var(--text-dim); margin: 0 0 24px; font-size: .9rem; }
.brand-mark { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.brand-mark svg { width: 30px; height: 30px; color: var(--brand); }
.brand-mark strong { font-size: 1.05rem; }

/* ---------- Layout ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 264px; flex: none; background: var(--bg-alt); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; border-bottom: 1px solid var(--border); }
.sidebar .brand svg { width: 26px; height: 26px; color: var(--brand); }
.sidebar .brand strong { font-size: .95rem; line-height: 1.2; }
.sidebar .brand span { display:block; font-size: .72rem; color: var(--text-dim); }
.nav { padding: 10px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: var(--text-dim); font-size: .86rem; margin-bottom: 2px;
}
.nav a:hover { background: var(--surface); color: var(--text); }
.nav a.active { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; }
.sidebar-foot { padding: 14px; border-top: 1px solid var(--border); font-size: .78rem; color: var(--text-dim); }

.main { flex: 1; min-width: 0; }
.topbar {
  height: 60px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px; border-bottom: 1px solid var(--border); background: var(--bg-alt);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 1.02rem; margin: 0; font-weight: 600; }
.topbar .user { display: flex; align-items: center; gap: 10px; font-size: .85rem; color: var(--text-dim); }
.topbar .user .avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--surface-2); display:flex;align-items:center;justify-content:center; color: var(--text); font-weight:600; }
.content { padding: 22px; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid.cols-4, .grid.cols-3 { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 680px) { .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; } .sidebar { display:none; } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px;
}
.stat .label { color: var(--text-dim); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.7rem; font-weight: 700; margin-top: 6px; }
.stat.ok .value { color: var(--ok); }
.stat.warn .value { color: var(--warn); }
.stat.danger .value { color: var(--danger); }

.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; flex-wrap: wrap; }
.panel-head h2 { font-size: 1rem; margin: 0; }
.panel-head .tools { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Buttons / inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); padding: 8px 14px; border-radius: 8px; font-size: .84rem; cursor: pointer;
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); border: none; color: #fff; }
.btn.danger { background: var(--danger); border: none; color: #fff; }
.btn.sm { padding: 5px 10px; font-size: .76rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 9px 11px; border-radius: 8px; font-size: .86rem; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); }
label { display: block; font-size: .78rem; color: var(--text-dim); margin-bottom: 5px; }
.field { margin-bottom: 14px; }
.error-box { background: rgba(229,72,77,.12); border: 1px solid var(--danger); color: #ffb3b5; padding: 10px 12px; border-radius: 8px; font-size: .82rem; margin-bottom: 14px; }
.ok-box { background: rgba(47,191,113,.12); border: 1px solid var(--ok); color: #a8f0c6; padding: 10px 12px; border-radius: 8px; font-size: .82rem; margin-bottom: 14px; }

/* ---------- Table ---------- */
table.data { width: 100%; border-collapse: collapse; font-size: .84rem; }
table.data th { text-align: left; color: var(--text-dim); font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:hover td { background: rgba(255,255,255,.02); }
.table-wrap { overflow-x: auto; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: .74rem; font-weight: 600; background: var(--surface-2); }
.pill.green { color: #a8f0c6; background: rgba(47,191,113,.15); }
.pill.amber { color: #ffe0a8; background: rgba(230,162,60,.15); }
.pill.red { color: #ffb3b5; background: rgba(229,72,77,.15); }
.pill.gray { color: var(--text-dim); }
.muted { color: var(--text-dim); }
.pagination { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin-top: 12px; font-size: .82rem; color: var(--text-dim); }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(5,8,16,.6); display: none; align-items: center; justify-content: center; z-index: 50; }
.modal-backdrop.open { display: flex; }
.modal { width: 480px; max-width: 92vw; max-height: 88vh; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 16px; font-size: 1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tabs button { background: none; border: none; color: var(--text-dim); padding: 10px 14px; cursor: pointer; font-size: .85rem; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--brand); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.badge-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.toast-wrap { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--surface-2); border: 1px solid var(--border); padding: 10px 16px; border-radius: 8px; font-size: .84rem; box-shadow: var(--shadow); }
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--ok); }
