/* Meridian Design System — Base Styles */

:root {
  /* Brand */
  --primary: #3A4A9C;
  --primary-hover: #2C3A80;
  --primary-soft: #8B9AE8;
  --accent: #B45309;

  /* Neutrals */
  --paper: #FAF7F2;
  --surface: #FFFFFF;
  --border: #E7E1D6;
  --ink: #232838;
  --muted: #6E6759;

  /* Semantic */
  --success: #2E7D46;
  --success-pale: #E9F5EC;
  --success-text: #1D5330;
  --warning: #9A6700;
  --warning-pale: #FBF3DE;
  --warning-text: #6E4A00;
  --danger: #B3382C;
  --danger-pale: #FBEAE7;
  --danger-text: #7E2318;
  --info: #3A4A9C;
  --info-pale: #EDF0FB;
  --info-text: #2C3A80;

  /* Typography */
  --font-display: 'Fraunces', Georgia, serif;
  --font-text: 'Inter', system-ui, sans-serif;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  /* Radius */
  --radius-md: 6px;
  --radius-lg: 10px;
  --radius-full: 9999px;

  /* Elevation */
  --elev-1: 0 1px 2px rgba(35, 40, 56, .06);
  --elev-2: 0 2px 8px rgba(35, 40, 56, .10);
  --elev-3: 0 8px 24px rgba(35, 40, 56, .14);

  /* Motion */
  --fast: 120ms;
  --base: 200ms;
  --slow: 320ms;
  --ease-enter: cubic-bezier(0.2, 0, 0, 1);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-text);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
}

h1, h2 {
  font-family: var(--font-display);
  font-weight: 600;
}

h1 { font-size: 2.25rem; line-height: 1.2; }
h2 { font-size: 1.5rem; line-height: 1.3; }
h3 { font-size: 1.25rem; font-weight: 600; }

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover { color: var(--primary-hover); }

a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-md);
}

img { max-width: 100%; display: block; }

/* Header */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: var(--space-md) var(--space-xl);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo-text {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--ink);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.site-nav a {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  transition: color var(--fast) var(--ease-enter);
}

.site-nav a:hover { color: var(--ink); }

/* Logout is a POST form (CSRF-protected); its button reads as a nav link */
.nav-logout { display: contents; }

.nav-logout button {
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  transition: color var(--fast) var(--ease-enter);
}

.nav-logout button:hover { color: var(--ink); }

.nav-logout button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-md);
}

/* Main */
.site-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-2xl) var(--space-xl);
  min-height: calc(100vh - 200px);
}

/* Hero */
.hero {
  text-align: center;
  padding: var(--space-3xl) 0;
}

.hero h1 {
  margin-bottom: var(--space-md);
}

.hero p {
  font-size: 1.125rem;
  color: var(--muted);
  max-width: 42rem;
  margin: 0 auto var(--space-xl);
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.625rem 1.25rem;
  font-family: var(--font-text);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1;
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--fast) var(--ease-enter), border-color var(--fast) var(--ease-enter);
  text-align: center;
  min-height: 2.5rem;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
  color: #fff;
}

.btn-secondary {
  background: transparent;
  border-color: var(--primary);
  color: var(--primary);
}

.btn-secondary:hover {
  background: var(--primary);
  color: #fff;
}

.btn-quiet {
  background: transparent;
  color: var(--primary);
}

.btn-quiet:hover {
  background: var(--paper);
  color: var(--primary-hover);
}

/* Irreversible acts only */
.btn-destructive {
  background: var(--danger);
  color: #fff;
}

.btn-destructive:hover {
  background: var(--danger-text);
  color: #fff;
}

.btn-lg {
  padding: 0.875rem 2rem;
  font-size: 1rem;
  min-height: 3rem;
}

.btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Glyph beside text (css/icons.css draws it): 20px, 0.25rem icon-to-text.
   The negative block margins keep a 20px glyph from making 14px text rows
   taller. */
.btn .icon,
.site-nav .icon,
.admin-sidebar .icon {
  font-size: 1.25rem;
  vertical-align: middle;
  margin: -0.25rem var(--space-xs) -0.25rem 0;
}

/* Page heading with a glyph: 36px, centered on the text, 0.5rem gap.
   Decoration only; admin headings reuse their sidebar glyph. */
.heading-icon {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.heading-icon .icon { font-size: 2.25rem; }

/* Icon-only button: 24px glyph in a 32px hit box; the name is visually
   hidden text plus a matching title (DESIGN.md → icon buttons) */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--muted);
  font-size: 1.5rem;
  vertical-align: middle;
  cursor: pointer;
  transition: color var(--fast) var(--ease-enter);
}

.btn-icon:hover { color: var(--ink); }

.btn-icon-danger:hover { color: var(--danger); }

.btn-icon:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn-icon + .btn-icon { margin-left: var(--space-sm); }

/* Forms */
.auth-section {
  max-width: 28rem;
  margin: var(--space-xl) auto;
}

.auth-section h2 {
  margin-bottom: var(--space-xl);
  text-align: center;
}

.auth-form {
  background: var(--surface);
  padding: var(--space-xl);
  border-radius: var(--radius-lg);
  box-shadow: var(--elev-1);
}

.form-group {
  margin-bottom: var(--space-lg);
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: var(--space-xs);
  color: var(--ink);
}

.form-group input {
  width: 100%;
  padding: 0.75rem;
  font-family: var(--font-text);
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  transition: border-color var(--fast) var(--ease-enter);
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(58, 74, 156, 0.15);
}

.form-group .required {
  color: var(--danger);
}

.field-help,
.field-error {
  margin-top: var(--space-xs);
  font-size: 0.8125rem;
}

.field-help {
  color: var(--muted);
}

.field-error {
  color: var(--danger-text);
}

.field-error::before {
  content: "⚠" / "";
  margin-right: var(--space-xs);
}

.form-group input[aria-invalid="true"] {
  border-color: var(--danger);
}

.auth-form .btn {
  width: 100%;
  margin-top: var(--space-sm);
}

.auth-link {
  text-align: center;
  margin-top: var(--space-lg);
  font-size: 0.875rem;
  color: var(--muted);
}

/* Alerts */
.alert {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-xl);
  font-size: 0.875rem;
}

.alert-info {
  background: var(--info-pale);
  color: var(--info-text);
}

.alert-danger {
  background: var(--danger-pale);
  color: var(--danger-text);
}

.alert-success {
  background: var(--success-pale);
  color: var(--success-text);
}

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  box-shadow: var(--elev-1);
}

/* Footer */
.site-footer {
  text-align: center;
  padding: var(--space-xl);
  font-size: 0.75rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

/* Dashboard: a working screen, so admin density */
.dashboard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.dashboard .alert { margin-bottom: var(--space-md); }

.upload-form {
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--elev-1);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
}

.upload-form .form-group { flex: 1; margin-bottom: 0; }

.upload-form input[type="file"] { padding: 0.5rem; font-size: 0.875rem; }

/* Line the button up with the input, below the label */
.upload-form .btn { margin-top: 1.5rem; }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: var(--space-2xl) var(--space-md);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
}

/* Design cards: heterogeneous summaries (DESIGN.md → Layout). The swatch
   strip is an SVG so its colours are attributes, not inline styles. */
.design-cards {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
  gap: var(--space-md);
}

.design-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--elev-1);
}

.swatches {
  display: block;
  width: 100%;
  height: 2.5rem;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.swatches-none {
  background: var(--paper);
  border-bottom: 1px solid var(--border);
}

.design-card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  padding: var(--space-md);
}

.design-card-title {
  font-family: var(--font-text);
  font-size: 1rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.design-card-meta {
  font-size: 0.8125rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.design-card-status {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-top: var(--space-sm);
}

.design-card-actions {
  display: flex;
  justify-content: flex-end;
  padding: var(--space-sm);
  border-top: 1px solid var(--border);
}

/* Findings: a popover panel (no JavaScript needed); Esc or a click outside
   closes it. Browsers without popover support show it inline. */
.findings-panel {
  margin: auto; /* the reset zeroes the browser's centring */
  max-width: min(32rem, calc(100vw - 2rem));
  max-height: min(36rem, calc(100vh - 4rem));
  overflow-y: auto;
  padding: var(--space-lg);
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--elev-3);
}

.findings-panel::backdrop { background: rgba(35, 40, 56, .3); }

.findings-panel h3 {
  font-family: var(--font-text);
  font-size: 1.25rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.findings {
  list-style: none;
  margin-top: var(--space-md);
}

.finding {
  padding: var(--space-sm) 0;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
}

.finding-tier,
.finding-line {
  font-size: 0.75rem;
  font-weight: 600;
  margin-right: var(--space-xs);
}

.finding-error .finding-tier { color: var(--danger-text); }
.finding-warning .finding-tier { color: var(--warning-text); }
.finding-note .finding-tier { color: var(--muted); }
.finding-line { color: var(--muted); }

.finding-message {
  display: block;
  margin-top: var(--space-xs);
  overflow-wrap: anywhere;
}

/* Destructive confirmation: a page, so it works without JavaScript */
.confirm-panel {
  max-width: 32rem;
  margin: 0 auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--elev-3);
  padding: var(--space-xl);
}

.confirm-panel h2 { font-size: 1.5rem; margin-bottom: var(--space-md); }

.confirm-panel p { overflow-wrap: anywhere; }

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}

/* Utilities */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.muted { color: var(--muted); }

/* Small button (admin tables): 2rem tall, never smaller */
.btn-sm {
  padding: 0.5rem 0.875rem;
  font-size: 0.8125rem;
  min-height: 2rem;
}

/* Badges: pale/text pairs, radius-full, 0.75rem/600 */
.badge {
  display: inline-block;
  padding: 0.125rem 0.625rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-info { background: var(--info-pale); color: var(--info-text); }
.badge-success { background: var(--success-pale); color: var(--success-text); }
.badge-danger { background: var(--danger-pale); color: var(--danger-text); }
.badge-warning { background: var(--warning-pale); color: var(--warning-text); }
.badge-muted { background: var(--paper); color: var(--muted); }

/* Badge glyph: the tier's shape beside its word (never instead of it), so
   the tier reads without color; same color as the text */
.badge .icon {
  font-size: 1.25em;
  vertical-align: middle;
  margin: -0.125rem var(--space-xs) -0.125rem 0;
}

/* A badge that opens details: same look, plus a pointer and focus ring */
.badge-button {
  border: 0;
  font-family: inherit;
  line-height: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.badge-button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Admin shell: 240px sidebar + fluid main; admin density (compact, sans) */
.admin-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: var(--space-md);
}

.admin-sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.admin-sidebar a {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
}

.admin-sidebar a:hover { color: var(--ink); background: var(--surface); }

.admin-sidebar a[aria-current="page"] {
  background: var(--primary-soft);
  color: var(--ink);
}

.admin-main h2 {
  font-family: var(--font-text);
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: var(--space-md);
}

.admin-main .alert { margin-bottom: var(--space-md); }

.admin-note {
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: var(--space-md);
}

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--elev-1);
}

/* Tables: 0.875rem/600 muted header, border rows, paper hover, no zebra.
   .data-table is the same table outside the admin area. */
.admin-table,
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.admin-table th,
.data-table th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.admin-table td,
.data-table td {
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.admin-table tbody tr:last-child td,
.data-table tbody tr:last-child td { border-bottom: 0; }
.admin-table tbody tr:hover,
.data-table tbody tr:hover { background: var(--paper); }
.admin-table .cell-action,
.data-table .cell-action { text-align: right; white-space: nowrap; }

/* Admin FAQ: recipes rendered from Markdown; reading measure 72ch */
.faq { max-width: 72ch; }

.faq-toc {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--elev-1);
  padding: var(--space-md) var(--space-lg);
  margin-bottom: var(--space-xl);
  font-size: 0.875rem;
}

.faq-toc ol { padding-left: var(--space-lg); }
.faq-toc li + li { margin-top: var(--space-xs); }

.faq-recipe {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--elev-1);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
  scroll-margin-top: var(--space-md);
}

/* Shown only until faq.js renders it (or if the scripts fail to load) */
.faq-source {
  white-space: pre-wrap;
  font-size: 0.8125rem;
}

.prose { font-size: 0.9375rem; line-height: 1.6; }
.prose > * + * { margin-top: var(--space-md); }

.prose h3 {
  font-family: var(--font-text);
  font-size: 1.125rem;
  font-weight: 600;
}

.prose h4 {
  font-size: 1rem;
  font-weight: 600;
  margin-top: var(--space-lg);
}

.prose ol, .prose ul { padding-left: var(--space-lg); }
.prose li + li { margin-top: var(--space-sm); }
.prose li > * + * { margin-top: var(--space-sm); }

.prose code,
.admin-note code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8125rem;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.0625rem 0.3125rem;
}

.prose pre {
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  overflow-x: auto;
}

.prose pre code {
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
}

.prose blockquote {
  border-left: 3px solid var(--warning);
  background: var(--warning-pale);
  color: var(--warning-text);
  padding: var(--space-sm) var(--space-md);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.prose th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding: var(--space-xs) var(--space-sm);
}

.prose td {
  border-bottom: 1px solid var(--border);
  padding: var(--space-xs) var(--space-sm);
  vertical-align: top;
}

.code-block { position: relative; }

/* Quiet button: text-only, admin toolbars */
.btn-copy {
  position: absolute;
  top: var(--space-xs);
  right: var(--space-xs);
  font-family: var(--font-text);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--paper);
  background: transparent;
  border: 1px solid rgba(250, 247, 242, .3);
  border-radius: var(--radius-md);
  padding: 0.25rem 0.5rem;
  min-height: 2rem;
  cursor: pointer;
}

.btn-copy:hover { border-color: var(--paper); }

.btn-copy:focus-visible {
  outline: 2px solid var(--primary-soft);
  outline-offset: 2px;
}

/* Admin Overview: stat tiles (label, then a sans-semibold value in ink) */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.stat-tile {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--elev-1);
  padding: var(--space-md);
}

.stat-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
}

.stat-value {
  font-family: var(--font-text);
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink);
  margin-top: var(--space-xs);
}

.admin-panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--elev-1);
  padding: var(--space-md) var(--space-lg);
  margin-bottom: var(--space-md);
  font-size: 0.875rem;
}

.admin-panel h3 {
  font-family: var(--font-text);
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: var(--space-sm);
}

.admin-facts {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: var(--space-sm) var(--space-lg);
}

.admin-facts dt { color: var(--muted); }
.admin-facts dd { overflow-wrap: anywhere; }
.admin-facts .badge { margin-right: var(--space-xs); }

.admin-links { padding-left: var(--space-lg); }
.admin-links li + li { margin-top: var(--space-xs); }

/* Responsive */
@media (max-width: 639px) {
  .header-inner {
    flex-direction: column;
    gap: var(--space-sm);
  }

  .site-nav {
    gap: var(--space-md);
  }

  .site-main {
    padding: var(--space-xl) var(--space-md);
  }

  .admin-shell { grid-template-columns: minmax(0, 1fr); }

  .admin-sidebar { flex-direction: row; flex-wrap: wrap; }

  .admin-facts { grid-template-columns: minmax(0, 1fr); gap: 0; }

  .admin-facts dd + dt { margin-top: var(--space-sm); }

  .upload-form { flex-direction: column; align-items: stretch; }

  .upload-form .btn { margin-top: 0; }

  h1 { font-size: 1.75rem; }
  h2 { font-size: 1.25rem; }
}
