/* ═══════════════════════════════════════════════════════════
   MONÍ — Tajik Law AI Assistant
   Design System v4 — Refined Edition
   ═══════════════════════════════════════════════════════════ */

/* ── CSS Variables ── */
:root {
  --bg-primary: #f8f7f4;
  --bg-secondary: #f1f0ec;
  --bg-tertiary: #eae8e3;
  --text-primary: #1a1a1f;
  --text-secondary: #7a7a85;
  --text-accent: #c18d48;
  --border-color: #e0ddd6;
  --input-bg: #ffffff;
  --user-msg-bg: #eae8e3;
  --ai-msg-bg: transparent;
  --input-border: #ddd9d0;
  --input-border-focus: #c18d48;
  --send-bg: #eae8e3;
  --send-bg-hover: #ddd9d0;
  --send-icon: #7a7a85;
  --tooltip-bg: rgba(26, 26, 31, 0.92);
  --tooltip-text: #fff;
  --header-height: 70px;
  --gold: #c18d48;
  --gold-soft: rgba(193, 141, 72, 0.12);
  --danger: #e05252;
  --danger-soft: rgba(224, 82, 82, 0.1);
  --ease-spring: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="dark"] {
  --bg-primary: #1a1a1f;
  --bg-secondary: #222228;
  --bg-tertiary: #2a2a32;
  --text-primary: #e8e6e1;
  --text-secondary: #8a8a95;
  --text-accent: #daa96a;
  --border-color: #333340;
  --input-bg: #222228;
  --user-msg-bg: #2a2a32;
  --ai-msg-bg: transparent;
  --input-border: #333340;
  --input-border-focus: #daa96a;
  --send-bg: #2a2a32;
  --send-bg-hover: #333340;
  --send-icon: #8a8a95;
  --tooltip-bg: rgba(232, 230, 225, 0.92);
  --tooltip-text: #1a1a1f;
  --gold: #daa96a;
  --gold-soft: rgba(218, 169, 106, 0.12);
  --danger: #f06060;
  --danger-soft: rgba(240, 96, 96, 0.1);
}

/* ── Reset ── */
*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.5s var(--ease-spring), color 0.4s;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ══════════════════════════════════════════════════════════
   HEADER
   ══════════════════════════════════════════════════════════ */
.header {
  padding: 14px 32px;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1001;
  transition: background 0.4s, box-shadow 0.4s;
  gap: 16px;
}
.header.scrolled {
  box-shadow: 0 1px 16px rgba(0,0,0,0.05);
}
[data-theme="dark"] .header.scrolled {
  box-shadow: 0 1px 16px rgba(0,0,0,0.25);
}
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  position: relative;
}
.logo-img {
  height: 48px;
  width: auto;
  object-fit: contain;
  transition: transform 0.3s var(--ease-spring), opacity 0.4s;
}
.logo-link:hover .logo-img { transform: scale(1.03); }

/* Dark mode logo switching with crossfade */
.dark-logo { display: none; opacity: 0; position: absolute; top: 0; left: 0; }
.light-logo { opacity: 1; }
[data-theme="dark"] .light-logo { display: none; opacity: 0; }
[data-theme="dark"] .dark-logo { display: block; opacity: 1; position: static; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}
.hdr-btn {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  cursor: pointer;
  padding: 12px 18px;
  border-radius: 50px;
  font-size: 16px;
  transition: all 0.25s var(--ease-spring);
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}
.hdr-btn:hover {
  border-color: var(--gold);
  color: var(--gold);
  background: var(--gold-soft);
}
.hdr-btn:active { transform: scale(0.95); }
.hdr-btn i, .hdr-btn svg { font-size: 20px; width: 20px; height: 20px; }

/* ── Theme Toggle Icon Morph ── */
.theme-icon { display: flex; align-items: center; justify-content: center; }
.theme-icon svg { width: 20px; height: 20px; overflow: visible; }
.theme-circle {
  transition: transform 0.5s var(--ease-spring);
}
.theme-rays line {
  transition: opacity 0.3s 0.1s, transform 0.4s var(--ease-spring);
  transform-origin: 12px 12px;
}
.theme-mask {
  transition: transform 0.5s var(--ease-spring), opacity 0.3s;
}

/* Light mode: show moon (mask visible, rays hidden) */
.theme-rays line { opacity: 0; transform: rotate(-30deg) scale(0); }
.theme-mask { transform: translate(0, 0); opacity: 1; }
.theme-circle { transform: scale(1); }

/* Dark mode: show sun (mask hidden, rays visible) */
[data-theme="dark"] .theme-rays line { opacity: 1; transform: rotate(0deg) scale(1); }
[data-theme="dark"] .theme-mask { transform: translate(8px, -8px); opacity: 0; }
[data-theme="dark"] .theme-circle { transform: scale(0.7); }

/* Language dropdown arrow */
.lang-arrow {
  font-size: 9px !important;
  width: auto !important;
  height: auto !important;
  margin-left: 2px;
  transition: transform 0.3s var(--ease-spring);
  display: flex;
  align-items: center;
}
.lang-arrow.open { transform: rotate(180deg); }

/* Language dropdown */
.lang-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.1);
  min-width: 160px;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  z-index: 2000;
  transition: max-height 0.35s var(--ease-spring), opacity 0.25s;
  padding: 0;
}
.lang-dropdown.open {
  max-height: 400px;
  overflow-y: auto;
  opacity: 1;
  padding: 4px;
}
[data-theme="dark"] .lang-dropdown {
  box-shadow: 0 8px 32px rgba(0,0,0,0.35);
}
.lang-dropdown button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
  font-family: 'Nunito', sans-serif;
}
.lang-dropdown button:hover { background: var(--bg-tertiary); }
.lang-dropdown button.selected { color: var(--gold); font-weight: 600; }
.lang-dropdown button .check { font-size: 12px; opacity: 0.7; }

/* ══════════════════════════════════════════════════════════
   MAIN CONTENT
   ══════════════════════════════════════════════════════════ */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  padding-top: var(--header-height);
}

/* ══════════════════════════════════════════════════════════
   WELCOME SCREEN
   ══════════════════════════════════════════════════════════ */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px 64px;
  gap: 20px;
}
.welcome-title {
  font-family: 'Roboto Serif', serif;
  font-size: 52px;
  font-weight: 500;
  text-align: center;
  letter-spacing: -2px;
  line-height: 1.25;
  color: var(--text-primary);
  opacity: 0;
  animation: fadeUp 0.7s var(--ease-spring) 0.1s forwards;
}
.welcome-sub {
  font-size: 20px;
  color: var(--text-secondary);
  text-align: center;
  font-family: 'Roboto Serif', serif;
  opacity: 0;
  animation: fadeUp 0.7s var(--ease-spring) 0.25s forwards;
}

/* ── Mode selector ── */
.mode-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 8px;
  opacity: 0;
  animation: fadeUp 0.6s var(--ease-spring) 0.4s forwards;
}
.mode-bar.compact { animation: none; opacity: 1; padding: 8px 16px 0; }
.mode-btn {
  padding: 11px 24px;
  border: 1px solid var(--border-color);
  border-radius: 26px;
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.25s var(--ease-spring);
  font-family: 'Nunito', sans-serif;
}
.mode-btn i { font-size: 15px; opacity: 0.7; }
.mode-btn:hover {
  border-color: var(--gold);
  color: var(--gold);
  background: var(--gold-soft);
}
.mode-btn:active { transform: scale(0.95); }
.mode-btn.active {
  background: var(--gold);
  color: #fff;
  border-color: var(--gold);
}
.mode-btn.active i { opacity: 1; }

/* ══════════════════════════════════════════════════════════
   INPUT AREA
   ══════════════════════════════════════════════════════════ */
.input-wrap {
  width: 100%;
  max-width: 800px;
  align-self: center;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 0 16px 8px;
}
.input-wrap.centered {
  padding: 0;
  flex-direction: column;
  opacity: 0;
  animation: fadeUp 0.6s var(--ease-spring) 0.5s forwards;
}
.input-form {
  display: flex;
  align-items: center;
  width: 100%;
  position: relative;
  flex: 1;
  gap: 0;
  background: var(--input-bg);
  border: 2px solid var(--input-border);
  border-radius: 30px;
  padding: 6px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.04);
  transition: border 0.3s, box-shadow 0.3s;
}
.input-form:focus-within {
  border-color: var(--input-border-focus);
  box-shadow: 0 0 0 3px var(--gold-soft), 0 4px 16px rgba(0,0,0,0.06);
}
[data-theme="dark"] .input-form { box-shadow: 0 2px 12px rgba(0,0,0,0.2); }
[data-theme="dark"] .input-form:focus-within { box-shadow: 0 0 0 3px var(--gold-soft), 0 4px 16px rgba(0,0,0,0.3); }

.input-textarea {
  flex: 1;
  background: transparent;
  border: none;
  padding: 14px 16px;
  color: var(--text-primary);
  font-size: 18px;
  resize: none;
  min-height: 24px;
  max-height: 160px;
  outline: none;
  overflow-y: hidden;
  line-height: 1.4;
  font-family: 'Nunito', sans-serif;
}
.input-textarea::placeholder {
  color: var(--text-secondary);
  transition: opacity 0.3s;
}
.input-textarea:focus::placeholder { opacity: 0.5; }

.input-btns-right {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
  padding-right: 2px;
}

.send-btn, .mic-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--input-border);
  background: var(--send-bg);
  color: var(--send-icon);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s var(--ease-spring);
  font-size: 17px;
  flex-shrink: 0;
}
.send-btn:hover, .mic-btn:hover {
  background: var(--send-bg-hover);
  transform: scale(0.95);
}
.send-btn:active, .mic-btn:active { transform: scale(0.9); }
.send-btn.enabled {
  background: var(--text-primary);
  color: var(--bg-primary);
  border-color: var(--text-primary);
}
.send-btn:disabled { opacity: 0.4; cursor: default; }
.send-btn:disabled:hover { transform: none; }

/* Loading spinner in send button */
.send-btn .spinner {
  width: 18px; height: 18px;
  border: 2px solid transparent;
  border-top: 2px solid currentColor;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── Mic button states ── */
.mic-btn.recording {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
  animation: micPulse 1.5s ease-in-out infinite;
}
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(224, 82, 82, 0.4); }
  50% { box-shadow: 0 0 0 12px rgba(224, 82, 82, 0); }
}

/* ── Voice Waveform Visualizer ── */
.voice-wave {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-radius: 24px;
  width: 100%;
  max-width: 400px;
  animation: fadeUp 0.25s var(--ease-out);
}
.voice-wave.active { display: flex; }
.voice-wave-bars {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 36px;
  flex: 1;
  justify-content: center;
}
.voice-wave-bars span {
  width: 3px;
  height: 6px;
  border-radius: 2px;
  background: var(--gold);
  animation: waveBar 0.8s ease-in-out infinite;
  transform-origin: center;
}
.voice-wave-bars span:nth-child(1)  { animation-delay: 0s; }
.voice-wave-bars span:nth-child(2)  { animation-delay: 0.05s; }
.voice-wave-bars span:nth-child(3)  { animation-delay: 0.1s; }
.voice-wave-bars span:nth-child(4)  { animation-delay: 0.15s; }
.voice-wave-bars span:nth-child(5)  { animation-delay: 0.2s; }
.voice-wave-bars span:nth-child(6)  { animation-delay: 0.25s; }
.voice-wave-bars span:nth-child(7)  { animation-delay: 0.3s; }
.voice-wave-bars span:nth-child(8)  { animation-delay: 0.35s; }
.voice-wave-bars span:nth-child(9)  { animation-delay: 0.4s; }
.voice-wave-bars span:nth-child(10) { animation-delay: 0.45s; }
.voice-wave-bars span:nth-child(11) { animation-delay: 0.5s; }
.voice-wave-bars span:nth-child(12) { animation-delay: 0.55s; }
.voice-wave-bars span:nth-child(13) { animation-delay: 0.6s; }
.voice-wave-bars span:nth-child(14) { animation-delay: 0.55s; }
.voice-wave-bars span:nth-child(15) { animation-delay: 0.5s; }
.voice-wave-bars span:nth-child(16) { animation-delay: 0.45s; }
.voice-wave-bars span:nth-child(17) { animation-delay: 0.4s; }
.voice-wave-bars span:nth-child(18) { animation-delay: 0.35s; }
.voice-wave-bars span:nth-child(19) { animation-delay: 0.3s; }
.voice-wave-bars span:nth-child(20) { animation-delay: 0.25s; }
@keyframes waveBar {
  0%, 100% { height: 6px; }
  50% { height: 28px; }
}
.voice-stop-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  transition: all 0.2s var(--ease-spring);
}
.voice-stop-btn:hover { transform: scale(0.93); }
.voice-stop-btn:active { transform: scale(0.88); }

/* ── Clear button — RED for destructive action ── */
.clear-btn {
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--danger-soft);
  color: var(--danger);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s var(--ease-spring);
  font-size: 14px;
  flex-shrink: 0;
}
.clear-btn:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
  transform: scale(0.93);
}
.clear-btn:active { transform: scale(0.88); }

/* ══════════════════════════════════════════════════════════
   CHAT AREA & MESSAGES
   ══════════════════════════════════════════════════════════ */
.chat-area {
  flex: 1;
  padding: 32px 40px 180px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 800px;
  width: 100%;
  align-self: center;
  overflow-y: auto;
}
.chat-footer {
  position: fixed;
  bottom: 0; left: 0; width: 100%;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-primary);
  transition: background 0.4s;
}
.footer-bottom {
  padding: 4px 16px 14px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.footer-bottom .disclaimer-link {
  font-size: 13px;
  color: var(--gold);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s;
}
.footer-bottom .disclaimer-link:hover {
  text-shadow: 0 0 12px rgba(193,141,72,0.3);
}
.powered-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  opacity: 0.6;
  transition: opacity 0.3s;
}
.powered-inline:hover { opacity: 1; }
.powered-inline a { display: inline-flex; align-items: center; }
.powered-inline img { height: 20px; width: auto; }

/* ── Scroll to bottom button ── */
.scroll-bottom-btn {
  position: fixed;
  bottom: 180px;
  left: 50%;
  transform: translateX(-50%) scale(0);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  transition: all 0.25s var(--ease-bounce);
  opacity: 0;
}
.scroll-bottom-btn.visible {
  transform: translateX(-50%) scale(1);
  opacity: 1;
}
.scroll-bottom-btn:hover {
  background: var(--gold);
  color: #fff;
  border-color: var(--gold);
}

/* ── Messages (ChatGPT-style) ── */
.msg {
  max-width: 100%;
  opacity: 0;
  transform: translateY(12px);
  animation: fadeUp 0.3s var(--ease-out) forwards;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.msg-user { align-items: flex-end; }
.msg-ai { align-items: flex-start; }

.msg-content {
  padding: 14px 20px;
  border-radius: 20px;
  line-height: 1.75;
  font-size: 16px;
  max-width: 85%;
  word-wrap: break-word;
  overflow-wrap: break-word;
  transition: background 0.3s;
}
.msg-user .msg-content {
  background: var(--user-msg-bg);
  border-bottom-right-radius: 6px;
  font-size: 16px;
}
.msg-ai .msg-content {
  color: var(--text-primary);
  border-bottom-left-radius: 6px;
  padding: 16px 4px;
  max-width: 100%;
}

/* ── AI Message Markdown Styling (ChatGPT-like) ── */
.msg-ai .msg-content h1 { font-size: 20px; font-weight: 700; margin: 16px 0 8px; letter-spacing: -0.3px; }
.msg-ai .msg-content h2 { font-size: 18px; font-weight: 700; margin: 14px 0 6px; letter-spacing: -0.2px; }
.msg-ai .msg-content h3 { font-size: 16px; font-weight: 700; margin: 12px 0 4px; }
.msg-ai .msg-content p { margin: 8px 0; }
.msg-ai .msg-content ul, .msg-ai .msg-content ol {
  margin: 8px 0;
  padding-left: 24px;
}
.msg-ai .msg-content li {
  margin: 6px 0;
  line-height: 1.6;
}
.msg-ai .msg-content li::marker {
  color: var(--gold);
}
.msg-ai .msg-content strong { font-weight: 700; color: var(--text-primary); }
.msg-ai .msg-content em { font-style: italic; color: var(--text-secondary); }
.msg-ai .msg-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  font-size: 14px;
  border-radius: 8px;
  overflow: hidden;
}
.msg-ai .msg-content th, .msg-ai .msg-content td {
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  text-align: left;
}
.msg-ai .msg-content th {
  background: var(--bg-tertiary);
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.msg-ai .msg-content code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 14px;
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.msg-ai .msg-content pre {
  background: var(--bg-tertiary);
  padding: 14px 18px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 13px;
}
.msg-ai .msg-content pre code {
  background: none;
  padding: 0;
}
.msg-ai .msg-content blockquote {
  border-left: 3px solid var(--gold);
  padding: 8px 16px;
  margin: 10px 0;
  color: var(--text-secondary);
  font-style: italic;
  background: var(--gold-soft);
  border-radius: 0 8px 8px 0;
}
.msg-ai .msg-content a { color: var(--gold); text-decoration: underline; text-underline-offset: 2px; }
.msg-ai .msg-content hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 16px 0;
}

/* Message action buttons */
.msg-btns {
  display: flex;
  gap: 2px;
  padding: 2px 4px;
  transition: opacity 0.3s;
  height: 32px;
  opacity: 0;
}
.msg:hover .msg-btns { opacity: 1; }
.msg-ai .msg-btns { opacity: 1; }
.msg-user .msg-btns { justify-content: flex-end; }
.mbtn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  opacity: 0.6;
  transition: all 0.2s var(--ease-spring);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: 8px;
  font-size: 14px;
}
.mbtn:hover { opacity: 1; background: var(--bg-tertiary); transform: scale(0.92); }
.mbtn.active { color: var(--gold); opacity: 1; }
.mbtn.done { color: var(--gold); opacity: 1; }

/* Table export buttons */
.table-export-bar {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  padding: 4px 0;
}
.table-export-btn {
  padding: 4px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 11px;
  transition: all 0.2s var(--ease-spring);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: 'Nunito', sans-serif;
}
.table-export-btn:hover {
  border-color: var(--gold);
  color: var(--gold);
  background: var(--gold-soft);
}

/* ── Typing indicator ── */
.typing-msg {
  opacity: 0;
  animation: fadeUp 0.3s var(--ease-out) forwards;
}
.typing-msg .msg-content {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
}
.dot-pulse {
  display: flex;
  gap: 5px;
}
.dot-pulse span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: dotBounce 1.4s infinite both;
}
.dot-pulse span:nth-child(2) { animation-delay: 0.16s; }
.dot-pulse span:nth-child(3) { animation-delay: 0.32s; }
@keyframes dotBounce {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-6px); }
}
.typing-status {
  font-size: 13px;
  color: var(--text-secondary);
  font-style: italic;
}

/* ── Calculator Result Card ── */
.calc-result-card {
  background: var(--bg-secondary);
  border-radius: 16px;
  overflow: hidden;
  opacity: 0;
  animation: cardReveal 0.5s var(--ease-spring) forwards;
}
.calc-result-header {
  background: linear-gradient(135deg, var(--gold), #d4a55a);
  color: #fff;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
}
.calc-result-header i { font-size: 18px; }
.calc-result-body {
  padding: 16px 20px;
}
.calc-result-body .msg-content {
  padding: 0;
  max-width: 100%;
}
@keyframes cardReveal {
  0% { opacity: 0; transform: translateY(16px) scale(0.97); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Shimmer loading ── */
.shimmer {
  background: linear-gradient(90deg,
    var(--bg-tertiary) 25%,
    var(--bg-secondary) 50%,
    var(--bg-tertiary) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease infinite;
  border-radius: 8px;
  height: 16px;
  margin: 6px 0;
}
.shimmer:nth-child(2) { width: 80%; }
.shimmer:nth-child(3) { width: 60%; }
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ══════════════════════════════════════════════════════════
   CALCULATOR PANEL
   ══════════════════════════════════════════════════════════ */
.calc-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 24px;
  max-width: 600px;
  width: 100%;
  margin: 8px auto;
  display: none;
  animation: fadeUp 0.3s var(--ease-spring);
}
.calc-panel.show { display: block; }
.chat-footer .calc-panel {
  max-height: 50vh;
  overflow-y: auto;
  margin: 0 auto 4px;
  border-radius: 16px;
  max-width: 600px;
  width: calc(100% - 32px);
}
.calc-header {
  font-size: 16px;
  margin-bottom: 20px;
  color: var(--gold);
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}
.calc-header i { font-size: 18px; }
.calc-group { margin-bottom: 16px; }
.calc-group label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}
.calc-input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--input-bg);
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  transition: border 0.3s, box-shadow 0.3s;
  font-family: 'Nunito', sans-serif;
}
.calc-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}
.calc-select {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--input-bg);
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%237a7a85' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
  transition: border 0.3s, box-shadow 0.3s;
}
.calc-select:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}
.calc-row { display: flex; gap: 12px; }
.calc-row > * { flex: 1; }
.calc-rates {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 8px 0;
  opacity: 0.7;
}
.calc-submit {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--gold), #d4a55a);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s var(--ease-spring);
  font-family: 'Nunito', sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}
.calc-submit:hover { opacity: 0.92; transform: translateY(-1px); box-shadow: 0 6px 20px rgba(193,141,72,0.3); }
.calc-submit:active { transform: scale(0.98); }

/* ══════════════════════════════════════════════════════════
   MODALS
   ══════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(6px);
  background: rgba(0, 0, 0, 0.3);
}
.modal-overlay.show { display: flex; }
.modal-box {
  background: var(--bg-primary);
  border-radius: 20px;
  padding: 28px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  animation: modalIn 0.3s var(--ease-spring);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(-16px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 14px;
}
.modal-hdr h2 { font-size: 18px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  transition: all 0.2s;
  border-radius: 8px;
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { color: var(--text-primary); background: var(--bg-tertiary); }
.modal-body { font-size: 15px; line-height: 1.7; color: var(--text-primary); }
.modal-foot {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 20px;
}
.modal-foot button {
  padding: 10px 22px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
  font-family: 'Nunito', sans-serif;
  font-weight: 500;
}
.modal-foot button:hover { background: var(--bg-tertiary); }
.modal-foot button.danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.modal-foot button.danger:hover { opacity: 0.9; }
.modal-foot button.primary {
  background: var(--gold);
  color: #fff;
  border-color: var(--gold);
}

/* Share modal */
.share-preview {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 16px;
  font-size: 14px;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.6;
}
.share-links {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}
.share-links button {
  width: 48px; height: 48px;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 20px;
  transition: all 0.2s var(--ease-spring);
  display: flex;
  align-items: center;
  justify-content: center;
}
.share-links button:hover {
  background: var(--gold-soft);
  border-color: var(--gold);
  color: var(--gold);
  transform: scale(0.93);
}

/* ── Cookie banner ── */
.cookie-banner {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  padding: 18px 28px;
  z-index: 3000;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.08);
}
.cookie-banner.show { display: flex; }
.cookie-banner p { font-size: 14px; color: var(--text-primary); max-width: 600px; line-height: 1.5; }
.cookie-btns { display: flex; gap: 8px; }
.cookie-btns button {
  padding: 10px 24px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s var(--ease-spring);
  font-family: 'Nunito', sans-serif;
  font-weight: 500;
}
.cookie-btns button:hover { transform: scale(0.97); }
.cookie-btns .accept { background: var(--gold); color: #fff; border-color: var(--gold); }
.cookie-btns .reject { background: var(--bg-primary); color: var(--text-primary); }

/* ══════════════════════════════════════════════════════════
   POWERED BY FOOTER — always bottom-right
   ══════════════════════════════════════════════════════════ */
.powered-by-footer {
  position: fixed;
  bottom: 18px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0.5;
  transition: opacity 0.3s;
  z-index: 999;
}
.powered-by-footer:hover { opacity: 1; }
.powered-by-footer span { font-size: 12px; color: var(--text-secondary); }
.powered-by-footer a { display: flex; align-items: center; }
.powered-by-footer img { height: 28px; width: auto; }

/* ── Disclaimer text — ALWAYS GOLD ── */
.disclaimer-text {
  text-align: center;
  font-size: 14px;
  padding: 8px 16px 24px;
  max-width: 800px;
  align-self: center;
  opacity: 0;
  animation: fadeUp 0.6s var(--ease-spring) 0.55s forwards;
}
.disclaimer-text a, .disclaimer-link {
  color: var(--gold) !important;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.3s;
}
.disclaimer-text a:hover, .disclaimer-link:hover {
  text-shadow: 0 0 12px rgba(193,141,72,0.3);
}

/* ══════════════════════════════════════════════════════════
   ANIMATIONS
   ══════════════════════════════════════════════════════════ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE OPTIMIZATION
   Tested for: iPhone SE (375), iPhone 14 (390), iPhone 15 Pro Max (430),
   Samsung Galaxy S24 (412), Pixel 8 (412)
   ══════════════════════════════════════════════════════════ */

/* ── Tablet (≤768px) ── */
@media (max-width: 768px) {
  :root { --header-height: 60px; }
  .header {
    padding: 10px 14px;
    gap: 6px;
  }
  .logo-img { height: 34px; }
  
  /* MOBILE WELCOME — ChatGPT pattern:
     Title centered in screen, input pinned to bottom */
  .welcome {
    padding: 0 20px 16px;
    gap: 12px;
    justify-content: flex-start;
  }
  .welcome-title {
    font-size: 28px;
    letter-spacing: -1px;
    margin-top: auto; /* pushes title group to vertical center */
  }
  .welcome-sub {
    font-size: 15px;
    margin-bottom: auto; /* creates space below, pushes input to bottom */
  }
  /* Input area pins to bottom on mobile */
  .input-wrap.centered {
    padding: 0;
    width: 100%;
    margin-top: 0;
  }
  .welcome .calc-panel {
    width: 100%;
    margin: 0;
  }
  .disclaimer-text {
    font-size: 12px;
    padding: 4px 12px 8px !important;
  }

  .mode-bar { gap: 4px; }
  .mode-btn {
    padding: 9px 16px;
    font-size: 13px;
    border-radius: 22px;
  }
  .mode-btn svg { width: 14px; height: 14px; }

  .chat-area {
    padding: 20px 14px 170px;
    max-width: none;
    gap: 16px;
  }
  
  .msg-content {
    max-width: 92% !important;
    font-size: 15px;
    padding: 12px 16px;
    border-radius: 16px;
  }
  .msg-ai .msg-content {
    padding: 10px 4px;
    max-width: 100% !important;
  }
  .msg-ai .msg-content h1 { font-size: 18px; }
  .msg-ai .msg-content h2 { font-size: 16px; }
  .msg-ai .msg-content h3 { font-size: 15px; }
  .msg-ai .msg-content table { font-size: 13px; }
  .msg-ai .msg-content th, .msg-ai .msg-content td { padding: 6px 8px; }
  .msg-ai .msg-content pre { font-size: 12px; padding: 10px 12px; }

  .input-wrap { padding: 0 10px 6px; }
  .input-wrap.centered { padding: 0 16px; }
  .input-form {
    padding: 4px;
    border-radius: 24px;
    border-width: 1.5px;
  }
  /* iOS zoom prevention: keep font-size >= 16px */
  .input-textarea {
    font-size: 16px;
    padding: 10px 10px;
    min-height: 22px;
  }
  
  /* Touch targets: min 44px */
  .send-btn, .mic-btn {
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
  }
  .clear-btn {
    width: 42px;
    height: 42px;
    min-width: 42px;
  }

  .hdr-btn {
    padding: 10px 14px;
    font-size: 14px;
    border-radius: 40px;
    min-height: 44px;
  }
  .hdr-btn svg { width: 18px; height: 18px; }

  .disclaimer-text {
    font-size: 12px;
    padding: 2px 12px 40px !important; /* extra bottom for powered-by */
  }

  .calc-panel {
    margin: 8px 16px;
    padding: 18px;
    border-radius: 16px;
  }
  .chat-footer .calc-panel {
    width: calc(100% - 20px);
    max-height: 45vh;
  }
  .calc-input, .calc-select {
    padding: 12px 14px;
    font-size: 16px; /* prevent iOS zoom */
  }
  .calc-submit {
    padding: 14px;
    font-size: 15px;
    border-radius: 12px;
  }

  .msg-btns { gap: 2px; }
  .mbtn {
    width: 32px;
    height: 32px;
    min-width: 32px;
  }

  .footer-bottom { padding: 2px 12px 10px; }

  .powered-by-footer {
    bottom: 10px;
    right: 12px;
  }
  .powered-by-footer span { font-size: 10px; }
  .powered-by-footer img { height: 22px; }

  .scroll-bottom-btn { bottom: 170px; }

  .voice-wave {
    max-width: 90%;
    padding: 10px 16px;
  }
  .voice-wave-bars { height: 30px; }
  .voice-wave-bars span { width: 2.5px; }

  /* Modal full-width on mobile */
  .modal-box {
    width: 95%;
    max-width: none;
    padding: 20px;
    border-radius: 16px;
  }
  .modal-hdr h2 { font-size: 16px; }
  .modal-body { font-size: 14px; }
  .modal-foot button { padding: 10px 18px; font-size: 14px; }

  .share-links button {
    width: 44px;
    height: 44px;
  }

  /* Cookie banner stacks vertically */
  .cookie-banner {
    flex-direction: column;
    padding: 14px 16px;
    gap: 12px;
    text-align: center;
  }
  .cookie-banner p { font-size: 13px; }
  .cookie-btns {
    width: 100%;
    justify-content: center;
  }
  .cookie-btns button {
    flex: 1;
    padding: 10px 16px;
  }

  /* Calc result card */
  .calc-result-header {
    padding: 12px 16px;
    font-size: 14px;
  }
  .calc-result-body { padding: 12px 14px; }
}

/* ── Small phones (≤480px) — iPhone SE, older Androids ── */
@media (max-width: 480px) {
  .header { padding: 8px 10px; }
  .logo-img { height: 28px; }

  .welcome {
    padding: 10px 14px 8px;
    gap: 10px;
  }
  .welcome-title {
    font-size: 26px;
    letter-spacing: -0.5px;
    line-height: 1.2;
  }
  .welcome-sub { font-size: 13px; }

  .mode-btn {
    padding: 8px 14px;
    font-size: 12px;
    gap: 4px;
  }
  .mode-btn svg { width: 13px; height: 13px; }

  .chat-area {
    padding: 8px 10px 160px;
    gap: 12px;
  }
  .msg-content {
    font-size: 14px;
    padding: 10px 14px;
    border-radius: 14px;
    max-width: 95% !important;
  }
  .msg-ai .msg-content {
    padding: 8px 2px;
  }

  .input-textarea {
    padding: 10px 8px;
    font-size: 16px; /* MUST stay >=16 for iOS */
  }
  .send-btn, .mic-btn, .clear-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
  }

  .hdr-btn {
    padding: 8px 10px;
    min-height: 40px;
  }
  .hdr-btn svg { width: 16px; height: 16px; }

  .calc-panel {
    margin: 6px 10px;
    padding: 14px;
  }
  .calc-group label { font-size: 12px; }
  .calc-row { flex-direction: column; gap: 0; }

  .scroll-bottom-btn {
    bottom: 155px;
    width: 36px;
    height: 36px;
  }

  .voice-wave-bars span { width: 2px; gap: 2px; }

  .powered-by-footer {
    bottom: 8px;
    right: 8px;
  }
  .powered-by-footer span { font-size: 9px; }
  .powered-by-footer img { height: 18px; }

  /* Lang dropdown from bottom on small phones */
  .lang-dropdown {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    border-radius: 16px 16px 0 0;
    max-height: 50vh;
    min-width: auto;
    width: 100%;
    box-shadow: 0 -8px 32px rgba(0,0,0,0.15);
  }
  .lang-dropdown.open {
    padding: 8px;
  }
  .lang-dropdown button {
    padding: 14px 16px;
    font-size: 15px;
    justify-content: center;
  }
}

/* ── Very small screens (≤360px) — iPhone SE 1st gen, old Androids ── */
@media (max-width: 360px) {
  .welcome-title { font-size: 22px; }
  .welcome-sub { font-size: 12px; }
  .mode-btn { padding: 7px 10px; font-size: 11px; }
  .mode-btn span { display: none; }
  .hdr-btn { padding: 7px 8px; }
  .msg-content { font-size: 13px; padding: 8px 10px; }
}

/* ── Safe area for notched phones (iPhone X+) ── */
@supports (padding: max(0px)) {
  .header {
    padding-top: max(10px, env(safe-area-inset-top));
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  .chat-footer {
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }
  .cookie-banner {
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }
  .powered-by-footer {
    bottom: max(12px, env(safe-area-inset-bottom));
  }
}

/* ── Landscape phone ── */
@media (max-height: 500px) and (orientation: landscape) {
  .welcome {
    padding: 8px 24px;
    gap: 8px;
  }
  .welcome-title { font-size: 22px; }
  .welcome-sub { font-size: 13px; }
  .chat-area { padding-bottom: 130px; }
  .calc-panel { max-height: 60vh; overflow-y: auto; }
}

/* ── Virtual keyboard handling ── */
@media (max-height: 450px) {
  .welcome-title { display: none; }
  .welcome-sub { display: none; }
  .welcome { gap: 6px; justify-content: flex-end; padding-bottom: 8px; }
  .mode-bar { margin-bottom: 4px; }
}

/* ══════════════════════════════════════════════════════════
   GENERATION INDICATOR — Clean wave animation
   ══════════════════════════════════════════════════════════ */
.gen-indicator {
  max-width: 100%;
  opacity: 0;
  animation: fadeUp 0.3s var(--ease-out) forwards;
}
.gen-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 16px 20px;
  overflow: hidden;
  position: relative;
  max-width: 280px;
}
.gen-progress {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--bg-tertiary);
  overflow: hidden;
}
.gen-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold), #e8c078, var(--gold));
  background-size: 200% 100%;
  border-radius: 3px;
  animation: genProgress 45s ease-out forwards, genShimmer 2s ease-in-out infinite;
}
@keyframes genProgress {
  0% { width: 0%; }
  5% { width: 12%; }
  20% { width: 30%; }
  40% { width: 50%; }
  60% { width: 65%; }
  80% { width: 80%; }
  100% { width: 92%; }
}
@keyframes genShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.gen-body {
  display: flex;
  align-items: center;
  gap: 14px;
}
.gen-wave {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 24px;
}
.gen-wave span {
  width: 3px;
  height: 6px;
  border-radius: 2px;
  background: var(--gold);
  animation: genWave 1.2s ease-in-out infinite;
}
.gen-wave span:nth-child(1) { animation-delay: 0s; }
.gen-wave span:nth-child(2) { animation-delay: 0.1s; }
.gen-wave span:nth-child(3) { animation-delay: 0.2s; }
.gen-wave span:nth-child(4) { animation-delay: 0.3s; }
.gen-wave span:nth-child(5) { animation-delay: 0.4s; }
.gen-wave span:nth-child(6) { animation-delay: 0.3s; }
.gen-wave span:nth-child(7) { animation-delay: 0.2s; }
@keyframes genWave {
  0%, 100% { height: 6px; opacity: 0.4; }
  50% { height: 20px; opacity: 1; }
}
.gen-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.gen-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
.gen-time {
  font-size: 12px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.gen-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}
.gen-stop-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  font-family: 'Nunito', sans-serif;
  font-weight: 500;
  transition: all 0.2s var(--ease-spring);
}
.gen-stop-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-soft);
}
.gen-stop-btn:active { transform: scale(0.95); }
.gen-stop-btn svg { width: 10px; height: 10px; }

/* Stop button in send position */
.send-btn.stop-mode {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger);
}
.send-btn.stop-mode:hover {
  background: var(--danger);
  color: #fff;
}

@media (max-width: 768px) {
  .gen-card { padding: 12px 14px; border-radius: 12px; max-width: 240px; }
  .gen-label { font-size: 13px; }
  .gen-wave span { width: 2.5px; }
}