:root {
  color-scheme: light dark;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --text: #0f172a;
  --muted: #475569;
  --border: #e2e8f0;
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-text: #ffffff;
  --pass: #15803d;
  --pass-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --fail: #b91c1c;
  --fail-bg: #fee2e2;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120;
    --surface: #111827;
    --surface-alt: #1e293b;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --border: #273549;
    --primary: #38bdf8;
    --primary-hover: #0ea5e9;
    --primary-text: #082f49;
    --pass: #4ade80;
    --pass-bg: rgba(34, 197, 94, 0.16);
    --warn: #fbbf24;
    --warn-bg: rgba(245, 158, 11, 0.16);
    --fail: #f87171;
    --fail-bg: rgba(239, 68, 68, 0.16);
    --shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  }
}

:root[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-alt: #1e293b;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: #273549;
  --primary: #38bdf8;
  --primary-hover: #0ea5e9;
  --primary-text: #082f49;
  --pass: #4ade80;
  --pass-bg: rgba(34, 197, 94, 0.16);
  --warn: #fbbf24;
  --warn-bg: rgba(245, 158, 11, 0.16);
  --fail: #f87171;
  --fail-bg: rgba(239, 68, 68, 0.16);
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.login-shell {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.login-card, .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.login-card { padding: 1.75rem; }

.login-brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-bottom: 1.4rem;
}

.login-brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.login-subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.login-footer, .app-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
}

.app-footer {
  max-width: 1320px;
  margin: 0 auto 2rem;
  padding: 0 1.25rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0.7rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1.05rem;
}

.brand-icon { border-radius: 6px; flex-shrink: 0; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border-radius: 7px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  padding: 0.55rem 0.95rem;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.85rem; }
.btn-block { width: 100%; }

.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { border-color: var(--muted); }

.btn-danger { background: var(--fail); color: #ffffff; }
.btn-danger:hover { filter: brightness(0.92); }

.btn-icon {
  padding: 0.42rem;
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.user-menu-wrap { position: relative; }

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.65rem 0.25rem 0.3rem;
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  anchor-name: --user-pill;
}

.avatar, .avatar-fallback {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.user-popover {
  margin: 0;
  padding: 0.8rem;
  width: 220px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.22);
  position: fixed;
  position-anchor: --user-pill;
  top: anchor(bottom);
  right: anchor(right);
  margin-top: 0.4rem;
}

.user-popover-header {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}

.container {
  max-width: 1320px;
  margin: 1.25rem auto;
  padding: 0 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.banner, .alert {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.85rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.9rem;
}

.alert-danger, .banner-error {
  background: var(--fail-bg);
  color: var(--fail);
  border-color: currentColor;
}

.banner-ok {
  background: var(--pass-bg);
  color: var(--pass);
  border-color: currentColor;
}

.alert p { margin: 0.25rem 0 0; }
.badge-icon {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: currentColor;
  color: var(--surface);
  font-weight: 800;
  flex-shrink: 0;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.8rem;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field select, .field input, .sort-select {
  padding: 0.46rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
}

.field-search { grid-column: span 2; }
@media (max-width: 640px) {
  .field-search { grid-column: span 1; }
}

.field-actions {
  flex-direction: row;
  gap: 0.45rem;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.kpi-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
}

.kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0.2rem 0;
}

.kpi-sub { font-size: 0.83rem; color: var(--muted); }

.analytics-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 1rem;
}

@media (max-width: 960px) {
  .analytics-grid { grid-template-columns: 1fr; }
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
  flex-wrap: wrap;
}

.card-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.muted-label { color: var(--muted); font-size: 0.82rem; }

.legend { display: flex; gap: 0.9rem; font-size: 0.82rem; }
.legend-item { display: inline-flex; align-items: center; gap: 0.35rem; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.swatch-pass { background: var(--pass); }
.swatch-fail { background: var(--fail); }

.trend-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 190px;
  padding-top: 1.2rem;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
}

.trend-col {
  flex: 1 0 18px;
  max-width: 36px;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
}

.trend-stack {
  width: 100%;
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-start;
  border-radius: 3px 3px 0 0;
  overflow: hidden;
  min-height: 2px;
}

.bar-pass { background: var(--pass); }
.bar-fail { background: var(--fail); }

.trend-date {
  font-size: 0.65rem;
  color: var(--muted);
  white-space: nowrap;
}

.split-tables {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
}

@media (max-width: 680px) {
  .split-tables { grid-template-columns: 1fr; }
}

.table-container {
  container-type: inline-size;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}

.data-table th, .data-table td {
  text-align: left;
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table th {
  font-size: 0.76rem;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

.data-table th.num, .data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }

.clickable-row { cursor: pointer; }
.clickable-row:hover { background: var(--surface-alt); }

@container (max-width: 620px) {
  .reports-table .col-align,
  .reports-table .col-raw { display: none; }
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.16rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

.pill-pass { background: var(--pass-bg); color: var(--pass); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-fail { background: var(--fail-bg); color: var(--fail); }
.pill-neutral { background: var(--surface-alt); color: var(--muted); }

.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--primary);
  font: inherit;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  cursor: pointer;
  text-decoration: underline;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.9rem;
  gap: 0.75rem;
}

.pagination-controls { display: flex; gap: 0.5rem; }

.modal-dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(92vw, 760px);
  max-height: 88vh;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.modal-lg { width: min(94vw, 1080px); }

.modal-dialog[open] {
  display: flex;
  flex-direction: column;
}

.modal-dialog::backdrop {
  background: rgba(15, 23, 42, 0.65);
  overflow: hidden;
  overscroll-behavior: contain;
}

.dialog-panel {
  display: flex;
  flex-direction: column;
  max-height: 88vh;
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.dialog-header h2 { margin: 0; font-size: 1.1rem; }

.dialog-body {
  padding: 1.15rem 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  padding: 0.85rem;
  background: var(--surface-alt);
  border-radius: 8px;
}

.meta-item span { display: block; font-size: 0.74rem; color: var(--muted); text-transform: uppercase; }
.meta-item strong { font-size: 0.9rem; word-break: break-word; }

.xml-details summary {
  cursor: pointer;
  font-weight: 600;
  padding: 0.5rem 0;
}

.xml-actions {
  display: flex;
  gap: 0.5rem;
  margin: 0.5rem 0;
}

.xml-pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem;
  overflow: auto;
  max-height: 360px;
  font-size: 0.78rem;
  line-height: 1.45;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.empty-state {
  padding: 1.5rem;
  text-align: center;
  color: var(--muted);
}

