:root {
  --bg: #0A0E13;
  --panel: #121821;
  --panel-raised: #17202B;
  --border: #232F3B;
  --text: #E7EDF3;
  --text-muted: #8996A5;
  --text-faint: #566072;
  --accent: #38D9A9;       /* healthy / pass */
  --accent-dim: #1E5943;
  --warn: #E8A94A;         /* neutral / needs attention */
  --warn-dim: #4A3B1E;
  --crit: #E85D5D;         /* fail / broken */
  --crit-dim: #4A2323;
  --info: #5CA9E8;
  --radius: 10px;
  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { font-family: var(--font-display); margin: 0; }
.mono { font-family: var(--font-mono); }

/* ---------- Shell / rail nav ---------- */
.shell { display: flex; min-height: 100vh; }
.rail {
  width: 220px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
}
.rail-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 32px; padding: 0 8px; }
.rail-brand-mark { font-size: 22px; color: var(--accent); }
.rail-brand-text {
  font-family: var(--font-display); font-weight: 600; font-size: 12px;
  line-height: 1.25; letter-spacing: 0.03em; text-transform: uppercase; color: var(--text);
}
.rail-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.rail-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  color: var(--text-muted); font-weight: 500; font-size: 13.5px;
}
.rail-nav a:hover { background: var(--panel-raised); color: var(--text); }
.rail-nav a.active { background: var(--accent-dim); color: var(--accent); }
.rail-icon { font-size: 14px; width: 16px; text-align: center; }
.rail-foot { border-top: 1px solid var(--border); padding-top: 14px; }
.rail-foot a { color: var(--text-faint); font-size: 12.5px; }
.rail-foot a:hover { color: var(--text-muted); }

.main { flex: 1; padding: 32px 40px; max-width: 1400px; min-width: 0; }

/* ---------- Mobile top bar + nav drawer (< 900px) ---------- */
.mobile-topbar { display: none; }
.rail-backdrop { display: none; }

/* ---------- Flash messages ---------- */
.flash-stack { margin-bottom: 20px; display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 10px 14px; border-radius: 8px; font-size: 13px; }
.flash-success { background: var(--accent-dim); color: var(--accent); border: 1px solid var(--accent); }
.flash-error { background: var(--crit-dim); color: var(--crit); border: 1px solid var(--crit); }

/* ---------- Page header ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 14px; flex-wrap: wrap; margin-bottom: 28px; }
.page-head h1 { font-size: 24px; font-weight: 600; word-break: break-word; }
.page-head .sub { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.eyebrow {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-faint); margin-bottom: 6px;
}

/* ---------- Stat strip ---------- */
.stat-strip { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 32px; }
.stat-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; flex: 1; min-width: 140px;
}
.stat-box .val { font-family: var(--font-mono); font-size: 28px; font-weight: 600; }
.stat-box .label { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.stat-box.crit .val { color: var(--crit); }
.stat-box.warn .val { color: var(--warn); }
.stat-box.ok .val { color: var(--accent); }

/* ---------- Project grouping on overview ---------- */
.project-group { margin-bottom: 32px; }
.project-group-head { margin-bottom: 14px; }
.project-group-head h2 { font-size: 17px; font-weight: 600; margin-top: 2px; }

/* ---------- Site cards grid ---------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.site-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; display: flex; flex-direction: column; gap: 14px;
  transition: border-color 0.15s ease;
}
.site-card:hover { border-color: var(--text-faint); }
.site-card-top { display: flex; justify-content: space-between; align-items: flex-start; }
.site-card-name { font-family: var(--font-display); font-weight: 600; font-size: 16px; }
.site-card-url { color: var(--text-faint); font-size: 12px; font-family: var(--font-mono); }
.site-card-name a { display: block; }
.site-card-name a:hover { color: var(--accent); }

.signal-strip { display: flex; gap: 4px; }
.signal-dot { width: 8px; height: 8px; border-radius: 50%; }
.signal-dot.ok { background: var(--accent); }
.signal-dot.warn { background: var(--warn); }
.signal-dot.crit { background: var(--crit); }
.signal-dot.na { background: var(--border); }

.card-metrics { display: flex; gap: 20px; flex-wrap: wrap; row-gap: 10px; }
.card-metric .val { font-family: var(--font-mono); font-size: 20px; font-weight: 600; }
.card-metric .label { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }

.sparkline { width: 100%; height: 36px; }

.card-issues { display: flex; flex-direction: column; gap: 4px; }
.issue-pill {
  font-size: 11.5px; color: var(--text-muted); padding: 3px 0;
  border-top: 1px solid var(--border); padding-top: 6px;
}
.issue-pill:first-child { border-top: none; padding-top: 0; }
.issue-pill.crit { color: var(--crit); }
.issue-pill.warn { color: var(--warn); }

/* ---------- Buttons / forms ---------- */
.btn {
  display: inline-block; background: var(--accent); color: #06120D; font-weight: 600;
  font-size: 13px; padding: 9px 16px; border-radius: 8px; border: none; cursor: pointer;
  font-family: var(--font-body);
}
.btn:hover { opacity: 0.9; }
.btn-ghost {
  background: transparent; color: var(--text-muted); border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-faint); }
.btn-sm { padding: 6px 12px; font-size: 12px; }

form.inline { display: inline; }

input[type="text"], input[type="password"], input[type="email"], input[type="url"], select, textarea {
  width: 100%; background: var(--panel-raised); border: 1px solid var(--border); color: var(--text);
  padding: 9px 12px; border-radius: 7px; font-family: var(--font-body); font-size: 13.5px; margin-bottom: 14px;
}
textarea { font-family: var(--font-mono, monospace); resize: vertical; }
input[type="file"] {
  width: 100%; background: var(--panel-raised); border: 1px dashed var(--border); color: var(--text-muted);
  padding: 9px 12px; border-radius: 7px; font-size: 13px; margin-bottom: 14px;
}
label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.03em; }

/* ---------- Login ---------- */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 20px; }
.login-card {
  width: 340px; max-width: 100%; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 32px;
  text-align: center;
}
.login-mark { font-size: 32px; color: var(--accent); margin-bottom: 8px; }
.login-card h1 { font-size: 18px; margin-bottom: 4px; }
.login-sub { color: var(--text-muted); font-size: 12.5px; margin-bottom: 20px; }
.login-card form { text-align: left; }
.login-card button { width: 100%; padding: 11px; margin-top: 6px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -2px; }
.table-wrap table { min-width: 620px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; color: var(--text-faint); font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.04em; padding: 8px 10px; border-bottom: 1px solid var(--border);
}
td { padding: 10px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
.badge { font-family: var(--font-mono); font-size: 11px; padding: 2px 8px; border-radius: 20px; display: inline-block; }
.badge.ok { background: var(--accent-dim); color: var(--accent); }
.badge.warn { background: var(--warn-dim); color: var(--warn); }
.badge.crit { background: var(--crit-dim); color: var(--crit); }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; margin-bottom: 20px; }
.panel h2 { font-size: 15px; margin-bottom: 16px; }
.panel-row { display: flex; gap: 20px; }
.panel-col { flex: 1; }

.psi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.psi-score { text-align: center; padding: 14px; background: var(--panel-raised); border-radius: 8px; }
.psi-score .num { font-family: var(--font-mono); font-size: 26px; font-weight: 600; }
.psi-score .lbl { font-size: 11px; color: var(--text-muted); margin-top: 4px; text-transform: uppercase; }
.psi-score.good .num { color: var(--accent); }
.psi-score.mid .num { color: var(--warn); }
.psi-score.bad .num { color: var(--crit); }

.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-muted);
  border: 1px dashed var(--border); border-radius: var(--radius);
}

/* ---------- AI recommendation report (rendered markdown) ---------- */
.ai-report { font-size: 13.5px; line-height: 1.65; color: var(--text); overflow-x: auto; }
.ai-report h2 {
  font-size: 15px; color: var(--accent); margin: 22px 0 10px; padding-top: 14px;
  border-top: 1px solid var(--border);
}
.ai-report h2:first-child { margin-top: 0; padding-top: 0; border-top: none; }
.ai-report h3 { font-size: 13.5px; margin: 14px 0 6px; color: var(--text); }
.ai-report p { margin: 0 0 10px; color: var(--text-muted); }
.ai-report ul, .ai-report ol { margin: 0 0 12px; padding-left: 20px; color: var(--text-muted); }
.ai-report li { margin-bottom: 6px; }
.ai-report strong { color: var(--text); }
.ai-report code { font-family: var(--font-mono); background: var(--panel-raised); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.ai-report table { margin: 10px 0; }

.client-group { margin-bottom: 24px; }
.client-group h3 { font-size: 14px; margin-bottom: 10px; color: var(--text-muted); }
.site-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; margin-bottom: 6px; font-size: 13px;
}
.site-row .name { font-weight: 500; }
.site-row .url { color: var(--text-faint); font-family: var(--font-mono); font-size: 11.5px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

/* ================= Responsive ================= */
@media (max-width: 900px) {
  .shell { display: block; }
  .main { padding: 20px 18px 48px; }

  .mobile-topbar {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--panel); border-bottom: 1px solid var(--border);
    padding: 12px 16px; position: sticky; top: 0; z-index: 45;
  }
  .mobile-topbar .brand { display: flex; align-items: center; gap: 8px; }
  .mobile-topbar .brand-mark { font-size: 18px; color: var(--accent); }
  .mobile-topbar .brand-text {
    font-family: var(--font-display); font-weight: 600; font-size: 13px;
    letter-spacing: 0.03em; text-transform: uppercase; color: var(--text);
  }
  .hamburger-btn {
    background: var(--panel-raised); border: 1px solid var(--border); color: var(--text);
    width: 38px; height: 38px; border-radius: 8px; font-size: 16px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
  }

  .rail {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 60;
    width: 78vw; max-width: 280px;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 12px 0 32px rgba(0,0,0,0.45);
  }
  .rail.is-open { transform: translateX(0); }

  .rail-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(4,7,10,0.6);
    z-index: 55; opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
  }
  .rail-backdrop.is-open { opacity: 1; pointer-events: auto; }

  .two-col { grid-template-columns: 1fr; }
  .psi-grid { grid-template-columns: repeat(2, 1fr); }
  .card-grid { grid-template-columns: 1fr; }
  .page-head { align-items: flex-start; }
  .page-head > div:last-child { width: 100%; flex-direction: column; }
  .page-head form, .page-head a.btn { width: 100%; }
  .page-head form button, .page-head a.btn { width: 100%; text-align: center; box-sizing: border-box; }
}

@media (max-width: 520px) {
  .stat-strip { flex-direction: column; }
  .stat-box { min-width: 100%; }
  .psi-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .psi-score { padding: 10px; }
  .psi-score .num { font-size: 21px; }
  .login-card { padding: 24px 20px; }
  .panel { padding: 16px; }
  .card-metrics { gap: 14px; }
}
