/* ============================================================
   Live Translate — dizayn tizimi
   Shrift: Inter. Rejimlar: yorug' (default) + qorong'i.
   ============================================================ */

:root {
  /* Yorug' rejim (default) */
  --bg: #f8f8f7;
  --surface: #ffffff;
  --surface-2: #f1f2f4;
  --border: #e7e8eb;
  --border-strong: #d7d9dd;
  --text: #16181d;
  --text-secondary: #545a64;
  --text-muted: #8a9099;
  --accent: #4f5fe8;
  --accent-soft: rgba(79, 95, 232, 0.12);
  --rec: #e5344b;
  --rec-soft: rgba(229, 52, 75, 0.13);
  --shadow-mic: 0 8px 24px rgba(22, 24, 29, 0.14);
  --shadow-pop: 0 4px 16px rgba(22, 24, 29, 0.08);

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --r-full: 999px;

  --reading: 720px;
  --header-h: 64px;

  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto,
    'Noto Sans', 'Noto Sans Arabic', 'Noto Sans JP', 'Noto Sans KR', sans-serif;
}

/* Qorong'i rejim — tizim sozlamasi bo'yicha (aniq tanlanmagan bo'lsa) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0a0b0d;
    --surface: #16181d;
    --surface-2: #1d2027;
    --border: #262a32;
    --border-strong: #353a44;
    --text: #f3f4f6;
    --text-secondary: #a7adba;
    --text-muted: #71767f;
    --accent: #6d8bff;
    --accent-soft: rgba(109, 139, 255, 0.16);
    --rec: #f4556a;
    --rec-soft: rgba(244, 85, 106, 0.16);
    --shadow-mic: 0 8px 28px rgba(0, 0, 0, 0.45);
    --shadow-pop: 0 4px 18px rgba(0, 0, 0, 0.4);
  }
}

/* Qorong'i rejim — qo'lda tanlangan */
:root[data-theme='dark'] {
  --bg: #0a0b0d;
  --surface: #16181d;
  --surface-2: #1d2027;
  --border: #262a32;
  --border-strong: #353a44;
  --text: #f3f4f6;
  --text-secondary: #a7adba;
  --text-muted: #71767f;
  --accent: #6d8bff;
  --accent-soft: rgba(109, 139, 255, 0.16);
  --rec: #f4556a;
  --rec-soft: rgba(244, 85, 106, 0.16);
  --shadow-mic: 0 8px 28px rgba(0, 0, 0, 0.45);
  --shadow-pop: 0 4px 18px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

/* [hidden] class-selektorlar (display:flex) tomonidan bosib ketmasin */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* ---------------- Topbar ---------------- */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  min-height: var(--header-h);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 0 0 auto;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.brand-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.lang-bar {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
}

.lang-select {
  position: relative;
  display: flex;
  align-items: center;
}

/* Til tanlash tugmasi (dropdown trigger) */
.lang-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 9px 11px 9px 13px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  max-width: 210px;
  min-width: 130px;
}
.lang-trigger:hover { background: color-mix(in srgb, var(--surface-2) 70%, var(--border)); }
.lang-trigger[aria-expanded='true'] {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.lang-trigger:focus-visible { outline: none; border-color: var(--accent); }

.lang-flag {
  font-size: 17px;
  line-height: 1;
  flex: 0 0 auto;
  filter: saturate(1.05);
}
.lang-name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lang-trigger.is-detect .lang-name { color: var(--accent); font-weight: 600; }

.lang-trigger .chevron {
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  flex: 0 0 auto;
  transition: transform 0.2s ease;
}
.lang-trigger[aria-expanded='true'] .chevron { transform: rotate(180deg); }

/* Ochiladigan panel */
.lang-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 60;
  width: 264px;
  max-width: min(88vw, 320px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-pop), 0 12px 40px rgba(0, 0, 0, 0.16);
  overflow: hidden;
  animation: panel-in 0.16s cubic-bezier(0.2, 0.9, 0.3, 1);
  transform-origin: top;
}
/* Nishon tanlagichni chapga tekislaymiz (o'ngdagi) */
#targetSelect .lang-panel { left: auto; right: 0; }

.lang-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  padding: 10px 10px 6px;
}
.lang-search-ico {
  position: absolute;
  left: 20px;
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  pointer-events: none;
}
.lang-search {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 8px 12px 8px 34px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.lang-search:focus { border-color: var(--accent); background: var(--surface); }
.lang-search::placeholder { color: var(--text-muted); }

.lang-list {
  max-height: min(340px, 52vh);
  overflow-y: auto;
  padding: 4px;
  overscroll-behavior: contain;
}

.lang-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  scroll-margin: 6px;
}
.lang-opt .lang-flag { font-size: 18px; }
.lang-opt-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lang-opt.active { background: var(--surface-2); }
.lang-opt.selected { color: var(--accent); font-weight: 600; }
.lang-opt.selected::after {
  content: '';
  margin-left: auto;
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  background: var(--accent);
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M5 12l5 5L20 7' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/></svg>") center / contain no-repeat;
}
.lang-opt.is-detect {
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  margin-bottom: 4px;
  padding-bottom: 12px;
}
.lang-opt.is-detect .lang-opt-name { font-weight: 600; }

.lang-none {
  padding: 18px 12px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ---------------- Tugmalar ---------------- */

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  flex: 0 0 auto;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.icon-btn:focus-visible {
  outline: none;
  border-color: var(--accent);
}
.icon-btn svg { width: 18px; height: 18px; }

.swap-btn { width: 34px; height: 34px; }
.swap-btn:active { transform: rotate(180deg); transition: transform 0.25s; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  margin-left: auto;
}

.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 36px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: all 0.15s;
}
.chip-btn svg { width: 15px; height: 15px; }
.chip-btn:hover { background: var(--surface-2); color: var(--text); }
.chip-btn[aria-pressed='true'] {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}
.chip-btn:focus-visible { outline: none; border-color: var(--accent); }

/* Ovoz turi (♀ ayol / ♂ erkak) — faqat Azure ovozi bor tillarda ko'rinadi */
.voice-picker-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 36px;
  margin-left: -2px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 17px;
  line-height: 1;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.voice-picker-btn:hover { background: var(--surface-2); color: var(--text); }
.voice-picker-btn.is-male { color: #4b9fff; }
.voice-picker-btn:not(.is-male) { color: #f472b6; }
.voice-picker-btn:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--accent-soft); }

/* ---------------- Eksport menyusi ---------------- */

.export-wrap {
  position: relative;
  display: inline-flex;
}

.export-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 60;
  width: 232px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-pop), 0 12px 40px rgba(0, 0, 0, 0.16);
  animation: panel-in 0.16s cubic-bezier(0.2, 0.9, 0.3, 1);
  transform-origin: top right;
}

.export-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: background 0.13s;
}
.export-item:hover { background: var(--surface-2); }
.export-item:focus-visible { outline: none; background: var(--surface-2); box-shadow: 0 0 0 2px var(--accent-soft); }
.export-item svg { width: 19px; height: 19px; flex: 0 0 auto; color: var(--text-secondary); }
.export-item:hover svg { color: var(--accent); }
.export-item span { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.export-item b { font-weight: 600; }
.export-item small { color: var(--text-muted); font-size: 11.5px; }

/* ---------------- Transkript ---------------- */

.transcript {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 32px 24px 40px;
  scroll-behavior: smooth;
}

.transcript > * {
  max-width: var(--reading);
  margin-left: auto;
  margin-right: auto;
}

.entry {
  padding: 14px 0 14px 16px;
  margin-bottom: 6px;
  border-left: 2px solid transparent;
  animation: rise 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.entry + .entry { border-top: 1px solid var(--border); }

.entry.active {
  border-left-color: var(--accent);
}

/* So'zlovchi yorlig'i (diarization) — rangli nuqta + "So'zlovchi N" */
.speaker-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.speaker-label::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--spk-color, var(--accent));
  flex: 0 0 auto;
}

.entry .original {
  font-size: 16px;
  font-weight: 450;
  line-height: 1.55;
  color: var(--text-secondary);
}

.entry.active .original::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 3px;
  vertical-align: -0.18em;
  background: var(--accent);
  border-radius: 1px;
  animation: caret 1.1s steps(1) infinite;
}

.translation-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 5px;
}

.entry .translation {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 21px;
  font-weight: 450;
  line-height: 1.5;
  letter-spacing: -0.011em;
  color: var(--text);
}

/* Ovozda eshitish tugmasi — tarjima yonida */
.speak-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin-top: 1px;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0.4;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.entry:hover .speak-btn,
.entry.speaking .speak-btn { opacity: 1; }
.speak-btn:hover { background: var(--surface-2); color: var(--accent); }
.speak-btn:focus-visible { outline: none; opacity: 1; color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.speak-btn svg { width: 18px; height: 18px; }
.speak-btn .ic-stop { display: none; }

/* O'qilayotgan yozuv — accent, "stop" ikonkasi, ovoz to'lqini */
.entry.speaking .speak-btn { color: var(--accent); background: var(--accent-soft); }
.entry.speaking .speak-btn .ic-speak { display: none; }
.entry.speaking .speak-btn .ic-stop { display: block; animation: pulse-soft 1.1s ease-in-out infinite; }
.entry.speaking .translation { color: var(--accent); }

/* Gap tugashidan oldingi taxminiy tarjima — yakuniysi kelguncha xiraroq */
.entry .translation.speculative { color: var(--text-secondary); }

/* Tarjima olinmadi — ko'zni qamashtirmaydigan, xolis ko'rinish */
.entry .translation.failed {
  color: var(--text-muted);
  font-size: 15px;
  font-style: italic;
}

/* Birinchi token kelguncha — animatsion nuqtalar */
.entry .translation.pending { color: var(--text-muted); }
.entry .translation.pending::after {
  content: '·';
  animation: dots 1.4s steps(1) infinite;
}

/* Claude sifatlash bosqichida ishlayotgani — kichik nur */
.entry .translation.refining::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 7px;
  vertical-align: 0.1em;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse-soft 1s ease-in-out infinite;
}

/* ---------------- Bo'sh holat ---------------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-top: min(16vh, 120px);
  color: var(--text-muted);
  animation: rise 0.4s ease;
}

.empty-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-muted);
  margin-bottom: 20px;
}
.empty-icon svg { width: 30px; height: 30px; }

.empty-title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  margin: 0 0 8px;
}

.empty-sub {
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-muted);
  margin: 0;
  max-width: 340px;
}

/* ---------------- Dok (mikrofon) ---------------- */

.dock {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px 20px calc(20px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  position: relative;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 26px;
  padding: 0 12px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  position: absolute;
  top: -13px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status.listening { background: var(--rec-soft); color: var(--rec); }
.status.listening .status-dot { background: var(--rec); animation: pulse-soft 1.2s ease-in-out infinite; }
.status.error { background: var(--rec-soft); color: var(--rec); }
.status.error .status-dot { background: var(--rec); }

.mic-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow-mic);
  transition: transform 0.12s ease, background 0.25s ease, box-shadow 0.25s ease;
  position: relative;
}
.mic-btn:hover { transform: translateY(-1px); }
.mic-btn:active { transform: scale(0.96); }
.mic-btn:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 3px; }
.mic-btn .mic-icon { width: 27px; height: 27px; position: relative; z-index: 2; }

/* Faol: qizil, nafas oluvchi glow + doimiy tarqaladigan halqalar */
.mic-btn.active {
  background: var(--rec);
  box-shadow: 0 8px 24px var(--rec-soft), 0 0 0 0 var(--rec-soft);
  animation: mic-breathe 2.4s ease-in-out infinite;
}
/* Ikki halqa turli fazada — uzluksiz "radar" to'lqini */
.mic-btn.active::before,
.mic-btn.active::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--rec);
  animation: ring 2s cubic-bezier(0.2, 0.6, 0.3, 1) infinite;
  z-index: 1;
}
.mic-btn.active::after { animation-delay: 1s; }

.dock-hint {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 0;
  height: 16px;
}
.mic-btn.active ~ .dock-hint { color: transparent; }

/* ---------------- Animatsiyalar ---------------- */

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes caret { 50% { opacity: 0; } }
@keyframes dots {
  0% { content: '·'; }
  33% { content: '··'; }
  66% { content: '···'; }
}
@keyframes pulse-soft {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.82); }
}
@keyframes ring {
  0% { transform: scale(1); opacity: 0.65; }
  100% { transform: scale(1.85); opacity: 0; }
}
@keyframes mic-breathe {
  0%, 100% { box-shadow: 0 8px 24px var(--rec-soft), 0 0 0 3px var(--rec-soft); }
  50% { box-shadow: 0 8px 30px var(--rec-soft), 0 0 0 8px transparent; }
}
@keyframes panel-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto; }
}

/* ---------------- Chop etish / PDF ---------------- */

/* Ekranda bosma sarlavhasi ko'rinmaydi */
.print-header { display: none; }

@media print {
  /* Faqat transkript qoladi — boshqaruvlar chiqmaydi */
  .topbar,
  .dock,
  .speak-btn,
  .empty-state,
  .export-menu,
  .lang-panel { display: none !important; }

  html, body {
    height: auto;
    overflow: visible;
    background: #fff;
    color: #000;
    font-size: 11pt;
  }

  .print-header {
    display: block;
    margin: 0 0 14pt;
    padding-bottom: 8pt;
    border-bottom: 1pt solid #bbb;
  }
  .print-header h1 { font-size: 16pt; margin: 0 0 3pt; color: #000; }
  .print-header p { font-size: 9.5pt; color: #555; margin: 0; }

  .transcript {
    overflow: visible !important;
    height: auto !important;
    padding: 0;
    display: block;
  }
  .transcript > * { max-width: none; }

  .entry {
    padding: 7pt 0 7pt 9pt;
    margin: 0 0 3pt;
    border-left: 1.5pt solid #999;
    border-top: none !important;
    animation: none;
    /* Yozuv sahifalar orasida bo'linib ketmasin */
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .entry.active .original::after { display: none; } /* kursor chiziqchasi */

  .speaker-label { color: #444; font-size: 8.5pt; margin-bottom: 3pt; }
  .speaker-label::before { background: #666 !important; }

  .entry .original {
    color: #555;
    font-size: 9.5pt;
    line-height: 1.4;
  }
  .entry .translation,
  .entry .translation.speculative {
    color: #000 !important;
    font-size: 11.5pt;
    line-height: 1.45;
    margin-top: 2pt;
  }
  .translation-row { display: block; }

  @page { margin: 16mm 14mm; }
}

/* ---------------- Skrollbar ---------------- */

.transcript::-webkit-scrollbar { width: 10px; }
.transcript::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--r-full);
  border: 3px solid var(--bg);
}
.transcript::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---------------- Mobil ---------------- */

@media (max-width: 640px) {
  .topbar {
    padding: 10px 14px;
    gap: 10px;
  }
  .lang-bar {
    order: 3;
    flex-basis: 100%;
    margin-top: 2px;
  }
  .lang-select { flex: 1 1 0; min-width: 0; }
  .lang-trigger { max-width: none; width: 100%; min-width: 0; }
  .lang-panel { width: 100%; max-width: none; }
  #targetSelect .lang-panel { right: 0; left: 0; }

  .transcript { padding: 22px 18px 32px; }

  .entry .translation { font-size: 19px; }
  .entry .original { font-size: 15px; }
  .speak-btn { opacity: 0.55; } /* mobilda hover yo'q — doim ko'rinsin */

  .mic-btn { width: 62px; height: 62px; }
  .empty-state { padding-top: 14vh; }
}

@media (max-width: 340px) {
  .brand-name { display: none; }
}
