/* ─────────────────────────────────────────────────────────────────────────────
   Ebru — Main stylesheet
   Turkish AI brand: Aegean Teal palette
   Full token reference: branding/ebru-color-tokens.css
───────────────────────────────────────────────────────────────────────────── */

/* ── CSS variables ──────────────────────────────────────────────────────────── */
:root {
  --color-bg: #f7f5f0;            /* Parchment Ivory */
  --color-surface: #ffffff;       /* White Marble */
  --color-surface-warm: #f0ede6;  /* Stone Cream */
  --color-border: #e0ddd5;        /* Marble Line */
  --color-primary: #1a7a78;       /* Aegean Teal — İznik turquoise */
  --color-primary-dark: #125c5a;  /* Deep Teal — hover state */
  --color-primary-light: #d0ecea; /* Teal Mist — subtle backgrounds */
  --color-primary-pale: #eef8f7;  /* Teal Wash — selection, focus */
  --color-accent: #1a2744;        /* Bosphorus Navy — headlines */
  --color-flag-red: #c0392b;      /* Flag Red — error/alert ONLY (sparse) */
  --color-flag-red-dark: #96281b;
  --color-flag-red-light: #f8d7d5;
  --color-ebru-copper: #b87333;   /* Anatolian Copper — warm accent */
  --color-ebru-gold: #b8943f;     /* Ottoman Gold — premium highlight */
  --color-text: #1a1a1a;
  --color-text-muted: #6b6560;    /* Warm gray */
  --color-bilge: #1a6b3c;         /* educational green */
  --color-divan: #1a3a6b;         /* institutional navy */
  --color-katip: #4a2c6b;         /* business purple */
  --color-risale: #8b6914;        /* Risale-i Nur — warm gold/amber */
  --radius: 12px;
  --radius-sm: 6px;
  --shadow: 0 2px 16px rgba(26, 39, 68, 0.08);
  --shadow-md: 0 4px 32px rgba(26, 39, 68, 0.12);
  --font: 'Inter', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --nav-h: 60px;
}

/* ── Reset / base ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
}
a { color: inherit; text-decoration: none; }

/* ── Nav ─────────────────────────────────────────────────────────────────────── */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow);
}
.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
}
.logo {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--color-primary);
  letter-spacing: -0.5px;
}
.logo-lockup {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.logo-wordmark {
  height: 34px;
  width: auto;
  display: block;
}
.logo-mark {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}
.logo-ebru {
  font-weight: 300;
  color: var(--color-accent);
  margin-left: 4px;
}
.nav-tagline {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  flex: 1;
}
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.nav-links { display: flex; align-items: center; gap: 24px; margin-right: 16px; }
.nav-link {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-primary);
  padding: 6px 14px;
  border-radius: 6px;
  transition: all 0.18s;
  background: var(--color-primary-pale);
  border: 1px solid var(--color-primary-light);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.nav-link:hover {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  border-color: var(--color-primary);
  box-shadow: 0 2px 8px rgba(26, 122, 120, 0.15);
}
.nav-menu-btn {
  display: none;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-size: 1.1rem;
}
.landing-profile-menu {
  margin-left: auto;
  position: relative;
}
.profile-avatar-btn {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-size: 1rem;
}
.profile-avatar-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.profile-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 120;
}
.profile-dropdown[hidden] {
  display: none !important;
}
.profile-dropdown-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-border);
}
.profile-dropdown-head small {
  color: var(--color-text-muted);
  font-size: 0.75rem;
}
.profile-dropdown-btn {
  width: 100%;
  text-align: left;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--color-bg);
  cursor: pointer;
  font-size: 0.85rem;
}
.profile-dropdown-link {
  display: block;
}
.profile-dropdown-btn:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-pale);
}
.profile-dropdown-btn.danger {
  border-color: var(--color-flag-red);
  color: var(--color-flag-red);
}
.profile-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 16px;
}
.profile-modal-backdrop[hidden] {
  display: none !important;
}
.profile-modal {
  width: min(520px, 100%);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  padding: 16px;
  box-shadow: var(--shadow-md);
}
.profile-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.profile-modal-avatar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.profile-modal-avatar-row img {
  width: 56px;
  height: 56px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid var(--color-border);
}
.profile-modal-avatar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.profile-file-input-label {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  align-self: center;
}
.profile-file-input {
  max-width: 220px;
  font-size: 0.78rem;
}
.profile-modal form label {
  display: block;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}
.profile-modal form .input-text,
.profile-modal form .input-select {
  margin-bottom: 10px;
}
.profile-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.feedback-modal {
  max-width: 560px;
}
.feedback-modal .input-textarea,
.feedback-modal .input-select,
.feedback-modal .input-text {
  margin-bottom: 10px;
}
.feedback-status {
  min-height: 1.4em;
  margin: 6px 0 12px;
  font-size: 0.84rem;
  color: var(--color-text-muted);
}
.feedback-status.success {
  color: var(--color-primary-dark);
}
.feedback-status.error {
  color: var(--color-flag-red-dark);
}

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.15s;
  line-height: 1.4;
}
.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.btn-primary:hover { background: var(--color-primary-dark); border-color: var(--color-primary-dark); }
.btn-outline {
  background: transparent;
  color: var(--color-primary);
  border-color: var(--color-primary);
}
.btn-outline:hover { background: var(--color-primary-light); }
.btn-lg { padding: 12px 28px; font-size: 1rem; border-radius: var(--radius); }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-send {
  padding: 10px 20px;
  align-self: flex-end;
  white-space: nowrap;
}

/* ── Hero ─────────────────────────────────────────────────────────────────────── */
.hero {
  padding: 80px 24px 60px;
  text-align: center;
  background: linear-gradient(160deg, #ffffff 0%, var(--color-primary-pale) 50%, var(--color-bg) 100%);
}
.hero-inner { max-width: 720px; margin: 0 auto; }
.hero-wordmark {
  width: min(100%, 360px);
  margin-bottom: 20px;
}
.hero-title {
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 800;
  line-height: 1.15;
  color: var(--color-accent);
  margin-bottom: 20px;
}
.accent { color: var(--color-primary); }
.hero-sub {
  font-size: 1.1rem;
  color: var(--color-text-muted);
  margin-bottom: 36px;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}
.hero-cta { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.hero-motif {
  width: min(100%, 600px);
  margin-top: 32px;
  opacity: 0.75;
}

/* ── Section shared ──────────────────────────────────────────────────────────── */
.section-inner { max-width: 1100px; margin: 0 auto; padding: 0 24px; }
.section-title {
  font-size: 1.8rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 10px;
  color: var(--color-accent);
}
.section-sub {
  text-align: center;
  color: var(--color-text-muted);
  margin-bottom: 40px;
}

/* ── Mode cards ──────────────────────────────────────────────────────────────── */
.modes { padding: 60px 0; }
.mode-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
}
.mode-card {
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  padding: 32px 28px;
  cursor: pointer;
  transition: all 0.18s;
  box-shadow: var(--shadow);
}
.mode-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.mode-ebru:hover   { border-color: var(--color-primary); }
.mode-divan:hover  { border-color: var(--color-divan); }
.mode-katip:hover  { border-color: var(--color-katip); }
.mode-icon { font-size: 2.4rem; margin-bottom: 14px; }
.mode-name { font-size: 1.3rem; font-weight: 700; margin-bottom: 10px; }
.mode-desc { font-size: 0.92rem; color: var(--color-text-muted); margin-bottom: 16px; }
.mode-tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--color-bg);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

/* ── Features ────────────────────────────────────────────────────────────────── */
.features {
  padding: 60px 0;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
}
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 32px;
}
.feature-item { text-align: center; }
.feature-icon { font-size: 2rem; display: block; margin-bottom: 10px; }
.feature-item h4 { font-size: 1rem; font-weight: 700; margin-bottom: 6px; }
.feature-item p { font-size: 0.88rem; color: var(--color-text-muted); }

/* ── About ───────────────────────────────────────────────────────────────────── */
.about {
  padding: 60px 0;
  background: linear-gradient(135deg, var(--color-surface-warm) 0%, var(--color-primary-pale) 100%);
  border-top: 3px solid var(--color-primary);
  border-bottom: 1px solid var(--color-border);
  scroll-margin-top: 80px;
}
.about .section-title {
  position: relative;
  display: inline-block;
  width: 100%;
  color: var(--color-primary);
}
.about-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  margin-top: 40px;
}
.about-block {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.about-block-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: 6px;
  position: relative;
  padding-left: 12px;
}
.about-block-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--color-primary);
  border-radius: 2px;
}
.about-block p {
  font-size: 0.92rem;
  color: var(--color-text-muted);
  line-height: 1.7;
}
.about-block strong {
  color: var(--color-text);
  font-weight: 600;
}
.founder-link {
  color: var(--color-primary);
  font-weight: 500;
  transition: color 0.15s;
}
.founder-link:hover {
  color: var(--color-primary-dark);
}

@media (max-width: 768px) {
  .about-content {
    grid-template-columns: 1fr;
    gap: 28px;
  }
}

/* ── Footer ──────────────────────────────────────────────────────────────────── */
.footer {
  padding: 36px 24px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.85rem;
}
.footer .logo { display: block; margin-bottom: 8px; }
.footer-wordmark { margin: 0 auto 8px; }
.footer-note { margin-top: 8px; font-size: 0.78rem; }

/* ────────────────────────────────────────────────────────────────────────────
   CHAT PAGE
───────────────────────────────────────────────────────────────────────────── */
body.chat-page {
  /* Fallback for older browsers */
  height: 100vh;
  /* Use 100dvh for better mobile keyboard handling */
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.chat-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────────── */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 20px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  z-index: 20;
}
.sidebar-backdrop { display: none; }
.sidebar-mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.sidebar-mobile-wordmark {
  width: 140px;
  height: auto;
}
.sidebar-close-btn {
  border: none;
  background: transparent;
  font-size: 1rem;
  cursor: pointer;
  color: var(--color-text-muted);
}
.sidebar-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}
.mode-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 12px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}
.mode-btn:hover { border-color: var(--color-primary); background: var(--color-primary-light); }
.mode-btn.active { border-color: var(--color-primary); background: var(--color-primary-light); }
.mode-btn-icon { font-size: 1.5rem; flex-shrink: 0; }
.mode-btn-info { display: flex; flex-direction: column; }
.mode-btn-info strong { font-size: 0.9rem; line-height: 1.2; }
.mode-btn-info small { font-size: 0.75rem; color: var(--color-text-muted); }
.sidebar-divider { border: none; border-top: 1px solid var(--color-border); margin: 8px 0; }
.sidebar-section { display: flex; flex-direction: column; gap: 6px; font-size: 0.82rem; }
.sidebar-section h4 { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-text-muted); }
.input-text {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  background: var(--color-bg);
  color: var(--color-text);
}
.disclaimer-box {
  background: #fff8e1;
  border: 1px solid #f5d060;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.78rem;
  color: #6d5300;
  line-height: 1.45;
}

/* ── Chat main ──────────────────────────────────────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  min-width: 0;
}
.chat-header {
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-accent);
  /* Padding: fallback for older browsers */
  padding-top: 12px;
  padding-bottom: 12px;
  padding-left: 20px;
  padding-right: 20px;
  /* Add safe area for notched devices */
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  /* Flex shrink to prevent issues */
  flex-shrink: 0;
}
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 16px;
  /* Ensure proper scroll behavior on mobile */
  min-height: 0;
  /* Padding: fallback for older browsers */
  padding-top: 20px;
  padding-left: 20px;
  padding-right: 20px;
  padding-bottom: 20px;
  /* Add safe area for notched devices (left/right/bottom only; top not needed for scrollable content) */
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}
.message { display: flex; gap: 12px; }
.message.user { justify-content: flex-end; }
.message-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(100%, 680px);
}
.message-bubble {
  padding: 14px 16px;
  border-radius: var(--radius);
  line-height: 1.7;
  font-size: 1rem;
  white-space: pre-wrap;
  word-break: break-word;
  /* Better handling for long words on mobile */
  overflow-wrap: break-word;
  /* Ensure proper wrapping in narrow viewports */
  min-width: 0;
}
.message.user .message-bubble {
  background: var(--color-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.message.assistant .message-bubble {
  background: var(--color-surface);
  border: 1.5px solid var(--color-primary);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(26, 39, 68, 0.12);
  color: var(--color-text);
}
.message.welcome-msg .message-bubble {
  background: linear-gradient(135deg, var(--color-primary-light), #fff);
  border-color: var(--color-primary);
}
.message-typing .message-bubble {
  color: var(--color-text-muted);
  font-style: italic;
}
.citation-panel {
  background: #f7f3ea;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.8rem;
  color: var(--color-text);
  margin-top: 6px;
  width: 100%;
}
.citation-panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}
.citation-toggle-btn {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 0.72rem;
  cursor: pointer;
  color: var(--color-text-muted);
  transition: background 0.12s;
}
.citation-toggle-btn:hover { background: var(--color-primary-light); }
.citation-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.citation-list-collapsed {
  display: none;
}
.citation-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.citation-heading {
  font-weight: 700;
}
.citation-meta {
  color: var(--color-text-muted);
}
.citation-excerpt-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.citation-excerpt-toggle {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.75rem;
  color: var(--color-primary);
  cursor: pointer;
  text-align: left;
}
.citation-excerpt-toggle:hover { text-decoration: underline; }
.citation-excerpt {
  color: var(--color-text-muted);
  font-style: italic;
  padding: 4px 6px;
  background: rgba(0,0,0,0.03);
  border-left: 2px solid var(--color-border);
  border-radius: 2px;
}
.citation-excerpt-hidden {
  display: none;
}
.citation-link {
  color: var(--color-divan);
  font-size: 0.75rem;
  text-decoration: none;
}
.citation-link:hover { text-decoration: underline; }

/* ── Operator debug panel ────────────────────────────────────────────────────── */
.debug-panel {
  background: #1a1a2e;
  border: 1px solid #444;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.75rem;
  color: #e0e0e0;
  margin-top: 6px;
  overflow-x: auto;
}
.debug-panel-title {
  font-weight: 700;
  color: #7fb3ff;
  margin-bottom: 8px;
  letter-spacing: 0.03em;
}
.debug-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.72rem;
}
.debug-table th {
  text-align: left;
  color: #aaa;
  padding: 2px 8px 4px 0;
  border-bottom: 1px solid #444;
  font-weight: 600;
}
.debug-table td {
  padding: 3px 8px 3px 0;
  vertical-align: top;
  border-bottom: 1px solid #2a2a3e;
}
.debug-score {
  font-weight: 700;
  color: #7fb3ff;
  white-space: nowrap;
}
.debug-excerpt {
  color: #bbb;
  max-width: 320px;
}

/* ── Risale mode button accent ───────────────────────────────────────────────── */
.mode-btn-risale { border-left: 3px solid var(--color-risale); }
.mode-btn-risale.active { background: #fdf5e0; border-color: var(--color-risale); }

/* ── Image mode button accent ───────────────────────────────────────────────── */
.mode-btn-image { border-left: 3px solid var(--color-ebru-copper); }
.mode-btn-image:hover { background: #fdf7f0; border-color: var(--color-ebru-copper); }

/* ── Input select ────────────────────────────────────────────────────────────── */
.input-select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  background: var(--color-bg);
  color: var(--color-text);
  cursor: pointer;
}

/* ── Image generation panel ──────────────────────────────────────────────────── */
.image-panel-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 200;
}
body.image-panel-open .image-panel-backdrop { display: block; }
body.image-panel-open .image-panel { transform: translateX(0); }

.image-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 96vw);
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  box-shadow: var(--shadow-md);
  z-index: 210;
  display: flex;
  flex-direction: column;
  transform: translateX(105%);
  transition: transform 0.2s ease;
  overflow-y: auto;
}
.image-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  background: var(--color-surface);
  z-index: 1;
}
.image-panel-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-accent);
}
.image-panel-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.image-panel-hint {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  line-height: 1.45;
}
.image-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}
.image-prompt-textarea {
  min-height: 80px;
  resize: vertical;
}
.image-options-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.image-option-group { display: flex; flex-direction: column; }
.image-generate-btn {
  width: 100%;
  padding: 12px;
  font-size: 0.95rem;
  font-weight: 700;
}
.image-status {
  font-size: 0.84rem;
  color: var(--color-text-muted);
  padding: 8px 10px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
}
.image-status.error {
  color: var(--color-flag-red);
  background: var(--color-flag-red-light);
  border-color: var(--color-flag-red);
}
.image-result {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.image-result-img {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  display: block;
}
.image-result-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.image-revised-prompt {
  font-size: 0.76rem;
  color: var(--color-text-muted);
  font-style: italic;
  line-height: 1.4;
  padding: 8px 10px;
  background: var(--color-primary-pale);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--color-primary);
}

/* ── Operator panel ──────────────────────────────────────────────────────────── */
.operator-panel h4 { color: var(--color-text-muted); }
.operator-debug-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
}
.operator-debug-hint {
  display: block;
  color: var(--color-text-muted);
  font-size: 0.72rem;
  line-height: 1.4;
  margin-top: 4px;
}


/* ── Input area ──────────────────────────────────────────────────────────────── */
.chat-input-area {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  /* Padding: fallback for older browsers */
  padding-top: 12px;
  padding-left: 20px;
  padding-right: 20px;
  padding-bottom: 16px;
  /* Add safe area support for notched devices and iOS keyboard */
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  /* Prevent shrinking and ensure visibility */
  flex-shrink: 0;
  box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.05);
}
.sample-questions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.sample-q {
  padding: 5px 12px;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  font-size: 0.8rem;
  cursor: pointer;
  background: var(--color-bg);
  transition: all 0.12s;
}
.sample-q:hover { border-color: var(--color-primary); background: var(--color-primary-light); }
.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  /* Prevent shrinking of input area on mobile */
  min-width: 0;
}
.chat-textarea {
  flex: 1;
  padding: 12px 14px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 1rem;
  resize: none;
  line-height: 1.6;
  background: var(--color-bg);
  transition: border-color 0.15s;
}
.chat-textarea:focus { outline: none; border-color: var(--color-primary); background: #fff; }
.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}
.message-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all 0.12s;
}
.message-action-btn:hover,
.message-action-btn.is-active {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-light);
}

/* ── Demo start button ──────────────────────────────────────────────────────── */
.demo-start-section {
  text-align: center;
}
.btn-demo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 9px 14px;
  background: linear-gradient(135deg, var(--color-risale), #b8890e);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s, transform 0.12s;
  letter-spacing: 0.02em;
}
.btn-demo:hover { opacity: 0.88; transform: translateY(-1px); }
.demo-start-hint {
  display: block;
  color: var(--color-text-muted);
  font-size: 0.72rem;
  margin-top: 4px;
  text-align: center;
}

/* ── Voice input ─────────────────────────────────────────────────────────────── */
.btn-mic {
  padding: 10px 14px;
  align-self: flex-end;
  background: var(--color-bg);
  border: 2px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 1.1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-mic:hover { border-color: var(--color-primary); color: var(--color-primary); background: var(--color-primary-light); }
.btn-mic.mic-active {
  background: #fee2e2;
  border-color: #ef4444;
  color: #dc2626;
  animation: mic-pulse 1.2s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.35); }
  50%       { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}
.voice-status {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  min-height: 1.2em;
}

/* ── Speak (TTS) button on assistant messages ────────────────────────────────── */
.speak-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  cursor: pointer;
  margin-top: 6px;
  transition: all 0.12s;
}
.speak-btn:hover { border-color: var(--color-primary); color: var(--color-primary); background: var(--color-primary-light); }

/* ── Voice panel sidebar ─────────────────────────────────────────────────────── */
.voice-panel h4 { color: var(--color-text-muted); }

/* ── Session history panel ──────────────────────────────────────────────────── */
.history-panel { gap: 4px; }
.history-panel h4 { color: var(--color-text-muted); }
.history-empty {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  font-style: italic;
  padding: 4px 0;
}
.history-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, border-color 0.12s;
  font-family: var(--font);
}
.history-item:hover { background: var(--color-bg); border-color: var(--color-primary); }
.history-item-body { flex: 1; min-width: 0; }
.history-item-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
.history-item-meta {
  font-size: 0.72rem;
  color: var(--color-text-muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
.history-item-delete {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  padding: 0 2px;
  line-height: 1;
  opacity: 0.5;
  transition: opacity 0.12s;
}
.history-item-delete:hover { opacity: 1; color: var(--color-primary); }
.dashboard-panel { gap: 8px; }
.dashboard-panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.dashboard-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.dashboard-stat {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  padding: 8px 10px;
}
.dashboard-stat strong {
  display: block;
  font-size: 0.95rem;
  color: var(--color-accent);
}
.dashboard-stat span,
.dashboard-list,
.dashboard-list li,
.share-banner {
  font-size: 0.76rem;
}
.dashboard-list {
  margin: 0;
  padding-left: 16px;
  color: var(--color-text-muted);
}
.dashboard-list li + li { margin-top: 4px; }
.share-banner {
  margin: 0 20px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: #eef5ff;
  border: 1px solid #c9dcff;
  color: #284b7a;
}

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 960px) {
  .nav-menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .nav-tagline { display: none; }
  .logo-wordmark { height: 30px; }
  .logo-lockup .logo-wordmark { max-width: 170px; }
  .sidebar-backdrop {
    position: fixed;
    inset: var(--nav-h) 0 0 0;
    background: rgba(0,0,0,0.35);
  }
  .sidebar-mobile-header { display: flex; }
  .sidebar {
    position: fixed;
    top: var(--nav-h);
    left: 0;
    bottom: 0;
    width: min(320px, 85vw);
    transform: translateX(-105%);
    transition: transform 0.18s ease;
    box-shadow: var(--shadow-md);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { display: block; }
  .chat-main { min-width: 0; width: 100%; }
  .chat-header { flex-wrap: wrap; gap: 8px; }
  .input-row { align-items: stretch; }
}
@media (max-width: 700px) {
  .hero-title { font-size: 1.8rem; }
  .logo-mark { width: 24px; height: 24px; }
  .logo-lockup .logo-wordmark { max-width: 150px; }
  /* Fallback for older browsers */
  .messages,
  .chat-input-area,
  .chat-header { padding-left: 14px; padding-right: 14px; }
  /* Add safe area support for notched devices */
  .messages,
  .chat-input-area,
  .chat-header { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  /* Increase gap for better message separation on mobile */
  .messages { gap: 20px; }
  .input-row { flex-direction: column; }
  .btn-send,
  .btn-mic { width: 100%; justify-content: center; }
  .sample-questions { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }
  .sample-q { flex-shrink: 0; }
  .dashboard-summary-grid { grid-template-columns: 1fr; }
  .share-banner { margin: 0 14px; }
}
@media (max-width: 500px) {
  /* Keep fixed layout on mobile, don't let it scroll */
  body.chat-page { overflow: hidden; }
  .chat-main { overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
  /* Remove the max-height constraint that breaks flex layout */
  .messages { max-height: none; }
  .message-content { max-width: 100%; }
  .citation-panel-title { align-items: flex-start; gap: 6px; flex-direction: column; }
  .debug-table { min-width: 520px; }
}
