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

body, html {
  width: 100%;
  height: 100%;
  font-family: 'Plus Jakarta Sans', sans-serif;
  overflow: hidden;
  background-color: #121212;
  color: #ffffff;
}

/* The whole UI sits on dark surfaces, so the browser's default link colours
   (#0000EE, and #551A8B when visited) are unreadable. Default every link to
   the Imperial Gold accent; specific components can still override below.
   This is a safety net so new markup never reintroduces dark blue links. */
a {
  color: #ebd08a;
}

a:visited {
  color: #ebd08a;
}

/* ------------------------------------
   HERO CONTAINER (CLEAN BACKGROUND)
------------------------------------ */
.hero-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  /* dvh follows the on-screen keyboard on phones; the fallback above keeps
     older browsers on the layout viewport. --kb-inset is the extra part the
     keyboard covers that dvh does not account for on iOS Safari. */
  height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 2.5rem 2rem calc(2.5rem + var(--kb-inset, 0px));
  
  background-image: url('background.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.hero-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 1;
}

/* ------------------------------------
   TOP HEADER & MENU BUTTON
------------------------------------ */
.menu-btn {
  position: absolute;
  top: 2rem;
  left: 2.5rem;
  z-index: 12;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: all 0.25s ease;
}

.menu-btn:hover {
  background: rgba(0, 0, 0, 0.55);
  transform: scale(1.05);
}

.menu-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background-color: #ffffff;
  border-radius: 2px;
}

/* ------------------------------------
   SIDEBAR DRAWER OVERLAY
------------------------------------ */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.sidebar-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 380px;
  max-width: 85vw;
  background: transparent;
  border-right: 1px solid rgba(255, 255, 255, 0.12);
  z-index: 101;
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  transform: translateX(-100%);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  overflow-y: auto;
  box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.sidebar-title {
  font-size: 1.2rem;
  font-weight: 500;
  color: #ffffff;
  line-height: 1.3;
}

.close-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: #d63d1e;
  border: none;
  color: #ffffff;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.close-btn-pattern {
  position: absolute;
  inset: 0;
  background-image: url('send.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.6;
  z-index: 1;
  pointer-events: none;
}

.close-btn svg {
  position: relative;
  z-index: 2;
}

.close-btn:hover {
  transform: scale(1.08);
}

.nav-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}


.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px; /* 🟢 Allows the button to expand if text wraps */
  height: auto;
  padding: 10px 18px; /* 🟢 Vertical padding so wrapped text looks spaced */
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.92);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  position: relative;
  background: transparent;
  transition: background 0.25s ease, color 0.25s ease;
  user-select: none;
  overflow: hidden; /* 🟢 Automatically and cleanly clips everything to the pill shape */
  white-space: normal; /* 🟢 Allows text to wrap safely instead of truncating with ... */
}


.sidebar-nav-item span {
  position: relative;
  z-index: 2;
  line-height: 1.3;
}

.sidebar.searching .hide-on-search {
  display: none !important;
}

.sidebar-nav-item.is-selected {
  background: #c82316;
  color: #ffffff;
}

.sidebar-nav-item::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 60px;
  background-image: url('button_corner.png');
  background-size: cover; /* 🟢 Changed from contain to cover */
  background-position: left center;
  background-repeat: no-repeat;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
  z-index: 1;
}

.sidebar-nav-item::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 60px;
  background-image: url('button_corner.png');
  background-size: cover; /* 🟢 Changed from contain to cover */
  background-position: right center;
  background-repeat: no-repeat;
  transform: scaleX(-1);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
  z-index: 1;
}

.sidebar-nav-item.is-selected::before,
.sidebar-nav-item.is-selected::after {
  opacity: 1;
}

.nav-icon {
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

.sidebar-nav-item span {
  position: relative;
  z-index: 2;
}

.sidebar-search-input {
  display: none;
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #ffffff;
  font-size: 0.98rem;
  font-family: inherit;
  padding: 0 4px;
  position: relative;
  z-index: 2;
}

.sidebar-search-input::placeholder {
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.98rem;
}

.sidebar-nav-item.active .search-label {
  display: none;
}

.sidebar-nav-item.active .sidebar-search-input {
  display: block;
}

/* A phone keyboard has no Escape key, so search mode needs a visible exit. */
.search-cancel-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  margin-left: 4px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  cursor: pointer;
}
.sidebar-nav-item.active .search-cancel-btn { display: inline-flex; }
.search-cancel-btn:hover { background: rgba(255, 255, 255, 0.22); }
.search-cancel-btn:focus-visible { outline: 2px solid #ebd08a; outline-offset: 2px; }

/* Voice settings sit below the history list, pinned to the bottom of the
   sidebar so the recent conversations keep the top. */
.sidebar-footer {
  flex-shrink: 0;
  margin-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding-top: 0.75rem;
}

.sidebar-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.12);
  margin: 1.25rem 0;
}

.recent-section {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.recent-title {
  font-size: 0.88rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.45);
  margin-bottom: 0.75rem;
}

.recent-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.recent-list li {
  padding: 8px 12px;
  border-radius: 10px;
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.95rem;
  line-height: 1.4;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-list li:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

/* Search results need two lines (title + snippet), so they opt out of the
   single-line ellipsis behaviour above. */
.recent-list li.recent-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  white-space: normal;
}

.recent-item-title {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-item-snippet {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 0.8rem;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.55);
}

.recent-highlight {
  background: rgba(235, 208, 138, 0.28);
  color: #ebd08a;
  border-radius: 3px;
  padding: 0 1px;
}

.recent-list li.recent-empty {
  cursor: default;
  opacity: 0.7;
  font-size: 0.85rem;
  padding: 10px 8px;
  white-space: normal;
  line-height: 1.45;
}

.recent-list li.recent-empty:hover {
  background: transparent;
}

.recent-login-link {
  color: #ebd08a;
  text-decoration: underline;
}

/* ------------------------------------
   SIDEBAR VOICE / TTS CONTROLS
------------------------------------ */
.sidebar-voice-section {
  padding: 0;
}

.sidebar-voice-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.92);
  text-transform: none;
  letter-spacing: normal;
  margin: 0;
  list-style: none;
}

.sidebar-voice-title::-webkit-details-marker {
  display: none;
}

.sidebar-voice-title .nav-icon {
  color: #fffefc;
}

.sidebar-voice-chevron {
  margin-left: auto;
  font-size: 1.2rem;
  color: rgba(255, 255, 255, 0.65);
}

.sidebar-voice-chevron::before {
  content: '+';
}

.sidebar-voice-section[open] .sidebar-voice-chevron::before {
  content: '−';
}

.sidebar-voice-section > :not(.sidebar-voice-title) {
  margin-left: 14px;
  margin-right: 14px;
}

.sidebar-voice-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  transition: background 0.2s ease;
}

.sidebar-voice-toggle:hover {
  background: rgba(255, 255, 255, 0.07);
}

.sidebar-voice-toggle strong {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
}

.sidebar-voice-toggle small {
  display: block;
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.45);
  margin-top: 2px;
}

.sidebar-voice-picker {
  margin-top: 10px;
}

.sidebar-voice-picker label {
  display: block;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 5px;
}

.sidebar-voice-select {
  width: 100%;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.78rem;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.sidebar-voice-select:hover,
.sidebar-voice-select:focus {
  border-color: rgba(235, 208, 138, 0.4);
}

.sidebar-voice-select option {
  background: #1a1a2e;
  color: #fff;
}

.sidebar-voice-select optgroup {
  font-style: normal;
  color: rgba(255, 255, 255, 0.5);
}

.sidebar-test-voice-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 7px 14px;
  border: 1px solid rgba(235, 208, 138, 0.25);
  border-radius: 8px;
  background: rgba(235, 208, 138, 0.06);
  color: #ebd08a;
  font-size: 0.78rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.sidebar-test-voice-btn:hover,
.sidebar-test-voice-btn.playing {
  background: rgba(235, 208, 138, 0.12);
  border-color: rgba(235, 208, 138, 0.45);
}

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

/* ------------------------------------
   CENTERED SCROLLABLE CHAT CONTAINER
------------------------------------ */
.chat-stream-container {
  position: absolute;
  top: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 820px;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  z-index: 10;
  padding: 1rem;
  /* Room for the composer plus whatever the keyboard covers, so the last lines
     of an answer are never hidden behind it. */
  max-height: calc(100vh - 140px - var(--kb-inset, 0px));
  overflow-y: auto;
  scroll-behavior: smooth;
  pointer-events: auto; /* Enables scrolling and clicking */
}

/* Custom Scrollbar */
.chat-stream-container::-webkit-scrollbar {
  width: 6px;
}

.chat-stream-container::-webkit-scrollbar-track {
  background: transparent;
}

.chat-stream-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
}

.chat-stream-container::-webkit-scrollbar-thumb:hover {
  background: rgba(235, 208, 138, 0.4);
}

.user-message-bubble {
  pointer-events: auto;
  align-self: flex-end;
  background: rgba(28, 28, 28, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #ffffff;
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 1.05rem;
  font-weight: 400;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity 0.35s ease, transform 0.35s ease, visibility 0.35s ease;
}

.user-message-bubble.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.ai-response-card {
  pointer-events: auto;
  align-self: flex-start;
  max-width: 100%;
  background: rgba(24, 24, 24, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #e5e5e5;
  padding: 1.5rem 1.75rem;
  border-radius: 20px;
  font-size: 1.02rem;
  line-height: 1.65;
  font-weight: 400;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: opacity 0.4s ease, transform 0.4s ease, visibility 0.4s ease;
}

.ai-response-card.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* ------------------------------------
   MARKDOWN FORMATTING STYLES FOR AI CARD
------------------------------------ */
.ai-response-card p {
  margin-bottom: 0.75rem;
}

.ai-response-card p:last-child {
  margin-bottom: 0;
}

/* Bold text in Imperial Gold Accent */
.ai-response-card strong, 
.ai-response-card b {
  color: #ebd08a;
  font-weight: 600;
}

.ai-response-card ul, 
.ai-response-card ol {
  margin-left: 1.25rem;
  margin-bottom: 0.75rem;
}

.ai-response-card li {
  margin-bottom: 0.25rem;
}

.ai-response-card h1, 
.ai-response-card h2, 
.ai-response-card h3, 
.ai-response-card h4 {
  font-family: 'Playfair Display', Georgia, serif;
  color: #ebd08a;
  margin-top: 1rem;
  margin-bottom: 0.5rem;
}

.ai-response-card code {
  background: rgba(0, 0, 0, 0.4);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9em;
}

/* Links inside AI answers come from marked.js parsing model output, so they
   have no class we can target — they were falling back to the browser default
   #0000EE (and #551A8B once visited), which is nearly unreadable on the
   near-black card. Match the Imperial Gold accent used by strong/headings.
   :visited is set explicitly, otherwise visited links revert to purple. */
.ai-response-card a,
.ai-response-card a:visited {
  color: #ebd08a;
  text-decoration: underline;
  text-decoration-color: rgba(235, 208, 138, 0.45);
  text-underline-offset: 2px;
  transition: color 0.2s ease, text-decoration-color 0.2s ease;
}

.ai-response-card a:hover,
.ai-response-card a:focus-visible {
  color: #f5e3b3;
  text-decoration-color: #f5e3b3;
}

.ai-response-card a:focus-visible {
  outline: 2px solid #ebd08a;
  outline-offset: 2px;
  border-radius: 2px;
}

/* The user's own message bubble can contain pasted links too. */
.user-message-bubble a,
.user-message-bubble a:visited {
  color: #ebd08a;
  text-decoration: underline;
  text-decoration-color: rgba(235, 208, 138, 0.45);
  text-underline-offset: 2px;
}

.user-message-bubble a:hover {
  color: #f5e3b3;
  text-decoration-color: #f5e3b3;
}

/* ------------------------------------
   MAIN CENTER TYPOGRAPHY
------------------------------------ */
.hero-content {
  position: relative;
  z-index: 10;
  text-align: center;
  max-width: 900px;
  margin-top: auto;
  margin-bottom: auto;
  transition: opacity 0.4s ease, transform 0.4s ease, visibility 0.4s ease;
}

.hero-content.hidden {
  opacity: 0;
  visibility: hidden;
  transform: translateY(-20px);
  pointer-events: none;
}

.hero-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: clamp(2.5rem, 5vw, 4.8rem);
  font-weight: 400;
  line-height: 1.15;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.6);
  letter-spacing: 0.5px;
  margin-bottom: 0.4rem;
}

.hero-subtitle {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: clamp(1.3rem, 2.4vw, 2.2rem);
  font-weight: 400;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 0 3px 12px rgba(0, 0, 0, 0.6);
}

/* ------------------------------------
   FLOATING AI SEARCH BAR
------------------------------------ */
.ai-bar-container {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 680px;
  margin-bottom: 1rem;
}

.ai-bar {
  width: 100%;
  height: 60px;
  background: #181818;
  border: 1px solid #3c3c3c;
  border-radius: 999px;
  display: flex;
  align-items: center;
  padding: 0 8px 0 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  transition: all 0.3s ease;
}

.icon-btn {
  background: transparent;
  border: none;
  color: #ffffff;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

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

.ai-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: #ffffff;
  font-size: 1.05rem;
  font-family: inherit;
  padding: 0 12px;
}

.ai-input::placeholder {
  color: rgba(255, 255, 255, 0.85);
  font-size: 1.05rem;
}

/* The prompt is a textarea so a long, multi-line question is not hidden on a
   phone; one row by default, grown by script.js up to 168px. */
textarea.ai-input {
  resize: none;
  overflow-y: hidden;
  line-height: 1.45;
  padding: 9px 12px;
  max-height: 168px;
  align-self: center;
}

/* Growing the field must not push the buttons off the bar. */
.ai-bar.grown {
  align-items: flex-end;
  height: auto;
  min-height: 52px;
  padding-block: 5px;
  /* A pill with a 999px radius looks wrong once the bar is multi-line. */
  border-radius: 22px;
}

.right-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 0;
}

.mic-btn-container {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #363636;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  overflow: hidden;
  
  transition: width 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.25s ease,
              transform 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0.35s ease;
}

.mic-btn-container:hover {
  background: #444444;
}

.mic-btn-container.hidden {
  width: 0;
  opacity: 0;
  visibility: hidden;
  transform: scale(0.6);
  pointer-events: none;
}

.send-btn {
  width: 0;
  height: 44px;
  border-radius: 50%;
  background-color: #d63d1e;
  border: none;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  margin-left: 0;

  opacity: 0;
  visibility: hidden;
  transform: scale(0.6);

  transition: width 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              margin-left 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.25s ease,
              transform 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0.35s ease;
}

.send-btn.active {
  width: 44px;
  margin-left: 8px;
  opacity: 1;
  visibility: visible;
  transform: scale(1);
}

.send-btn-pattern {
  position: absolute;
  inset: 0;
  background-image: url('send.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.6;
  z-index: 1;
  pointer-events: none;
}

.send-btn svg {
  position: relative;
  z-index: 2;
  color: #ffffff;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}

.stop-btn {
  width: 0;
  height: 44px;
  border-radius: 50%;
  background-color: #d63d1e;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  margin-left: 0;
  overflow: hidden;

  opacity: 0;
  visibility: hidden;
  transform: scale(0.6);

  transition: width 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              margin-left 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.25s ease,
              transform 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0.35s ease;
}

.stop-btn.active {
  width: 44px;
  margin-left: 8px;
  opacity: 1;
  visibility: visible;
  transform: scale(1);
}

.stop-icon {
  width: 14px;
  height: 14px;
  background-color: #ffffff;
  border-radius: 3px;
}

/* ------------------------------------
   IMAGE ATTACHMENTS & LIVE AUDIO
------------------------------------ */
.attachment-menu {
  position: absolute;
  left: 0;
  bottom: calc(100% + 10px);
  width: min(360px, calc(100vw - 2rem));
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 18px;
  background: rgba(20, 20, 20, 0.96);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.55);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px) scale(0.98);
  transform-origin: bottom left;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s ease;
  z-index: 30;
}

.attachment-menu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.attachment-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: #ffffff;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s ease;
}

.attachment-menu-item:hover,
.attachment-menu-item:focus-visible {
  background: rgba(255, 255, 255, 0.09);
  outline: none;
}

.attachment-menu-item > span:last-child {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.attachment-menu-item strong {
  font-size: 0.92rem;
  font-weight: 600;
}

.attachment-menu-item small {
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.76rem;
  line-height: 1.35;
}

.attachment-menu-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  border-radius: 11px;
  color: #ebd08a;
  background: rgba(235, 208, 138, 0.1);
  border: 1px solid rgba(235, 208, 138, 0.16);
}

.attachment-tray {
  width: 100%;
  margin-bottom: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 18px;
  background: rgba(20, 20, 20, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.42);
  animation: tray-in 0.22s ease both;
}

.attachment-tray[hidden] {
  display: none;
}

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

.attachment-tray-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
  padding: 0 2px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.76rem;
}

.clear-attachments-btn {
  border: 0;
  background: transparent;
  color: #ebd08a;
  font-family: inherit;
  font-size: 0.75rem;
  cursor: pointer;
}

.clear-attachments-btn:hover {
  color: #ffffff;
}

.attachment-list {
  display: flex;
  gap: 9px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.attachment-preview {
  position: relative;
  width: 76px;
  height: 68px;
  flex: 0 0 76px;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: #111111;
}

.attachment-preview img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.remove-attachment-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.72);
  color: #ffffff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.ai-bar.dragging {
  border-color: #ebd08a;
  background: #242017;
  box-shadow: 0 0 0 4px rgba(235, 208, 138, 0.13), 0 10px 30px rgba(0, 0, 0, 0.5);
}

.icon-btn.active {
  background: rgba(235, 208, 138, 0.14);
  color: #ebd08a;
  transform: rotate(45deg);
}

.composer-status {
  position: absolute;
  top: calc(100% + 7px);
  left: 16px;
  right: 16px;
  min-height: 16px;
  color: rgba(255, 255, 255, 0.68);
  text-align: center;
  font-size: 0.74rem;
  line-height: 1.35;
  pointer-events: none;
}

.composer-status.error {
  color: #ff9b89;
}

.audio-switch {
  position: relative;
  width: 40px;
  height: 23px;
  flex: 0 0 40px;
}

.audio-switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.audio-switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #494949;
  transition: background 0.2s ease;
}

.audio-switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s ease;
}

.audio-switch input:checked + .audio-switch-track {
  background: #c6a84e;
}

.audio-switch input:checked + .audio-switch-track::after {
  transform: translateX(17px);
}

.audio-switch input:focus-visible + .audio-switch-track {
  outline: 2px solid #ebd08a;
  outline-offset: 2px;
}

.audio-switch input:disabled + .audio-switch-track {
  opacity: 0.4;
  cursor: not-allowed;
}


.response-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 28px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.response-actions:empty {
  display: none;
}

.auto-read-indicator {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.56);
  background: rgba(255, 255, 255, 0.045);
  font-size: 0.72rem;
}

.auto-read-indicator.speaking {
  color: #ebd08a;
  background: rgba(235, 208, 138, 0.08);
}

.audio-wave {
  height: 13px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.audio-wave i {
  width: 2px;
  height: 5px;
  border-radius: 2px;
  background: currentColor;
}

.auto-read-indicator.speaking .audio-wave i {
  animation: audio-wave 0.75s ease-in-out infinite alternate;
}

.auto-read-indicator.speaking .audio-wave i:nth-child(2) {
  animation-delay: -0.35s;
}

.auto-read-indicator.speaking .audio-wave i:nth-child(3) {
  animation-delay: -0.15s;
}

@keyframes audio-wave {
  from { height: 4px; opacity: 0.45; }
  to { height: 13px; opacity: 1; }
}

.response-audio-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.response-audio-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 5px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: rgba(255, 255, 255, 0.6);
  font-family: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease;
}

.response-audio-btn.primary {
  color: #ebd08a;
  background: rgba(235, 208, 138, 0.08);
}

.response-audio-btn:hover,
.response-audio-btn.playing {
  color: #ebd08a;
  background: rgba(235, 208, 138, 0.15);
}

.response-audio-btn.secondary {
  color: rgba(255, 255, 255, 0.45);
  font-size: 0.72rem;
}

.response-audio-btn.secondary:hover,
.response-audio-btn.secondary.playing {
  color: rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.06);
}

.response-audio-btn svg {
  flex: 0 0 auto;
}

.user-message-bubble.has-attachments {
  max-width: min(520px, 88%);
  padding: 10px;
  border-radius: 20px;
}

.user-message-text {
  margin: 4px 8px 8px;
  line-height: 1.45;
}

.message-image-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 150px));
  gap: 6px;
  overflow: hidden;
  border-radius: 13px;
}

.message-image-grid.single {
  grid-template-columns: minmax(180px, 280px);
}

.message-image-grid img {
  width: 100%;
  height: 120px;
  display: block;
  object-fit: cover;
  background: #0b0b0b;
}

.message-image-grid.single img {
  height: min(220px, 32vh);
}

@media (max-width: 600px) {
  .hero-container {
    padding: 1.5rem 1rem;
  }
  .menu-btn {
    top: 1.5rem;
    left: 1.5rem;
  }
  .chat-stream-container {
    top: 1.5rem;
  }
  .sidebar {
    width: 100vw;
    max-width: 100vw;
  }
  .ai-bar {
    height: 52px;
  }
  .ai-input, .ai-input::placeholder {
    /* 16px is the iOS Safari threshold: anything smaller zooms the page when
       the field is focused. */
    font-size: 1rem;
  }
  .send-btn, .mic-btn-container, .stop-btn {
    height: 38px;
  }
  .send-btn.active, .stop-btn.active, .mic-btn-container {
    width: 38px;
  }
  .audio-mode-btn {
    position: relative;
    min-width: 38px;
    width: 38px;
    height: 36px;
    margin-right: 3px;
    padding: 0;
  }
  .audio-mode-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  .audio-mode-btn .audio-state-dot {
    position: absolute;
    top: 5px;
    right: 4px;
    width: 5px;
    height: 5px;
  }
  .audio-panel {
    position: fixed;
    right: 1rem;
    bottom: 5.8rem;
    left: 1rem;
    width: auto;
    max-height: calc(100vh - 7.5rem);
    overflow-y: auto;
    transform-origin: bottom center;
  }
  .attachment-menu {
    left: 0;
    right: 0;
    width: 100%;
  }
  .message-image-grid {
    grid-template-columns: repeat(2, minmax(0, 120px));
  }
  .user-message-bubble.has-attachments {
    max-width: 94%;
  }
}

/* ------------------------------------
   LOGIN PAGE STYLES
------------------------------------ */
.login-page-container {
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
}

.login-card {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 420px;
  background: rgba(24, 24, 24, 0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 24px;
  padding: 2.5rem 2rem;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.login-header {
  text-align: center;
}

.login-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 2.2rem;
  font-weight: 500;
  color: #ebd08a;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  margin-bottom: 0.3rem;
}

.login-subtitle {
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.65);
}

/* Alert Notification Banner */
.alert-box {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.9rem;
  line-height: 1.4;
  text-align: center;
  transition: all 0.3s ease;
}

.alert-box.hidden {
  display: none;
}

.alert-box.show {
  display: block;
}

.alert-box.error {
  background: rgba(214, 61, 30, 0.2);
  border: 1px solid rgba(214, 61, 30, 0.5);
  color: #ff8b7b;
}

.alert-box.success {
  background: rgba(46, 125, 50, 0.2);
  border: 1px solid rgba(46, 125, 50, 0.5);
  color: #81c784;
}

/* Form Controls */
.login-form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-group label {
  font-size: 0.88rem;
  font-weight: 500;
  color: rgba(235, 208, 138, 0.9);
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 14px;
  color: rgba(255, 255, 255, 0.45);
  pointer-events: none;
}

.form-input {
  width: 100%;
  height: 48px;
  background: #121212;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 0 16px 0 42px;
  color: #ffffff;
  font-size: 0.98rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.form-input::placeholder {
  color: rgba(255, 255, 255, 0.35);
}

.form-input:focus {
  border-color: #ebd08a;
  box-shadow: 0 0 0 3px rgba(235, 208, 138, 0.15);
}

/* Login Submit Button */
.login-btn {
  position: relative;
  width: 100%;
  height: 50px;
  margin-top: 0.5rem;
  background-color: #d63d1e;
  border: none;
  border-radius: 12px;
  color: #ffffff;
  font-size: 1.05rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(214, 61, 30, 0.35);
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.login-btn-pattern {
  position: absolute;
  inset: 0;
  background-image: url('send.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.5;
  pointer-events: none;
}

.login-btn span {
  position: relative;
  z-index: 2;
}

.login-btn:hover {
  background-color: #c82316;
  transform: translateY(-1px);
}

.login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Footer Link */
.login-footer {
  text-align: center;
  margin-top: 0.5rem;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: rgba(255, 255, 255, 0.65);
  font-size: 0.9rem;
  text-decoration: none;
  transition: color 0.2s ease;
}

.back-link:hover {
  color: #ebd08a;
}

.auth-switch {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.65);
}

.auth-switch a {
  color: #ebd08a;
  text-decoration: none;
  font-weight: 500;
}

.auth-switch a:hover {
  text-decoration: underline;
}

/* Pulsing Dots Loading Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background-color: #ebd08a;
  border-radius: 50%;
  animation: pulse 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

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

/* ------------------------------------
   MICROPHONE LISTENING PULSE ANIMATION
------------------------------------ */
.mic-btn-container.listening {
  background-color: #d63d1e !important;
  animation: mic-pulse 1.5s infinite;
}

@keyframes mic-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(214, 61, 30, 0.7);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(214, 61, 30, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(214, 61, 30, 0);
  }
}

/* Responsive layout: use the visible viewport, including mobile keyboards. */
:root {
  --app-height: 100vh;
  --app-top: 0px;
  --composer-height: 90px;
  --page-bottom: max(16px, env(safe-area-inset-bottom));
}
@supports (height: 100dvh) {
  :root { --app-height: 100dvh; }
}
.hero-container {
  width: 100%;
  height: var(--app-height);
  padding-bottom: calc(var(--page-bottom) + var(--kb-inset, 0px));
}
.hero-container:not(.login-page-container) {
  top: var(--app-top);
}
.ai-bar-container { flex-shrink: 0; margin-bottom: 0; }
.chat-stream-container {
  top: max(88px, calc(env(safe-area-inset-top) + 64px));
  bottom: calc(var(--composer-height) + var(--page-bottom) + 12px + var(--kb-inset, 0px));
  /* top/bottom already size the box; the cap only stops it from growing past
     the visible area when the keyboard is up. */
  max-height: calc(var(--app-height) - var(--composer-height) - var(--page-bottom) - 100px - var(--kb-inset, 0px));
  overscroll-behavior: contain;
  overflow-x: hidden;
}
.menu-btn {
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
}
.sidebar {
  top: var(--app-top);
  bottom: auto;
  height: var(--app-height);
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  padding-left: max(24px, env(safe-area-inset-left));
  overscroll-behavior: contain;
  visibility: hidden;
}
.sidebar.open { visibility: visible; }
.sidebar > * { flex-shrink: 0; }
.user-message-bubble, .ai-response-card {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  flex-shrink: 0;
}
.user-message-bubble { border-radius: 24px; }
.ai-response-card pre, .ai-response-card table {
  max-width: 100%;
  overflow-x: auto;
}
.ai-response-card table { display: block; }
.ai-response-card img { max-width: 100%; height: auto; }
button, .sidebar-nav-item { touch-action: manipulation; }
button:focus-visible, input:not(.ai-input):not(.sidebar-search-input):focus-visible, select:focus-visible {
  outline: 2px solid #ebd08a;
  outline-offset: 3px;
}
.close-btn { width: 44px; height: 44px; flex-shrink: 0; }
/* Auth screens must scroll on short screens and when the keyboard is open. */
.login-page-container {
  overflow-y: auto;
  justify-content: flex-start;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}
.login-card { flex-shrink: 0; margin-block: auto; }
.form-input, .sidebar-search-input, .sidebar-voice-select { font-size: 16px; }
@media (max-width: 900px) {
  .hero-container:not(.login-page-container) {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .chat-stream-container {
    padding-inline: max(12px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-right));
  }
}
@media (max-width: 600px) {
  .sidebar { width: 360px; max-width: 100%; }
  .hero-title { font-size: clamp(2rem, 9vw, 3rem); }
  .hero-subtitle { font-size: clamp(1.1rem, 5vw, 1.5rem); }
  .ai-response-card { padding: 16px; font-size: 1rem; }
  .ai-bar { height: 56px; padding: 0 5px; }
  .ai-input, .ai-input::placeholder { font-size: 16px; }
  .ai-input { padding-inline: 6px; }
  .icon-btn, .mic-btn-container, .send-btn, .stop-btn { height: 44px; }
  .icon-btn, .mic-btn-container, .send-btn.active, .stop-btn.active { width: 44px; }
  .login-card { padding: 24px 20px; }
}
@media (pointer: coarse) {
  .clear-attachments-btn, .sidebar-test-voice-btn, .response-audio-btn { min-height: 44px; }
  .remove-attachment-btn { width: 44px; height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  .chat-stream-container { scroll-behavior: auto; }
}

/* PDF reference: "Bản sao của 1543", pages 1–10.
   Text fields stay seamless; keyboard focus is still visible on controls. */
.ai-input:focus, .ai-input:focus-visible,
.sidebar-search-input:focus, .sidebar-search-input:focus-visible {
  outline: none;
  box-shadow: none;
}
.sidebar-search-input { min-width: 0; width: 100%; }
.sidebar-voice-title { cursor: pointer; min-height: 44px; }
.sidebar-voice-section { margin-top: 0; }
.sidebar-voice-title:focus-visible { outline: 2px solid #ebd08a; outline-offset: 2px; }
.sidebar.searching .sidebar-voice-section { display: none; }
.sidebar.searching .sidebar-divider { margin-block: 8px; }

@media (max-width: 600px) {
  .hero-container:not(.login-page-container) {
    position: fixed;
    left: 0;
    right: 0;
    overflow: hidden;
  }
  .hero-overlay { background: rgba(0, 0, 0, 0.22); }
  .hero-content {
    position: absolute;
    top: 29%;
    left: 12px;
    right: 12px;
    margin: 0;
  }
  .hero-title { font-size: clamp(1.8rem, 8.8vw, 3rem); }
  .hero-subtitle { font-size: clamp(1rem, 5vw, 1.5rem); }
  .ai-bar-container { margin-top: auto; }
  .ai-bar {
    background: rgba(14, 14, 10, 0.62);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: none;
  }
  .mic-btn-container { background: transparent; box-shadow: none; }
  .menu-btn {
    background: rgba(25, 25, 16, 0.25);
    border: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .sidebar-backdrop {
    /* Black at 45% opacity; keep text and controls fully opaque. */
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .sidebar {
    width: 100%;
    max-width: 100%;
    padding: max(16px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    background: transparent;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .hero-container:has(.sidebar.open) > .hero-content,
  .hero-container:has(.sidebar.open) > .chat-stream-container,
  .hero-container:has(.sidebar.open) > .ai-bar-container,
  .hero-container:has(.sidebar.open) > .menu-btn { visibility: hidden; }
  .sidebar-header { margin-bottom: 8px; padding-inline: 8px; }
  .sidebar-title { font-size: 1.15rem; }
  .nav-list { gap: 0; }
  .sidebar-nav-item { min-height: 44px; padding: 8px 14px; gap: 8px; font-size: 0.9rem; }
  .sidebar-divider { margin-block: 12px; }
  .sidebar-nav-item.is-selected { background: #b91810; }
  .recent-section { flex: 0 0 auto; padding-inline: 8px; }
  .recent-title { margin-bottom: 6px; }
  .recent-list { gap: 0; }
  .recent-item { padding-block: 10px; }
  .sidebar-voice-section { padding: 0; }
  .sidebar.searching .sidebar-title { font-size: 1rem; }
  .ai-response-card {
    background: rgba(242, 222, 182, 0.94);
    color: #241c12;
    border: none;
    border-radius: 20px;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .ai-response-card strong,
  .ai-response-card b,
  .ai-response-card h1, .ai-response-card h2, .ai-response-card h3,
  .ai-response-card h4, .ai-response-card a, .ai-response-card a:visited { color: #673619; }
  .ai-response-card a { text-decoration-color: currentColor; }
  .ai-response-card code { background: rgba(65, 42, 13, 0.1); }
}
@media (max-width: 600px) {
  .ai-response-card .response-audio-btn,
  .ai-response-card .response-audio-btn:hover,
  .ai-response-card .auto-read-indicator {
    color: #593719;
    background: rgba(65, 42, 13, 0.09);
  }
  .response-audio-actions { flex-wrap: wrap; }
}

/* Answer stationery from the PDF, page 6, on both desktop and mobile.
   Decorations live below the content so long answers never overlap them. */
.ai-response-card {
  width: 100%;
  background: #ead8b4 url('assets/answer-paper.webp') repeat;
  color: #211b12;
  border: none;
  border-radius: 28px;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  font-family: Arial, sans-serif;
  font-size: 1.05rem;
  line-height: 1.38;
}
.ai-response-card strong, .ai-response-card b,
.ai-response-card h1, .ai-response-card h2,
.ai-response-card h3, .ai-response-card h4,
.ai-response-card a, .ai-response-card a:visited { color: #673619; }
.ai-response-card a { text-decoration-color: currentColor; }
.ai-response-card code { background: rgba(65, 42, 13, 0.1); }
.ai-response-card .typing-indicator span { background: #673619; }
.response-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}
.response-footer .response-actions { flex: 1 1 180px; border: 0; }
.response-artwork {
  display: none;
  flex: 0 0 84px;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 4px 12px 0 auto;
  pointer-events: none;
  user-select: none;
}
.is-complete .response-artwork { display: flex; }
.ai-response-card .response-dragon { width: 84px; height: auto; }
.ai-response-card .response-seal { width: 40px; height: auto; }
.ai-response-card .response-audio-btn,
.ai-response-card .response-audio-btn:hover,
.ai-response-card .auto-read-indicator {
  color: #593719;
  background: rgba(65, 42, 13, 0.09);
}
.response-audio-actions { flex-wrap: wrap; }
@media (max-width: 600px) {
  .ai-response-card { padding: 14px 18px 12px; border-radius: 26px; font-size: 1rem; }
  .chat-stream-container { gap: 10px; }
}

/* Let scrolled answers pass under the menu with a soft, frosted fade.
   The initial top padding keeps the first message readable before scrolling.
   Older browsers retain the original clear space above the chat. */
@supports ((mask-image: linear-gradient(transparent, black)) or (-webkit-mask-image: linear-gradient(transparent, black))) {
  .hero-container:not(.login-page-container) {
    --chat-header-height: max(88px, calc(env(safe-area-inset-top) + 72px));
  }
  .chat-stream-container {
    top: 0;
    padding-top: calc(var(--chat-header-height) + 12px);
    scroll-padding-top: calc(var(--chat-header-height) + 12px);
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, rgba(0, 0, 0, 0.12) 24px, #000 var(--chat-header-height));
    mask-image: linear-gradient(to bottom, transparent 0, rgba(0, 0, 0, 0.12) 24px, #000 var(--chat-header-height));
  }
  .hero-container:not(.login-page-container)::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 820px;
    height: var(--chat-header-height);
    z-index: 11; /* Above answers (10), below the menu (12) and drawer (101). */
    pointer-events: none;
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    -webkit-mask-image: linear-gradient(to bottom, #000 0, rgba(0, 0, 0, 0.8) 35%, transparent 100%);
    mask-image: linear-gradient(to bottom, #000 0, rgba(0, 0, 0, 0.8) 35%, transparent 100%);
  }
}

/* A quiet focus transition: retain Hue imagery, soften it while composing.
   Animate a separate background layer, never the text, drawer or whole page. */
.hero-container:not(.login-page-container) {
  background-image: none;
  isolation: isolate;
  overflow: hidden;
}
.hero-container:not(.login-page-container)::before {
  content: '';
  position: absolute;
  top: 0;
  left: -8px;
  right: -8px;
  height: var(--background-height, 100vh);
  z-index: 0;
  pointer-events: none;
  background: url('background.png') center 50% / cover no-repeat;
  filter: brightness(1);
  transition: background-position 450ms ease, filter 450ms ease;
}
.hero-container.is-composing::before {
  background-position: center 56%;
  filter: brightness(1);
}
.hero-container.is-composing .hero-content {
  opacity: 0;
  visibility: hidden;
  transform: translateY(-12px);
  pointer-events: none;
}
.hero-content {
  transition: opacity 250ms ease, transform 300ms ease, visibility 250ms;
}
.ai-bar {
  transition: background-color 250ms ease, border-color 250ms ease, box-shadow 250ms ease;
}
.is-composing .ai-bar {
  background-color: rgba(24, 24, 24, 0.94);
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
}
@media (prefers-reduced-motion: reduce) {
  .hero-container:not(.login-page-container)::before,
  .hero-content, .ai-bar { transition: none; }
  .hero-container.is-composing::before {
    background-position: center 50%;
  }
  .hero-container.is-composing .hero-content { transform: none; }
}

/* ------------------------------------
   FEATURE PANELS (Bản đồ · Đóng góp ý kiến)
------------------------------------ */
.feature-panel {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(0, 0, 0, 0.72);
  font-family: 'Plus Jakarta Sans', sans-serif;
}

.feature-panel[hidden] {
  display: none;
}

.feature-panel-card {
  width: min(680px, 100%);
  max-height: calc(100vh - 2.5rem);
  max-height: calc(100dvh - 2.5rem);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.5rem;
  overflow-y: auto;
  background: rgba(24, 22, 20, 0.97);
  border: 1px solid rgba(235, 208, 138, 0.28);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.map-panel-card {
  width: min(960px, 100%);
}

.feature-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.feature-panel-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.45rem;
  font-weight: 600;
  color: #ebd08a;
}

.feature-panel-desc {
  margin-top: 0.3rem;
  font-size: 0.92rem;
  color: rgba(255, 255, 255, 0.72);
}

.feature-panel-close {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: transparent;
  color: #ffffff;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.feature-panel-close:hover,
.feature-panel-close:focus-visible {
  border-color: #ebd08a;
  color: #ebd08a;
}

.feature-panel-notice {
  font-size: 0.9rem;
  line-height: 1.5;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  background: rgba(235, 208, 138, 0.1);
  color: #f3e3b5;
}

.feature-panel-notice.is-error {
  background: rgba(220, 80, 70, 0.14);
  color: #ffb9b3;
}

.feature-panel-notice.is-success {
  background: rgba(120, 200, 140, 0.14);
  color: #c9f0d2;
}

/* Map */
.map-panel-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 1rem;
  min-height: 0;
}

.heritage-map {
  width: 100%;
  height: min(520px, 60vh);
  min-height: 320px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #1d1b19;
}

.heritage-map.is-unavailable {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  text-align: center;
  color: rgba(255, 255, 255, 0.7);
}

.heritage-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: min(520px, 60vh);
  overflow-y: auto;
}

.heritage-item {
  width: 100%;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: #ffffff;
  font: inherit;
  cursor: pointer;
}

.heritage-item strong {
  font-weight: 600;
  color: #ebd08a;
}

.heritage-item small {
  font-size: 0.8rem;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.68);
}

.heritage-item:hover,
.heritage-item:focus-visible,
.heritage-item.is-active {
  border-color: rgba(235, 208, 138, 0.6);
  background: rgba(235, 208, 138, 0.08);
}

.heritage-marker {
  background: transparent;
  border: none;
}

.heritage-marker span {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ebd08a;
  border: 3px solid #5a1f12;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35);
}

.heritage-map .leaflet-popup-content-wrapper,
.heritage-map .leaflet-popup-tip {
  background: #fdf8ec;
  color: #2a2016;
}

/* Feedback form */
.feedback-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.feedback-form label {
  margin-top: 0.4rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: #f3e3b5;
}

.feedback-hint {
  font-weight: 400;
  color: rgba(255, 255, 255, 0.55);
}

.feedback-form select,
.feedback-form textarea,
.feedback-form input {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.05);
  color: #ffffff;
  font: inherit;
  font-size: 0.95rem;
}

.feedback-form select option {
  background: #1d1b19;
}

.feedback-form textarea {
  resize: vertical;
  min-height: 110px;
}

.feedback-form select:focus-visible,
.feedback-form textarea:focus-visible,
.feedback-form input:focus-visible {
  outline: 2px solid #ebd08a;
  outline-offset: 1px;
}

.feedback-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

.feedback-btn {
  padding: 0.65rem 1.2rem;
  border-radius: 999px;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
}

.feedback-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.feedback-btn-ghost {
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: transparent;
  color: #ffffff;
}

.feedback-btn-primary {
  border: none;
  background: #ebd08a;
  color: #2a1f0e;
}

@media (max-width: 720px) {
  .feature-panel {
    padding: 0;
  }

  .feature-panel-card,
  .map-panel-card {
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
    border: none;
  }

  .map-panel-body {
    grid-template-columns: 1fr;
  }

  .heritage-map {
    height: 52vh;
    min-height: 260px;
  }

  .heritage-list {
    max-height: none;
  }
}

/* Map tiles unavailable (offline or blocked): keep the markers readable on a grid. */
.heritage-map.is-offline .leaflet-container,
.heritage-map.is-offline {
  background-color: #1d1b19;
  background-image:
    linear-gradient(rgba(235, 208, 138, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(235, 208, 138, 0.08) 1px, transparent 1px);
  background-size: 40px 40px;
}
