/* ---------- Design tokens (calcados de complex-web/src/assets/styles/global.css) ---------- */
:root {
  --background: oklch(1 0 0);
  --foreground: oklch(0.145 0 0);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.145 0 0);
  --popover: oklch(1 0 0);
  --popover-foreground: oklch(0.145 0 0);
  --primary: oklch(0.205 0 0);
  --primary-foreground: oklch(0.985 0 0);
  --secondary: oklch(0.97 0 0);
  --secondary-foreground: oklch(0.205 0 0);
  --muted: oklch(0.97 0 0);
  --muted-foreground: oklch(0.556 0 0);
  --accent: oklch(0.97 0 0);
  --accent-foreground: oklch(0.205 0 0);
  --destructive: oklch(0.577 0.245 27.325);
  --border: oklch(0.922 0 0);
  --input: oklch(0.922 0 0);
  --ring: oklch(0.708 0 0);
  --radius: 0.625rem;
  --radius-sm: calc(var(--radius) * 0.6);
  --radius-md: calc(var(--radius) * 0.8);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) * 1.4);
  --radius-2xl: calc(var(--radius) * 1.8);
  --radius-3xl: calc(var(--radius) * 2.2);
  --radius-4xl: calc(var(--radius) * 2.6);

  --status-ok-fg: oklch(0.42 0.09 155);
  --status-ok-bg: oklch(0.93 0.045 155);
  --status-fail-fg: oklch(0.45 0.16 25);
  --status-fail-bg: oklch(0.93 0.06 25);
  --status-rbac-fg: var(--muted-foreground);
  --status-rbac-bg: var(--muted);
  --status-unver-fg: oklch(0.65 0.01 90);
  --status-unver-bg: transparent;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: oklch(0.205 0 0);
    --foreground: oklch(0.985 0 0);
    --card: oklch(0.205 0 0);
    --card-foreground: oklch(0.985 0 0);
    --popover: oklch(0.205 0 0);
    --popover-foreground: oklch(0.985 0 0);
    --primary: oklch(0.922 0 0);
    --primary-foreground: oklch(0.205 0 0);
    --secondary: oklch(0.269 0 0);
    --secondary-foreground: oklch(0.985 0 0);
    --muted: oklch(0.269 0 0);
    --muted-foreground: oklch(0.708 0 0);
    --accent: oklch(0.269 0 0);
    --accent-foreground: oklch(0.985 0 0);
    --destructive: oklch(0.704 0.191 22.216);
    --border: oklch(1 0 0 / 10%);
    --input: oklch(1 0 0 / 15%);
    --ring: oklch(0.556 0 0);

    --status-ok-fg: oklch(0.78 0.09 155);
    --status-ok-bg: oklch(0.32 0.055 155);
    --status-fail-fg: oklch(0.78 0.13 25);
    --status-fail-bg: oklch(0.34 0.08 25);
    --status-rbac-fg: var(--muted-foreground);
    --status-rbac-bg: var(--muted);
    --status-unver-fg: oklch(0.5 0.01 90);
    --status-unver-bg: transparent;
  }
}

/* ---------- Theme overrides (explicit data-theme attribute wins over prefers-color-scheme) ---------- */
:root[data-theme="light"] {
  --background: oklch(1 0 0);
  --foreground: oklch(0.145 0 0);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.145 0 0);
  --popover: oklch(1 0 0);
  --popover-foreground: oklch(0.145 0 0);
  --primary: oklch(0.205 0 0);
  --primary-foreground: oklch(0.985 0 0);
  --secondary: oklch(0.97 0 0);
  --secondary-foreground: oklch(0.205 0 0);
  --muted: oklch(0.97 0 0);
  --muted-foreground: oklch(0.556 0 0);
  --accent: oklch(0.97 0 0);
  --accent-foreground: oklch(0.205 0 0);
  --destructive: oklch(0.577 0.245 27.325);
  --border: oklch(0.922 0 0);
  --input: oklch(0.922 0 0);
  --ring: oklch(0.708 0 0);

  --status-ok-fg: oklch(0.42 0.09 155);
  --status-ok-bg: oklch(0.93 0.045 155);
  --status-fail-fg: oklch(0.45 0.16 25);
  --status-fail-bg: oklch(0.93 0.06 25);
  --status-rbac-fg: var(--muted-foreground);
  --status-rbac-bg: var(--muted);
  --status-unver-fg: oklch(0.65 0.01 90);
  --status-unver-bg: transparent;
}

:root[data-theme="dark"] {
  --background: oklch(0.205 0 0);
  --foreground: oklch(0.985 0 0);
  --card: oklch(0.205 0 0);
  --card-foreground: oklch(0.985 0 0);
  --popover: oklch(0.205 0 0);
  --popover-foreground: oklch(0.985 0 0);
  --primary: oklch(0.922 0 0);
  --primary-foreground: oklch(0.205 0 0);
  --secondary: oklch(0.269 0 0);
  --secondary-foreground: oklch(0.985 0 0);
  --muted: oklch(0.269 0 0);
  --muted-foreground: oklch(0.708 0 0);
  --accent: oklch(0.269 0 0);
  --accent-foreground: oklch(0.985 0 0);
  --destructive: oklch(0.704 0.191 22.216);
  --border: oklch(1 0 0 / 10%);
  --input: oklch(1 0 0 / 15%);
  --ring: oklch(0.556 0 0);

  --status-ok-fg: oklch(0.78 0.09 155);
  --status-ok-bg: oklch(0.32 0.055 155);
  --status-fail-fg: oklch(0.78 0.13 25);
  --status-fail-bg: oklch(0.34 0.08 25);
  --status-rbac-fg: var(--muted-foreground);
  --status-rbac-bg: var(--muted);
  --status-unver-fg: oklch(0.5 0.01 90);
  --status-unver-bg: transparent;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: 'Inter Variable', Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

.mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace; }
.tabular { font-variant-numeric: tabular-nums; }
button, [role="button"] { cursor: pointer; }

:focus-visible {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring) 30%, transparent);
}

/* ---------- Shell / topbar (reemplaza el sidebar del mockup: esto no vive dentro del producto) ---------- */
.shell { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: var(--primary-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
  flex-shrink: 0;
}

.brand-name { font-size: 13.5px; font-weight: 600; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; padding: 22px 28px 48px; display: flex; flex-direction: column; gap: 18px; }

.banner {
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  font-size: 12.5px;
}
.banner-error { background: var(--status-fail-bg); color: var(--status-fail-fg); }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-title-group h1 { font-size: 15px; font-weight: 500; margin: 0 0 4px; }
.page-title-group p { font-size: 13px; color: var(--muted-foreground); margin: 0; max-width: 46ch; }
.header-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ---------- Buttons (calco de button.tsx) ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius-4xl);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  height: 34px;
  padding: 0 14px;
  transition: all 0.15s ease;
  background: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover { background: color-mix(in oklch, var(--primary) 80%, transparent); }
.btn-outline { border-color: var(--border); background: var(--background); color: var(--foreground); }
.btn-outline:hover { background: var(--muted); }
.btn-ghost { background: transparent; color: var(--foreground); }
.btn-ghost:hover { background: var(--muted); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-xs { height: 24px; padding: 0 9px; font-size: 11.5px; border-radius: var(--radius-4xl); }
.btn:disabled { opacity: 0.5; pointer-events: none; }

.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-4xl);
  border: 1px solid transparent;
  background: transparent;
  color: var(--foreground);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s ease;
  flex-shrink: 0;
}
.theme-toggle:hover {
  background: var(--muted);
}

/* ---------- Badge ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 8px;
  border-radius: var(--radius-3xl);
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-fail { background: var(--status-fail-bg); color: var(--status-fail-fg); }
.badge-ok { background: var(--status-ok-bg); color: var(--status-ok-fg); }
.badge-muted { background: var(--muted); color: var(--muted-foreground); }
.badge-outline { border-color: var(--border); color: var(--foreground); }

/* ---------- Card ---------- */
.card {
  background: var(--card);
  color: var(--card-foreground);
  border-radius: var(--radius-4xl);
  box-shadow: 0 4px 10px -4px oklch(0 0 0 / 0.08);
  outline: 1px solid color-mix(in oklch, var(--foreground) 5%, transparent);
  padding: 20px;
}
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-title { font-size: 14px; font-weight: 500; }
.card-desc { font-size: 12.5px; color: var(--muted-foreground); }

.empty-state { display: flex; justify-content: center; padding: 60px 0; }
.empty-card { max-width: 420px; text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: center; }

/* ---------- Running banner ---------- */
.run-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 12px 16px;
}
.spinner {
  width: 16px; height: 16px; flex-shrink: 0; border-radius: 999px;
  border: 2px solid color-mix(in oklch, var(--foreground) 18%, transparent);
  border-top-color: var(--foreground);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.run-banner .rb-title { font-size: 13px; font-weight: 500; }
.run-banner .rb-sub { font-size: 12px; color: var(--muted-foreground); }

/* ---------- Stat cards row ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 900px) { .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat-card { background: var(--card); border-radius: var(--radius-2xl); padding: 16px 18px; outline: 1px solid var(--border); }
.stat-label { font-size: 11.5px; color: var(--muted-foreground); text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 8px; }
.stat-value { font-size: 20px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.stat-meta { margin-top: 8px; font-size: 11.5px; color: var(--muted-foreground); display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Selection bar ---------- */
.selection-bar {
  position: sticky; top: 12px; z-index: 20;
  display: none; align-items: center; gap: 14px;
  background: var(--primary); color: var(--primary-foreground);
  border-radius: var(--radius-2xl); padding: 10px 16px;
  box-shadow: 0 8px 24px -8px oklch(0 0 0 / 0.35);
}
.selection-bar.visible { display: flex; }
.selection-bar .sel-count { font-size: 13px; font-weight: 500; }
.selection-bar .btn-primary { background: var(--primary-foreground); color: var(--primary); }
.selection-bar .btn-primary:hover { background: color-mix(in oklch, var(--primary-foreground) 85%, transparent); }
.selection-bar .btn-ghost { color: var(--primary-foreground); }
.selection-bar .btn-ghost:hover { background: color-mix(in oklch, var(--primary-foreground) 15%, transparent); }
.selection-bar .sep { margin-left: auto; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search-input {
  background: var(--background);
  border: 1px solid var(--input);
  border-radius: var(--radius-4xl);
  padding: 0 12px;
  height: 34px;
  min-width: 220px;
  color: var(--foreground);
  font-size: 13px;
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border);
  background: var(--background);
  color: var(--foreground);
  border-radius: var(--radius-4xl);
  padding: 5px 12px;
  font-size: 12.5px;
  font-weight: 500;
}
.chip.active { background: var(--primary); color: var(--primary-foreground); border-color: transparent; }
.chip.fail-chip { color: var(--status-fail-fg); }

/* ---------- Layout: matrix + detail ---------- */
.content-grid { display: grid; grid-template-columns: 1fr 340px; gap: 18px; align-items: start; }
@media (max-width: 1100px) { .content-grid { grid-template-columns: 1fr; } }

/* ---------- Matrix table ---------- */
.matrix-scroll { overflow-x: auto; }
table.matrix { width: 100%; border-collapse: collapse; min-width: 760px; }
table.matrix thead th {
  text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.03em; color: var(--muted-foreground); padding: 8px 10px; border-bottom: 1px solid var(--border);
}
table.matrix thead th.center { text-align: center; }
tr.group-row td { background: var(--muted); font-size: 12.5px; font-weight: 600; padding: 8px 10px; border-top: 1px solid var(--border); }
tr.group-row .group-count { font-weight: 400; color: var(--muted-foreground); margin-left: 6px; }
tr.view-row td { padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
tr.view-row:hover td { background: color-mix(in oklch, var(--muted) 55%, transparent); }
.view-name { font-weight: 500; }
.view-path { display: block; font-size: 11px; color: var(--muted-foreground); margin-top: 1px; }
td.center { text-align: center; }
.row-check, .group-check { width: 15px; height: 15px; accent-color: var(--primary); vertical-align: middle; }

.status-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 999px; font-size: 12px; font-weight: 700; border: none; background: transparent;
}
.status-ok { color: var(--status-ok-fg); background: var(--status-ok-bg); }
.status-fail { color: var(--status-fail-fg); background: var(--status-fail-bg); cursor: pointer; }
.status-fail:hover { background: color-mix(in oklch, var(--status-fail-bg) 70%, var(--status-fail-fg) 15%); }
.status-rbac { color: var(--status-rbac-fg); background: var(--status-rbac-bg); }
.status-unver { color: var(--status-unver-fg); border: 1px dashed var(--border); }

.run-view-btn {
  width: 26px; height: 26px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--background); color: var(--foreground); font-size: 11px;
  display: inline-flex; align-items: center; justify-content: center;
}
.run-view-btn:hover { background: var(--muted); }

/* ---------- Detail panel ---------- */
.detail-panel { position: sticky; top: 60px; display: flex; flex-direction: column; gap: 12px; }
.detail-error {
  background: var(--status-fail-bg); color: var(--status-fail-fg); border-radius: var(--radius-lg);
  padding: 10px 12px; font-size: 12px; line-height: 1.5; overflow-x: auto; white-space: pre;
}
.kv { display: grid; grid-template-columns: 84px 1fr; gap: 6px 10px; font-size: 12px; }
.kv dt { color: var(--muted-foreground); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.screenshot-ph {
  aspect-ratio: 16 / 9; border-radius: var(--radius-lg); border: 1px solid var(--border);
  background: repeating-linear-gradient(135deg, var(--muted), var(--muted) 8px, color-mix(in oklch, var(--muted) 60%, var(--background)) 8px, color-mix(in oklch, var(--muted) 60%, var(--background)) 16px);
  display: flex; align-items: center; justify-content: center; color: var(--muted-foreground); font-size: 11.5px;
}
.screenshot-img { width: 100%; border-radius: var(--radius-lg); border: 1px solid var(--border); display: block; }

/* ---------- Legend ---------- */
.legend { display: flex; gap: 20px; flex-wrap: wrap; font-size: 12px; color: var(--muted-foreground); padding: 4px 2px; }
.legend-item { display: flex; align-items: center; gap: 6px; }

/* ---------- History table ---------- */
table.history { width: 100%; border-collapse: collapse; }
table.history thead th {
  text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--muted-foreground); padding: 8px 10px; border-bottom: 1px solid var(--border);
}
table.history tbody td { padding: 10px; font-size: 13px; border-bottom: 1px solid var(--border); }
table.history tbody tr:last-child td { border-bottom: none; }
table.history tbody tr:hover td { background: color-mix(in oklch, var(--muted) 45%, transparent); }
.scope-full { font-weight: 500; }
.scope-partial { color: var(--muted-foreground); }
.section-title { font-size: 13px; font-weight: 600; margin: 4px 0 2px; }

::selection { background: color-mix(in oklch, var(--ring) 40%, transparent); }

/* ---------- Login ---------- */
.login-body { margin: 0; display: flex; min-height: 100vh; background: var(--background); }
.login-shell { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 18px; }
.login-brand { justify-content: center; }
.login-brand .brand-mark { width: 34px; height: 34px; font-size: 13px; }
.login-brand .brand-name { font-size: 14px; }
.login-field { display: flex; flex-direction: column; gap: 6px; }
.login-label { font-size: 12.5px; font-weight: 500; color: var(--muted-foreground); }
.login-input {
  background: var(--background);
  border: 1px solid var(--input);
  border-radius: var(--radius-lg);
  padding: 0 12px;
  height: 38px;
  color: var(--foreground);
  font-size: 14px;
}
.login-error { font-size: 12.5px; color: var(--status-fail-fg); }
.login-submit { width: 100%; }
