/* GRC Execution Tracker — dashboard styles.
 *
 * Design language is ported from the compliance docs site
 * (src/grc_xl_framework/docs_site/templates/base.html): Inter, the pink brand
 * accent, the surface/border/ink token system, restrained badges, card and table
 * components. Dashboard-specific additions (metric cards, run-status colours,
 * filter bar, connect overlay) extend the same tokens rather than introducing a
 * second visual language. */

/* ─── Design tokens ───────────────────────────────────────── */
:root {
  /* Brand */
  --pink:        #e8185c;
  --pink-hover:  #c41350;
  --pink-subtle: #fce8ef;

  /* Ink */
  --ink:   #111111;
  --ink-2: #374151;
  --ink-3: #6b7280;
  --ink-4: #9ca3af;

  /* Surfaces */
  --bg:        #ffffff;
  --surface-2: #f9fafb;
  --surface-3: #f3f4f6;
  --border:    #e5e7eb;
  --border-2:  #d1d5db;

  /* Run / finding status — muted to match the restrained palette */
  --ok:        #15803d; --ok-bg:   #f0fdf4; --ok-border:   #bbf7d0;
  --fail:      #b91c1c; --fail-bg: #fef2f2; --fail-border: #fecaca;
  --warn:      #b45309; --warn-bg: #fffbeb; --warn-border: #fde68a;

  /* Shape */
  --r-sm:   4px;
  --r:      8px;
  --r-lg:   12px;
  --r-pill: 999px;

  /* Type */
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;

  /* Layout */
  --sidebar-w:   264px;
  --content-pad: 3rem;
  --content-max: 70rem;
}

/* ─── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  min-height: 100vh;
}

/* ─── Sidebar ─────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  flex-shrink: 0;
  padding-bottom: 3rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 1rem 1rem 0.9rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
}
.sidebar-brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex;
  width: 22px;
  height: 22px;
  background: var(--pink);
  border-radius: var(--r-sm);
  overflow: hidden;
  flex-shrink: 0;
}
.brand-mark svg { width: 100%; height: 100%; display: block; fill: #fff; }
.brand-text {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.nav-tree { padding: 0.5rem 0; }
.nav-section { padding: 0.75rem 0 0.5rem; }
.nav-section + .nav-section { border-top: 1px solid var(--border); margin-top: 0.25rem; }
.nav-label {
  display: block;
  padding: 0.2rem 1rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-4);
}
a.nav-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.28rem 1rem 0.28rem 1.25rem;
  font-size: 0.84rem;
  color: var(--ink-3);
  text-decoration: none;
  border-left: 2px solid transparent;
  margin: 1px 0;
  transition: background 0.1s, color 0.1s;
}
a.nav-item:hover { background: var(--surface-3); color: var(--ink); text-decoration: none; }
a.nav-item.active {
  background: var(--pink-subtle);
  color: var(--pink);
  border-left-color: var(--pink);
  font-weight: 500;
}
a.nav-item .nav-count { font-size: 0.72rem; color: var(--ink-4); font-variant-numeric: tabular-nums; }
a.nav-item.active .nav-count { color: var(--pink); }
.nav-repo { word-break: break-word; }

/* ─── Main content ────────────────────────────────────────── */
#content {
  flex: 1;
  min-width: 0;
  padding: 1.5rem var(--content-pad) 3rem;
  max-width: calc(var(--content-max) + var(--content-pad) * 2);
}

.content-topbar {
  display: flex;
  align-items: center;
  min-height: 1.5rem;
  margin-bottom: 1.5rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--ink-3);
}
.topbar-label { color: var(--ink-4); letter-spacing: 0.01em; }

/* ─── Typography ──────────────────────────────────────────── */
h1 {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
  text-wrap: balance;
  margin-bottom: 0.5rem;
}
h2 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 2.5rem 0 0.9rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--border);
}
p { margin-bottom: 0.9rem; }
p:last-child { margin-bottom: 0; }
a { color: var(--pink); text-decoration: none; transition: color 0.1s; }
a:hover { color: var(--pink-hover); text-decoration: underline; }
code {
  font-family: var(--mono);
  font-size: 0.82em;
  background: var(--surface-3);
  padding: 0.12em 0.4em;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  border: 1px solid var(--border);
}
strong { font-weight: 600; }

.lead {
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--ink-2);
  text-wrap: pretty;
  margin: 0.55rem 0 1.5rem;
  max-width: 46rem;
}

/* ─── Breadcrumb ──────────────────────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem;
  font-size: 0.78rem;
  color: var(--ink-3);
  margin-bottom: 1.25rem;
}
.breadcrumb a { color: var(--ink-3); }
.breadcrumb a:hover { color: var(--pink); text-decoration: none; }
.breadcrumb .sep { color: var(--border-2); user-select: none; }

/* ─── Filter bar ──────────────────────────────────────────── */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
  margin: 0 0 1.75rem;
}
.filter-field { display: flex; flex-direction: column; gap: 0.3rem; }
.filter-field label {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-4);
}
.filter-field select,
.filter-field input {
  font-family: var(--font);
  font-size: 0.84rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--r);
  padding: 0.4rem 0.6rem;
  min-width: 11rem;
}
.filter-field select:focus,
.filter-field input:focus { outline: none; border-color: var(--pink); }
.filter-reset {
  font-size: 0.8rem;
  color: var(--ink-3);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.45rem 0.2rem;
}
.filter-reset:hover { color: var(--pink); text-decoration: underline; }

/* ─── Metric cards ────────────────────────────────────────── */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  gap: 0.85rem;
  margin: 0 0 2rem;
}
.metric {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-2);
  padding: 0.9rem 1.1rem;
}
.metric-value {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.metric-value.ok   { color: var(--ok); }
.metric-value.fail { color: var(--fail); }
.metric-value.warn { color: var(--warn); }
.metric-label {
  margin-top: 0.3rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-4);
}

/* ─── Tables ──────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  margin: 0.75rem 0 2rem;
}
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
thead th {
  padding: 0.6rem 1rem;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-3);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr.row-link { cursor: pointer; transition: background 0.1s; }
tbody tr.row-link:hover { background: var(--surface-2); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--ink-3); }
.mono { font-family: var(--mono); font-size: 0.82em; }
.col-id { white-space: nowrap; }

/* ─── Status + count badges ───────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 0.16em 0.6em;
  border-radius: var(--r-pill);
  border: 1px solid transparent;
  white-space: nowrap;
  line-height: 1.5;
}
.badge .dot { width: 0.45em; height: 0.45em; border-radius: 50%; background: currentColor; }
.badge.completed { color: var(--ok);   background: var(--ok-bg);   border-color: var(--ok-border); }
.badge.partial   { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-border); }
.badge.failed    { color: var(--fail); background: var(--fail-bg); border-color: var(--fail-border); }
.badge.neutral   { color: var(--ink-3); background: var(--surface-3); border-color: var(--border); }

/* Inline finding counts (pass / fail / needs-evidence) */
.counts { display: inline-flex; gap: 0.55rem; font-variant-numeric: tabular-nums; }
.count { font-size: 0.82rem; font-weight: 600; }
.count.ok   { color: var(--ok); }
.count.fail { color: var(--fail); }
.count.warn { color: var(--warn); }
.count.zero { color: var(--ink-4); font-weight: 500; }

/* ─── Detail meta block ───────────────────────────────────── */
.meta-block {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.4rem 1.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1.1rem 1.35rem;
  margin: 0 0 2rem;
  font-size: 0.84rem;
  max-width: 46rem;
}
.meta-block dt { color: var(--ink-3); font-weight: 500; }
.meta-block dd { color: var(--ink); word-break: break-word; }

/* ─── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: var(--r);
  border: 1px solid var(--border-2);
  background: var(--bg);
  color: var(--ink-2);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.btn:hover { background: var(--surface-3); color: var(--ink); text-decoration: none; }
.btn-primary { background: var(--pink); border-color: var(--pink); color: #fff; }
.btn-primary:hover { background: var(--pink-hover); border-color: var(--pink-hover); color: #fff; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 0.7rem; margin: 1.5rem 0 0.5rem; }

/* ─── States: empty / error / loading ─────────────────────── */
.state {
  border: 1px dashed var(--border-2);
  border-radius: var(--r-lg);
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--ink-3);
  font-size: 0.9rem;
  background: var(--surface-2);
}
.state strong { display: block; color: var(--ink-2); margin-bottom: 0.3rem; font-size: 0.95rem; }
.state.error { border-color: var(--fail-border); background: var(--fail-bg); color: var(--fail); }

/* ─── Connect overlay (shared-secret gate) ────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 17, 17, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 50;
}
.overlay[hidden] { display: none; }
.connect-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1.75rem;
  width: 100%;
  max-width: 26rem;
  box-shadow: 0 10px 40px rgba(17, 17, 17, 0.18);
}
.connect-card h2 { border: none; margin: 0 0 0.4rem; padding: 0; font-size: 1.15rem; }
.connect-card p { font-size: 0.85rem; color: var(--ink-3); margin-bottom: 1.25rem; }
.connect-field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 1rem; }
.connect-field label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-4);
}
.connect-field input {
  font-family: var(--font);
  font-size: 0.9rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border-2);
  border-radius: var(--r);
  color: var(--ink);
}
.connect-field input:focus { outline: none; border-color: var(--pink); }
.connect-error {
  font-size: 0.82rem;
  color: var(--fail);
  margin: -0.4rem 0 0.9rem;
}
.connect-error[hidden] { display: none; }
.connect-card .btn-primary { width: 100%; justify-content: center; }
.connect-demo {
  display: block;
  width: 100%;
  margin-top: 0.85rem;
  background: none;
  border: none;
  font-size: 0.82rem;
  color: var(--ink-3);
  cursor: pointer;
}
.connect-demo:hover { color: var(--pink); text-decoration: underline; }

/* ─── Footer ──────────────────────────────────────────────── */
.site-footer {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--ink-4);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.site-footer button {
  background: none;
  border: none;
  color: var(--ink-4);
  font-size: 0.78rem;
  cursor: pointer;
  padding: 0;
}
.site-footer button:hover { color: var(--pink); text-decoration: underline; }

/* ─── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
  body { flex-direction: column; }
  #sidebar {
    width: 100%;
    min-width: 0;
    height: auto;
    position: static;
    overflow-y: visible;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
  }
  .nav-tree { display: flex; overflow-x: auto; gap: 0.25rem; padding: 0.4rem 1rem 0.6rem; }
  .nav-section, .nav-section + .nav-section { border: none; margin: 0; padding: 0; display: contents; }
  .nav-label { display: none; }
  a.nav-item {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 0.25rem 0.65rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--r-pill);
    font-size: 0.78rem;
    margin: 0;
  }
  a.nav-item.active { background: var(--pink-subtle); color: var(--pink); border-color: var(--pink); }
  #content { padding: 1.75rem 1.5rem 4rem; }
}
@media (max-width: 560px) {
  #content { padding: 1.5rem 1.15rem 4rem; }
  .meta-block { grid-template-columns: 1fr; gap: 0.1rem 0; }
  .meta-block dt { margin-top: 0.5rem; }
  .meta-block dt:first-child { margin-top: 0; }
}

/* ─── Focus + reduced motion ──────────────────────────────── */
:focus-visible { outline: 2px solid var(--pink); outline-offset: 2px; border-radius: var(--r-sm); }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
