:root {
  --forest: #060E18;
  --forest-light: #16283D;
  --sage: #526E76;
  --cream: #F4EFE3;
  --cream-dark: #E4DCCB;
  --ivory: #FAF7F0;
  --gold: #C1913F;
  --gold-light: #E8C87E;
  --ink: #101A26;
  --ink-muted: #425C6A;
  --line: rgba(6, 14, 24, 0.12);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --sidebar-w: 260px;
}

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

html { font-size: 16px; }

body {
  font-family: 'Geist', 'Segoe UI', sans-serif;
  font-weight: 400;
  color: var(--ink);
  background: var(--ivory);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .serif {
  font-family: 'Newsreader', Georgia, serif;
  font-weight: 500;
  color: var(--forest);
}

a { color: inherit; }

/* ─── Auth page ─── */
.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.auth-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 3rem;
}

.auth-panel--brand {
  background: var(--forest);
  color: var(--cream);
  position: relative;
  overflow: hidden;
}

.auth-panel--brand::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23ffffff'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/svg%3E");
}

.auth-brand {
  position: relative;
  z-index: 1;
}

.auth-brand__logo {
  width: 48px;
  height: 48px;
  margin-bottom: 2rem;
}

.auth-brand h1 {
  font-size: 2.75rem;
  color: var(--cream);
  line-height: 1.1;
  margin-bottom: 1rem;
}

.auth-brand h1 em {
  font-style: italic;
  color: var(--gold-light);
}

.auth-brand p {
  font-weight: 300;
  opacity: 0.7;
  max-width: 340px;
  line-height: 1.75;
}

.auth-form-wrap {
  max-width: 400px;
  margin: 0 auto;
  width: 100%;
}

.auth-form-wrap h2 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.auth-form-wrap > p {
  color: var(--ink-muted);
  font-weight: 300;
  margin-bottom: 2.5rem;
}

.auth-back {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--sage);
  margin-bottom: 2rem;
  transition: color 0.3s;
}

.auth-back:hover { color: var(--forest); }

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sage);
  margin-bottom: 0.5rem;
}

.form-input {
  width: 100%;
  padding: 0.85rem 1rem;
  font-family: inherit;
  font-size: 0.95rem;
  border: 1px solid var(--line);
  background: var(--ivory);
  color: var(--ink);
  transition: border-color 0.3s, box-shadow 0.3s;
}

.form-input:focus {
  outline: none;
  border-color: var(--forest);
  box-shadow: 0 0 0 3px rgba(6, 14, 24, 0.08);
}

.form-input::placeholder { color: var(--ink-muted); opacity: 0.5; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  border: none;
  cursor: pointer;
  padding: 0.85rem 1.5rem;
  transition: background 0.3s, transform 0.3s var(--ease), border-color 0.3s;
}

.btn--primary {
  background: var(--forest);
  color: var(--cream);
  width: 100%;
}

.btn--primary:hover {
  background: var(--forest-light);
  transform: translateY(-1px);
}

.btn--ghost {
  background: transparent;
  color: var(--forest);
  border: 1px solid var(--line);
}

.btn--ghost:hover { border-color: var(--forest); }

.btn--sm { padding: 0.55rem 1rem; font-size: 0.68rem; }

.btn--gold {
  background: var(--gold);
  color: var(--forest);
}

.btn--gold:hover { background: var(--gold-light); color: var(--forest); }

.auth-note {
  margin-top: 1.5rem;
  font-size: 0.8rem;
  color: var(--ink-muted);
  text-align: center;
}

/* ─── App shell ─── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--forest);
  color: var(--cream);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 50;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  text-decoration: none;
}

.sidebar__brand svg { width: 36px; height: 36px; flex-shrink: 0; }

.sidebar__brand-name {
  font-family: 'Newsreader', Georgia, serif;
  font-size: 1.15rem;
  line-height: 1.1;
}

.sidebar__brand-name span {
  display: block;
  font-family: 'Geist', 'Segoe UI', sans-serif;
  font-size: 0.55rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  opacity: 0.5;
  margin-top: 0.15rem;
}

.sidebar__nav {
  flex: 1;
  padding: 1.25rem 0;
  list-style: none;
}

.sidebar__nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-decoration: none;
  color: rgba(244, 239, 227, 0.65);
  border-left: 2px solid transparent;
  transition: color 0.3s, background 0.3s, border-color 0.3s;
}

.sidebar__nav a:hover {
  color: var(--cream);
  background: rgba(255, 255, 255, 0.04);
}

.sidebar__nav a.active {
  color: var(--cream);
  background: rgba(255, 255, 255, 0.06);
  border-left-color: var(--gold-light);
}

.sidebar__nav svg { width: 18px; height: 18px; opacity: 0.7; }

.sidebar__footer {
  padding: 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar__user {
  font-size: 0.75rem;
  opacity: 0.5;
  margin-bottom: 0.75rem;
}

.sidebar__logout {
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold-light);
  text-decoration: none;
  opacity: 0.8;
  transition: opacity 0.3s;
}

.sidebar__logout:hover { opacity: 1; }

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
}

.main__header {
  padding: 2rem 2.5rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: var(--ivory);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}

.main__header h1 {
  font-size: 2rem;
  font-weight: 400;
  line-height: 1.1;
}

.main__header p {
  color: var(--ink-muted);
  font-weight: 300;
  font-size: 0.9rem;
  margin-top: 0.35rem;
}

.main__body {
  padding: 2rem 2.5rem;
}

/* ─── Cards & grid ─── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  margin-bottom: 2.5rem;
}

.stat-card {
  background: var(--ivory);
  padding: 1.75rem;
}

.stat-card__value {
  font-family: 'Newsreader', Georgia, serif;
  font-size: 2.5rem;
  color: var(--forest);
  line-height: 1;
}

.stat-card__label {
  font-size: 0.75rem;
  color: var(--ink-muted);
  margin-top: 0.35rem;
}

.card {
  background: var(--ivory);
  border: 1px solid var(--line);
  padding: 1.5rem;
}

.card__title {
  font-family: 'Newsreader', Georgia, serif;
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

/* ─── Tables & lists ─── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th {
  text-align: left;
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sage);
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
}

.data-table td {
  padding: 1rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.data-table tr:hover td { background: var(--cream); }

.data-table .actions {
  display: flex;
  gap: 0.5rem;
}

.link-btn {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--sage);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.3s;
}

.link-btn:hover { color: var(--forest); }

.link-btn--primary { color: var(--forest); font-weight: 500; }

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

.empty-state p { margin-bottom: 1.25rem; font-weight: 300; }

/* ─── Wizard steps ─── */
.wizard-steps {
  display: flex;
  gap: 0;
  margin-bottom: 2rem;
  border: 1px solid var(--line);
  background: var(--cream);
}

.wizard-step {
  flex: 1;
  padding: 1rem 1.25rem;
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  text-align: center;
  border-right: 1px solid var(--line);
  position: relative;
}

.wizard-step:last-child { border-right: none; }

.wizard-step.active {
  background: var(--forest);
  color: var(--cream);
}

.wizard-step.done {
  background: var(--ivory);
  color: var(--forest);
}

.wizard-panel { display: none; }
.wizard-panel.active { display: block; }

.select-card {
  display: block;
  padding: 1.25rem;
  border: 1px solid var(--line);
  background: var(--ivory);
  cursor: pointer;
  transition: border-color 0.3s, background 0.3s;
  margin-bottom: 0.75rem;
}

.select-card:hover { border-color: var(--sage); background: var(--cream); }

.select-card.selected {
  border-color: var(--forest);
  background: var(--cream);
  box-shadow: inset 3px 0 0 var(--forest);
}

.select-card__title {
  font-family: 'Newsreader', Georgia, serif;
  font-size: 1.15rem;
  margin-bottom: 0.25rem;
}

.select-card__meta {
  font-size: 0.8rem;
  color: var(--ink-muted);
}

/* ─── Diagnostic editor ─── */
.editor-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  min-height: calc(100vh - 180px);
}

.editor-col {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ai-panel {
  background: var(--forest);
  color: var(--cream);
  padding: 1.5rem;
  flex-shrink: 0;
}

.ai-panel__label {
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold-light);
  margin-bottom: 0.75rem;
}

.ai-panel textarea {
  width: 100%;
  min-height: 120px;
  padding: 1rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 300;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--cream);
  resize: vertical;
  margin-bottom: 1rem;
}

.ai-panel textarea::placeholder { color: rgba(244, 239, 227, 0.4); }

.ai-panel textarea:focus {
  outline: none;
  border-color: var(--gold-light);
}

.ai-hints {
  font-size: 0.75rem;
  opacity: 0.55;
  line-height: 1.6;
}

.ai-dictate-status {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.78rem;
  color: var(--gold-light);
  margin-bottom: 0.75rem;
}

.ai-dictate-status[hidden] { display: none; }

.recording-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e8705f;
  flex-shrink: 0;
  animation: recordPulse 1.2s ease-in-out infinite;
}

@keyframes recordPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.85); }
}

#aiDictateBtn {
  gap: 0.6rem;
}

.ai-panel__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.ai-apply-btn {
  color: var(--cream) !important;
  border-color: rgba(244, 239, 227, 0.35) !important;
}

.ai-apply-btn:hover {
  border-color: var(--cream) !important;
  background: rgba(255, 255, 255, 0.08) !important;
}

#aiDictateBtn.is-recording {
  background: #c45c4a;
  color: var(--cream);
}

#aiDictateBtn.is-recording:hover {
  background: #b54e3e;
}

#aiDictateBtn.is-processing {
  opacity: 0.65;
  pointer-events: none;
}

.ai-panel textarea.is-recording {
  border-color: rgba(232, 112, 95, 0.45);
}

.template-form {
  flex: 1;
  overflow-y: auto;
  border: 1px solid var(--line);
  background: var(--ivory);
  padding: 1.5rem;
}

.template-section {
  margin-bottom: 1.75rem;
  padding-bottom: 1.75rem;
  border-bottom: 1px solid var(--line);
}

.template-section:last-child { border-bottom: none; margin-bottom: 0; }

.template-section h4 {
  font-family: 'Newsreader', Georgia, serif;
  font-size: 1.1rem;
  margin-bottom: 1rem;
  color: var(--forest);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.report-preview {
  flex: 1;
  overflow-y: auto;
  border: 1px solid var(--line);
  background: white;
  padding: 2rem;
  font-size: 0.875rem;
  line-height: 1.7;
}

.report-preview__header {
  text-align: center;
  padding-bottom: 1.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--forest);
}

.report-preview__header h2 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.report-preview__header p {
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.report-field {
  margin-bottom: 0.75rem;
}

.report-field__label {
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sage);
}

.report-field__value {
  font-weight: 500;
  color: var(--ink);
}

.report-field__value.empty {
  color: var(--cream-dark);
  font-style: italic;
  font-weight: 300;
}

.badge {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.3rem 0.6rem;
}

.badge--draft { background: var(--cream-dark); color: var(--ink-muted); }
.badge--progress { background: rgba(193, 145, 63, 0.18); color: var(--forest); }
.badge--done { background: rgba(6, 14, 24, 0.1); color: var(--forest); }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.toolbar__actions { display: flex; gap: 0.75rem; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 26, 38, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1.5rem;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--ivory);
  border: 1px solid var(--line);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 2rem;
}

.modal h3 {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
}

.modal__actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.modal__actions .btn--primary { width: auto; flex: 1; }

.relation-chain {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--ink-muted);
  margin-bottom: 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--cream);
  border: 1px solid var(--line);
}

.relation-chain strong { color: var(--forest); font-weight: 500; }

.relation-chain svg { width: 14px; height: 14px; opacity: 0.4; }

.view { display: none; }
.view.active { display: block; }

@media (max-width: 900px) {
  .auth-page { grid-template-columns: 1fr; }
  .auth-panel--brand { display: none; }
  .sidebar { transform: translateX(-100%); }
  .main { margin-left: 0; }
  .editor-layout, .grid-2, .stats-grid, .form-row { grid-template-columns: 1fr; }
}
