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

:root {
  --accent: #D4AF37;
  --accent-dark: #C9A330;
  --accent-light: #F0DFB8;
  --accent-bg: rgba(212, 175, 55, 0.08);
  --deep-red: #8B5E3C;
  --gold: #D4AF37;
  --cream: #F8F5EF;
  --cream-dark: #EDE3D0;
  --brown: #2C2C2C;
  --brown-light: #8B5E3C;
  --brown-muted: #A0825E;
  --gray: #9E9E9E;
  --gray-light: #E0E0E0;
  --gray-bg: #EDE3D0;
  --white: #FFFFFF;
  --green: #27AE60;
  --amber: #F39C12;
  --red: #E74C3C;
  --shadow-sm: 0 1px 4px rgba(44, 44, 44, 0.06);
  --shadow: 0 2px 12px rgba(44, 44, 44, 0.08);
  --shadow-lg: 0 8px 30px rgba(44, 44, 44, 0.12);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --max-width: 960px;
}

html, body {
  height: 100%;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--cream);
  color: var(--brown);
  line-height: 1.6;
  display: flex;
  justify-content: center;
}

#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--max-width);
  height: 100vh;
  padding: 0 1.2em;
  background: var(--white);
  box-shadow: var(--shadow-lg);
}

/* ─── Header ─── */
header {
  padding: 0.6em 0;
  border-bottom: 1px solid var(--cream-dark);
  flex-shrink: 0;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75em;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75em;
}
.header-home-link {
  display: flex;
  align-items: center;
  gap: inherit;
  text-decoration: none;
  color: inherit;
}

.logo {
  height: 36px;
  width: auto;
}

.header-text h1 {
  font-size: 1.1em;
  font-weight: 600;
  color: var(--deep-red);
  letter-spacing: -0.01em;
}

.header-tagline {
  font-size: 0.75em;
  color: var(--gray);
  font-style: italic;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.6em;
}

/* ─── Beta Badge ─── */
.beta-badge {
  display: inline-block;
  font-size: 0.58em;
  font-weight: 600;
  padding: 0.15em 0.5em;
  border-radius: 50px;
  background: rgba(212, 175, 55, 0.2);
  color: #D4AF37;
  border: 1px solid rgba(212, 175, 55, 0.25);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  line-height: 1.4;
  vertical-align: middle;
  margin-left: 0.25em;
}

/* ─── Maharshi Header Button ─── */
.maharshi-header-btn {
  display: none;
  align-items: center;
  gap: 0.35em;
  padding: 0.25em 0.55em 0.25em 0.25em;
  border-radius: 50px;
  border: 1px solid rgba(212, 175, 55, 0.25);
  background: linear-gradient(135deg, #2C2C2C, #8B5E3C);
  text-decoration: none;
  color: var(--cream);
  font-size: 0.72em;
  white-space: nowrap;
  transition: all 0.2s;
  cursor: pointer;
}
.maharshi-header-btn:hover {
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(212, 175, 55, 0.15);
}
.maharshi-header-btn.visible { display: flex; }
.mhb-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: url("cosmic-maharshi.webp") center center / cover;
  flex-shrink: 0;
}
.mhb-label {
  color: var(--gold);
  font-weight: 500;
}

/* ─── Maharshi Banner ─── */
.maharshi-banner {
  display: flex;
  align-items: center;
  gap: 0.75em;
  margin: 0.5em 0.5em 0;
  padding: 0.7em 1em;
  background: linear-gradient(135deg, #2C2C2C, #8B5E3C);
  border: 1px solid rgba(212, 175, 55, 0.2);
  border-radius: 12px;
  text-decoration: none;
  color: var(--cream);
  transition: all 0.25s;
  flex-shrink: 0;
}

.maharshi-banner:hover {
  background: linear-gradient(135deg, #2C2C2C, #8B5E3C);
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(212, 175, 55, 0.15);
}
.maharshi-banner.hidden { display: none; }

.maharshi-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  border: 2px solid rgba(212, 175, 55, 0.3);
  box-shadow: 0 0 12px rgba(212, 175, 55, 0.15);
}

.maharshi-banner-text {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.maharshi-banner-text strong {
  font-size: 0.95em;
  font-weight: 600;
  color: var(--gold);
}

.maharshi-banner-text span {
  font-size: 0.75em;
  color: rgba(255,255,255,0.55);
}

.maharshi-arrow {
  font-size: 1.2em;
  color: var(--gold);
  transition: transform 0.2s;
  flex-shrink: 0;
}

.maharshi-banner:hover .maharshi-arrow {
  transform: translateX(4px);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--cream-dark);
  background: var(--white);
  color: var(--brown-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.icon-btn:hover { background: var(--gray-bg); color: var(--deep-red); }
.icon-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ─── Status ─── */
.status {
  display: flex;
  align-items: center;
  gap: 0.35em;
  font-size: 0.72em;
  color: var(--gray);
  white-space: nowrap;
  padding: 0.3em 0.6em;
  border-radius: 50px;
  background: var(--gray-bg);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gray);
  transition: background 0.3s;
}

.status-dot.online { background: var(--green); box-shadow: 0 0 5px rgba(39, 174, 96, 0.35); }
.status-dot.connecting { background: var(--amber); animation: pulse 1s infinite; }
.status-dot.offline { background: var(--red); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ─── Layout ─── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.8em 0.5em 0.5em;
  scroll-behavior: smooth;
}

#messages::-webkit-scrollbar { width: 5px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--cream-dark); border-radius: 3px; }

/* ─── Welcome ─── */
.welcome {
  text-align: center;
  padding: 2.5em 1em;
}

.welcome-icon { font-size: 3.5em; margin-bottom: 0.4em; opacity: 0.45; }

.welcome h2 {
  font-size: 1.25em;
  font-weight: 500;
  color: var(--brown-light);
  margin-bottom: 0.3em;
}

.welcome p { font-size: 0.9em; color: var(--gray); margin-bottom: 1.5em; }

.welcome-login-hint {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  margin-top: 1.2em;
  font-size: 0.78em;
  color: var(--brown-muted);
  cursor: pointer;
  transition: color 0.15s;
}
.welcome-login-hint.visible { display: flex; }
.welcome-login-hint:hover { color: var(--accent-dark); }
.welcome-login-hint svg { flex-shrink: 0; }

.suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5em;
}

.chip {
  background: var(--white);
  border: 1px solid var(--cream-dark);
  padding: 0.5em 1em;
  border-radius: 50px;
  font-family: inherit;
  font-size: 0.8em;
  color: var(--brown-light);
  cursor: pointer;
  transition: all 0.2s;
}

.chip:hover {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--brown);
}

/* ─── Messages ─── */
.msg {
  display: flex;
  gap: 0.65em;
  margin-bottom: 1em;
  animation: msgIn 0.3s ease-out;
  position: relative;
}

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

.msg.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.8em;
  margin-top: 2px;
}

.msg.bot .msg-avatar { background: var(--accent); font-size: 0.85em; }
.msg.user .msg-avatar { background: var(--deep-red); color: var(--white); font-weight: 600; font-size: 0.78em; }

.msg-bubble {
  max-width: 80%;
  padding: 0.65em 1em;
  border-radius: var(--radius);
  font-size: 0.9em;
  line-height: 1.7;
  position: relative;
}

.msg.bot .msg-bubble {
  background: var(--cream);
  border: 1px solid var(--cream-dark);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.msg.user .msg-bubble {
  background: var(--accent);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

/* ─── Bubble footer (timestamp + actions) ─── */
.bubble-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4em;
  margin-top: 0.3em;
  font-size: 0.72em;
  opacity: 0;
  transition: opacity 0.2s;
}

.msg:hover .bubble-footer { opacity: 1; }

.msg.user .bubble-footer { justify-content: flex-start; }

.bubble-time {
  color: var(--gray);
}

.msg.user .bubble-time { color: rgba(255,255,255,0.7); }

.bubble-action {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--gray);
  padding: 2px;
  display: flex;
  align-items: center;
  border-radius: 4px;
  transition: all 0.15s;
}

.bubble-action:hover { color: var(--accent-dark); background: rgba(0,0,0,0.04); }

.feedback-btn.active[data-value="up"] { color: var(--green); }
.feedback-btn.active[data-value="down"] { color: var(--red); }

.msg.user .bubble-action { color: rgba(255,255,255,0.7); }
.msg.user .bubble-action:hover { color: var(--white); background: rgba(255,255,255,0.12); }

/* ─── Markdown ─── */
.msg-bubble p { margin: 0.3em 0; }
.msg-bubble p:first-child { margin-top: 0; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble strong { font-weight: 600; }
.msg.user .msg-bubble strong { color: var(--white); }

.msg-bubble code {
  font-family: "JetBrains Mono", "Consolas", monospace;
  font-size: 0.88em;
  background: rgba(212, 175, 55, 0.08);
  padding: 0.08em 0.35em;
  border-radius: 4px;
}

.msg.user .msg-bubble code { background: rgba(255,255,255,0.15); }

.msg-bubble pre {
  background: linear-gradient(135deg, #F8F5EF, #fdf2e3);
  border: 1px solid var(--cream-dark);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius-sm);
  padding: 1em 1.2em;
  overflow-x: auto;
  margin: 0.6em 0;
  font-family: "Cormorant Garamond", "Georgia", "JetBrains Mono", serif;
  font-size: 1.05em;
  line-height: 1.8;
  color: var(--brown);
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.03);
}

.msg-bubble pre code {
  background: none;
  padding: 0;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  line-height: inherit;
}

.msg-bubble a { color: var(--accent-dark); text-decoration: underline; text-underline-offset: 2px; }
.msg.user .msg-bubble a { color: rgba(255,255,255,0.9); }

.msg-bubble ul, .msg-bubble ol { padding-left: 1.3em; margin: 0.3em 0; }
.msg-bubble li { margin: 0.15em 0; }

/* ─── Sources ─── */
.sources-toggle {
  margin-top: 0.4em;
  font-size: 0.82em;
}

.sources-toggle summary {
  cursor: pointer;
  color: var(--brown-muted);
  user-select: none;
  font-size: 0.9em;
}

.sources-toggle summary:hover { color: var(--accent-dark); }

.sources-list { list-style: none; padding: 0.3em 0 0 0; }
.sources-list li { margin: 0.15em 0; }
.sources-list a { color: var(--accent-dark); font-size: 0.9em; text-decoration: none; }
.sources-list a:hover { text-decoration: underline; }

/* ─── Typing ─── */
.typing-indicator {
  display: flex;
  gap: 0.65em;
  margin-bottom: 1em;
  animation: msgIn 0.2s ease-out;
}

.typing-dots {
  background: var(--cream);
  border: 1px solid var(--cream-dark);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  padding: 0.7em 1.2em;
  display: flex;
  gap: 5px;
  align-items: center;
  box-shadow: var(--shadow-sm);
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: dotBounce 1.4s infinite;
}

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

@keyframes dotBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ─── Mode Dropdown ─── */
.mode-dropdown {
  position: relative;
  margin-bottom: 0.5rem;
  width: fit-content;
}

.mode-dropdown-trigger {
  display: flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.35em 0.8em;
  border: 1px solid rgba(212,160,23,0.3);
  border-radius: 10px;
  background: var(--white);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}
.mode-dropdown-trigger:hover {
  border-color: var(--accent-dark);
  background: var(--accent-bg);
}

.mode-trigger-label {
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--brown);
}

.mode-trigger-sub {
  font-size: 0.58rem;
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.mode-arrow {
  color: var(--gray);
  transition: transform 0.2s;
}
.mode-dropdown.open .mode-arrow {
  transform: rotate(180deg);
}

.mode-dropdown-menu {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  min-width: 210px;
  background: var(--white);
  border: 1px solid var(--cream-dark);
  border-radius: 12px;
  padding: 0.3rem;
  display: none;
  z-index: 20;
  box-shadow: var(--shadow-lg);
}
.mode-dropdown.open .mode-dropdown-menu {
  display: block;
}

.mode-option {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  width: 100%;
  padding: 0.45em 0.8em;
  border: none;
  border-radius: 8px;
  background: none;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: background 0.2s;
}
.mode-option:hover {
  background: var(--accent-bg);
}
.mode-option.active {
  background: var(--accent-bg);
}

.mode-opt-label {
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--brown-muted);
}
.mode-option.active .mode-opt-label {
  color: var(--accent-dark);
  font-weight: 700;
}
.mode-option:hover .mode-opt-label {
  color: var(--brown);
}

.mode-opt-sub {
  font-size: 0.62rem;
  color: var(--gray);
}

/* ─── Input Mode Actions ─── */
.input-mode-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 0.35rem;
  gap: 0.3rem;
}

/* ─── PDF Generate Button ─── */
.pdf-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.3em 0.7em;
  border: 1px solid var(--cream-dark);
  border-radius: 8px;
  background: var(--white);
  color: var(--brown-muted);
  font-family: inherit;
  font-size: 0.72rem;
  cursor: pointer;
  transition: all 0.2s;
  margin-left: auto;
}
.pdf-btn:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
  background: var(--accent-bg);
}
.pdf-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}
.pdf-btn svg { flex-shrink: 0; }
.pdf-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(212,160,23,0.15);
  border-top-color: #D4AF37;
  border-radius: 50%;
  animation: pdfSpin 0.6s linear infinite;
}
@keyframes pdfSpin {
  to { transform: rotate(360deg); }
}

/* ─── Agent Status (live progress) ─── */
.agent-status-msg .msg-avatar {
  background: rgba(139,94,60,0.1);
  color: #8B5E3C;
}
.agent-status-bubble {
  display: flex;
  flex-direction: column;
  gap: 0.3em;
  padding: 0.6em 1em !important;
  min-width: 240px;
  background: var(--white) !important;
  border: 1px solid var(--cream-dark) !important;
}
.agent-step-log {
  display: flex;
  flex-direction: column;
  gap: 0.2em;
}
.agent-step-done {
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.3em;
  line-height: 1.3;
}
.step-check {
  color: var(--green);
  font-weight: 700;
  font-size: 0.65rem;
  flex-shrink: 0;
}
.step-text {
  color: var(--brown-muted);
}
.agent-step-current {
  display: flex;
  align-items: center;
  gap: 0.4em;
  padding-top: 0.2em;
  border-top: 1px solid var(--cream-dark);
}
.agent-status-icon {
  font-size: 1rem;
  white-space: nowrap;
}
.agent-status-text {
  font-size: 0.82rem;
  color: var(--brown);
  font-weight: 600;
  white-space: nowrap;
}
.agent-status-bar {
  width: 70px;
  height: 3px;
  background: rgba(0,0,0,0.06);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
  margin-left: auto;
  flex-shrink: 0;
}
.agent-status-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 40%;
  background: linear-gradient(90deg, var(--accent), var(--gold), var(--accent));
  border-radius: 2px;
  animation: agentStatusPulse 1.2s ease-in-out infinite;
}
@keyframes agentStatusPulse {
  0% { left: -40%; }
  100% { left: 100%; }
}

/* ─── Agent Message ─── */
.msg.agent .msg-avatar {
  background: rgba(139,94,60,0.1);
  color: #8B5E3C;
}
.msg.agent .msg-bubble {
  background: var(--white);
  border: 1px solid var(--cream-dark);
  border-bottom-left-radius: 4px;
}

.agent-download-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  margin-top: 0.8rem;
  padding: 0.55em 1.2em;
  border-radius: 10px;
  border: 1px solid rgba(212,160,23,0.2);
  background: rgba(212,160,23,0.08);
  color: #D4AF37;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}
.agent-download-btn:hover {
  background: rgba(212,160,23,0.15);
  border-color: rgba(212,160,23,0.35);
}

.agent-summary {
  font-size: 0.92rem;
  line-height: 1.7;
  color: rgba(44,44,44,0.75);
}

.agent-summary strong {
  color: #D4AF37;
}

/* ─── Input ─── */
.input-area {
  flex-shrink: 0;
  padding: 0.6em 0 0.8em;
  border-top: 1px solid var(--cream-dark);
}

.input-row {
  display: flex;
  gap: 0.5em;
  background: var(--cream);
  border: 2px solid var(--cream-dark);
  border-radius: 16px;
  padding: 0.3em;
  transition: border-color 0.2s, box-shadow 0.2s;
  align-items: flex-end;
}

.input-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.1);
}

.input-row.disabled { opacity: 0.5; }

#input {
  flex: 1;
  border: none;
  outline: none;
  padding: 0.5em 0.8em;
  font-family: inherit;
  font-size: 0.9em;
  background: transparent;
  color: var(--brown);
  resize: none;
  min-height: 38px;
  max-height: 250px;
  line-height: 1.5;
  scrollbar-width: thin;
}

#input::placeholder { color: var(--brown-muted); }
#input::-webkit-scrollbar { width: 3px; }
#input::-webkit-scrollbar-thumb { background: var(--cream-dark); border-radius: 2px; }

/* ─── Stop Button ─── */
.stop-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid var(--red);
  background: var(--white);
  color: var(--red);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.stop-btn:hover { background: var(--red); color: var(--white); }
.stop-btn:active { transform: scale(0.92); }

#send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.15s;
  flex-shrink: 0;
}

#send:hover { background: var(--accent-dark); }
#send:active { transform: scale(0.92); }
#send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.input-hint {
  font-size: 0.7em;
  color: var(--gray-light);
  text-align: right;
  margin-top: 4px;
  padding-right: 4px;
}

/* ─── Suggestion Chips ─── */
.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45em;
  padding: 0 0.5em 0.8em;
  animation: msgIn 0.3s ease-out;
}
.suggestion-chip {
  background: var(--cream);
  border: 1px solid var(--cream-dark);
  padding: 0.4em 0.9em;
  border-radius: 50px;
  font-family: inherit;
  font-size: 0.78em;
  color: var(--brown-muted);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.suggestion-chip:hover {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--brown);
}

/* ─── Error ─── */
.msg.error .msg-bubble {
  background: #FDF8F0;
  border-color: #F0DFB8;
  color: var(--deep-red);
}
.msg.error .msg-avatar { background: var(--red); }

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--brown);
  color: var(--white);
  padding: 0.5em 1.2em;
  border-radius: 8px;
  font-size: 0.82em;
  opacity: 0;
  transition: all 0.3s;
  z-index: 100;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── Auth Button ─── */
.auth-btn {
  display: flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.3em 0.7em;
  border-radius: 8px;
  border: 1px solid var(--cream-dark);
  background: var(--white);
  color: var(--brown-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.78em;
  transition: all 0.15s;
  white-space: nowrap;
}
.auth-btn:hover { background: var(--gray-bg); color: var(--deep-red); }
.auth-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.auth-btn.logged-in {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent-dark);
}

/* ─── Auth Modal ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.5em;
  width: 90%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  position: relative;
  animation: modalIn 0.2s ease-out;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  font-size: 1.5em;
  color: var(--gray);
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--brown); }

.modal-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1em;
  border-bottom: 2px solid var(--cream-dark);
}
.modal-tab {
  flex: 1;
  padding: 0.5em;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.85em;
  color: var(--gray);
  cursor: pointer;
  transition: all 0.15s;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}
.modal-tab.active {
  color: var(--deep-red);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.modal-tab:hover { color: var(--brown); }

.modal-body { margin-bottom: 1em; }
.form-group { margin-bottom: 0.7em; }
.form-group label {
  display: block;
  font-size: 0.78em;
  color: var(--brown-muted);
  margin-bottom: 0.25em;
}
.form-group input {
  width: 100%;
  padding: 0.55em 0.75em;
  border: 1px solid var(--cream-dark);
  border-radius: var(--radius-xs);
  font-family: inherit;
  font-size: 0.85em;
  outline: none;
  transition: border-color 0.2s;
}
.form-group input:focus { border-color: var(--accent); }

.form-error {
  font-size: 0.78em;
  color: var(--red);
  min-height: 1.2em;
}

.modal-submit {
  width: 100%;
  padding: 0.6em;
  border: none;
  border-radius: var(--radius-xs);
  background: var(--accent);
  color: var(--white);
  font-family: inherit;
  font-size: 0.85em;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.modal-submit:hover { background: var(--accent-dark); }
.modal-submit:disabled { opacity: 0.5; cursor: not-allowed; }

.form-footer {
  text-align: center;
  margin-top: 0.7em;
  font-size: 0.75em;
  color: var(--gray);
}
.form-footer a { color: var(--accent-dark); cursor: pointer; }

/* ─── Profile Modal ─── */
.profile-modal { max-width: 360px; }

.profile-modal-header {
  display: flex;
  align-items: center;
  gap: 0.7em;
  margin-bottom: 1em;
  padding-bottom: 0.8em;
  border-bottom: 1px solid var(--cream-dark);
}
.profile-modal .profile-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2em;
  flex-shrink: 0;
}
.profile-modal .profile-info { min-width: 0; flex: 1; }
.profile-modal .profile-name {
  font-size: 0.9em;
  font-weight: 600;
  color: var(--brown);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-modal .profile-email {
  font-size: 0.72em;
  color: var(--gray);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-modal-body { margin-bottom: 0.8em; }
.profile-modal .profile-field label {
  display: block;
  font-size: 0.75em;
  color: var(--brown-muted);
  margin-bottom: 0.3em;
}
.profile-field-row {
  display: flex;
  gap: 0.4em;
}
.profile-input {
  flex: 1;
  padding: 0.45em 0.65em;
  border: 1px solid var(--cream-dark);
  border-radius: var(--radius-xs);
  font-family: inherit;
  font-size: 0.82em;
  outline: none;
  transition: border-color 0.15s;
}
.profile-input:focus { border-color: var(--accent); }

.profile-save-btn {
  padding: 0.45em 0.9em;
  border: none;
  border-radius: var(--radius-xs);
  background: var(--accent);
  color: var(--white);
  font-family: inherit;
  font-size: 0.78em;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.profile-save-btn:hover { background: var(--accent-dark); }
.profile-save-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.profile-logout-btn {
  width: 100%;
  padding: 0.5em;
  border: 1px solid var(--cream-dark);
  border-radius: var(--radius-xs);
  background: none;
  font-family: inherit;
  font-size: 0.8em;
  color: var(--gray);
  cursor: pointer;
  transition: all 0.12s;
}
.profile-logout-btn:hover {
  border-color: var(--red);
  color: var(--red);
  background: rgba(231,76,60,0.04);
}

/* ─── History Panel ─── */
.history-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.2);
  z-index: 150;
  display: none;
}
.history-overlay.open { display: block; }

.history-panel {
  position: fixed;
  top: 0;
  right: -380px;
  width: 360px;
  height: 100%;
  background: var(--white);
  box-shadow: -4px 0 30px rgba(0,0,0,0.1);
  z-index: 160;
  transition: right 0.3s ease;
  display: flex;
  flex-direction: column;
}
.history-panel.open { right: 0; }

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1em 1.2em;
  border-bottom: 1px solid var(--cream-dark);
  flex-shrink: 0;
}
.history-header h3 {
  font-size: 0.95em;
  font-weight: 600;
  color: var(--brown);
}
.history-header-actions {
  display: flex;
  align-items: center;
  gap: 0.4em;
}
.history-new {
  background: var(--accent);
  color: var(--white);
  border: none;
  padding: 0.3em 0.7em;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.72em;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
}
.history-new:hover { background: var(--accent-dark); }
.history-logout {
  background: none;
  border: 1px solid var(--cream-dark);
  padding: 0.2em 0.6em;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.72em;
  color: var(--gray);
  cursor: pointer;
  transition: all 0.12s;
}
.history-logout:hover {
  border-color: var(--red);
  color: var(--red);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.2em 0;
}
.history-empty {
  text-align: center;
  color: var(--gray);
  font-size: 0.82em;
  padding: 2em 1em;
}
.history-group { margin-bottom: 0.3em; }
.history-group-label {
  font-size: 0.68em;
  font-weight: 600;
  color: var(--brown-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.6em 1.2em 0.3em;
}
.history-item {
  display: flex;
  align-items: flex-start;
  gap: 0.3em;
  padding: 0.5em 1.2em;
  cursor: pointer;
  transition: background 0.12s;
  border-bottom: 1px solid var(--gray-bg);
}
.history-item:hover { background: var(--accent-bg); }
.history-item:last-of-type { border-bottom: none; }
.history-item-content { flex: 1; min-width: 0; }
.history-item-title {
  font-size: 0.82em;
  font-weight: 500;
  color: var(--brown);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item-preview {
  font-size: 0.72em;
  color: var(--brown-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.history-item-meta {
  display: flex;
  gap: 0.6em;
  margin-top: 3px;
}
.history-item-date {
  font-size: 0.65em;
  color: var(--gray);
}
.history-item-count {
  font-size: 0.65em;
  color: var(--brown-muted);
  background: var(--gray-bg);
  padding: 0 0.4em;
  border-radius: 4px;
}
.history-item-del {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--gray-light);
  padding: 3px;
  border-radius: 4px;
  margin-top: 1px;
  opacity: 0;
  transition: all 0.12s;
  line-height: 1;
}
.history-item:hover .history-item-del { opacity: 1; }
.history-item-del:hover { color: var(--red); background: rgba(231,76,60,0.08); }

@media (min-width: 769px) {
  .history-panel { width: 400px; right: -420px; }
  .history-panel.open { right: 0; }
}

/* ─── Connecting overlay ─── */
.connecting-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 1em;
  padding: 2em;
}

.connecting-overlay .spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--cream-dark);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.connecting-overlay p { color: var(--gray); font-size: 0.9em; }

/* ─── Invocation Overlay ─── */
.invocation-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #2C2C2C 0%, #1A1A1A 100%);
  transition: opacity 0.8s ease, visibility 0.8s ease;
}
.invocation-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.invocation-modal {
  text-align: center;
  padding: 2em;
  max-width: 500px;
  animation: invocationFadeIn 2s ease-out;
}

@keyframes invocationFadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.invocation-om {
  font-size: 5em;
  line-height: 1;
  margin-bottom: 0.5em;
  animation: omPulse 3s ease-in-out infinite;
  filter: drop-shadow(0 0 30px rgba(212, 175, 55, 0.3));
}

@keyframes omPulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 20px rgba(212, 175, 55, 0.2)); }
  50% { transform: scale(1.06); filter: drop-shadow(0 0 50px rgba(212, 175, 55, 0.5)); }
}

.invocation-mantra {
  margin-bottom: 1.5em;
}

.invocation-line {
  font-size: 1.1em;
  line-height: 1.8;
  opacity: 0;
  animation: lineAppear 1s ease-out forwards;
}

.invocation-line.hindi {
  font-size: 1.3em;
  color: #F0DFB8;
  animation-delay: 0.3s;
}
.invocation-line.telugu {
  font-size: 1.15em;
  color: #D4AF37;
  animation-delay: 1s;
}
.invocation-line.english {
  font-size: 1em;
  color: #D4AF37;
  font-style: italic;
  animation-delay: 1.7s;
}

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

.invocation-message {
  margin-bottom: 1.2em;
}

.invocation-text {
  font-size: 1.05em;
  color: rgba(255,255,255,0.85);
  font-weight: 400;
  margin-bottom: 0.3em;
}

.invocation-sub {
  font-size: 0.85em;
  color: rgba(255,255,255,0.45);
  font-weight: 300;
}

.invocation-dots {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 0.6em;
}

.invocation-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #D4AF37;
  animation: dotFade 1.6s infinite;
}

.invocation-dots span:nth-child(2) { animation-delay: 0.4s; }
.invocation-dots span:nth-child(3) { animation-delay: 0.8s; }
.invocation-dots span:nth-child(4) { animation-delay: 1.2s; }

@keyframes dotFade {
  0%, 100% { opacity: 0.2; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.1); }
}

.invocation-attempt {
  font-size: 0.72em;
  color: rgba(255,255,255,0.2);
  font-family: "JetBrains Mono", "Consolas", monospace;
}

/* Invocation error state */
.invocation-overlay.error .invocation-om {
  animation: none;
  filter: drop-shadow(0 0 30px rgba(192, 57, 43, 0.3));
  opacity: 0.4;
}
.invocation-overlay.error .invocation-text {
  color: rgba(255,255,255,0.5);
}
.invocation-overlay.error .invocation-sub {
  color: #8B5E3C;
}
.invocation-overlay.error .invocation-dots span {
  background: #8B5E3C;
  animation: none;
  opacity: 0.3;
}

.invocation-retry-btn {
  display: inline-block;
  margin-top: 1em;
  padding: 0.6em 1.8em;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 50px;
  background: transparent;
  color: rgba(255,255,255,0.7);
  font-family: inherit;
  font-size: 0.82em;
  cursor: pointer;
  transition: all 0.2s;
}
.invocation-retry-btn:hover {
  border-color: #D4AF37;
  color: #D4AF37;
  background: rgba(230,126,34,0.1);
}

/* ─── Export Modal ─── */
.export-modal-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,0.35);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(2px);
  opacity: 0; visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
}
.export-modal-overlay.active { opacity: 1; visibility: visible; }
.export-modal {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.8em;
  max-width: 480px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  animation: modalIn 0.2s ease-out;
}
.export-modal-om { display: block; text-align: center; font-size: 2.5em; margin-bottom: 0.2em; }
.export-modal h3 { text-align: center; margin: 0 0 0.3em; color: var(--deep-red); font-size: 1.2em; }
.export-modal-sub { text-align: center; font-size: 0.85em; color: var(--brown-muted); margin: 0 0 1.2em; line-height: 1.5; }
.export-modal-input {
  width: 100%; padding: 0.75em 0.9em;
  border: 1px solid var(--cream-dark);
  border-radius: var(--radius-xs);
  font-family: inherit; font-size: 0.9em;
  resize: vertical;
  background: var(--white);
  color: var(--brown);
  box-sizing: border-box;
  transition: border-color 0.15s;
}
.export-modal-input:focus { outline: none; border-color: var(--accent); }
.export-modal-input::placeholder { color: var(--gray); }
.export-modal-actions { display: flex; gap: 0.6em; justify-content: flex-end; margin-top: 1em; }
.export-modal-cancel, .export-modal-submit {
  padding: 0.55em 1.5em; border-radius: var(--radius-xs); border: none;
  font-family: inherit; font-size: 0.85em; cursor: pointer;
  font-weight: 500;
}
.export-modal-cancel { background: var(--gray-bg); color: var(--brown-muted); }
.export-modal-cancel:hover { background: var(--cream-dark); }
.export-modal-submit { background: var(--accent); color: #fff; font-weight: 600; }
.export-modal-submit:hover { background: var(--accent-dark); }

/* ─── Connection Status Card (shown in chat while server wakes up) ─── */
.connection-status {
  display: flex;
  gap: 0.75em;
  margin: 1em 0.5em;
  padding: 0.9em 1em;
  background: linear-gradient(135deg, #fff9f0, #fef3e0);
  border: 1px solid rgba(212, 175, 55, 0.2);
  border-radius: 12px;
  animation: msgIn 0.4s ease-out;
}
.connection-icon {
  font-size: 1.6em;
  flex-shrink: 0;
  margin-top: 0.1em;
}
.connection-body { flex: 1; min-width: 0; }
.connection-title {
  font-size: 0.9em;
  font-weight: 600;
  color: var(--brown);
  margin-bottom: 0.2em;
}
.connection-sub {
  font-size: 0.78em;
  color: var(--brown-muted);
  line-height: 1.5;
  margin-bottom: 0.1em;
}
.connection-elapsed {
  font-size: 0.72em;
  color: var(--gray);
  font-family: "JetBrains Mono", "Consolas", monospace;
  margin-top: 0.2em;
}

/* ─── Floating Backend Status (for pages without header status) ─── */
.backend-status-floating {
  position: fixed;
  bottom: 12px;
  right: 12px;
  z-index: 9999;
  pointer-events: none;
  transition: opacity 0.4s;
}
.backend-status-floating.online {
  opacity: 0.35;
}
.backend-status-floating.online:hover {
  opacity: 1;
}
.backend-status-floating.offline {
  opacity: 1;
}
.backend-status-floating .status-label {
  font-size: 0.7rem;
}

@media (max-width: 600px) {
  .invocation-om { font-size: 3.5em; }
  .invocation-line.hindi { font-size: 1.1em; }
  .invocation-line.telugu { font-size: 1em; }
  .invocation-line.english { font-size: 0.9em; }
  .invocation-modal { padding: 1.5em; }
}
@media (min-width: 769px) {
  #app {
    padding: 0 2em;
    border-left: 1px solid var(--cream-dark);
    border-right: 1px solid var(--cream-dark);
  }

  body {
    background: #F8F5EF;
  }

  .msg-bubble { max-width: 75%; }
  .msg-bubble { font-size: 0.92em; }

  .bubble-footer { opacity: 1; }

  .welcome { padding: 3.5em 2em; }
  .welcome h2 { font-size: 1.4em; }
}

@media (min-width: 1200px) {
  #app { max-width: 1000px; }
  .msg-bubble { max-width: 70%; }
}

/* ─── Mobile ─── */
@media (max-width: 600px) {
  #app { padding: 0 0.6em; }
  .msg-bubble { max-width: 88%; font-size: 0.85em; }
  .welcome { padding: 1.5em 0.5em; }
  .welcome h2 { font-size: 1em; }
  .chip { font-size: 0.75em; padding: 0.4em 0.7em; }
  .logo { height: 30px; }
  .header-text h1 { font-size: 1em; }
  .status { font-size: 0.65em; padding: 0.2em 0.5em; }
  .bubble-footer { opacity: 1; }
  .input-hint { display: none; }
  #input { font-size: 0.85em; min-height: 36px; }
  .suggestion-chip { font-size: 0.72em; }
}
