*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  color-scheme: dark;
  --primary: #2196F3;
  --primary-dim: rgba(33,150,243,0.14);
  --bg: #0d1117;
  --surface: #161d2b;
  --surface-hi: #1e2a3d;
  --surface-hx: #263347;
  --text: #e2e8f4;
  --text-muted: #7f94b0;
  --error: #f87171;
  --radius: 16px;
  --ease: 160ms ease;
}

html, body { height: 100%; font-family: Inter, system-ui, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }

/* ── Shell ─────────────────────────────────────────────────────────── */
.app {
  height: 100dvh;
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 0 16px 14px;
  overflow: hidden;
}

/* ── Topbar ────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 8px;
  flex-shrink: 0;
}

.app-title { font-size: 1.1rem; font-weight: 700; letter-spacing: -.3px; }

.topbar-right { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 7px; border-radius: 10px;
  display: flex; align-items: center; transition: color var(--ease), background var(--ease);
}
.icon-btn:hover { color: var(--text); background: var(--surface-hi); }

.model-chip {
  display: flex; align-items: center; gap: 5px;
  background: var(--surface-hi);
  border: 1px solid rgba(33,150,243,0.3);
  color: var(--text-muted);
  border-radius: 999px;
  font-size: .78rem; font-weight: 500;
  padding: 4px 12px 4px 14px;
  cursor: pointer;
  transition: background var(--ease), color var(--ease);
}
.model-chip:hover { background: var(--surface-hx); color: var(--text); }

/* ── Status strip ──────────────────────────────────────────────────── */
.status-bar {
  display: flex; align-items: center; gap: 8px;
  font-size: .75rem; color: var(--text-muted);
  min-height: 16px; flex-shrink: 0; padding: 0 2px 6px;
}

.dots { display: flex; gap: 3px; }
.dots span {
  width: 5px; height: 5px; border-radius: 50%; background: var(--primary);
  animation: blink 1.2s infinite;
}
.dots span:nth-child(2) { animation-delay: .2s; }
.dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100%{opacity:.2} 40%{opacity:1} }

.stats { margin-left: auto; color: var(--primary); font-variant-numeric: tabular-nums; }

.provider-banner {
  margin: 0 2px 8px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(33,150,243,0.3);
  background: var(--primary-dim);
  color: var(--text);
  font-size: .82rem;
  line-height: 1.4;
  flex-shrink: 0;
}

/* ── Messages ──────────────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 6px 2px 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-hx) transparent;
}

/* history items are slightly dimmed */
.bubble {
  max-width: min(78%, 700px);
  border-radius: var(--radius);
  padding: 10px 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: .88rem;
  opacity: .7;
  transition: opacity var(--ease);
}
.bubble.user { align-self: flex-end; background: #1e3555; border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: var(--surface); border: 1px solid rgba(255,255,255,0.05); border-bottom-left-radius: 4px; }
.bubble.system { align-self: center; background: transparent; border: 1px dashed rgba(127,148,176,.3); color: var(--text-muted); font-size:.78rem; padding: 4px 10px; border-radius: 999px; }

/* last exchange is full opacity and slightly larger */
.bubble.latest-user, .bubble.latest-asst {
  opacity: 1;
  font-size: .95rem;
}
.bubble.latest-user { background: #1a3a6b; padding: 12px 16px; border-radius: var(--radius); border-bottom-right-radius: 4px; }
.bubble.latest-asst {
  background: var(--surface-hi);
  border: 1px solid rgba(33,150,243,0.2);
  padding: 16px 18px;
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  line-height: 1.65;
}

/* streaming cursor on latest assistant bubble */
.bubble.streaming::after {
  content: "▍";
  display: inline-block;
  animation: cur .7s step-end infinite;
  color: var(--primary);
  margin-left: 2px;
}
@keyframes cur { 0%,100%{opacity:1} 50%{opacity:0} }

.bubble-error { align-self: flex-start; font-size:.78rem; color: var(--error); padding: 0 4px; }

/* ── Model loading progress ────────────────────────────────────────── */
.model-loading {
  flex-shrink: 0; padding: 6px 0 2px;
  display: flex; flex-direction: column; gap: 5px;
}
.model-loading-bar { height: 3px; background: var(--surface-hi); border-radius: 999px; overflow: hidden; }
.model-loading-fill { height: 100%; background: linear-gradient(90deg, var(--primary), #21D4F3); border-radius: 999px; transition: width .3s ease; }
.model-loading-text { font-size: .72rem; color: var(--text-muted); }

/* ── Composer ──────────────────────────────────────────────────────── */
.composer { flex-shrink: 0; }

.composer-row {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface-hi);
  border: 1px solid rgba(127,148,176,.18);
  border-radius: var(--radius);
  padding: 10px 10px 10px 16px;
  transition: border-color var(--ease);
}
.composer-row:focus-within { border-color: rgba(33,150,243,.45); }

#promptInput {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-family: inherit; font-size: .95rem;
  line-height: 1.5; resize: none; max-height: 140px;
  overflow-y: auto; scrollbar-width: thin;
}
#promptInput::placeholder { color: var(--text-muted); }

.send-btn, .stop-btn {
  width: 38px; height: 38px; border: none; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background var(--ease), transform var(--ease), opacity var(--ease);
}
.send-btn { background: var(--primary); color: #fff; }
.send-btn:hover:not(:disabled) { background: #42a5f5; }
.send-btn:active:not(:disabled) { transform: scale(.93); }
.send-btn:disabled { opacity: .4; cursor: default; }
.stop-btn { background: var(--surface-hx); color: var(--error); }
.stop-btn:hover { background: rgba(248,113,113,.15); }

/* ── Settings overlay ──────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(3px);
  z-index: 100; display: flex; justify-content: flex-end;
  animation: fade .16s ease;
}
.overlay.hidden { display: none; }
@keyframes fade { from{opacity:0} }

.drawer {
  width: min(380px, 93vw); height: 100%;
  background: var(--surface);
  border-left: 1px solid rgba(255,255,255,.07);
  display: flex; flex-direction: column; overflow-y: auto;
  animation: slide .2s ease;
}
@keyframes slide { from{transform:translateX(36px)} }

.drawer-head {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 20px 14px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.drawer-head h2 { font-size: 1rem; font-weight: 600; }

.drawer-section { padding: 16px 20px; }
.section-label { font-size: .68rem; font-weight: 600; letter-spacing: .08em; color: var(--primary); margin-bottom: 10px; }
.drawer-divider { height: 1px; background: rgba(255,255,255,.07); margin: 0 20px; }

/* model rows */
.model-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px; border-radius: 12px; cursor: default;
  transition: background var(--ease);
}
.model-row:hover { background: var(--surface-hi); }
.model-row.active { background: var(--primary-dim); }

.model-info { flex: 1; min-width: 0; }
.model-name { font-size: .88rem; font-weight: 600; margin-bottom: 2px; }
.model-meta { font-size: .72rem; color: var(--text-muted); margin-bottom: 2px; }
.model-desc { font-size: .72rem; color: var(--text-muted); line-height: 1.4; }
.model-progress-wrap { margin-top: 6px; }
.model-progress-bar2 { height: 3px; background: var(--surface-hx); border-radius: 999px; overflow: hidden; }
.model-progress-fill2 { height: 100%; background: linear-gradient(90deg,var(--primary),#21D4F3); transition: width .3s; }

.model-action { flex-shrink: 0; display: flex; align-items: center; }
.badge { background: var(--primary); color: #fff; border-radius: 999px; font-size: .68rem; font-weight: 700; padding: 3px 10px; }
.btn-sm {
  border: none; border-radius: 9px;
  font-size: .76rem; font-weight: 600;
  padding: 5px 12px; cursor: pointer;
  transition: background var(--ease);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #42a5f5; }
.btn-outline { background: var(--surface-hi); color: var(--text); border: 1px solid rgba(33,150,243,.3); }
.btn-outline:hover { background: var(--surface-hx); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid rgba(255,255,255,.1); }
.btn-ghost:hover { background: rgba(248,113,113,.1); color: var(--error); }

.danger-btn { background: none; border: none; color: var(--error); font-size: .88rem; font-weight: 500; cursor: pointer; padding: 8px 0; width: 100%; text-align: left; }
.danger-btn:hover { opacity: .75; }

.drawer-btn {
  background: var(--surface-hi);
  border: 1px solid rgba(33,150,243,.3);
  color: var(--text);
  border-radius: 10px;
  font-size: .82rem;
  font-weight: 600;
  padding: 8px 12px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  margin-top: 8px;
  transition: background var(--ease), border-color var(--ease);
}
.drawer-btn:hover { background: var(--surface-hx); border-color: rgba(33,150,243,.45); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(3px);
  z-index: 110;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: min(460px, 94vw);
  background: var(--surface);
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 14px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  line-height: 1.45;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.hidden { display: none !important; }
