/* =========================================================================
   Kod Yozish Agenti — Dizayn tizimi
   Mavzu: terminal / kod muharriri estetikasi. Signature element: prompt
   belgisi ">" va miltillovchi kursor — brendni "kod yozuvchi agent" g'oyasiga
   bog'laydi. Ikki tema: dark (standart) va light, data-theme orqali.
   ========================================================================= */

@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&family=Inter:wght@400;500;600;700;800&family=Lora:ital,wght@0,500;0,600;0,700;1,500&display=swap");

:root,
:root[data-theme="dark"] {
  /* --- Rang tokenlari --- */
  --bg: #0a0c11;
  --bg-elevated: #0d1017;
  --surface: #12151d;
  --surface-2: #191d28;
  --surface-3: #212637;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #e9ecf3;
  --text-muted: #8890a3;
  --text-faint: #565d70;

  --accent: #5eead4;
  --accent-strong: #2dd4bf;
  --accent-soft: rgba(94, 234, 212, 0.12);
  --accent-ink: #06201c;
  --accent-2: #a78bfa;
  --accent-2-soft: rgba(167, 139, 250, 0.14);
  --accent-3: #fb923c;
  --accent-3-soft: rgba(251, 146, 60, 0.14);

  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, 0.12);

  --glass-bg: rgba(13, 16, 23, 0.6);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-glow: 0 0 0 1px var(--accent-soft), 0 0 24px -4px rgba(94, 234, 212, 0.35);
  --text-glow: 0 0 12px rgba(94, 234, 212, 0.55), 0 0 2px rgba(94, 234, 212, 0.8);

  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  color-scheme: dark;
}

/* Aksent rang doim "klassik teal" — yozuvlarga (havolalar, tugmalar) nozik
   neon-glow beradi, orqa fondagi ASCII-art surat esa doim monoxrom bo'lib
   qoladi. Oldin bir nechta rang varianti (neon yashil/ko'k, binafsha, amber)
   tanlab bo'lardi, lekin bu shунchaki ortiqcha rang-baranglik qilardi —
   shu sabab olib tashlandi va faqat standart teal qoldirildi. */

:root[data-theme="light"] {
  --bg: #f5f6fa;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --surface-3: #e3e7f0;
  --border: rgba(16, 24, 40, 0.09);
  --border-strong: rgba(16, 24, 40, 0.18);
  --text: #12151f;
  --text-muted: #5b6478;
  --text-faint: #9aa2b4;

  --accent: #0f8f81;
  --accent-strong: #0b6f64;
  --accent-soft: rgba(15, 143, 129, 0.1);
  --accent-ink: #ffffff;
  --accent-2: #6d5ce8;
  --accent-2-soft: rgba(109, 92, 232, 0.1);
  --accent-3: #c2410c;
  --accent-3-soft: rgba(194, 65, 12, 0.1);

  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.08);
  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, 0.08);

  --glass-bg: rgba(255, 255, 255, 0.68);

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 12px 28px rgba(16, 24, 40, 0.1);
  --shadow-glow: 0 0 0 1px var(--accent-soft), 0 0 24px -6px rgba(15, 143, 129, 0.25);
  --text-glow: none; /* Yorug' rejimda glow effekti kerak emas — o'qishni qiyinlashtiradi */

  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  color-scheme: light;
}


/* --- Shrift variantlari --- */
:root[data-font="mono"] { --font-body: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; }
:root[data-font="serif"] { --font-body: "Lora", Georgia, "Iowan Old Style", serif; }
:root[data-font="system"] { --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }

/* --- Reset & asos --- */
* { box-sizing: border-box; }
html, body { height: 100%; }

/* Ba'zi elementlar (.icon-btn, .mic-button, .attached-files va h.k.)
   o'zining "display: flex" qoidasiga ega, bu esa brauzerning ichki
   "[hidden] { display: none }" qoidasidan KUCHLIROQ bo'lib chiqadi va
   uni bekor qiladi — natijada "hidden" atributi qo'yilgan elementlar
   baribir ko'rinib qolardi (masalan: mobil menyu tugmasi desktopda,
   yoki brauzer ovozni qo'llab-quvvatlamasa ham mikrofon tugmasi).
   Shu qoida bilan "hidden" har doim eng yuqori ustunlikka ega bo'ladi. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
}

.mono {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--accent-soft); color: var(--text); }

*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* --- Orqa fon: ASCII-art surat, xira (blur) holatda ---
   Har sahifada bitta surat (3 tadan tasodifiy tanlanadi, sessiya davomida
   bir xil qoladi — bg-art.js'ga qarang). Oddiy holatda juda xira va past
   shaffoflikda turadi — shунchaki chuqurlik va atmosfera beradi, diqqatni
   chalg'itmaydi. Agent javob yozayotganda (bg-art.js orqali .is-active
   klassi qo'shiladi) surat biroz ochiqroq va aniqroq ko'rinadi — xuddi
   "parda ortidan" chiqib turgandek. Ustidagi shisha panellar (.sidebar,
   .topbar, .chat, .auth-card...) o'zlarining backdrop-filter: blur()
   xossasi orqali suratni yana ham yumshoqroq ko'rsatadi. */
.ascii-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ascii-bg__glow {
  position: absolute;
  inset: -10%;
  background: radial-gradient(ellipse 60% 45% at 50% 20%, var(--accent-soft) 0%, transparent 70%);
  opacity: 0.6;
  transition: opacity 1.3s ease, filter 1.3s ease;
  animation: ascii-bg-drift 14s ease-in-out infinite;
  will-change: opacity, filter;
}
/* Agent javob yozayotganda (typing indikatori faol): glow kuchayadi. */
.ascii-bg.is-active .ascii-bg__glow {
  opacity: 1;
  filter: brightness(1.15);
}
@keyframes ascii-bg-drift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(1.5%, 1%) scale(1.04); }
}
:root[data-theme="light"] .ascii-bg__glow {
  opacity: 0.5;
}
:root[data-theme="light"] .ascii-bg.is-active .ascii-bg__glow {
  opacity: 0.8;
}
.ascii-bg.is-static .ascii-bg__glow {
  animation: none;
}
@media (prefers-reduced-motion: reduce) {
  .ascii-bg__glow { animation: none; transition: none; }
}

/* =========================================================================
   Umumiy: brend, top-bar, tugmalar
   ========================================================================= */

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  color: var(--text);
}

.brand__prompt {
  color: var(--accent);
  text-shadow: var(--text-glow);
}

.brand__caret {
  display: inline-block;
  width: 9px;
  height: 1.15em;
  background: var(--accent);
  animation: caret-blink 1.05s steps(1) infinite;
  border-radius: 1px;
  transform: translateY(2px);
  box-shadow: var(--shadow-glow);
}

@keyframes caret-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 10px;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.icon-btn svg { width: 17px; height: 17px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-size: 14.5px;
  font-weight: 600;
  transition: transform 0.12s ease, background 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow-sm);
}
.btn--primary:hover:not(:disabled) { background: var(--accent-strong); box-shadow: var(--shadow-glow); }

.btn--ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn--ghost:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border-strong); }

.btn--block { width: 100%; }

/* Tema almashtirish tugmasi */
.theme-toggle {
  position: relative;
  width: 52px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 3px;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}
.theme-toggle__thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-ink);
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  transform: translateX(0);
}
[data-theme="light"] .theme-toggle__thumb { transform: translateX(22px); }
.theme-toggle__thumb svg { width: 13px; height: 13px; }

/* =========================================================================
   App shell (chat)
   ========================================================================= */

.shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 236px 1fr;
  height: 100vh;
  transition: grid-template-columns 0.18s ease;
}

.shell.is-collapsed {
  grid-template-columns: 68px 1fr;
}

.sidebar {
  background: var(--glass-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 16px;
  overflow: hidden;
}

.sidebar__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
}

.sidebar__collapse-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar__collapse-btn:hover { background: var(--surface-2); color: var(--text); }
.sidebar__collapse-btn svg { width: 16px; height: 16px; }

.sidebar__brand { padding: 0 4px; white-space: nowrap; overflow: hidden; }

.sidebar__new {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  border: 1px solid var(--accent-soft);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar__new:hover { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.sidebar__sessions-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.sidebar__sessions {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar__sessions-empty {
  font-size: 12px;
  color: var(--text-faint);
  padding: 8px 6px;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 8px;
  transition: background 0.15s ease;
}
.session-item:hover { background: var(--surface-2); }
.session-item.is-active { background: var(--surface-2); }
.session-item__text {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  padding: 9px 4px 9px 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-item.is-active .session-item__text,
.session-item:hover .session-item__text { color: var(--text); }
.session-item__del {
  background: none;
  border: none;
  color: var(--text-faint);
  padding: 6px;
  margin-right: 4px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.session-item:hover .session-item__del { opacity: 1; }
.session-item__del:hover { color: var(--danger); background: var(--danger-soft); }

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text-muted);
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar__link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar__link.is-active { background: var(--surface-2); color: var(--accent-strong); text-shadow: var(--text-glow); }
.sidebar__link svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.85; }

.sidebar__footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  position: relative;
}

.account-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  background: transparent;
  border: none;
  border-radius: 10px;
  padding: 7px 8px;
  text-align: left;
}
.account-btn:hover { background: var(--surface-2); }
.account-btn__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}
.account-btn__text {
  min-width: 0;
  flex: 1;
  overflow: hidden;
}
.account-btn__name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.account-btn__hint {
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-popover {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 4px;
  right: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 6px;
  display: none;
  z-index: 30;
}
.account-popover.is-open { display: block; }
.account-popover a,
.account-popover button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  padding: 9px 10px;
  border-radius: 8px;
  text-align: left;
}
.account-popover a:hover,
.account-popover button:hover { background: var(--surface-2); text-decoration: none; }
.account-popover svg { width: 15px; height: 15px; color: var(--text-muted); flex-shrink: 0; }
.account-popover hr { border: none; border-top: 1px solid var(--border); margin: 5px 2px; }

/* --- Collapsed (rail) holat: matn va sarlavhalarni yashiramiz --- */
.shell.is-collapsed .sidebar__brand span:not(.brand__prompt),
.shell.is-collapsed .sidebar__new span,
.shell.is-collapsed .sidebar__link span,
.shell.is-collapsed .sidebar__sessions-wrap,
.shell.is-collapsed .account-btn__text {
  display: none;
}
.shell.is-collapsed .sidebar__new,
.shell.is-collapsed .sidebar__link,
.shell.is-collapsed .account-btn {
  justify-content: center;
}
.shell.is-collapsed .sidebar { align-items: center; }
.shell.is-collapsed .sidebar__top { justify-content: center; flex-direction: column; gap: 10px; }
.shell.is-collapsed .account-popover { left: 60px; bottom: 8px; right: auto; width: 220px; }

/* --- Asosiy chat maydoni --- */

.main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--glass-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.topbar h1 {
  font-size: 15px;
  margin: 0;
  font-weight: 600;
  color: var(--text-muted);
}

.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* ---------- Model picker (input ichida, Gemini uslubida) ---------- */

.model-picker {
  position: relative;
  flex-shrink: 0;
}

.model-picker__btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
  font-family: "JetBrains Mono", monospace;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.model-picker__btn:hover { background: var(--surface-3); color: var(--text); }
.model-picker__btn.is-open { border-color: var(--accent); color: var(--text); }

.model-popover {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  padding: 6px;
  z-index: 40;
}

.model-popover__option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  width: 100%;
  background: none;
  border: none;
  border-radius: 10px;
  padding: 9px 11px;
  text-align: left;
}
.model-popover__option:hover { background: var(--surface-2); }
.model-popover__option.is-active { background: var(--accent-soft); }
.model-popover__option.is-active .model-popover__title { color: var(--accent-strong); }

.model-popover__title { font-size: 13.5px; font-weight: 600; color: var(--text); }
.model-popover__desc { font-size: 11.5px; color: var(--text-faint); }

.model-popover hr { border: none; border-top: 1px solid var(--border); margin: 6px 4px; }

.model-popover__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 10px;
  cursor: pointer;
}
.model-popover__toggle:hover { background: var(--surface-2); }

@media (max-width: 860px) {
  .model-popover { right: auto; left: 0; width: 240px; }
}

.rate-limit-badge {
  font-size: 11px;
  color: var(--text-faint);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 10px;
  white-space: nowrap;
}
.rate-limit-badge.is-low { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }

.attached-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 clamp(20px, 6vw, 96px) 10px;
}
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 6px 5px 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.file-chip button {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 15px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 50%;
}
.file-chip button:hover { color: var(--danger); background: var(--danger-soft); }

/* --- Kod bloklari --- */
.code-block {
  margin: 10px 0 2px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
}
.code-block__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-faint);
  text-transform: lowercase;
}
.code-block__actions { display: flex; gap: 6px; }
.code-block__actions button {
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 11px;
  font-family: "JetBrains Mono", monospace;
}
.code-block__actions button:hover { color: var(--text); border-color: var(--border-strong); }
.code-block pre {
  margin: 0;
  padding: 13px 15px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.55;
}
.code-block code {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  background: none !important;
}
.code-block__output {
  border-top: 1px solid var(--border);
  padding: 10px 15px;
  font-size: 12px;
  white-space: pre-wrap;
  color: var(--accent-strong);
  background: var(--surface);
}

.chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: var(--glass-bg);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
}

.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 28px clamp(20px, 6vw, 96px);
}

.message {
  max-width: 680px;
  padding: 13px 16px;
  border-radius: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  font-size: 14.5px;
  animation: rise 0.22s ease;
  box-shadow: var(--shadow-sm);
}

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

.message--user {
  align-self: flex-end;
  background: var(--accent-soft);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-bottom-right-radius: 4px;
  font-weight: 500;
}

.message--assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* ---------- Xabar ichidagi formatlash (oddiy markdown) ---------- */

.message--assistant h1,
.message--assistant h2,
.message--assistant h3 {
  margin: 14px 0 8px;
  font-weight: 700;
  line-height: 1.3;
}
.message--assistant h1:first-child,
.message--assistant h2:first-child,
.message--assistant h3:first-child { margin-top: 2px; }
.message--assistant h1 { font-size: 18px; }
.message--assistant h2 { font-size: 16.5px; }
.message--assistant h3 { font-size: 15px; color: var(--accent-strong); }

.message--assistant strong { font-weight: 700; color: var(--text); }
.message--assistant em { font-style: italic; }

.message--assistant ul,
.message--assistant ol {
  margin: 6px 0 10px;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.message--assistant li { line-height: 1.55; }

.message--assistant p { margin: 0 0 10px; }
.message--assistant p:last-child { margin-bottom: 0; }

.md-table-wrap {
  overflow-x: auto;
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.md-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13.5px;
}
.md-table th,
.md-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.md-table th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.md-table tr:last-child td { border-bottom: none; }
.md-table tr:hover td { background: var(--surface-2); }

.md-inline-code {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.9em;
  color: var(--accent-strong);
}

.message--system {
  align-self: center;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger-soft);
  font-size: 12.5px;
  border-radius: 10px;
}

.message__badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: "JetBrains Mono", monospace;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 3px 8px;
  border-radius: 999px;
  margin-bottom: 8px;
  text-transform: lowercase;
}
.message__badge.is-code { background: var(--accent-soft); color: var(--accent-strong); text-shadow: var(--text-glow); }
.message__badge.is-idea { background: var(--accent-2-soft); color: var(--accent-2); }
.message__badge.is-image { background: var(--success-soft); color: var(--success); }
.message__badge.is-research { background: var(--accent-3-soft); color: var(--accent-3); }

.message__image-wrap {
  position: relative;
  display: inline-block;
  max-width: min(420px, 100%);
  margin-top: 10px;
}
.message__image {
  display: block;
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
}
.message__image-download {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: rgba(13, 16, 23, 0.65);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.message__image-wrap:hover .message__image-download,
.message__image-download:focus-visible {
  opacity: 1;
}
.message__image-download:hover { background: rgba(13, 16, 23, 0.85); }
@media (max-width: 767px) {
  /* Sensorli ekranda hover bo'lmaydi — tugma doim ko'rinadi */
  .message__image-download { opacity: 1; }
}

/* --- Kiritish formasi --- */

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 16px clamp(20px, 6vw, 96px) 22px;
  border-top: 1px solid var(--border);
  background: var(--glass-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.chat-form textarea {
  flex: 1;
  resize: none;
  max-height: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 13px 15px;
  color: var(--text);
  font-size: 14.5px;
  font-family: inherit;
  line-height: 1.5;
}
.chat-form textarea::placeholder { color: var(--text-faint); }
.chat-form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.chat-form button[type="submit"] {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 12px;
  padding: 13px 22px;
  font-size: 14.5px;
  font-weight: 700;
  font-family: "JetBrains Mono", monospace;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
  box-shadow: var(--shadow-sm);
}
.chat-form button[type="submit"]:hover:not(:disabled) { background: var(--accent-strong); box-shadow: var(--shadow-glow); }
.chat-form button[type="submit"]:active:not(:disabled) { transform: scale(0.97); }
.chat-form button:disabled { opacity: 0.55; cursor: not-allowed; }

.mic-button {
  position: relative;
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.mic-button:hover { color: var(--text); border-color: var(--accent); }

.mic-icon { display: block; transition: opacity 0.15s ease; }

.mic-waves {
  position: absolute;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 18px;
}
.mic-waves span {
  display: block;
  width: 2.5px;
  border-radius: 2px;
  background: var(--danger);
  animation: wave 0.9s ease-in-out infinite;
}
.mic-waves span:nth-child(1) { height: 6px;  animation-delay: 0s; }
.mic-waves span:nth-child(2) { height: 14px; animation-delay: 0.1s; }
.mic-waves span:nth-child(3) { height: 18px; animation-delay: 0.2s; }
.mic-waves span:nth-child(4) { height: 12px; animation-delay: 0.3s; }
.mic-waves span:nth-child(5) { height: 7px;  animation-delay: 0.4s; }

@keyframes wave {
  0%, 100% { transform: scaleY(0.4); opacity: 0.6; }
  50% { transform: scaleY(1); opacity: 1; }
}

.mic-button--active {
  border-color: var(--danger);
  animation: mic-pulse 1.4s infinite;
}
.mic-button--active .mic-icon { display: none; }
.mic-button--active .mic-waves { display: flex; }

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.35); }
  50% { box-shadow: 0 0 0 8px rgba(248, 113, 113, 0); }
}

.status {
  min-height: 18px;
  font-size: 12.5px;
  font-family: "JetBrains Mono", monospace;
  color: var(--text-faint);
  margin: 0;
  padding: 0 clamp(20px, 6vw, 96px) 4px;
}

.typing-dots { display: inline-flex; gap: 4px; padding: 2px 0; }
.typing-dots span {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* =========================================================================
   Auth sahifalari
   ========================================================================= */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  z-index: 1;
}

.auth-topbar {
  position: fixed;
  top: 20px;
  left: 24px;
  right: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 2;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--glass-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 36px 32px 30px;
  display: flex;
  flex-direction: column;
  gap: 15px;
  box-shadow: var(--shadow-md);
}

.auth-card__eyebrow {
  font-family: "JetBrains Mono", monospace;
  font-size: 11.5px;
  color: var(--accent-strong);
  text-transform: lowercase;
  letter-spacing: 0.02em;
  margin: 0 0 -6px;
}

.auth-card h1 {
  margin: 0 0 2px;
  font-size: 23px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.auth-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.auth-card input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
.auth-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.auth-card input::placeholder { color: var(--text-faint); }

.auth-card button[type="submit"] { margin-top: 6px; }

.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-faint);
  font-size: 12px;
  text-transform: lowercase;
  margin: 2px 0;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.btn--google {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn--google:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
  text-decoration: none;
}

.auth-note {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  margin: 0;
  line-height: 1.5;
}

.auth-switch {
  font-size: 13px;
  color: var(--text-muted);
  margin: 4px 0 0;
  text-align: center;
}

.auth-error {
  color: var(--danger);
  font-size: 12.5px;
  min-height: 16px;
  margin: 0;
  font-weight: 500;
}

/* =========================================================================
   Sozlamalar
   ========================================================================= */

.page {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--glass-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.page-nav {
  display: flex;
  gap: 18px;
  font-size: 13.5px;
  font-family: "JetBrains Mono", monospace;
  align-items: center;
}
.page-nav a { color: var(--text-muted); }
.page-nav a:hover { color: var(--text); }
.page-nav a.is-active { color: var(--accent-strong); text-shadow: var(--text-glow); }

.page-body {
  padding: 28px 24px 40px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  flex: 1;
}

.section-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 11.5px;
  color: var(--text-faint);
  text-transform: lowercase;
  letter-spacing: 0.03em;
  margin: 0 0 -8px;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  transition: border-color 0.15s ease;
}
.settings-row:hover { border-color: var(--border-strong); }

.settings-row__text { display: flex; flex-direction: column; gap: 3px; }
.settings-row__title { font-size: 14.5px; font-weight: 600; }
.settings-row__desc { font-size: 12.5px; color: var(--text-muted); }

.settings-row select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13.5px;
  font-family: inherit;
}

/* Switch (checkbox) */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch__track {
  position: absolute;
  inset: 0;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.switch__track::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: var(--text-faint);
  border-radius: 50%;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), background 0.2s ease;
}
.switch input:checked + .switch__track { background: var(--accent-soft); border-color: var(--accent); }
.switch input:checked + .switch__track::before { transform: translateX(18px); background: var(--accent); }

/* Sozlamalar sahifasi ichidagi bo'lim-tablari ("Mavzular" / "Suhbat") */
.settings-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--border);
}
.settings-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 4px;
  margin-bottom: -1px;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 600;
}
.settings-tab + .settings-tab { margin-left: 14px; }
.settings-tab:hover { color: var(--text); }
.settings-tab.is-active {
  color: var(--accent-strong);
  border-bottom-color: var(--accent);
  text-shadow: var(--text-glow);
}
.settings-panel[hidden] { display: none; }

.theme-row {
  display: flex;
  gap: 8px;
}
.theme-pill {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  transition: all 0.15s ease;
}
.theme-pill svg { width: 14px; height: 14px; }
.theme-pill.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.badge-soon {
  font-family: "JetBrains Mono", monospace;
  font-size: 9.5px;
  text-transform: lowercase;
  color: var(--text-faint);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 7px;
  margin-left: 8px;
  vertical-align: middle;
}

.font-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.font-pill {
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  text-align: left;
}
.font-pill__sample { font-size: 15px; color: var(--text); }
.font-pill__label { font-size: 11px; }
.font-pill.is-active { border-color: var(--accent); background: var(--accent-soft); }
.font-pill.is-active .font-pill__label { color: var(--accent-strong); }

@media (max-width: 480px) {
  .font-row { grid-template-columns: 1fr; }
}

/* =========================================================================
   Tarix (history) sahifasi
   ========================================================================= */

.history-toolbar {
  display: flex;
  gap: 10px;
}

.history-toolbar input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 14px;
  color: var(--text);
  font-size: 13.5px;
  font-family: "JetBrains Mono", monospace;
}
.history-toolbar input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-empty {
  border: 1px dashed var(--border-strong);
  border-radius: 14px;
  padding: 40px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
}
.history-empty strong { display: block; color: var(--text); font-size: 14.5px; margin-bottom: 6px; }

.history-entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
}
.history-entry__role {
  font-family: "JetBrains Mono", monospace;
  font-size: 10.5px;
  text-transform: lowercase;
  color: var(--accent-strong);
  margin-bottom: 6px;
  display: block;
}
.history-entry.is-assistant .history-entry__role { color: var(--accent-2); }
.history-entry__text { white-space: pre-wrap; line-height: 1.55; font-size: 14px; }

/* =========================================================================
   Responsive
   ========================================================================= */

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 30% 0 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-md);
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 15;
  }
  .sidebar-scrim.is-open { display: block; }
  .topbar { padding: 14px 16px; }
  .messages { padding: 20px 16px; }
  .chat-form { padding: 14px 16px 18px; }
  .status { padding: 0 16px 4px; }
  .message { max-width: 90%; }
}

@media (max-width: 600px) {
  .auth-card { padding: 28px 22px; }
  .page-header { padding: 16px; }
  .page-body { padding: 22px 16px 32px; }

  /* Tor ekranlarda mic/attach/model-picker/yuborish tugmalari matnni
     siqib, textarea joyini yeb qo'yardi (flex-shrink: 0 tufayli butun
     siqilish yukini yagona textarea ko'tarardi). Shu sabab kiritish
     qatorini ikki qatorga bo'lamiz: birinchi qatorda to'liq kengliqdagi
     textarea, ikkinchisida tugmalar. */
  .chat-form { flex-wrap: wrap; row-gap: 8px; }
  .chat-form textarea { order: 1; flex-basis: 100%; }
  .mic-button { order: 2; }
  .model-picker { order: 3; }
  .chat-form button[type="submit"] { order: 4; margin-left: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .brand__caret,
  .message,
  .typing-dots span,
  .mic-button--active { animation: none !important; }
}
