/* ── Bootstrap Icons (local subset) ── */
@font-face {
  font-family: "bootstrap-icons";
  font-display: block;
  src: url("fonts/bootstrap-icons.woff2") format("woff2"),
       url("fonts/bootstrap-icons.woff") format("woff");
}

[class^="bi-"]::before,
[class*=" bi-"]::before {
  font-family: "bootstrap-icons" !important;
  font-style: normal;
  font-weight: normal;
  line-height: 1;
  vertical-align: -0.125em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.bi-list::before               { content: "\f479"; }
.bi-gear::before               { content: "\f3e5"; }
.bi-volume-mute::before        { content: "\f60d"; }
.bi-volume-up::before          { content: "\f611"; }
.bi-send-fill::before          { content: "\f6b9"; }
.bi-skip-backward-fill::before { content: "\f551"; }
.bi-skip-forward-fill::before  { content: "\f55d"; }
.bi-stop-fill::before          { content: "\f592"; }
.bi-play-fill::before          { content: "\f4f4"; }
.bi-mic::before                { content: "\f490"; }
.bi-arrow-repeat::before       { content: "\f130"; }
.bi-arrow-clockwise::before    { content: "\f116"; }
.bi-pencil::before             { content: "\f4cb"; }
.bi-check-lg::before           { content: "\f633"; }
.bi-key::before                { content: "\f44f"; }
.bi-x-lg::before               { content: "\f659"; }
.bi-arrow-left::before         { content: "\f12f"; }

/* ── Theme variables ── */
:root {
  --bg-primary: #1a1b2e;
  --bg-secondary: #222340;
  --bg-tertiary: #2a2b4a;
  --bg-input: #2e2f52;
  --bg-hover: #33345a;
  --bg-user-bubble: #3d5afe;
  --bg-bot-bubble: #2a2b4a;
  --text-primary: #e8e8f0;
  --text-secondary: #9a9ab0;
  --text-muted: #6a6a80;
  --accent: #6c63ff;
  --accent-hover: #7b73ff;
  --border: #3a3b5a;
  --danger: #e74c5e;
  --danger-hover: #ff5c6e;
  --success: #4caf80;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --danger-bg: rgba(231, 76, 94, 0.12);
  --overlay-subtle: rgba(255,255,255,0.06);
  --overlay-medium: rgba(255,255,255,0.12);
  --code-bg: rgba(255,255,255,0.08);
  --pre-bg: rgba(0,0,0,0.3);
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-width: 280px;
  --header-height: 50px;
  --transition: 0.2s ease;
}

/* ── Light theme ── */
[data-theme="light"] {
  --bg-primary: #f5f5f8;
  --bg-secondary: #ffffff;
  --bg-tertiary: #ebedf0;
  --bg-input: #ffffff;
  --bg-hover: #e2e4e8;
  --bg-user-bubble: #3d5afe;
  --bg-bot-bubble: #ebedf0;
  --text-primary: #1a1b2e;
  --text-secondary: #5a5a70;
  --text-muted: #8a8a9a;
  --accent: #5a52e0;
  --accent-hover: #4a42d0;
  --border: #d8dae0;
  --danger: #d63a4a;
  --danger-hover: #c0202f;
  --success: #3a9a6a;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --danger-bg: rgba(214, 58, 74, 0.10);
  --overlay-subtle: rgba(0,0,0,0.04);
  --overlay-medium: rgba(0,0,0,0.08);
  --code-bg: rgba(0,0,0,0.06);
  --pre-bg: rgba(0,0,0,0.04);
}
[data-theme="light"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235a5a70' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}

button { cursor: pointer; font-family: inherit; font-size: inherit; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; font-size: inherit; color: var(--text-primary); background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239a9ab0' d='M2 4l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }

.hidden { display: none !important; }

/* ── Header ── */
#header {
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  position: relative;
  z-index: 20;
}
#header h1 { font-size: 16px; font-weight: 600; letter-spacing: 0.5px; }
#sidebar-toggle { font-size: 18px; padding: 4px 8px; border-radius: var(--radius-sm); }
#sidebar-toggle:hover { background: var(--bg-hover); }

/* ── Layout ── */
#app { display: flex; flex-direction: column; height: 100vh; }
#main-layout { display: flex; flex: 1; overflow: hidden; }

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: margin-left var(--transition), opacity var(--transition);
  z-index: 10;
}
#sidebar.collapsed { margin-left: calc(var(--sidebar-width) * -1); opacity: 0; pointer-events: none; }

.sidebar-search { padding: 12px; }
.sidebar-search input { width: 100%; }

.sidebar-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.sidebar-list::-webkit-scrollbar { width: 4px; }
.sidebar-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.chat-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
  transition: background var(--transition);
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-tertiary); }
.chat-item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; font-size: 13px; }
.chat-item-delete {
  opacity: 0; font-size: 16px; padding: 0 4px; color: var(--text-muted);
  transition: opacity var(--transition), color var(--transition);
}
.chat-item:hover .chat-item-delete { opacity: 1; }
.chat-item-delete:hover { color: var(--danger); }

.sidebar-actions { padding: 8px; display: flex; flex-direction: column; gap: 4px; border-top: 1px solid var(--border); }
.sidebar-btn {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  text-align: left;
  font-size: 13px;
  transition: background var(--transition);
}
.sidebar-btn:hover { background: var(--bg-hover); }

/* ── Chat View ── */
#chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#config-bubble-wrapper { display: flex; justify-content: center; padding: 10px 16px 0; }
#config-bubble {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  padding: 6px 18px;
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-secondary);
  transition: background var(--transition), border-color var(--transition);
}
#config-bubble:hover { background: var(--bg-hover); border-color: var(--accent); }

/* ── Messages ── */
#messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#messages-container::-webkit-scrollbar { width: 6px; }
#messages-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.message { display: flex; }
.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }

.bubble {
  max-width: 72%;
  padding: 10px 16px;
  border-radius: var(--radius);
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.message.user .bubble { background: var(--bg-user-bubble); border-bottom-right-radius: 2px; }
.message.assistant .bubble { background: var(--bg-bot-bubble); border-bottom-left-radius: 2px; border: 1px solid var(--border); }

.bubble-stats {
  display: flex;
  gap: 12px;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--overlay-subtle);
}
.bubble-actions { display: flex; gap: 6px; margin-top: 6px; }
.bubble-actions button {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  background: var(--overlay-subtle);
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}
.bubble-actions button:hover { background: var(--overlay-medium); color: var(--text-primary); }

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 15px;
  text-align: center;
  padding: 40px;
}

/* ── Streaming cursor ── */
.streaming-cursor::after {
  content: "\25AE";
  animation: blink 0.8s infinite;
  color: var(--accent);
  margin-left: 2px;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

/* ── Input bar ── */
#input-bar {
  padding: 12px 24px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}
#input-bar-default {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
#msg-input {
  flex: 1;
  resize: none;
  max-height: 150px;
  min-height: 38px;
  padding: 8px 14px;
  border-radius: var(--radius);
  line-height: 1.45;
}
.icon-btn {
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  transition: background var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-hover); }
.send-btn { background: var(--accent); border-radius: 50%; color: #fff; }
.send-btn:hover { background: var(--accent-hover); }
.send-btn.stop { background: var(--danger); }
.send-btn.stop:hover { background: var(--danger-hover); }

#btn-tts-toggle.active { color: var(--accent); }

/* ── Playback Control Bar ── */
#playback-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
}
.playback-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
}
.playback-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}
.playback-time {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  min-width: 120px;
  text-align: center;
  letter-spacing: 0.5px;
}
.playback-stop-btn {
  padding: 6px 16px;
  font-size: 14px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}
.playback-stop-btn:hover { background: var(--danger-hover); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from{opacity:0} to{opacity:1} }

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 420px;
  max-width: 92vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 15px; font-weight: 600; }
.modal-close { font-size: 22px; padding: 2px 6px; border-radius: var(--radius-sm); }
.modal-close:hover { background: var(--bg-hover); }

.modal-body { padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 8px; }
.modal-body label { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.modal-body select { width: 100%; }
.modal-divider { border: none; border-top: 1px solid var(--border); margin: 8px 0; }
.modal-section-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); }

.primary-btn {
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 500;
  margin-top: 8px;
  transition: background var(--transition);
}
.primary-btn:hover { background: var(--accent-hover); }

/* ── Settings View ── */
#settings-view { flex: 1; overflow-y: auto; padding: 20px 28px; }
.settings-header { margin-bottom: 16px; }

.settings-tabs { display: flex; gap: 4px; margin-bottom: 20px; }
.tab-btn {
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}
.tab-btn:hover { background: var(--bg-hover); }
.tab-btn.active { background: var(--bg-tertiary); color: var(--text-primary); }

#settings-content { max-width: 640px; }

/* Settings items */
.settings-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.settings-item {
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background var(--transition);
}
.settings-item:hover { background: var(--bg-hover); }
.settings-item.active { border-color: var(--accent); }
.settings-item-name { font-size: 13px; }
.settings-item-meta { font-size: 11px; color: var(--text-muted); }
.settings-item-actions { display: flex; gap: 4px; }
.settings-item-actions button {
  font-size: 14px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}
.settings-item-actions button:hover { color: var(--danger); background: var(--danger-bg); }

.settings-form {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}
.settings-form label { font-size: 12px; color: var(--text-secondary); }
.settings-form input, .settings-form textarea, .settings-form select { width: 100%; }
.settings-form textarea { min-height: 120px; resize: vertical; }
.form-actions { display: flex; gap: 8px; margin-top: 4px; }
.form-actions button { padding: 8px 16px; border-radius: var(--radius-sm); font-size: 13px; }
.btn-save { background: var(--accent); color: #fff; }
.btn-save:hover { background: var(--accent-hover); }
.btn-cancel { background: var(--bg-input); }
.btn-cancel:hover { background: var(--bg-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-add {
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-align: center;
  transition: border-color var(--transition), color var(--transition);
}
.btn-add:hover { border-color: var(--accent); color: var(--accent); }

/* Voices grid */
.voices-grid {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px;
}
.voice-chip {
  padding: 5px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 12px;
  color: var(--text-secondary);
}

/* ── TTS Model Cards ── */
.tts-model-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 8px;
}
.tts-model-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 4px;
}
.tts-model-name { font-size: 14px; font-weight: 600; }
.tts-model-size { font-size: 12px; color: var(--text-muted); }
.tts-model-desc { font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.tts-model-meta { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.tts-model-actions { display: flex; gap: 6px; margin-top: 8px; }
.tts-model-actions button {
  padding: 6px 14px; border-radius: var(--radius-sm); font-size: 12px;
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text-secondary); cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.tts-model-actions button:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--accent); }
.tts-model-actions .btn-danger { color: var(--danger); border-color: transparent; }
.tts-model-actions .btn-danger:hover { background: var(--danger-bg); border-color: var(--danger); }

.tts-model-disabled { opacity: 0.5; }
.tts-gpu-badge {
  font-size: 10px; font-weight: 600; color: var(--danger);
  border: 1px solid var(--danger); border-radius: var(--radius-sm);
  padding: 1px 6px; margin-left: 8px;
}

/* ── TTS Model Card Extras ── */
.tts-model-specs {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
  display: flex;
  gap: 12px;
}

.tts-device-info {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.config-status-info {
  font-size: 11px;
  margin-top: 2px;
}
.config-status-info a {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

.tts-progress-section { margin-bottom: 10px; }
.tts-progress-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 3px; display: flex; justify-content: space-between; }
.tts-progress-bar { height: 6px; background: var(--bg-input); border-radius: 3px; overflow: hidden; margin-bottom: 8px; }
.tts-progress-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.3s ease; }
.tts-progress-speed { font-size: 11px; color: var(--text-muted); margin-top: -4px; margin-bottom: 6px; }

/* ── Markdown inside bubbles ── */
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { margin: 10px 0 4px; font-weight: 600; }
.bubble h1 { font-size: 1.3em; }
.bubble h2 { font-size: 1.15em; }
.bubble h3 { font-size: 1.05em; }
.bubble p { margin: 4px 0; }
.bubble ul, .bubble ol { margin: 4px 0 4px 20px; }
.bubble li { margin: 2px 0; }
.bubble code {
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 0.9em;
}
.bubble pre {
  background: var(--pre-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  overflow-x: auto;
  margin: 8px 0;
}
.bubble pre code { background: none; padding: 0; font-size: 0.85em; }
.bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 6px 0;
  color: var(--text-secondary);
}
.bubble a { color: var(--accent); text-decoration: underline; }
.bubble hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }

/* ── Utility classes ── */
.text-muted { color: var(--text-muted); font-size: 12px; }
.text-danger { color: var(--danger); }
.section-title { margin-bottom: 12px; }
.section-title-spaced { margin-top: 24px; margin-bottom: 12px; }
.sub-heading { font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; }
.primary-btn.danger { background: var(--danger); }
.primary-btn.danger:hover { background: var(--danger-hover); }

/* ── General settings ── */
.general-action { margin-bottom: 16px; }
.general-action h3 { margin: 0 0 4px; font-size: 14px; }
.general-action p { margin: 0 0 8px; font-size: 12px; color: var(--text-muted); }

/* ── Login screen ── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg-primary);
}
.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h2 { text-align: center; margin-bottom: 8px; }
.login-card input { width: 100%; }
.login-card .login-btn {
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  border: none;
  cursor: pointer;
  margin-top: 4px;
}
.login-card .login-btn:hover { background: var(--accent-hover); }
.login-error { color: var(--danger); font-size: 12px; text-align: center; min-height: 18px; }

/* ── Responsive ── */
@media (max-width: 768px) {
  :root { --sidebar-width: 260px; }
  #sidebar { position: fixed; top: var(--header-height); left: 0; bottom: 0; z-index: 30; }
  #sidebar.collapsed { margin-left: calc(var(--sidebar-width) * -1); }
  #sidebar-overlay {
    position: fixed;
    inset: var(--header-height) 0 0 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 29;
    transition: opacity var(--transition);
  }
  #sidebar.collapsed ~ #sidebar-overlay {
    opacity: 0;
    pointer-events: none;
  }
  .bubble { max-width: 90%; }
  #input-bar { padding: 10px 12px 14px; }
  #messages-container { padding: 12px 12px; }

  /* Settings responsive */
  #settings-view { padding: 14px 12px; }
  .settings-tabs { flex-wrap: wrap; }
  .tab-btn { padding: 6px 12px; font-size: 12px; }
  #settings-content { max-width: 100%; }
}
