:root {
  color-scheme: light;
  --bg: #f5f5f5;
  --panel: #ffffff;
  --panel-alt: #fafafa;
  --border: #cccccc;
  --ink: #333333;
  --muted: #666666;
  --accent: #005a9c;
  --accent-strong: #003d6b;
  --ok: #2f7a42;
  --warn: #c47a00;
  --deny: #cc0000;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

/* ── Header ─────────────────────────────────────────────── */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto minmax(260px, 340px) auto;
  gap: 1.5rem;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: #fff;
  border-bottom: 3px solid var(--accent);
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

.brand {
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--accent);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.admin-key-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.key-input-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.key-input-row input {
  flex: 1;
  min-width: 0;
}

/* ── Auth lock icon ──────────────────────────────────────── */

.auth-lock {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  cursor: default;
  color: var(--muted);
  opacity: 0.55;
  transition: color 0.2s, opacity 0.2s;
}

.auth-lock.ok   { color: var(--ok);   opacity: 1; }
.auth-lock.fail { color: var(--deny); opacity: 1; }

/* Swap locked/unlocked SVG based on state */
.auth-lock .lock-open            { display: none; }
.auth-lock.fail .lock-closed     { display: none; }
.auth-lock.fail .lock-open       { display: inline-flex; }

/* CSS tooltip via data-tooltip attribute */
.auth-lock::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  background: #222;
  color: #fff;
  font-size: 0.75rem;
  padding: 0.25rem 0.55rem;
  border-radius: 3px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 100;
}

.auth-lock:hover::after {
  opacity: 1;
}

/* ── Form elements ───────────────────────────────────────── */

input,
select,
textarea {
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.4rem 0.6rem;
  background: #fff;
  color: var(--ink);
  width: 100%;
  font-size: 0.9rem;
}

textarea {
  min-height: 110px;
  resize: vertical;
  font-family: monospace;
  font-size: 0.85rem;
}

button {
  border: 1px solid var(--accent);
  border-radius: 3px;
  background: var(--accent);
  color: #fff;
  padding: 0.4rem 1rem;
  font-weight: bold;
  cursor: pointer;
  font-size: 0.9rem;
}

button.secondary {
  background: #fff;
  color: var(--accent);
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ── Health chip ─────────────────────────────────────────── */

.health-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 3px;
  padding: 0.35rem 0.7rem;
  font-size: 0.86rem;
}

.dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: #999;
  display: inline-block;
}

.dot.ok { background: var(--ok); }
.dot.bad { background: var(--deny); }

/* ── Auth error banner ───────────────────────────────────── */

.admin-auth-error {
  margin: 0;
  padding: 0.6rem 1.25rem;
  background: #fff0f0;
  color: var(--deny);
  border-bottom: 1px solid #ffbbbb;
  font-weight: bold;
}

/* ── Layout ──────────────────────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  min-height: calc(100vh - 60px);
}

.sidebar {
  border-right: 1px solid var(--border);
  background: #fff;
  padding: 1rem 0.6rem;
}

#side-nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

#side-nav a,
#side-nav a:link,
#side-nav a:visited {
  display: block;
  text-decoration: none;
  color: var(--ink);
  padding: 0.45rem 0.65rem;
  border-radius: 3px;
  font-weight: 500;
  font-size: 0.9rem;
}

#side-nav a:hover,
#side-nav a:visited:hover {
  background: #eef4ff;
  color: var(--accent);
}

#side-nav a.active,
#side-nav a.active:link,
#side-nav a.active:visited {
  background: var(--accent);
  color: #fff;
}

.content {
  padding: 1.25rem 1.5rem;
  max-width: 1100px;
}

/* ── View headings ───────────────────────────────────────── */

.view > h1 {
  margin-top: 0;
  margin-bottom: 0.3rem;
  border-bottom: 2px solid var(--accent);
  padding-bottom: 0.3rem;
  color: var(--accent);
}

.concept {
  margin-top: 0;
  color: var(--muted);
  font-style: italic;
}

/* ── Panels ──────────────────────────────────────────────── */

.panel {
  margin-top: 1.1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1rem 1.1rem;
}

.panel > h2 {
  margin-top: 0;
  font-size: 1rem;
  color: var(--accent-strong);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.35rem;
  margin-bottom: 0.75rem;
}

/* ── Pre / architecture ──────────────────────────────────── */

.architecture,
pre {
  background: #f8f8f8;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.75rem;
  overflow-x: auto;
  white-space: pre-wrap;
  font-family: monospace;
  font-size: 0.84rem;
}

.architecture {
  white-space: pre;
}

/* ── Actions row ─────────────────────────────────────────── */

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

/* ── Field grid ──────────────────────────────────────────── */

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

/* ── Tables ──────────────────────────────────────────────── */

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
}

th,
td {
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  padding: 0.45rem 0.5rem;
  font-size: 0.9rem;
}

th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: #f5f5f5;
}

/* ── Status banner ───────────────────────────────────────── */

.status-banner {
  margin-top: 0.7rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.5rem 0.7rem;
  background: var(--panel-alt);
  font-weight: bold;
  font-size: 0.9rem;
}

.status-banner.valid  { border-color: #99ccaa; color: var(--ok); background: #f0fff4; }
.status-banner.invalid { border-color: #ffaaaa; color: var(--deny); background: #fff0f0; }
.status-banner.warn   { border-color: #ffcc88; color: var(--warn); background: #fffbf0; }

/* ── Claims ──────────────────────────────────────────────── */

.claims { display: grid; gap: 0.5rem; }

.claim-row {
  border: 1px solid var(--border);
  border-radius: 3px;
  background: #fafafa;
  padding: 0.5rem 0.7rem;
}

.claim-key   { font-family: monospace; font-weight: bold; font-size: 0.88rem; }
.claim-value { font-family: monospace; font-size: 0.84rem; margin-top: 0.15rem; }
.claim-note  { color: var(--muted); font-size: 0.8rem; font-style: italic; }

/* ── Overview narrative lists ───────────────────────────── */

.narrative-list,
.tour-steps {
  margin: 0;
  padding-left: 1.4rem;
  line-height: 1.7;
}

.tour-steps li { margin-bottom: 0.4rem; }

/* ── Pill row (overview) ─────────────────────────────────── */

.pill-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.dependency-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border-radius: 3px;
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--border);
  font-size: 0.84rem;
  font-weight: bold;
}

.dependency-pill.ok  { color: var(--ok); border-color: #99ccaa; background: #f0fff4; }
.dependency-pill.bad { color: var(--deny); border-color: #ffaaaa; background: #fff0f0; }

/* ── Timeline ────────────────────────────────────────────── */

.timeline { margin: 0.8rem 0 0; padding-left: 1.4rem; }
.timeline li { margin-bottom: 0.45rem; font-size: 0.9rem; }

/* ── Failure tests ───────────────────────────────────────── */

.failure-tests { display: flex; flex-direction: column; gap: 1rem; }
.failure-header-actions { display: flex; gap: 0.45rem; flex-wrap: wrap; }

.failure-category-selector { display: flex; flex-wrap: wrap; gap: 0.45rem; }

.failure-category-pill {
  border-radius: 3px;
  border: 1px solid var(--border);
  background: #fff;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  font-size: 0.88rem;
}

.failure-category-pill.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.failure-test-list { display: grid; gap: 0.65rem; }

.failure-test-card {
  border: 1px solid var(--border);
  border-radius: 3px;
  background: #fff;
  padding: 0.75rem;
}

.failure-test-card header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.failure-test-card h3 {
  margin: 0;
  flex: 1;
  font-size: 0.95rem;
}

.failure-priority-badge {
  font-size: 0.72rem;
  border-radius: 3px;
  padding: 0.12rem 0.45rem;
  color: #fff;
  font-weight: bold;
}

.failure-priority-badge.CRITICAL { background: #cc0000; }
.failure-priority-badge.HIGH     { background: #c04000; }
.failure-priority-badge.MEDIUM   { background: #b07000; }
.failure-priority-badge.LOW      { background: #3d7030; }

.failure-status-pill {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.18rem 0.55rem;
  font-size: 0.8rem;
  font-weight: bold;
}

.failure-status-pill.PASS                      { color: var(--ok); }
.failure-status-pill.FAIL,
.failure-status-pill.ERROR                     { color: var(--deny); }

/* ── Responsive ──────────────────────────────────────────── */

@media (max-width: 900px) {
  .app-header {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  #side-nav {
    flex-direction: row;
    overflow-x: auto;
  }
}
