/* Component classes — same names the templates already use (btn, card,
   badge, table, ...), hand-restyled for a dense, border-driven look.
   No DaisyUI/Tailwind underneath. */

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s ease, border-color 0.1s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { background: var(--surface-3); }
.btn-sm { padding: 0.32rem 0.65rem; font-size: 0.75rem; }
.btn-xs { padding: 0.18rem 0.5rem; font-size: 0.7rem; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-outline { background: transparent; }
.btn-error { background: var(--error); border-color: var(--error); color: #fff; }
.btn-error:hover { filter: brightness(0.92); }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #fff; }
.btn-warning:hover { filter: brightness(0.92); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(0.92); }
.btn-circle { border-radius: var(--radius-full); padding: 0; width: 2rem; height: 2rem; }
.btn-active { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
.btn-disabled, .btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.card-body { padding: var(--sp-4); }
.card-title { font-size: 0.95rem; font-weight: 700; display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-1); }

/* ---------- table ---------- */
.table { width: 100%; font-size: 0.8125rem; border-collapse: collapse; }
.table th {
  text-align: left;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-faint);
  font-weight: 600;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border-strong);
  background: var(--surface-2);
}
.table td { padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); }
.table tbody tr.hover:hover { background: var(--surface-2); }
.table-zebra tbody tr:nth-child(even) { background: var(--surface-2); }
.table-sm th, .table-sm td { padding: 0.35rem 0.5rem; font-size: 0.78rem; }
.table-xs th, .table-xs td { padding: 0.22rem 0.4rem; font-size: 0.72rem; }

/* ---------- badge ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.05rem 0.5rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--ghost-border);
  background: var(--ghost-bg);
  color: var(--text-dim);
  line-height: 1.6;
}
.badge-sm { font-size: 0.66rem; padding: 0.02rem 0.4rem; }
.badge-xs { font-size: 0.6rem; padding: 0 0.32rem; }
.badge-lg { font-size: 0.8rem; padding: 0.15rem 0.65rem; }
.badge-ghost { background: var(--ghost-bg); border-color: var(--ghost-border); color: var(--text-dim); }
.badge-outline { background: transparent; }
.badge-primary { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
.badge-secondary { background: var(--secondary-bg); border-color: var(--secondary-border); color: var(--secondary); }
.badge-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success); }
.badge-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning); }
.badge-error { background: var(--error-bg); border-color: var(--error-border); color: var(--error); }
.badge-info { background: var(--info-bg); border-color: var(--info-border); color: var(--info); }

/* ---------- alert ---------- */
.alert {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.85rem;
}
.alert-info { background: var(--info-bg); border-color: var(--info-border); color: #075985; }
.alert-success { background: var(--success-bg); border-color: var(--success-border); color: #0d6b3d; }
.alert-warning { background: var(--warning-bg); border-color: var(--warning-border); color: #8a5a12; }
.alert-error { background: var(--error-bg); border-color: var(--error-border); color: #a23434; }

/* ---------- form controls ---------- */
.input, .select, .textarea, .file-input {
  font: inherit;
  font-size: 0.8125rem;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
}
.input:focus, .select:focus, .textarea:focus, .file-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg);
}
.input-bordered, .select-bordered, .textarea-bordered, .file-input-bordered { border-color: var(--border-strong); }
.input-sm, .select-sm { padding: 0.28rem 0.5rem; font-size: 0.76rem; }
.select-xs { padding: 0.16rem 0.4rem; font-size: 0.7rem; }
.checkbox { width: 1rem; height: 1rem; accent-color: var(--accent); }
.checkbox-sm { width: 0.9rem; height: 0.9rem; }
.checkbox-xs { width: 0.8rem; height: 0.8rem; }
.form-control { display: flex; flex-direction: column; gap: 0.2rem; }
.label-text { font-size: 0.75rem; color: var(--text-dim); font-weight: 500; }
.label-text-alt { font-size: 0.7rem; color: var(--text-faint); }
.label { display: flex; align-items: center; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: var(--sp-1); }
.tabs-bordered { border-bottom: 1px solid var(--border); }
.tabs-boxed { background: var(--surface-2); padding: 0.2rem; border-radius: var(--radius); display: inline-flex; }
.tab {
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tabs-boxed .tab { border-radius: var(--radius-sm); border-bottom: none; }
.tab-active { color: var(--accent); border-color: var(--accent); }
.tabs-boxed .tab-active { background: var(--surface); box-shadow: var(--shadow-sm); }

/* ---------- stat ---------- */
.stat { padding: var(--sp-3); }
.stats { display: flex; }
.stat-title { font-size: 0.7rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.02em; }
.stat-value { font-size: 1.5rem; font-weight: 700; margin-top: 0.15rem; }
.stat-desc { font-size: 0.72rem; color: var(--text-faint); margin-top: 0.15rem; }

/* ---------- divider ---------- */
.divider {
  display: flex;
  align-items: center;
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-faint);
  margin: var(--sp-3) 0;
}
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.divider::before { margin-right: var(--sp-2); }
.divider::after { margin-left: var(--sp-2); }

/* ---------- tooltip ---------- */
.tooltip { position: relative; }
.tooltip::before {
  content: attr(data-tip);
  position: absolute;
  bottom: 125%;
  left: 50%;
  transform: translateX(-50%);
  background: #1a2027;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 400;
  padding: 0.35rem 0.55rem;
  border-radius: var(--radius-sm);
  white-space: normal;
  width: max-content;
  max-width: 20rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease;
  z-index: 20;
}
.tooltip:hover::before { opacity: 1; }

/* ---------- join (button groups) ---------- */
.join { display: flex; }
.join-item { border-radius: 0; margin-left: -1px; }
.join-item:first-child { border-top-left-radius: var(--radius); border-bottom-left-radius: var(--radius); margin-left: 0; }
.join-item:last-child { border-top-right-radius: var(--radius); border-bottom-right-radius: var(--radius); }

/* ---------- progress ---------- */
.progress { -webkit-appearance: none; appearance: none; width: 100%; height: 0.5rem; border-radius: var(--radius-full); overflow: hidden; background: var(--surface-3); border: none; }
.progress::-webkit-progress-bar { background: var(--surface-3); border-radius: var(--radius-full); }
.progress::-webkit-progress-value { background: var(--text-dim); border-radius: var(--radius-full); }
.progress::-moz-progress-bar { background: var(--text-dim); border-radius: var(--radius-full); }
.progress-primary::-webkit-progress-value { background: var(--accent); }
.progress-primary::-moz-progress-bar { background: var(--accent); }

/* ---------- breadcrumbs ---------- */
.breadcrumbs ul { display: flex; align-items: center; gap: 0.4rem; list-style: none; margin: 0; padding: 0; flex-wrap: wrap; }
.breadcrumbs li:not(:last-child)::after { content: "/"; margin-left: 0.4rem; color: var(--text-faint); }
.breadcrumbs a { color: var(--text-dim); }
.breadcrumbs a:hover { color: var(--accent); }

/* ---------- link ---------- */
.link { color: var(--accent); }
.link-hover:hover { text-decoration: underline; }
.link-primary { color: var(--accent); font-weight: 600; }

/* ---------- loading spinner ---------- */
.loading { display: inline-block; }
.loading-spinner {
  width: 1rem; height: 1rem;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.loading-sm { width: 0.9rem; height: 0.9rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- native <dialog> modal ---------- */
.modal { border: none; padding: 0; background: transparent; }
.modal::backdrop { background: rgba(16, 22, 30, 0.65); }
.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}
.modal-backdrop button { all: unset; position: fixed; inset: 0; cursor: default; }

/* ---------- prose (KB markdown rendering) ---------- */
.prose { color: var(--text); line-height: 1.65; }
.prose h1, .prose h2, .prose h3 { margin-top: 1.4em; margin-bottom: 0.5em; }
.prose p { margin: 0.6em 0; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose a { color: var(--accent); text-decoration: underline; }
.prose code { background: var(--surface-3); }
.prose pre { background: #1a2027; color: #e6e9ee; padding: var(--sp-3); border-radius: var(--radius); overflow-x: auto; }
.prose pre code { background: none; padding: 0; color: inherit; }
.prose blockquote { border-left: 3px solid var(--border-strong); padding-left: var(--sp-3); color: var(--text-dim); margin: 0.8em 0; }
.prose table { width: 100%; }

/* ==========================================================================
   Page-level patterns — phase 2. Additive on top of the primitives above;
   used by the per-page redesigns instead of every page hand-rolling the same
   flex/grid combos with raw utility classes.
   ========================================================================== */

/* ---------- page header: title (+ breadcrumbs/subtitle) + actions ---------- */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin-bottom: var(--sp-5);
}
.page-title { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.page-subtitle { font-size: 0.82rem; color: var(--text-dim); margin-top: 0.2rem; }
.page-header-actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }

/* ---------- filter bar: pills row (+ optional field form) ---------- */
.filter-bar { display: flex; flex-direction: column; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.filter-pills { display: flex; align-items: center; gap: var(--sp-1); flex-wrap: wrap; }
.filter-pills .pill-sep { width: 1px; height: 1rem; background: var(--border-strong); margin: 0 0.15rem; }
.pill {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-size: 0.76rem; font-weight: 600;
  padding: 0.28rem 0.65rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-dim);
}
.pill:hover { background: var(--surface-2); }
.pill.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.pill.is-active.is-error { background: var(--error); border-color: var(--error); }
.pill.is-active.is-success { background: var(--success); border-color: var(--success); }
.filter-fields { display: flex; align-items: flex-end; gap: var(--sp-3); flex-wrap: wrap; }

/* ---------- panel: section heading for tab content blocks ---------- */
.panel { margin-bottom: var(--sp-4); }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-2); margin-bottom: var(--sp-2); flex-wrap: wrap; }
.panel-title { font-size: 0.85rem; font-weight: 700; display: flex; align-items: center; gap: var(--sp-2); }
.panel-meta { font-size: 0.72rem; color: var(--text-faint); }
.panel-hint { font-size: 0.76rem; color: var(--text-dim); margin: -0.1rem 0 var(--sp-2); }

/* ---------- stat card: .stat + its own container in one class ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); margin-bottom: var(--sp-4); }
@media (min-width: 768px) { .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-3);
}

/* ---------- score / severity language ---------- */
.score-value { font-family: var(--font-mono); font-weight: 700; }
.score-value-lg { font-size: 1.9rem; font-weight: 800; font-family: var(--font-mono); }
.score-value-lg .score-max { font-size: 0.9rem; font-weight: 500; color: var(--text-faint); }
/* score-* classes drive a badge/text's color by the same 0-49/50-69/70-84/85-100
   thresholds already used in Jinja branches across the app — the branch
   picks the class, this just centralizes what each one looks like. */
.score-bad  { color: var(--error); }
.score-warn { color: var(--warning); }
.score-ok   { color: var(--info); }
.score-good { color: var(--success); }

/* ---------- empty state ---------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.3rem;
  padding: var(--sp-8) var(--sp-4);
  color: var(--text-faint);
  font-size: 0.85rem;
  text-align: center;
}
.empty-state-icon { font-size: 1.8rem; opacity: 0.6; }

/* ---------- tag / chip list (dialog tags, category labels) ---------- */
.chip-list { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.chip {
  font-size: 0.72rem; font-weight: 500;
  padding: 0.1rem 0.5rem;
  border-radius: var(--radius-full);
  background: var(--surface-3);
  color: var(--text-dim);
}
