/* ============================================================
   TALA — Design System
   Warm gold on dark. Calm. Breathing space.
   ============================================================ */

/* ── Self-hosted Fonts ──────────────────────────────────── */
/* GDPR-compliant: no external requests to Google or any CDN.  */
/* 3 variable-font WOFF2 files cover all required weights.     */
/* Source: fonts.gstatic.com, downloaded 2026-03-11, v21/v20.  */

/* Cormorant Garamond — Display — Normal 400 */
@font-face {
  font-family: 'Cormorant Garamond';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../assets/fonts/cormorant-garamond-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
                 U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F,
                 U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Cormorant Garamond — Display — Normal 600 (same variable font file) */
@font-face {
  font-family: 'Cormorant Garamond';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../assets/fonts/cormorant-garamond-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
                 U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F,
                 U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Cormorant Garamond — Display — Italic 400 */
@font-face {
  font-family: 'Cormorant Garamond';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url('../assets/fonts/cormorant-garamond-italic.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
                 U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F,
                 U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Inter — Body — Light 300 */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 300;
  font-display: swap;
  src: url('../assets/fonts/inter.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
                 U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F,
                 U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Inter — Body — Regular 400 (same variable font file) */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../assets/fonts/inter.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
                 U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F,
                 U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Inter — Body — Medium 500 (same variable font file) */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../assets/fonts/inter.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
                 U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F,
                 U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ── Tokens ─────────────────────────────────────────────── */
:root {
  /* Gold spectrum */
  --gold-50:  #fdf6e3;
  --gold-100: #f5e6c8;
  --gold-200: #e8d0a0;
  --gold-300: #d4b577;
  --gold-400: #c4993f;
  --gold-500: #b8860b;
  --gold-600: #956d09;
  --gold-700: #6b4f07;

  /* Neutrals (warm) */
  --dark-900: #1a1612;
  --dark-800: #231f1a;
  --dark-700: #2c2722;
  --dark-600: #3d3630;
  --dark-500: #524a42;
  --dark-400: #6b6159;
  --dark-300: #8a7f75;
  --dark-200: #b0a89f;
  --dark-100: #d4cfc9;
  --dark-50:  #eae7e3;

  /* Semantic */
  --bg-primary:    var(--dark-900);
  --bg-secondary:  var(--dark-800);
  --bg-card:       var(--dark-700);
  --bg-input:      var(--dark-600);
  --text-primary:  var(--dark-50);
  --text-secondary: var(--dark-200);
  --text-muted:    var(--dark-300);
  --accent:        var(--gold-500);
  --accent-light:  var(--gold-200);
  --accent-glow:   rgba(184, 134, 11, 0.15);
  --error:         #c0392b;
  --success:       #27ae60;

  /* Typography */
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-body: 'Inter', -apple-system, sans-serif;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  /* Transitions */
  --ease-gentle: cubic-bezier(0.25, 0.1, 0.25, 1);
  --duration-fast: 150ms;
  --duration-normal: 300ms;
  --duration-slow: 600ms;

  /* Safe areas (Capacitor/mobile) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* Theme-aware portrait (swapped via data-theme attribute) */
  --portrait-image: url('../assets/tala-portrait-dark.png');

  /* Borders & shadows (dark mode defaults) */
  --border-subtle: rgba(184, 134, 11, 0.12);
  --card-shadow: none;
}

/* ── Light Theme ────────────────────────────────────────── */
/* Applied via system preference (before JS loads) or explicit data-theme attr.  */
/* Using a shared mixin pattern: one definition, two selectors.                  */

/* Shared light-mode property values */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --portrait-image:  url('../assets/tala-portrait-light.png');
    --bg-primary:      #fdf6e3;
    --bg-secondary:    #f5e6c8;
    --bg-card:         #ffffff;
    --bg-input:        #ede8de;
    --text-primary:    #2c2722;
    --text-secondary:  #3d3630;
    --text-muted:      #6b6159;
    --accent:          #956d09;
    --accent-light:    #b8860b;
    --accent-glow:     rgba(149, 109, 9, 0.12);
    --border-subtle:   rgba(149, 109, 9, 0.15);
    --card-shadow:     0 2px 12px rgba(149, 109, 9, 0.08);
    /* Dark-scale overrides for components using --dark-xxx directly */
    --dark-100:  #2c2722;   /* assistant message text */
    --dark-300:  #6b6159;   /* dots, muted UI */
    --dark-400:  #6b6159;   /* placeholders, disclaimer */
    --dark-500:  #c4ae8a;   /* input borders, scrollbar */
    --dark-600:  #d4b577;   /* card borders, user bubble */
    --dark-700:  #e8d5b5;   /* section dividers */
  }
}

/* Explicit JS-set light mode — same values, higher specificity */
[data-theme="light"] {
  --portrait-image:  url('../assets/tala-portrait-light.png');
  --bg-primary:      #fdf6e3;
  --bg-secondary:    #f5e6c8;
  --bg-card:         #ffffff;
  --bg-input:        #ede8de;
  --text-primary:    #2c2722;
  --text-secondary:  #3d3630;
  --text-muted:      #6b6159;
  --accent:          #956d09;
  --accent-light:    #b8860b;
  --accent-glow:     rgba(149, 109, 9, 0.12);
  --border-subtle:   rgba(149, 109, 9, 0.15);
  --card-shadow:     0 2px 12px rgba(149, 109, 9, 0.08);
  --dark-100:  #2c2722;
  --dark-300:  #6b6159;
  --dark-400:  #6b6159;
  --dark-500:  #c4ae8a;
  --dark-600:  #d4b577;
  --dark-700:  #e8d5b5;
}

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

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

body {
  font-family: var(--font-body);
  font-weight: 300;
  color: var(--text-primary);
  background: var(--bg-primary);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  /* Smooth theme transition — only on intentional toggle, not initial render */
  transition: background-color var(--duration-normal) var(--ease-gentle),
              color var(--duration-normal) var(--ease-gentle);
}

/* ── Screens ────────────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-normal) var(--ease-gentle);
}

.screen.active {
  opacity: 1;
  pointer-events: all;
}

/* ── Loading Screen ─────────────────────────────────────── */
.loading-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-lg);
}

.loading-text {
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--accent);
  letter-spacing: 0.15em;
  animation: breathe 4s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 0.6; }
  50%      { opacity: 1; }
}

/* ── Auth Screen ────────────────────────────────────────── */
.auth-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl);
  padding-top: calc(var(--safe-top) + var(--space-xl));
}

.auth-logo { margin-bottom: var(--space-lg); }

.auth-title {
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 400;
  color: var(--accent);
  letter-spacing: 0.1em;
  margin-bottom: var(--space-xs);
}

.auth-subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: var(--space-2xl);
  text-align: center;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-secondary);
  border: 1px solid var(--dark-600);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
}

.auth-step { display: none; }
.auth-step.active { display: block; }

.step-info {
  color: var(--success);
  font-size: 0.875rem;
  margin-bottom: var(--space-lg);
  padding: var(--space-md);
  background: rgba(39, 174, 96, 0.08);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--success);
}

.auth-footer {
  margin-top: var(--space-lg);
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ── Inputs ─────────────────────────────────────────────── */
.input-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-xs);
  margin-top: var(--space-md);
}

.input-label:first-child { margin-top: 0; }

.input-field {
  width: 100%;
  padding: var(--space-md);
  background: var(--bg-input);
  border: 1px solid var(--dark-500);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 400;
  transition: border-color var(--duration-fast);
  outline: none;
}

.input-field::placeholder { color: var(--dark-400); }

.input-field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-field.error { border-color: var(--error); }

.error-text {
  color: var(--error);
  font-size: 0.8rem;
  margin-top: var(--space-sm);
}

.hidden { display: none !important; }

/* ── Buttons ────────────────────────────────────────────── */
.btn-primary {
  width: 100%;
  padding: var(--space-md) var(--space-lg);
  margin-top: var(--space-lg);
  background: var(--accent);
  color: var(--dark-900);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--duration-fast);
  letter-spacing: 0.02em;
}

.btn-primary:hover:not(:disabled) {
  background: var(--gold-400);
  transform: translateY(-1px);
}

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

.btn-primary.btn-large {
  padding: var(--space-lg);
  font-size: 1.05rem;
  border-radius: var(--radius-md);
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  margin-top: var(--space-md);
  text-decoration: underline;
  text-underline-offset: 3px;
}

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

.link-text {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-text-danger {
  width: 100%;
  background: none;
  border: none;
  color: var(--error);
  font-family: var(--font-body);
  font-size: 0.85rem;
  cursor: pointer;
  margin-top: var(--space-md);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-text-danger:hover {
  opacity: 0.85;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: var(--space-sm);
  border-radius: var(--radius-sm);
  transition: color var(--duration-fast);
}

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

/* ── Dashboard ──────────────────────────────────────────── */
.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  padding-top: calc(var(--safe-top) + var(--space-md));
  border-bottom: 1px solid var(--dark-700);
}

.dash-brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: var(--accent);
}

.dash-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.dash-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-xl);
  padding-bottom: calc(var(--safe-bottom) + var(--space-xl));
}

.dash-welcome {
  margin-bottom: var(--space-xl);
}

.dash-welcome h2 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 400;
  color: var(--text-primary);
}

.dash-plan {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: var(--space-xs);
}

/* Quota ring */
.dash-quota {
  margin-bottom: var(--space-xl);
  text-align: center;
}

.quota-visual {
  display: flex;
  justify-content: center;
  margin-bottom: var(--space-md);
}

.quota-ring {
  position: relative;
  width: 140px;
  height: 140px;
}

.quota-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.quota-bg {
  fill: none;
  stroke: var(--dark-600);
  stroke-width: 6;
}

.quota-fill {
  fill: none;
  stroke: url(#quota-gradient) var(--accent);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 264;
  stroke-dashoffset: 264;
  transition: stroke-dashoffset 1.2s var(--ease-gentle);
}

.quota-number {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 18px 6px;
  transform: translateY(-5px);
}

.quota-number span {
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--accent);
  line-height: 0.92;
  font-variant-numeric: tabular-nums;
}

.quota-number small {
  font-size: 0.64rem;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.quota-detail {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.dashboard-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: var(--space-lg);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.94rem;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: 0.01em;
  text-align: center;
  text-decoration: none;
  transition: transform var(--duration-fast), background var(--duration-fast), border-color var(--duration-fast), color var(--duration-fast), box-shadow var(--duration-fast);
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn-full {
  width: 100%;
}

.btn-group-half {
  display: flex;
  gap: 10px;
}

.btn-group-half > .btn {
  flex: 1 1 50%;
  min-width: 0;
}

a.btn-primary {
  background: var(--accent);
  color: var(--dark-900);
  box-shadow: 0 10px 24px rgba(184, 134, 11, 0.18);
}

a.btn-primary:hover {
  background: var(--gold-400);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--dark-600);
}

.btn-secondary:hover {
  background: var(--dark-600);
  border-color: var(--accent);
  color: var(--accent-light);
  transform: translateY(-1px);
}

/* Past sessions */
.dash-sessions {
  margin-top: var(--space-2xl);
}

.session-card {
  padding: var(--space-md);
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-sm);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: background var(--duration-fast);
}

.session-card:hover { background: var(--dark-600); }

.session-card-info {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.session-card-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ── Chat Screen ────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  padding: var(--space-md) var(--space-lg);
  padding-top: calc(var(--safe-top) + var(--space-md));
  border-bottom: 1px solid var(--dark-700);
  background: var(--bg-primary);
}

.chat-header-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--accent);
}

.chat-turn-counter {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-full);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* Messages */
.message {
  max-width: 85%;
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  line-height: 1.65;
  animation: msg-in var(--duration-normal) var(--ease-gentle);
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message-user {
  align-self: flex-end;
  background: var(--dark-600);
  color: var(--text-primary);
  border-bottom-right-radius: var(--space-xs);
}

.message-assistant {
  align-self: flex-start;
  background: var(--bg-secondary);
  border: 1px solid var(--dark-600);
  color: var(--dark-100);
  border-bottom-left-radius: var(--space-xs);
  position: relative;
}

.message-assistant::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 12px;
  bottom: 12px;
  width: 2px;
  background: linear-gradient(to bottom, var(--gold-300), var(--gold-600));
  border-radius: 1px;
  opacity: 0.85;
}

.message-system {
  align-self: center;
  background: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
  padding: var(--space-sm);
}

/* Typing indicator */
.message-typing {
  align-self: flex-start;
  background: var(--bg-secondary);
  border: 1px solid var(--dark-600);
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  display: flex;
  gap: 6px;
  align-items: center;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dark-300);
  animation: dot-pulse 1.4s ease-in-out infinite;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40%           { opacity: 1; transform: scale(1); }
}

/* Input area */
.chat-input-area {
  padding: var(--space-md) var(--space-lg);
  padding-bottom: calc(var(--safe-bottom) + var(--space-md));
  border-top: 1px solid var(--dark-700);
  background: var(--bg-primary);
}

.chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: var(--space-sm);
  background: var(--bg-input);
  border: 1px solid var(--dark-500);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-sm) var(--space-sm) var(--space-md);
  transition: border-color var(--duration-fast);
}

.chat-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#chat-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 300;
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 120px;
  padding: var(--space-sm) 0;
}

#chat-input::placeholder { color: var(--dark-400); }

.btn-send {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--dark-900);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--duration-fast);
}

.btn-send:hover:not(:disabled) { background: var(--gold-400); }
.btn-send:disabled { opacity: 0.3; cursor: not-allowed; }

.chat-disclaimer {
  text-align: center;
  font-size: 0.65rem;
  color: var(--dark-400);
  margin-top: var(--space-sm);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  background: rgba(26, 22, 18, 0.78);
}

.modal-card {
  width: min(100%, 420px);
  background: var(--bg-card);
  border: 1px solid var(--dark-600);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 400;
  color: var(--accent);
}

.modal-text {
  color: var(--text-secondary);
  font-size: 0.92rem;
  margin-top: var(--space-md);
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}

.modal-actions .btn-link,
.modal-actions .btn-primary {
  margin-top: 0;
}

/* ── Utilities ──────────────────────────────────────────── */
@media (min-width: 768px) {
  .auth-container { padding: var(--space-3xl); }
  .dash-content { max-width: 600px; margin: 0 auto; }
  .chat-messages { max-width: 700px; margin: 0 auto; width: 100%; }
  .chat-input-area > * { max-width: 700px; margin-left: auto; margin-right: auto; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--dark-500); border-radius: 4px; }

/* Selection */
::selection { background: var(--accent-glow); color: var(--accent); }

/* ── Brand: Loading Portrait ────────────────────────────── */
/* Replaces the CSS glow orb on the loading screen.             */
/* Theme is set by --portrait-image CSS custom property.        */
.loading-portrait {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background-image: var(--portrait-image);
  background-size: cover;
  background-position: center top;
  animation: breathe 4s ease-in-out infinite;
  /* Subtle warm ring */
  box-shadow: 0 0 40px rgba(184, 134, 11, 0.2), 0 0 80px rgba(184, 134, 11, 0.08);
}

/* ── Brand: Auth Screen Logo ─────────────────────────────── */
.auth-logo-img {
  width: 180px;
  height: 180px;
  object-fit: contain;
  animation: breathe 4s ease-in-out infinite;
  filter: drop-shadow(0 0 12px rgba(184, 134, 11, 0.35));
}

/* ── Brand: Small Logo (headers) ────────────────────────── */
.logo-small {
  width: 24px;
  height: 24px;
  object-fit: contain;
  flex-shrink: 0;
  /* Soft glow to match former CSS orb */
  filter: drop-shadow(0 0 4px rgba(184, 134, 11, 0.5));
}

/* ── Brand: Dashboard Header Banner ─────────────────────── */
/* Very subtle gold texture in the dashboard header.            */
.dash-header {
  position: relative;
  overflow: hidden;
}
.dash-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url('../assets/banner-gold.jpg');
  background-size: cover;
  background-position: center;
  opacity: 0.07;
  pointer-events: none;
}
[data-theme="light"] .dash-header::before { opacity: 0.04; }

/* ── Theme Toggle: Icon Visibility ──────────────────────── */
/* Dark mode (default): show sun icon → clicking switches to light  */
/* Light mode:          show moon icon → clicking switches to dark  */

/* Hide moon by default (dark mode) */
.icon-moon { display: none; }

/* Light mode: show moon, hide sun */
[data-theme="light"] .icon-sun  { display: none; }
[data-theme="light"] .icon-moon { display: block; }

/* System light preference before JS sets data-theme */
@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) .icon-sun  { display: none; }
  html:not([data-theme="dark"]) .icon-moon { display: block; }
}

/* ── Assistant message paragraphs ───────────────────────── */
/* Class-based (not inline style) to comply with CSP style-src 'self'. */
.msg-paragraph {
  margin-bottom: 0.8em;
  animation: para-in 350ms var(--ease-gentle) both;
}
.msg-paragraph:last-child { margin-bottom: 0; }
.msg-paragraph:nth-child(1) { animation-delay:   0ms; }
.msg-paragraph:nth-child(2) { animation-delay: 100ms; }
.msg-paragraph:nth-child(3) { animation-delay: 200ms; }
.msg-paragraph:nth-child(4) { animation-delay: 300ms; }
.msg-paragraph:nth-child(5) { animation-delay: 400ms; }
.msg-paragraph:nth-child(6) { animation-delay: 500ms; }

/* ── UI/UX Polish ───────────────────────────────────────── */

/* Chat: Paragraph entrance keyframe */
@keyframes para-in {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Chat: First paragraph — display font for the "Spiegel" opening line */
.msg-paragraph:first-child {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-style: italic;
  line-height: 1.5;
  color: var(--accent-light);
}
[data-theme="light"] .msg-paragraph:first-child { color: var(--accent); }

/* Chat: Session-close message — gold ring, centred */
.message-close {
  align-self: center !important;
  background: none !important;
  border: 1px solid var(--border-subtle) !important;
  color: var(--accent) !important;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  padding: var(--space-sm) var(--space-xl) !important;
  border-radius: var(--radius-full) !important;
  max-width: 85%;
  box-shadow: 0 0 12px var(--accent-glow);
}

/* Chat: Typing indicator logo */
.typing-logo {
  width: 16px;
  height: 16px;
  object-fit: contain;
  opacity: 0.65;
  flex-shrink: 0;
  filter: drop-shadow(0 0 3px rgba(184, 134, 11, 0.4));
}

/* Dashboard: Glow on new-session button hover */
.btn-primary.btn-large:hover:not(:disabled) {
  box-shadow: 0 4px 24px rgba(184, 134, 11, 0.3);
}

/* Dashboard: Past sessions list header */
.sessions-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: var(--space-md);
}

/* Dashboard: Session card preview text */
.session-card-preview {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

/* Auth: Valid code input glow */
.input-field.valid {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(184, 134, 11, 0.18);
}

@keyframes gold-pulse {
  0%   { box-shadow: 0 0 0 3px rgba(184, 134, 11, 0.18); }
  50%  { box-shadow: 0 0 0 9px rgba(184, 134, 11, 0.35); }
  100% { box-shadow: 0 0 0 3px rgba(184, 134, 11, 0.18); }
}

.input-field.pulse-success {
  border-color: var(--accent);
  animation: gold-pulse 600ms ease-out;
}

/* Auth: Password strength bar */
.pw-strength {
  height: 3px;
  background: var(--dark-600);
  border-radius: 3px;
  margin-top: var(--space-xs);
  overflow: hidden;
}

.pw-strength-bar {
  height: 100%;
  width: 0;
  border-radius: 3px;
  transition: width 300ms var(--ease-gentle), background-color 300ms;
}
.pw-strength-bar.weak   { width: 33%; background: var(--error); }
.pw-strength-bar.medium { width: 66%; background: var(--gold-400); }
.pw-strength-bar.strong { width: 100%; background: var(--success); }

/* Micro-interactions: Button press scale */
.btn-primary:active:not(:disabled)  { transform: scale(0.97); transition: transform 80ms; }
.btn-icon:active                     { transform: scale(0.90); transition: transform 80ms; }
.btn-send:active:not(:disabled)      { transform: scale(0.90); transition: transform 80ms; }

/* Toast notifications */
.toast-container {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 80px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  pointer-events: none;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(-4px); }
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--dark-600);
  color: var(--text-primary);
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  animation: toast-in 300ms var(--ease-gentle) both;
  white-space: nowrap;
}
.toast.success { border-color: var(--accent); color: var(--accent); }
.toast.error   { border-color: var(--error);  color: var(--error);  }
.toast.dismissing { animation: toast-out 300ms ease forwards; }

/* ── Accessibility: Reduced Motion ──────────────────────── */
/* Required for users with vestibular disorders (WCAG 2.1 AA criterion 2.3.3). */
/* Disables all decorative animations and transitions when the OS setting is on. */
@media (prefers-reduced-motion: reduce) {
  /* Loading text animation */
  .loading-text {
    animation: none;
  }

  /* Chat message entrance animation */
  .message {
    animation: none;
  }

  /* Typing indicator dots */
  .dot {
    animation: none;
    opacity: 0.6;
  }

  /* Quota ring animated fill */
  .quota-fill {
    transition: none;
  }

  /* UI transitions (hover effects, screen fade, input focus) */
  body,
  .screen,
  .btn-primary,
  .btn,
  .btn-icon,
  .btn-send,
  .btn-link,
  .input-field,
  .chat-input-wrap,
  .session-card {
    transition: none;
  }
  /* Brand image animations */
  .loading-portrait,
  .auth-logo-img {
    animation: none;
  }

  /* New UI polish elements */
  .msg-paragraph {
    animation: none;
    opacity: 1;
    transform: none;
  }
  .pw-strength-bar {
    transition: none;
  }
  .btn-primary:active,
  .btn-icon:active,
  .btn-send:active {
    transform: none;
  }
  .toast,
  .toast.dismissing {
    animation: none;
    opacity: 1;
  }
  .input-field.pulse-success {
    animation: none;
  }
}

/* ── Export PDF Button ──────────────────────────────────── */
.btn-export-pdf {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-left: var(--space-sm);
  padding: 5px 10px;
  background: transparent;
  border: 1px solid var(--dark-500);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color var(--duration-fast), color var(--duration-fast);
}
.btn-export-pdf:hover {
  border-color: var(--accent);
  color: var(--accent-light);
}
.btn-export-pdf svg {
  flex-shrink: 0;
}

/* ── Print / PDF Export ─────────────────────────────────── */
@media print {
  /* Utility: hide anything not meant for print */
  .print-hidden {
    display: none !important;
  }

  /* Hide all app chrome — only the chat messages survive.
     Root overflow and fixed positioning must be undone first so the
     browser's print renderer can measure the full document height. */
  html,
  body {
    background: #ffffff !important;
    color: #1a1a1a !important;
    margin: 0;
    padding: 0;
    /* Remove the overflow:hidden that clips content to viewport height */
    overflow: visible !important;
    height: auto !important;
  }

  /* .screen uses position:fixed; inset:0 — that pins every screen to the
     viewport and makes the page appear blank or truncated in print.
     Override ALL screens to static/block so the browser can paginate. */
  .screen {
    position: static !important;
    display: none !important;       /* hide every screen by default … */
    height: auto !important;
    overflow: visible !important;
    opacity: 1 !important;
    inset: auto !important;
  }

  /* … then show only the chat screen */
  #screen-chat {
    display: block !important;      /* block, not flex — avoids flex-height clipping */
    background: #ffffff !important;
  }

  /* Hide non-content screens (belt-and-suspenders alongside the .screen rule) */
  #screen-loading,
  #screen-code,
  #screen-dashboard,
  #screen-profile {
    display: none !important;
  }

  /* Hide interactive chrome inside the chat screen */
  .chat-header,
  .chat-input-area,
  .modal,
  .toast-container {
    display: none !important;
  }

  /* Chat messages: full width, no scroll container, white background */
  #chat-messages {
    display: block !important;
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
    background: #ffffff !important;
    padding: 24px 32px !important;
    position: static !important;
  }

  /* Individual messages — allow breaks BETWEEN messages, not within */
  .message {
    max-width: 80% !important;
    margin-bottom: 16px !important;
    page-break-inside: avoid;  /* legacy */
    break-inside: avoid;       /* modern */
    border-radius: 8px !important;
    box-shadow: none !important;
    animation: none !important;
    position: static !important;
  }

  .message-assistant {
    background: #f7f4ef !important;
    border: 1px solid #d6cfc4 !important;
    color: #1a1a1a !important;
  }

  /* Remove the gold left-border pseudo-element from print */
  .message-assistant::before {
    display: none !important;
  }

  .message-user {
    background: #ede8e0 !important;
    color: #1a1a1a !important;
    margin-left: auto !important;
  }

  .message-system,
  .message-close {
    color: #666666 !important;
    border-color: #cccccc !important;
    box-shadow: none !important;
  }

  /* Paragraph text inside assistant messages */
  .msg-paragraph {
    color: #1a1a1a !important;
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }

  .msg-paragraph:first-child {
    color: #7a6840 !important;
  }
}
