/* ─── DESIGN TOKENS ────────────────────────────────────────────────── */
:root {
  /* Editorial color scheme — navy/parchment/accent */
  --bg: #faf8f3;
  --bg-soft: #f4f1e8;
  --bg-card: #ffffff;
  --ink: #1a1f2e;
  --ink-soft: #4a5165;
  --ink-muted: #8b91a3;
  --line: #e5e1d3;
  --line-soft: #ece8da;

  --navy: #1a2b47;
  --navy-deep: #0f1829;
  --gold: #b8924a;
  --gold-soft: #d4b078;
  --sage: #7a8b6b;
  --rust: #b85c3f;
  --plum: #6b4a6b;

  --status-open: #b85c3f;
  --status-review: #c8a048;
  --status-answered: #7a8b6b;
  --status-closed: #8b91a3;

  --priority-critical: #a83232;
  --priority-high: #b85c3f;
  --priority-medium: #c8a048;
  --priority-low: #7a8b6b;

  --risk-low: #7a8b6b;
  --risk-medium: #c8a048;
  --risk-high: #b85c3f;

  --phase-notstarted: #c9c4b2;
  --phase-inprogress: #b8924a;
  --phase-completed: #7a8b6b;
  --phase-blocked: #a83232;
  --phase-onhold: #8b91a3;

  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(26, 31, 46, 0.06);
  --shadow: 0 2px 8px rgba(26, 31, 46, 0.08);
  --shadow-lg: 0 8px 24px rgba(26, 31, 46, 0.12);

  --font-serif: 'Libre Caslon Text', 'Playfair Display', Georgia, serif;
  --font-display: 'Fraunces', 'Playfair Display', Georgia, serif;
  --font-sans: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'IBM Plex Mono', monospace;
}

/* ─── RESET ─────────────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  min-height: 100vh;
  font-feature-settings: "ss01" 1, "cv11" 1;
}
a { color: var(--navy); text-decoration: none; }
a:hover { color: var(--gold); }
h1, h2, h3, h4 { font-family: var(--font-display); color: var(--ink); font-weight: 500; letter-spacing: -0.02em; line-height: 1.2; }
h1 { font-size: 2.2rem; margin-bottom: 0.5rem; }
h2 { font-size: 1.5rem; margin-bottom: 0.75rem; }
h3 { font-size: 1.2rem; margin-bottom: 0.5rem; }
h4 { font-size: 1rem; margin-bottom: 0.4rem; font-weight: 600; }
p { margin-bottom: 0.75rem; }
small { color: var(--ink-muted); }
code, pre { font-family: var(--font-mono); font-size: 0.88em; }
pre { background: var(--bg-soft); padding: 12px 16px; border-radius: var(--radius); overflow-x: auto; border: 1px solid var(--line); }
code { background: var(--bg-soft); padding: 1px 5px; border-radius: 3px; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-soft); }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-muted); }

/* ─── LAYOUT ───────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--navy-deep);
  color: #d4cfb8;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 0.5rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.sidebar-brand-mark {
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: var(--gold-soft);
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.sidebar-brand-sub {
  font-size: 0.72rem;
  color: #8a8670;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-top: 4px;
}

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav .nav-group {
  font-size: 0.7rem;
  color: #6b6850;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  padding: 8px 12px 4px;
  margin-top: 0.5rem;
}
.sidebar nav a {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: #b8b4a0;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.15s;
}
.sidebar nav a:hover { background: rgba(184, 146, 74, 0.1); color: var(--gold-soft); }
.sidebar nav a.active { background: rgba(184, 146, 74, 0.15); color: #faf8f3; border-left: 2px solid var(--gold-soft); padding-left: 10px; }
.sidebar nav a .icon { width: 16px; display: inline-block; font-weight: 600; color: #6b6850; }
.sidebar nav a.active .icon, .sidebar nav a:hover .icon { color: var(--gold-soft); }

.sidebar-user {
  margin-top: auto;
  padding: 12px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--gold); color: var(--navy-deep);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 0.85rem;
  flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 0.8rem; color: #faf8f3; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-role { font-size: 0.68rem; color: var(--gold-soft); text-transform: uppercase; letter-spacing: 0.08em; }

.main { padding: 2rem 2.5rem; max-width: 100%; overflow-x: hidden; }

.page-header {
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem;
}
.page-header .eyebrow {
  font-size: 0.72rem;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  margin-bottom: 0.35rem;
  font-weight: 500;
}
.page-header h1 { margin-bottom: 0.25rem; }
.page-header .subtitle { color: var(--ink-soft); font-size: 1rem; }

/* ─── CARDS ────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm);
}
.card-title { font-family: var(--font-display); font-size: 1.1rem; margin-bottom: 0.5rem; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--navy);
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
}
.stat-card.accent-gold { border-left-color: var(--gold); }
.stat-card.accent-sage { border-left-color: var(--sage); }
.stat-card.accent-rust { border-left-color: var(--rust); }
.stat-value {
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--ink);
  line-height: 1;
  margin-bottom: 4px;
}
.stat-label {
  font-size: 0.7rem;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 500;
}

/* ─── TIMELINE / PHASES ────────────────────────────────────────────── */
.timeline {
  position: relative;
  margin: 2rem 0;
}
.timeline-track {
  position: absolute;
  left: 32px;
  top: 24px;
  bottom: 24px;
  width: 2px;
  background: var(--line);
}

.phase-node {
  position: relative;
  padding-left: 72px;
  margin-bottom: 1.5rem;
}
.phase-node::before {
  content: '';
  position: absolute;
  left: 22px;
  top: 18px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg);
  border: 3px solid var(--line);
  z-index: 1;
}
.phase-node.status-in_progress::before {
  border-color: var(--phase-inprogress);
  background: var(--phase-inprogress);
  box-shadow: 0 0 0 4px rgba(184, 146, 74, 0.15);
  animation: pulse 2s ease-in-out infinite;
}
.phase-node.status-completed::before {
  border-color: var(--phase-completed);
  background: var(--phase-completed);
}
.phase-node.status-blocked::before {
  border-color: var(--phase-blocked);
  background: var(--phase-blocked);
}
.phase-node.status-on_hold::before {
  border-color: var(--phase-onhold);
  background: var(--phase-onhold);
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(184, 146, 74, 0.15); }
  50% { box-shadow: 0 0 0 10px rgba(184, 146, 74, 0.05); }
}

.phase-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.phase-card:hover { border-color: var(--gold-soft); box-shadow: var(--shadow); }
.phase-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 0.5rem;
}
.phase-number {
  font-family: var(--font-display);
  font-size: 0.75rem;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-weight: 600;
}
.phase-title {
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--ink);
  margin: 0;
  flex: 1;
}
.phase-meta {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  font-size: 0.8rem;
  color: var(--ink-muted);
  margin-top: 0.5rem;
}
.phase-desc { color: var(--ink-soft); margin-top: 0.5rem; font-size: 0.92rem; }

.progress-bar {
  height: 6px;
  background: var(--line-soft);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 0.75rem;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold) 0%, var(--gold-soft) 100%);
  transition: width 0.4s ease;
}

/* ─── BADGES ──────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 12px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.status-open, .badge.status-open { background: rgba(184, 92, 63, 0.12); color: var(--status-open); }
.status-in_review, .badge.status-in_review { background: rgba(200, 160, 72, 0.14); color: var(--status-review); }
.status-answered, .badge.status-answered { background: rgba(122, 139, 107, 0.14); color: var(--status-answered); }
.status-closed, .badge.status-closed { background: rgba(139, 145, 163, 0.14); color: var(--status-closed); }
.status-not_started { background: rgba(201, 196, 178, 0.25); color: #6b6850; }
.status-in_progress { background: rgba(184, 146, 74, 0.14); color: var(--gold); }
.status-completed { background: rgba(122, 139, 107, 0.14); color: var(--sage); }
.status-blocked { background: rgba(168, 50, 50, 0.14); color: var(--priority-critical); }
.status-on_hold { background: rgba(139, 145, 163, 0.15); color: var(--ink-soft); }

.priority-critical { background: rgba(168, 50, 50, 0.14); color: var(--priority-critical); }
.priority-high { background: rgba(184, 92, 63, 0.12); color: var(--priority-high); }
.priority-medium { background: rgba(200, 160, 72, 0.14); color: var(--priority-medium); }
.priority-low { background: rgba(122, 139, 107, 0.14); color: var(--priority-low); }

.risk-low { background: rgba(122, 139, 107, 0.14); color: var(--risk-low); }
.risk-medium { background: rgba(200, 160, 72, 0.14); color: var(--risk-medium); }
.risk-high { background: rgba(184, 92, 63, 0.14); color: var(--risk-high); }

.role-admin { background: var(--navy); color: #faf8f3; }
.role-architect { background: var(--plum); color: #faf8f3; }
.role-engineer { background: var(--sage); color: #faf8f3; }
.role-client_lead { background: var(--gold); color: var(--navy-deep); }
.role-business { background: var(--rust); color: #faf8f3; }
.role-auditor { background: var(--navy-deep); color: var(--gold-soft); border: 1px solid var(--gold-soft); }
.role-viewer { background: var(--line); color: var(--ink-soft); }

/* ─── FORMS & BUTTONS ─────────────────────────────────────────────── */
input, textarea, select {
  font-family: var(--font-sans);
  font-size: 0.92rem;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--ink);
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(184, 146, 74, 0.12);
}
textarea { resize: vertical; min-height: 100px; font-family: var(--font-sans); }
label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 4px;
}
.form-group { margin-bottom: 1rem; }
.form-row { display: grid; gap: 1rem; }
.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }

button, .btn {
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 500;
  padding: 8px 18px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-primary { background: var(--navy); color: #faf8f3; }
.btn-primary:hover { background: var(--navy-deep); color: #faf8f3; }
.btn-accent { background: var(--gold); color: var(--navy-deep); }
.btn-accent:hover { background: var(--gold-soft); }
.btn-ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--bg-soft); color: var(--ink); }
.btn-sm { font-size: 0.78rem; padding: 5px 12px; }
.btn-danger { background: var(--priority-critical); color: #faf8f3; }

/* ─── TABLES ──────────────────────────────────────────────────────── */
.table {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
}
.table th, .table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.table th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-muted);
  font-weight: 600;
  background: var(--bg-soft);
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg-soft); }

/* ─── QUESTION LIST ───────────────────────────────────────────────── */
.question-item {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.question-item:hover { border-left-color: var(--gold); box-shadow: var(--shadow); }
.question-item.priority-critical { border-left-color: var(--priority-critical); }
.question-item.priority-high { border-left-color: var(--priority-high); }
.question-item.priority-medium { border-left-color: var(--priority-medium); }
.question-item.priority-low { border-left-color: var(--priority-low); }
.question-title { font-family: var(--font-display); font-size: 1.05rem; font-weight: 500; margin-bottom: 4px; color: var(--ink); }
.question-meta { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; font-size: 0.78rem; color: var(--ink-muted); }

/* ─── FILTER BAR ──────────────────────────────────────────────────── */
.filter-bar {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr auto;
  gap: 0.75rem;
  align-items: center;
}

/* ─── ANSWER BOX ──────────────────────────────────────────────────── */
.answer-item {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  position: relative;
}
.answer-item.official {
  border-color: var(--sage);
  background: rgba(122, 139, 107, 0.04);
}
.answer-item.official::before {
  content: 'OFFICIAL';
  position: absolute;
  top: -9px;
  right: 12px;
  background: var(--sage);
  color: white;
  font-size: 0.65rem;
  padding: 2px 10px;
  border-radius: 10px;
  letter-spacing: 0.1em;
  font-weight: 600;
}
.answer-author {
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin-bottom: 6px;
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ─── MARKDOWN CONTENT ────────────────────────────────────────────── */
.prose {
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.7;
}
.prose h1 { font-size: 1.8rem; margin-top: 2rem; margin-bottom: 0.8rem; }
.prose h2 { font-size: 1.4rem; margin-top: 1.5rem; margin-bottom: 0.6rem; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.prose h3 { font-size: 1.15rem; margin-top: 1.2rem; margin-bottom: 0.5rem; }
.prose p, .prose ul, .prose ol { margin-bottom: 0.9rem; }
.prose ul, .prose ol { padding-left: 1.5rem; }
.prose li { margin-bottom: 0.3rem; }
.prose table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
.prose table th, .prose table td { padding: 8px 12px; border: 1px solid var(--line); text-align: left; }
.prose table th { background: var(--bg-soft); font-weight: 600; }
.prose blockquote { border-left: 3px solid var(--gold); padding: 4px 0 4px 14px; color: var(--ink-soft); font-style: italic; margin: 0.8rem 0; }

/* ─── LOGIN ───────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy-deep) 0%, var(--navy) 100%);
  padding: 2rem;
}
.login-box {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}
.login-brand {
  text-align: center;
  margin-bottom: 1.5rem;
}
.login-brand-mark {
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--navy);
  letter-spacing: -0.02em;
}
.login-brand-sub {
  font-size: 0.7rem;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin-top: 4px;
}
.login-box h2 { text-align: center; margin-bottom: 1.5rem; font-size: 1.3rem; }

/* ─── UTILITY ─────────────────────────────────────────────────────── */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-gap-sm { gap: 0.5rem; }
.flex-gap { gap: 1rem; }
.flex-col { flex-direction: column; }
.text-center { text-align: center; }
.text-muted { color: var(--ink-muted); }
.text-soft { color: var(--ink-soft); }
.text-small { font-size: 0.82rem; }
.text-tiny { font-size: 0.72rem; }
.mono { font-family: var(--font-mono); }
.mb-0 { margin-bottom: 0; }
.mb-sm { margin-bottom: 0.5rem; }
.mb-md { margin-bottom: 1rem; }
.mb-lg { margin-bottom: 1.5rem; }
.mt-md { margin-top: 1rem; }
.mt-lg { margin-top: 1.5rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.hidden { display: none; }
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 1rem; }
.alert-error { background: rgba(168, 50, 50, 0.08); color: var(--priority-critical); border: 1px solid rgba(168, 50, 50, 0.3); }
.alert-success { background: rgba(122, 139, 107, 0.08); color: var(--sage); border: 1px solid rgba(122, 139, 107, 0.3); }

.empty-state { padding: 3rem 1rem; text-align: center; color: var(--ink-muted); }
.empty-state-icon { font-size: 2.5rem; color: var(--line); margin-bottom: 0.5rem; }

/* HTMX transitions */
.htmx-indicator { opacity: 0; transition: opacity 0.2s; }
.htmx-request .htmx-indicator { opacity: 1; }
.htmx-swapping { opacity: 0; transition: opacity 0.15s; }
