/* ==========================================================================
   VolID — Design tokens (Nexus system) + base reset + component library
   ========================================================================== */

:root,
[data-theme='light'] {
  --color-bg: #f7f6f2;
  --color-surface: #f9f8f5;
  --color-surface-2: #fbfbf9;
  --color-surface-offset: #f3f0ec;
  --color-surface-offset-2: #edeae5;
  --color-surface-dynamic: #e6e4df;
  --color-divider: #dcd9d5;
  --color-border: #d4d1ca;

  --color-text: #28251d;
  --color-text-muted: #7a7974;
  --color-text-faint: #bab9b4;
  --color-text-inverse: #f9f8f4;

  --color-primary: #01696f;
  --color-primary-hover: #0c4e54;
  --color-primary-active: #0f3638;
  --color-primary-highlight: #cedcd8;

  --color-warning: #964219;
  --color-warning-highlight: #ddcfc6;

  --color-error: #a12c7b;
  --color-error-highlight: #e0ced7;

  --color-success: #437a22;
  --color-success-highlight: #d4dfcc;

  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  --shadow-sm: 0 1px 2px rgba(40, 37, 29, 0.06);
  --shadow-md: 0 4px 12px rgba(40, 37, 29, 0.08);
  --shadow-lg: 0 12px 32px rgba(40, 37, 29, 0.12);

  --content-narrow: 640px;
  --content-default: 960px;
  --content-wide: 1200px;

  --font-body: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Inter', -apple-system, 'Segoe UI', sans-serif;

  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);
  --text-2xl: clamp(2rem, 1.2rem + 2.5vw, 3rem);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
}

[data-theme='dark'] {
  --color-bg: #171614;
  --color-surface: #1c1b19;
  --color-surface-2: #201f1d;
  --color-surface-offset: #1d1c1a;
  --color-surface-offset-2: #22211f;
  --color-surface-dynamic: #2d2c2a;
  --color-divider: #262523;
  --color-border: #393836;
  --color-text: #cdccca;
  --color-text-muted: #797876;
  --color-text-faint: #5a5957;
  --color-text-inverse: #2b2a28;
  --color-primary: #4f98a3;
  --color-primary-hover: #227f8b;
  --color-primary-active: #1a626b;
  --color-primary-highlight: #313b3b;
  --color-warning: #bb653b;
  --color-warning-highlight: #564942;
  --color-error: #d163a7;
  --color-error-highlight: #4c3d46;
  --color-success: #6daa45;
  --color-success-highlight: #3a4435;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.4);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg: #171614;
    --color-surface: #1c1b19;
    --color-surface-2: #201f1d;
    --color-surface-offset: #1d1c1a;
    --color-surface-offset-2: #22211f;
    --color-surface-dynamic: #2d2c2a;
    --color-divider: #262523;
    --color-border: #393836;
    --color-text: #cdccca;
    --color-text-muted: #797876;
    --color-text-faint: #5a5957;
    --color-text-inverse: #2b2a28;
    --color-primary: #4f98a3;
    --color-primary-hover: #227f8b;
    --color-primary-active: #1a626b;
    --color-primary-highlight: #313b3b;
    --color-warning: #bb653b;
    --color-warning-highlight: #564942;
    --color-error: #d163a7;
    --color-error-highlight: #4c3d46;
    --color-success: #6daa45;
    --color-success-highlight: #3a4435;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.4);
  }
}

/* ---------- Base reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: none; text-size-adjust: none; -webkit-font-smoothing: antialiased; scroll-behavior: smooth; }
body { min-height: 100dvh; line-height: 1.55; font-family: var(--font-body); font-size: var(--text-base); color: var(--color-text); background-color: var(--color-bg); }
img, picture, svg { display: block; max-width: 100%; }
ul[role='list'], ol[role='list'] { list-style: none; }
input, button, textarea, select { font: inherit; color: inherit; }
h1, h2, h3, h4 { text-wrap: balance; line-height: 1.2; font-family: var(--font-display); }
a { color: var(--color-primary); text-decoration: none; }
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; border-radius: var(--radius-sm); }
button { cursor: pointer; background: none; border: none; }
table { border-collapse: collapse; width: 100%; }
a, button, [role='button'], input, textarea, select { transition: color var(--transition-interactive), background var(--transition-interactive), border-color var(--transition-interactive), box-shadow var(--transition-interactive); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

/* ---------- Layout shell ---------- */
.app-shell { display: flex; min-height: 100dvh; }
.sidebar { width: 240px; flex-shrink: 0; background: var(--color-surface); border-right: 1px solid var(--color-border); padding: var(--space-6) var(--space-4); display: flex; flex-direction: column; gap: var(--space-6); }
.sidebar-brand { display: flex; align-items: center; gap: var(--space-2); font-weight: 700; font-size: var(--text-base); color: var(--color-text); }
.sidebar-brand svg { color: var(--color-primary); }
.sidebar-nav { display: flex; flex-direction: column; gap: var(--space-1); }
.sidebar-nav a { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); color: var(--color-text-muted); font-size: var(--text-sm); font-weight: 500; }
.sidebar-nav a:hover { background: var(--color-surface-offset); color: var(--color-text); }
.sidebar-nav a.active { background: var(--color-primary-highlight); color: var(--color-primary-active); }
.sidebar-footer { margin-top: auto; font-size: var(--text-xs); color: var(--color-text-faint); }
.main-content { flex: 1; min-width: 0; padding: var(--space-8); max-width: var(--content-wide); }
.main-content-inner { max-width: var(--content-default); }

.page-header { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-6); flex-wrap: wrap; }
.page-title { font-size: var(--text-xl); font-weight: 700; }
.page-subtitle { color: var(--color-text-muted); font-size: var(--text-sm); margin-top: var(--space-1); }

/* ---------- Cards / surfaces ---------- */
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-6); }
.card + .card { margin-top: var(--space-4); }
.card-title { font-size: var(--text-lg); font-weight: 600; margin-bottom: var(--space-4); }
/* Collapsible cards (admin plans): the summary is the card title; collapsed
   cards keep even padding and the native disclosure marker as the affordance. */
details.card > summary { cursor: pointer; }
details.card > summary.card-title { margin-bottom: 0; }
details.card > summary + * { margin-top: var(--space-4); }
.card-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); padding: var(--space-3) 0; border-bottom: 1px solid var(--color-divider); }
.card-row:last-child { border-bottom: none; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); padding: var(--space-2) var(--space-4); font-size: var(--text-sm); font-weight: 600; border-radius: var(--radius-md); border: 1px solid transparent; }
.btn-primary { background: var(--color-primary); color: var(--color-text-inverse); }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary { background: var(--color-surface-offset); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-surface-offset-2); }
.btn-danger { background: transparent; color: var(--color-error); border-color: var(--color-error-highlight); }
.btn-danger:hover { background: var(--color-error-highlight); }
.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Social sign-in ---------- */
.oauth-stack { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }
.oauth-btn svg { flex-shrink: 0; }
.oauth-divider { display: flex; align-items: center; gap: var(--space-3); color: var(--color-text-muted); font-size: var(--text-xs); margin-top: var(--space-1); }
.oauth-divider::before, .oauth-divider::after { content: ""; flex: 1; height: 1px; background: var(--color-divider); }

/* ---------- Forms ---------- */
.form-group { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }
.form-label { font-size: var(--text-sm); font-weight: 600; color: var(--color-text); }
.form-hint { font-size: var(--text-xs); color: var(--color-text-muted); }
.form-error { font-size: var(--text-xs); color: var(--color-error); }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: var(--space-2) var(--space-3); font-size: var(--text-sm);
  border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface-2); color: var(--color-text);
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--color-primary); }
.form-checkbox-row { display: flex; align-items: center; gap: var(--space-2); }
.form-static-prefix { color: var(--color-text-muted); font-size: var(--text-sm); }
.input-group { display: flex; align-items: stretch; }
.input-group-prefix { display: flex; align-items: center; padding: 0 var(--space-3); background: var(--color-surface-offset); border: 1px solid var(--color-border); border-right: none; border-radius: var(--radius-md) 0 0 var(--radius-md); font-size: var(--text-sm); color: var(--color-text-muted); }
.input-group .form-input { border-radius: 0 var(--radius-md) var(--radius-md) 0; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
.table th, .table td { text-align: left; padding: var(--space-3) var(--space-3); font-size: var(--text-sm); border-bottom: 1px solid var(--color-divider); }
.table th { color: var(--color-text-muted); font-weight: 600; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.03em; }
.table tbody tr:hover { background: var(--color-surface-offset); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: var(--space-1); padding: 0.15rem var(--space-2); border-radius: var(--radius-full); font-size: var(--text-xs); font-weight: 600; }
.badge-primary { background: var(--color-primary-highlight); color: var(--color-primary-active); }
.badge-success { background: var(--color-success-highlight); color: var(--color-success); }
.badge-warning { background: var(--color-warning-highlight); color: var(--color-warning); }
.badge-error { background: var(--color-error-highlight); color: var(--color-error); }
.badge-neutral { background: var(--color-surface-offset); color: var(--color-text-muted); }

/* ---------- Alerts / flash ---------- */
.alert { padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); font-size: var(--text-sm); margin-bottom: var(--space-4); border: 1px solid transparent; }
.alert-success { background: var(--color-success-highlight); color: var(--color-success); }
.alert-error { background: var(--color-error-highlight); color: var(--color-error); }
.alert-info { background: var(--color-primary-highlight); color: var(--color-primary-active); }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: var(--space-12) var(--space-6); color: var(--color-text-muted); }
.empty-state svg { margin: 0 auto var(--space-4); color: var(--color-text-faint); }
.empty-state-title { font-size: var(--text-base); font-weight: 600; color: var(--color-text); margin-bottom: var(--space-1); }

/* ---------- Auth screens ---------- */
.auth-screen { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: var(--space-6); background: var(--color-bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-xl); padding: var(--space-8); box-shadow: var(--shadow-md); }
.auth-brand { display: flex; align-items: center; gap: var(--space-2); font-weight: 700; margin-bottom: var(--space-6); color: var(--color-text); }
.auth-brand svg { color: var(--color-primary); }
.auth-title { font-size: var(--text-lg); font-weight: 700; margin-bottom: var(--space-1); }
.auth-subtitle { color: var(--color-text-muted); font-size: var(--text-sm); margin-bottom: var(--space-6); }
.auth-footer { margin-top: var(--space-6); text-align: center; font-size: var(--text-sm); color: var(--color-text-muted); }

/* ---------- Public profile page ---------- */
.public-page { min-height: 100dvh; background: var(--color-bg); padding: var(--space-10) var(--space-4); }
.public-card { max-width: var(--content-narrow); margin: 0 auto; text-align: center; }
.public-avatar { width: 96px; height: 96px; border-radius: var(--radius-full); background: var(--color-primary-highlight); color: var(--color-primary-active); display: flex; align-items: center; justify-content: center; font-size: var(--text-xl); font-weight: 700; margin: 0 auto var(--space-4); }
.public-name { font-size: var(--text-xl); font-weight: 700; }
.public-handler { color: var(--color-text-muted); font-size: var(--text-sm); margin-bottom: var(--space-4); }
.public-bio { color: var(--color-text-muted); margin-bottom: var(--space-6); }
.public-links { display: flex; flex-direction: column; gap: var(--space-3); margin-bottom: var(--space-8); }
.public-link { display: block; padding: var(--space-4); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); font-weight: 600; text-align: center; color: var(--color-text); }
.public-link:hover { border-color: var(--color-primary); background: var(--color-surface-offset); }
.public-actions { display: flex; gap: var(--space-3); justify-content: center; flex-wrap: wrap; }

.business-hero { max-width: var(--content-default); margin: 0 auto; text-align: center; }
.business-logo { width: 88px; height: 88px; border-radius: var(--radius-lg); object-fit: cover; margin: 0 auto var(--space-4); background: var(--color-surface-offset); }
.business-headline { font-size: var(--text-xl); font-weight: 700; margin-bottom: var(--space-2); }
.business-description { color: var(--color-text-muted); max-width: var(--content-narrow); margin: 0 auto; }

/* ---------- Utility ---------- */
.stack-sm > * + * { margin-top: var(--space-2); }
.stack-md > * + * { margin-top: var(--space-4); }
.text-muted { color: var(--color-text-muted); }
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.mono { font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--space-4); margin-bottom: var(--space-6); }
.stat-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-4); }
.stat-value { font-size: var(--text-xl); font-weight: 700; }
.stat-label { font-size: var(--text-xs); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.03em; }

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--color-border); }
  .sidebar-nav { flex-direction: row; }
  .sidebar-footer { display: none; }
  .main-content { padding: var(--space-4); }
}

/* ---------- Language switcher (dropdown, cookie-persisted) ----------
   The header button shows only the current language; the remaining
   enabled languages appear in the menu after clicking (no-JS <details>). */
.lang-switch { position: relative; display: inline-block; flex: none; z-index: 1000; }
.lang-switch[open] { z-index: 1000; }
.lang-switch__btn { display: inline-block; border: 1px solid var(--color-border, #2f2642); border-radius: 999px; background: var(--color-surface, rgba(7, 6, 10, 0.82)); padding: 4px 10px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; color: var(--color-text-muted, #8b8598); cursor: pointer; list-style: none; }
.lang-switch__btn::-webkit-details-marker { display: none; }
.lang-switch__btn::after { content: ' ▾'; }
.lang-switch__menu { position: absolute; top: calc(100% + 6px); right: 0; z-index: 1000; display: flex; flex-direction: column; min-width: 100%; border: 1px solid var(--color-border, #2f2642); border-radius: 12px; overflow: hidden; background: var(--color-surface, rgba(7, 6, 10, 0.95)); }
.lang-switch__menu a { padding: 6px 12px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; color: var(--color-text-muted, #8b8598); text-decoration: none; white-space: nowrap; }
.lang-switch__menu a:hover { background: #d9b45c; color: #0b0910; }
.lang-switch-fixed { position: fixed; top: 12px; right: 12px; z-index: 1000; }
.topbar { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-bottom: var(--space-4); }
.topbar [data-theme-toggle]:hover { border-color: var(--color-primary); color: var(--color-text); }

/* ---------- Content-page Markdown editor (platform admin) ----------
   Toolbar + side-by-side source/preview. Panes collapse to one column
   below 900px. Plain <textarea> submit stays the no-JS fallback. */
.md-editor { display: flex; flex-direction: column; gap: var(--space-2); }
.md-toolbar { display: flex; flex-wrap: wrap; gap: 4px; }
.md-toolbar button { border: 1px solid var(--color-border); border-radius: 6px; background: var(--color-surface-offset); color: var(--color-text); font-size: var(--text-xs); font-weight: 600; padding: 2px 8px; cursor: pointer; }
.md-toolbar button:hover { border-color: var(--color-primary); }
.md-toolbar button:disabled { opacity: 0.4; cursor: not-allowed; }
.md-toolbar button:disabled:hover { border-color: var(--color-border); }
.md-source { min-height: 320px; font-family: ui-monospace, monospace; }
.md-status { font-size: var(--text-xs); color: var(--color-text-muted); text-align: right; }
.md-over { color: var(--color-error); font-weight: 700; }
.md-paste-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: var(--space-4); }
.md-paste-box { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 10px; padding: var(--space-4); width: min(560px, 100%); display: flex; flex-direction: column; gap: var(--space-2); }
.md-paste-title { font-weight: 700; }
.md-paste-box textarea { min-height: 160px; font-family: ui-monospace, monospace; }
.md-paste-row { display: flex; gap: var(--space-2); justify-content: flex-end; }
.md-paste-error { color: var(--color-error); }
.md-preview-box { width: min(900px, 100%); max-height: 85vh; }
.md-preview-head { display: flex; align-items: center; justify-content: space-between; }
.md-preview-title { font-weight: 700; }
.md-preview-content { overflow: auto; min-height: 0; border: 1px solid var(--color-border); border-radius: 8px; padding: var(--space-3); background: var(--color-surface); }

/* ---------- Rendered Markdown (public page + admin preview) ----------
   Only tags the CommonMark + GFM-tables renderer can emit (see
   app/content_pages._MD_TAGS); keep in sync when that set changes. */
.content-body { line-height: 1.6; overflow-wrap: break-word; }
.content-body > :first-child { margin-top: 0; }
.content-body > :last-child { margin-bottom: 0; }
.content-body h1, .content-body h2, .content-body h3,
.content-body h4, .content-body h5, .content-body h6 { margin: 1.2em 0 0.5em; line-height: 1.3; }
.content-body p { margin: 0.6em 0; }
.content-body ul, .content-body ol { margin: 0.6em 0; padding-left: 1.5em; }
.content-body li + li { margin-top: 0.25em; }
.content-body blockquote { margin: 0.8em 0; padding: 0.4em 1em; border-left: 3px solid var(--color-border); color: var(--color-text-muted); }
.content-body pre { margin: 0.8em 0; padding: var(--space-3); border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-surface-offset); overflow-x: auto; }
.content-body code { font-family: ui-monospace, monospace; font-size: 0.9em; }
.content-body pre code { font-size: 1em; }
.content-body hr { margin: 1.2em 0; border: none; border-top: 1px solid var(--color-border); }
.content-body img { max-width: 100%; height: auto; border-radius: 8px; }
.content-body table { display: block; width: 100%; margin: 0.8em 0; border-collapse: collapse; overflow-x: auto; }
.content-body th, .content-body td { border: 1px solid var(--color-border); padding: 6px 10px; text-align: left; }
.content-body thead th { background: var(--color-surface-offset); }

/* ---------- Public footer nav (platform content pages) ---------- */
.footer-nav { margin: var(--space-4) 0; font-size: var(--text-sm); text-align: center; }
.footer-nav a { color: var(--color-text-muted); }
.footer-nav-sep { color: var(--color-border); }
