/* Voice realtime overlay + archive sheet for v1 cabinet.
   Ported from cabinet_v2/styles.css, adapted to v1 tokens
   (--surface, --border, --text, --accent, --bg). v2-only tokens
   (--v2-surface-soft, --v2-text-muted, --v2-radius) get inline
   fallbacks so the visual matches v2 inside v1's pink theme. */

/* Без этого правила класс-селекторы с `display:flex`/`inline-flex` ниже
   перекрывают встроенный браузерный `[hidden]{display:none}` (одинаковая
   specificity, наш стиль идёт позже). В результате `el.hidden = true` в
   JS не прячет ни оверлей, ни back-кнопку, и закрыть архив/voice-mode
   становится невозможно. */
.voice-mode-overlay[hidden],
.voice-mode-voice-picker[hidden],
.archive-sheet[hidden],
.archive-back-btn[hidden],
.archive-detail[hidden],
.archive-list[hidden] { display: none !important; }

/* Header action cluster — 📚 / 📞 next to ✚ in the chat panel */
.rag-panel-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.rag-panel-icon {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.rag-panel-icon:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
.rag-panel-icon:active { transform: scale(0.96); }

/* ── Voice realtime overlay ── */
.voice-mode-overlay {
  position: fixed;
  inset: 0;
  z-index: 9500;
  display: flex;
  align-items: center;
  justify-content: center;
}
.voice-mode-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.62);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.voice-mode-panel {
  position: relative;
  z-index: 1;
  width: min(92vw, 420px);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 32px 24px 24px;
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 30px 80px rgba(0,0,0,0.35);
}
.voice-mode-orb {
  position: relative;
  width: 110px;
  height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.voice-mode-orb-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.18;
  animation: vm-orb-pulse 2.4s ease-in-out infinite;
}
.voice-mode-orb-core {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  box-shadow: 0 8px 30px rgba(190, 24, 93, 0.4);
}
@keyframes vm-orb-pulse {
  0%, 100% { transform: scale(1); opacity: 0.18; }
  50%      { transform: scale(1.18); opacity: 0.3; }
}
.voice-mode-orb.is-speaking .voice-mode-orb-pulse {
  animation-duration: 0.9s;
  opacity: 0.32;
}
.voice-mode-orb.is-speaking .voice-mode-orb-core {
  animation: vm-orb-speak 0.9s ease-in-out infinite;
}
@keyframes vm-orb-speak {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.08); }
}
.voice-mode-status {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-secondary);
  text-align: center;
  min-height: 1.4em;
}
.voice-mode-transcript {
  width: 100%;
  max-height: 220px;
  overflow-y: auto;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.9rem;
  line-height: 1.4;
}
.voice-mode-transcript:empty { display: none; }
.voice-mode-widgets {
  width: 100%;
  max-height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.voice-mode-widgets:empty { display: none; }
.voice-mode-widget {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-soft);
  font-size: 0.88rem;
  line-height: 1.35;
  color: var(--text);
}
.voice-mode-widget-head {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}
.voice-mode-widget-body { color: var(--text); }
.voice-mode-widget-hint {
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  opacity: 0.85;
}
.voice-mode-widget-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 2px;
}
.voice-mode-widget-item {
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.voice-mode-widget-item-title { font-size: 0.86rem; color: var(--text); }
.voice-mode-widget-item-sub {
  margin-top: 2px;
  font-size: 0.76rem;
  color: var(--text-secondary);
  opacity: 0.85;
}
.voice-mode-line {
  padding: 8px 12px;
  border-radius: 12px;
  word-wrap: break-word;
}
.voice-mode-line-user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  max-width: 88%;
}
.voice-mode-line-assistant {
  align-self: flex-start;
  background: var(--surface);
  color: var(--text);
  max-width: 92%;
  border: 1px solid var(--border);
}
.voice-mode-controls {
  display: flex;
  gap: 10px;
  width: 100%;
  margin-top: 4px;
}
.voice-mode-btn {
  flex: 1;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 0.95rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.voice-mode-btn:hover { background: var(--bg); }
.voice-mode-btn:active { transform: scale(0.98); }
.voice-mode-btn-secondary.is-muted {
  background: #fef3c7;
  border-color: #fcd34d;
  color: #92400e;
}
.voice-mode-btn-end {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
}
.voice-mode-btn-end:hover { background: #dc2626; border-color: #dc2626; }

/* Voice picker */
.voice-mode-voice-row {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}
.voice-mode-voice-toggle {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.86rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.voice-mode-voice-toggle:hover { background: var(--accent-soft); color: var(--accent); }
.voice-mode-voice-toggle-label { font-weight: 500; }
.voice-mode-voice-toggle-name { font-weight: 700; color: var(--text); }
.voice-mode-voice-toggle-chev { transition: transform 0.18s ease; }
.voice-mode-voice-toggle[aria-expanded="true"] .voice-mode-voice-toggle-chev {
  transform: rotate(180deg);
}
.voice-mode-voice-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 4px 4px;
  animation: vm-picker-pop 0.18s ease-out;
}
@keyframes vm-picker-pop {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.voice-mode-voice-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.voice-mode-voice-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.voice-mode-voice-chip:hover {
  background: var(--accent-soft);
  border-color: var(--accent-soft);
}
.voice-mode-voice-chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.voice-mode-voice-chip.is-active .voice-mode-voice-chip-hint { color: rgba(255,255,255,0.85); }
.voice-mode-voice-chip-name { font-size: 0.92rem; font-weight: 700; }
.voice-mode-voice-chip-hint { font-size: 0.78rem; color: var(--text-secondary); }
.voice-mode-voice-hint {
  margin: 0;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-secondary);
  opacity: 0.8;
  line-height: 1.4;
}

/* ── Archive sheet ── */
.archive-sheet {
  position: fixed;
  inset: 0;
  z-index: 9600;
  display: flex;
  align-items: stretch;
  justify-content: center;
}
.archive-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.archive-panel {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  animation: arch-slide-up 0.22s ease-out;
}
@keyframes arch-slide-up {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
.archive-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 2;
}
.archive-back-btn,
.archive-close-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.archive-back-btn:hover,
.archive-close-btn:hover {
  background: var(--accent-soft);
  color: var(--text);
}
.archive-title {
  flex: 1;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}
.archive-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px 24px;
}
.archive-loading {
  padding: 32px 8px;
  text-align: center;
  color: var(--text-secondary);
  opacity: 0.7;
  font-size: 0.92rem;
}
.archive-empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--text-secondary);
}
.archive-empty-title {
  margin: 0 0 6px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}
.archive-empty-sub {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

.archive-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.archive-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.archive-row:hover {
  background: var(--accent-soft);
  border-color: var(--accent-soft);
}
.archive-row:active { transform: scale(0.99); }
.archive-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.archive-row-ts {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.archive-row-arrow {
  color: var(--text-secondary);
  opacity: 0.6;
  font-size: 1.1rem;
}
.archive-row-preview {
  font-size: 0.97rem;
  line-height: 1.4;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.archive-row-preview-muted {
  color: var(--text-secondary);
  opacity: 0.7;
  font-style: italic;
}
.archive-row-meta {
  font-size: 0.82rem;
  color: var(--text-secondary);
  opacity: 0.8;
}

/* ── Thread switcher rows ─────────────────────────────────────────
   Row wrap = button + delete icon side-by-side. На активном треде
   подсвечиваем border-цветом + badge «Открыт». «+ Новый чат» — это
   тоже .archive-row, но с пунктирной рамкой, чтобы визуально отделить
   action-строку от списка тредов. */
.archive-row-wrap {
  display: flex;
  align-items: stretch;
  gap: 6px;
}
.archive-row-wrap .archive-row {
  flex: 1;
  margin: 0;
}
.archive-row-wrap-active .archive-row {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.archive-row-active-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent);
  background: rgba(0, 0, 0, 0);
  border: 1px solid var(--accent);
  border-radius: 999px;
  text-transform: uppercase;
  vertical-align: middle;
}
.archive-row-delete {
  flex: 0 0 auto;
  width: 44px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.archive-row-delete:hover {
  background: #fee;
  border-color: #fbb;
  color: #c33;
}
.archive-row-new {
  border-style: dashed;
  background: transparent;
}
.archive-row-new:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.archive-row-new .archive-row-ts {
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.archive-detail { padding-top: 4px; }
.archive-thread {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 4px 0 16px;
}
.archive-readonly-note {
  margin: 8px 0 24px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.4;
  text-align: center;
}

@media (max-width: 480px) {
  .archive-header { padding: 10px 10px; }
  .archive-body { padding: 10px 10px 20px; }
  .archive-row { padding: 12px 14px; }
  .voice-mode-panel { padding: 28px 18px 20px; }
}
