/* ResponsibleAI shared design system — self-contained, zero external
   dependencies (no CDN fonts, no CDN frameworks). This is deliberate: the
   Stitch-exported mockups reviewed this session broke exactly because they
   depended on a Tailwind CDN script and a Google Material Symbols font that
   silently fail to load offline / over file://. Every real page in this
   product must render correctly with zero network access beyond itself. */

:root {
  color-scheme: light dark;
  --bg: #fafafa;
  --bg-raised: #ffffff;
  --fg: #1a1a1a;
  --muted: #666666;
  --border: #e5e5e5;
  --accent: #2563eb;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --code-bg: #f1f1f1;
  --row-hover: #f3f4f6;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  --radius: 10px;
  --sidebar-w: 240px;
  --topbar-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b0c;
    --bg-raised: #17181a;
    --fg: #e8e8e8;
    --muted: #999999;
    --border: #2a2a2c;
    --code-bg: #232427;
    --row-hover: #1f2023;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0b0c;
  --bg-raised: #17181a;
  --fg: #e8e8e8;
  --muted: #999999;
  --border: #2a2a2c;
  --code-bg: #232427;
  --row-hover: #1f2023;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.55;
}
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
a { color: var(--accent); }

/* ── App shell: sidebar + topbar ─────────────────────────────────────────── */
.rai-app { display: flex; min-height: 100vh; }
.rai-sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--bg-raised);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.rai-sidebar .brand {
  padding: 1.1rem 1.25rem; font-weight: 800; font-size: 1rem; letter-spacing: -0.01em;
  border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 0.5rem;
}
.rai-sidebar .brand .brand-logo { max-height: 28px; max-width: 100%; object-fit: contain; }
.rai-sidebar nav { padding: 0.75rem; flex: 1; }
.rai-nav-group { margin-bottom: 1.1rem; }
.rai-nav-label {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
  padding: 0.4rem 0.6rem; font-weight: 700;
}
.rai-nav-item {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 0.6rem; border-radius: 8px;
  color: var(--fg); text-decoration: none; font-size: 0.88rem; margin-bottom: 2px;
}
.rai-nav-item:hover { background: var(--row-hover); }
.rai-nav-item.active { background: var(--row-hover); font-weight: 700; }
.rai-nav-item .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--border); flex-shrink: 0; }
.rai-nav-item.active .dot { background: var(--accent); }

.rai-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rai-topbar {
  height: var(--topbar-h); border-bottom: 1px solid var(--border); display: flex; align-items: center;
  justify-content: space-between; padding: 0 1.5rem; background: var(--bg); position: sticky; top: 0; z-index: 5;
}
.rai-topbar .actions { display: flex; align-items: center; gap: 0.6rem; }
.rai-content { padding: 2rem 2.25rem 4rem; max-width: 1200px; width: 100%; margin: 0 auto; }

@media (max-width: 860px) {
  .rai-sidebar { position: fixed; left: -260px; z-index: 20; transition: left 0.15s ease; }
  .rai-sidebar.open { left: 0; }
  .rai-content { padding: 1.25rem; }
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font-size: 0.86rem; font-weight: 600; padding: 0.55rem 1rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-raised); color: var(--fg);
  cursor: pointer; text-decoration: none; line-height: 1.2;
}
.btn:hover { background: var(--row-hover); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.78rem; }
.btn-icon { width: 2.1rem; height: 2.1rem; padding: 0; border-radius: 8px; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
label { font-size: 0.85rem; font-weight: 600; margin-bottom: 0.35rem; display: block; }
input, select, textarea {
  width: 100%; background: var(--bg-raised); border: 1px solid var(--border); color: var(--fg);
  border-radius: 8px; padding: 0.6rem 0.8rem; font-size: 0.9rem; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { min-height: 100px; resize: vertical; }
.field { margin-bottom: 1.1rem; }
.field .hint { font-size: 0.78rem; color: var(--muted); margin-top: 0.3rem; }
.row { display: flex; gap: 0.9rem; }
.row > * { flex: 1; }
input[type="range"] { padding: 0; }

/* ── Cards / panels ───────────────────────────────────────────────────────── */
.card {
  background: var(--bg-raised); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.5rem; box-shadow: var(--shadow);
}
.card + .card { margin-top: 1.25rem; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--bg-raised); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; }
.stat-card .label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 0.4rem; }
.stat-card .value { font-size: 1.7rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-card .delta { font-size: 0.78rem; color: var(--muted); margin-top: 0.2rem; }

/* ── Page header ──────────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.page-header h1 { font-size: 1.5rem; margin: 0 0 0.3rem; letter-spacing: -0.01em; }
.page-header p { color: var(--muted); margin: 0; max-width: 640px; font-size: 0.92rem; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap { background: var(--bg-raised); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
thead th {
  text-align: left; padding: 0.7rem 1rem; font-weight: 600; color: var(--muted);
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border);
}
tbody td { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--row-hover); }

/* ── Badges / pills ───────────────────────────────────────────────────────── */
.pill { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.72rem; font-weight: 700; border-radius: 999px; padding: 0.18rem 0.6rem; text-transform: uppercase; letter-spacing: 0.02em; }
.pill-outline { background: transparent; border: 1px solid var(--border); color: var(--muted); text-transform: none; font-weight: 600; }
.pill-critical, .pill-high { background: rgba(220,38,38,0.14); color: var(--red); }
.pill-medium { background: rgba(37,99,235,0.12); color: var(--accent); }
.pill-low, .pill-neutral { background: var(--code-bg); color: var(--muted); }
.pill-success { background: rgba(22,163,74,0.14); color: var(--green); }
.pill-warning { background: rgba(217,119,6,0.14); color: var(--amber); }

/* ── Grade badge (trust score) ────────────────────────────────────────────── */
.grade-badge { display: inline-flex; align-items: center; justify-content: center; width: 2rem; height: 2rem; border-radius: 8px; font-weight: 800; font-size: 0.95rem; }
.grade-badge.A { background: rgba(22,163,74,0.15); color: var(--green); }
.grade-badge.B { background: rgba(37,99,235,0.15); color: var(--accent); }
.grade-badge.C { background: rgba(217,119,6,0.15); color: var(--amber); }
.grade-badge.D, .grade-badge.F { background: rgba(220,38,38,0.15); color: var(--red); }

/* ── Empty / loading / error states ──────────────────────────────────────── */
.state-box { padding: 3rem 1.5rem; text-align: center; color: var(--muted); }
.state-box.error { color: var(--red); }
.spinner {
  width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border);
  border-top-color: var(--accent); animation: rai-spin 0.7s linear infinite; display: inline-block;
}
@keyframes rai-spin { to { transform: rotate(360deg); } }

/* ── Toasts ───────────────────────────────────────────────────────────────── */
#rai-toast-host { position: fixed; top: 1rem; right: 1rem; z-index: 100; display: flex; flex-direction: column; gap: 0.5rem; }
.rai-toast {
  background: var(--bg-raised); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.75rem 1rem; font-size: 0.85rem; box-shadow: 0 4px 16px rgba(0,0,0,0.15); max-width: 340px;
}
.rai-toast.error { border-color: var(--red); color: var(--red); }
.rai-toast.success { border-color: var(--green); color: var(--green); }

/* ── Utility ──────────────────────────────────────────────────────────────── */
.hash-box { font-family: ui-monospace, monospace; font-size: 0.76rem; color: var(--muted); background: var(--code-bg); padding: 0.75rem 1rem; border-radius: 8px; word-break: break-all; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.flex { display: flex; } .items-center { align-items: center; } .gap-2 { gap: 0.5rem; } .gap-3 { gap: 0.9rem; }
.text-muted { color: var(--muted); } .text-sm { font-size: 0.85rem; }
