/* ============================================================
   SecurityAI Portal - Dark theme design system
   ============================================================ */
:root {
  --bg: #0b0f16;
  --bg-2: #0f1622;
  --surface: #141c2b;
  --surface-2: #1b2537;
  --border: #263349;
  --border-soft: #1e2a3d;
  --text: #e6edf7;
  --text-dim: #8ea0b8;
  --text-faint: #5b6b82;

  --accent: #3b82f6;
  --accent-2: #2563eb;

  --green: #22c55e;
  --amber: #f59e0b;
  --orange: #fb923c;
  --red: #ef4444;
  --gray: #64748b;
  --purple: #a855f7;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --sidebar-w: 248px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: radial-gradient(1200px 800px at 80% -10%, #13203a 0%, var(--bg) 55%);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 .4em; font-weight: 650; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
small { color: var(--text-dim); }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: linear-gradient(180deg, var(--bg-2), #0a0e15);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  font-size: 18px;
  font-weight: 750;
  letter-spacing: .3px;
}
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: grid; place-items: center; font-size: 18px;
  box-shadow: 0 4px 14px rgba(59,130,246,.4);
}
.brand span b { color: var(--accent); }

.nav { padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 14px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-weight: 550;
  transition: background .15s, color .15s;
}
.nav a .ic { width: 18px; text-align: center; opacity: .9; }
.nav a:hover { background: var(--surface); color: var(--text); }
.nav a.active {
  background: linear-gradient(90deg, rgba(59,130,246,.18), rgba(59,130,246,.04));
  color: #fff;
  box-shadow: inset 2px 0 0 var(--accent);
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-faint);
}
.ws-status { display: flex; align-items: center; gap: 8px; }
.ws-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--gray); box-shadow: 0 0 0 3px rgba(100,116,139,.15);
}
.ws-dot.online { background: var(--green); box-shadow: 0 0 0 3px rgba(34,197,94,.18); }
.ws-dot.offline { background: var(--red); box-shadow: 0 0 0 3px rgba(239,68,68,.18); }

/* Crypto badge in the sidebar */
.crypto-badge {
  display: none;
  margin: 10px 8px 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(239,68,68,.14);
  border: 1px solid rgba(239,68,68,.5);
  color: #fff;
  font-weight: 700; font-size: 12px; letter-spacing: .5px;
  text-align: center;
  cursor: pointer;
  animation: pulse-red 1.1s infinite;
}
.crypto-badge.show { display: block; }

/* ---------- Main content ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 26px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,14,21,.6);
  backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 20;
}
.topbar .page-title { font-size: 18px; font-weight: 700; }
.topbar .user-box { display: flex; align-items: center; gap: 14px; color: var(--text-dim); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 13px;
}
.content { padding: 26px; max-width: 1400px; width: 100%; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  font-weight: 600; font-size: 13px; cursor: pointer;
  transition: filter .15s, transform .05s, background .15s;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff; }
.btn-danger { background: linear-gradient(135deg, #ef4444, #b91c1c); border-color: transparent; color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Cards ---------- */
.card {
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card h3 { color: var(--text); }

.grid { display: grid; gap: 16px; }
.stats-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.cards-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

.stat-card {
  display: flex; flex-direction: column; gap: 6px;
  position: relative; overflow: hidden;
}
.stat-card .stat-label { color: var(--text-dim); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.stat-card .stat-value { font-size: 30px; font-weight: 750; }
.stat-card .stat-ic {
  position: absolute; right: 14px; top: 14px; font-size: 22px; opacity: .25;
}
.stat-card.accent-green .stat-value { color: var(--green); }
.stat-card.accent-red .stat-value { color: var(--red); }
.stat-card.accent-amber .stat-value { color: var(--amber); }
.stat-card.accent-orange .stat-value { color: var(--orange); }
.stat-card.accent-blue .stat-value { color: var(--accent); }

/* ---------- Badges / chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .3px;
  border: 1px solid transparent;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.online   { color: var(--green);  background: rgba(34,197,94,.12);  border-color: rgba(34,197,94,.35); }
.badge.offline  { color: var(--gray);   background: rgba(100,116,139,.12); border-color: rgba(100,116,139,.35); }
.badge.learning { color: var(--orange); background: rgba(251,146,60,.12);  border-color: rgba(251,146,60,.4); }
.badge.alert    { color: var(--amber);  background: rgba(245,158,11,.12);  border-color: rgba(245,158,11,.4); }
.badge.critical { color: var(--red);    background: rgba(239,68,68,.12);   border-color: rgba(239,68,68,.4); }
.badge.crypto   { color: #fff; background: rgba(239,68,68,.25); border-color: var(--red); animation: pulse-red 1.2s infinite; }
.badge.suspended{ color: var(--purple); background: rgba(168,85,247,.12);  border-color: rgba(168,85,247,.4); }

.sev-info     { color: var(--accent); }
.sev-warning  { color: var(--amber); }
.sev-critical { color: var(--red); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border);
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
thead th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-faint); font-weight: 700;
  padding: 12px 14px; background: var(--bg-2); border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); }
tbody tr { transition: background .12s; }
tbody tr:hover { background: rgba(255,255,255,.02); }
tbody tr:last-child td { border-bottom: none; }
tr.row-crypto { box-shadow: inset 3px 0 0 var(--red); animation: rowpulse 1.4s infinite; }

.mini-bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; width: 70px; }
.mini-bar > span { display: block; height: 100%; background: var(--accent); }
.mini-bar > span.warn { background: var(--amber); }
.mini-bar > span.crit { background: var(--red); }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }
input, select, textarea {
  background: var(--bg-2); border: 1px solid var(--border); color: var(--text);
  padding: 9px 12px; border-radius: var(--radius-sm); font-size: 13px; font-family: var(--font);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
label { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 6px; font-weight: 600; }
.field { margin-bottom: 14px; }

/* ---------- Group cards ---------- */
.group-card { position: relative; padding-left: 22px; }
.group-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px;
  border-radius: var(--radius) 0 0 var(--radius); background: var(--accent);
}
.group-card .group-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.group-card .gs { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; }
.group-card .gs .k { font-size: 11px; color: var(--text-faint); text-transform: uppercase; }
.group-card .gs .v { font-size: 16px; font-weight: 700; }
.group-card .actions { display: flex; gap: 8px; margin-top: 14px; }

/* ---------- Alerts list ---------- */
.alert-item {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); margin-bottom: 10px; position: relative;
}
.alert-item::before { content:""; position:absolute; left:0; top:0; bottom:0; width:4px; border-radius: var(--radius) 0 0 var(--radius); background: var(--accent); }
.alert-item.sev-critical::before { background: var(--red); }
.alert-item.sev-warning::before { background: var(--amber); }
.alert-item.sev-info::before { background: var(--accent); }
.alert-item .body { flex: 1; }
.alert-item .meta { font-size: 12px; color: var(--text-faint); margin-top: 4px; }
.alert-item .acts { display: flex; gap: 8px; }
.alert-item.resolved { opacity: .55; }

/* ---------- Timeline (crypto) ---------- */
.timeline { position: relative; margin-left: 10px; padding-left: 26px; }
.timeline::before { content:""; position:absolute; left: 8px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.tl-item { position: relative; margin-bottom: 16px; }
.tl-item .tl-dot {
  position: absolute; left: -26px; top: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--red); display: grid; place-items: center; font-size: 10px; color: #fff;
  box-shadow: 0 0 0 4px rgba(239,68,68,.15);
}
.tl-item .card { border-left: 3px solid var(--red); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; margin-top: 8px; }
.kv .k { color: var(--text-faint); }
.device-affected { border: 1px solid var(--red); animation: pulse-red 1.3s infinite; }

/* ---------- Modals ---------- */
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 100;
  background: rgba(3,6,12,.72); backdrop-filter: blur(3px);
  align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal {
  width: 100%; max-width: 460px;
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px;
}
.modal.wide { max-width: 620px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head .x { cursor: pointer; color: var(--text-dim); font-size: 20px; background: none; border: none; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- Crypto full-screen blocking modal ---------- */
.crypto-modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(40,0,0,.78); backdrop-filter: blur(5px);
  align-items: center; justify-content: center; padding: 20px;
}
.crypto-modal-overlay.show { display: flex; }
.crypto-modal {
  width: 100%; max-width: 540px;
  background: linear-gradient(180deg, #1c1013, #120a0d);
  border: 2px solid var(--red); border-radius: var(--radius);
  box-shadow: 0 0 60px rgba(239,68,68,.5);
  padding: 26px; animation: pop .18s ease-out;
}
.crypto-modal .cm-head { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.crypto-modal .cm-icon {
  width: 52px; height: 52px; border-radius: 12px; display: grid; place-items: center;
  font-size: 28px; background: rgba(239,68,68,.2); border: 1px solid var(--red);
  animation: pulse-red 1s infinite;
}
.crypto-modal h2 { color: #fff; }
.crypto-modal .cm-sub { color: #ffb4b4; font-weight: 600; }

/* ---------- Toasts ---------- */
.toast-wrap { position: fixed; top: 18px; right: 18px; z-index: 300; display: flex; flex-direction: column; gap: 10px; }
.toast {
  min-width: 260px; max-width: 360px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm); padding: 12px 14px;
  box-shadow: var(--shadow); animation: slide-in .25s ease-out;
}
.toast.info { border-left-color: var(--accent); }
.toast.success { border-left-color: var(--green); }
.toast.warning { border-left-color: var(--amber); }
.toast.critical, .toast.error { border-left-color: var(--red); }
.toast .t-title { font-weight: 700; margin-bottom: 2px; }
.toast .t-msg { font-size: 12.5px; color: var(--text-dim); }
.toast.hide { animation: slide-out .25s ease-in forwards; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 400px; }
.login-card .brand { justify-content: center; padding: 0 0 18px; font-size: 22px; }
.tabs { display: flex; gap: 6px; background: var(--bg-2); padding: 5px; border-radius: var(--radius-sm); margin-bottom: 18px; }
.tabs button { flex: 1; padding: 9px; border: none; background: transparent; color: var(--text-dim); border-radius: 6px; cursor: pointer; font-weight: 600; }
.tabs button.active { background: var(--surface-2); color: #fff; }
.auth-form { display: none; }
.auth-form.active { display: block; }
.form-error { color: var(--red); font-size: 12.5px; margin-top: 8px; min-height: 16px; }

.empty { text-align: center; color: var(--text-faint); padding: 40px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; }
.copy-key { display: inline-flex; gap: 8px; align-items: center; background: var(--bg-2); border: 1px solid var(--border); padding: 6px 10px; border-radius: 6px; }

/* ---------- Animations ---------- */
@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,.5); }
  50% { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}
@keyframes rowpulse {
  0%, 100% { background: rgba(239,68,68,.05); }
  50% { background: rgba(239,68,68,.14); }
}
@keyframes slide-in { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slide-out { to { transform: translateX(120%); opacity: 0; } }
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .main { width: 100%; }
  .menu-toggle { display: inline-flex !important; }
}
.menu-toggle { display: none; }
