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

:root {
  --bg: #0a0e1a;
  --surface: #131a2e;
  --surface2: #1a2340;
  --border: #243052;
  --accent: #9046FF;
  --accent-glow: rgba(144, 70, 255, 0.3);
  --text: #e2e8f0;
  --text-muted: #7b8bab;
  --radius: 14px;
  --transition: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* ===== SPA Screen System ===== */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: scale(0.96);
  pointer-events: none;
  transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.screen.active {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
  z-index: 1;
}
.screen.fade-out {
  opacity: 0;
  transform: scale(1.04);
}

/* ===== Login ===== */
#login-screen {
  justify-content: center;
  align-items: center;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(144,70,255,0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 70%, rgba(59,130,246,0.05) 0%, transparent 50%);
  background-size: 200% 200%;
  animation: loginAmbient 15s ease-in-out infinite;
}
@keyframes loginAmbient {
  0%, 100% { background-position: 30% 30%; }
  33% { background-position: 70% 60%; }
  66% { background-position: 40% 80%; }
}

.login-card {
  background: var(--surface);
  padding: 2.5rem 2.5rem 2rem;
  border-radius: 20px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  border: 1px solid var(--border);
  box-shadow: 0 30px 80px rgba(0,0,0,0.5), 0 0 40px var(--accent-glow);
  animation: cardEntry 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes cardEntry {
  from { opacity: 0; transform: translateY(30px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Mascot */
.mascot-container {
  margin-bottom: 1rem;
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

#kiro-mascot { filter: drop-shadow(0 4px 20px var(--accent-glow)) drop-shadow(0 0 40px rgba(144,70,255,0.15)); }
#left-pupil, #right-pupil { transition: cx 0.15s ease-out; }
#left-eye, #right-eye { transition: transform 0.15s ease-out; }

.login-card h1 {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  background: linear-gradient(135deg, #e2e8f0, #9046FF);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.subtitle { color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.9rem; }

/* Input groups */
.input-group {
  position: relative;
  margin-bottom: 1rem;
}
.input-group input {
  width: 100%;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.input-line {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
  transition: width 0.3s ease, left 0.3s ease;
}
.input-group input:focus ~ .input-line {
  width: 100%;
  left: 0;
}

/* Login button */
#login-btn {
  width: 100%;
  padding: 0.85rem;
  background: linear-gradient(135deg, #9046FF, #7c3aed);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
  margin-top: 0.5rem;
}
#login-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 25px var(--accent-glow); }
#login-btn:active { transform: translateY(0); }
#login-btn:disabled { opacity: 0.7; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-loader {
  display: none;
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}
.btn-loader[hidden] { display: none; }
.btn-loader.visible { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.error {
  color: #f87171;
  margin-top: 0.75rem;
  font-size: 0.85rem;
  animation: shake 0.4s ease;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ===== Chat ===== */
#chat-screen {
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
  position: relative;
}
header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), rgba(59,130,246,0.5), transparent);
  background-size: 200% 100%;
  animation: headerGlow 8s ease-in-out infinite;
  opacity: 0.5;
}
@keyframes headerGlow {
  0%, 100% { background-position: -100% 0; }
  50% { background-position: 200% 0; }
}
.header-left { display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0; }
.header-mascot {
  filter: drop-shadow(0 0 6px var(--accent-glow));
  animation: headerFloat 3s ease-in-out infinite;
}
@keyframes headerFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
header h1 { font-size: 1.15rem; font-weight: 600; }

#logout-btn {
  padding: 0.4rem 1rem;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s;
}
#logout-btn:hover { background: var(--border); color: var(--text); }

/* Messages */
#messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
  position: relative;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(144, 70, 255, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 50%, rgba(59, 130, 246, 0.04) 0%, transparent 50%);
  background-size: 200% 200%;
  animation: ambientShift 20s ease-in-out infinite;
}
@keyframes ambientShift {
  0%, 100% { background-position: 0% 50%; }
  25% { background-position: 100% 30%; }
  50% { background-position: 50% 80%; }
  75% { background-position: 0% 60%; }
}

.message {
  max-width: 78%;
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius);
  line-height: 1.6;
  word-wrap: break-word;
  flex-shrink: 0;
  animation: msgIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #9046FF, #7c3aed);
  color: white;
  border-bottom-right-radius: 4px;
}
.message.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  position: relative;
  overflow: hidden;
}
.message.assistant::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 60%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(144, 70, 255, 0.06), rgba(59, 130, 246, 0.04), transparent);
  animation: messageShimmer 3s ease-in-out 0.3s 1;
}
@keyframes messageShimmer {
  0% { left: -100%; }
  100% { left: 200%; }
}

/* Markdown in messages */
.message.assistant p { margin-bottom: 0.5em; }
.message.assistant p:last-child { margin-bottom: 0; }
.message.assistant code {
  background: var(--bg);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.88em;
  color: #c4b5fd;
}
.message.assistant pre {
  background: var(--bg);
  padding: 0.8rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.5em 0;
  border: 1px solid var(--border);
}
.message.assistant pre code {
  background: none;
  padding: 0;
  color: var(--text);
}
.message.assistant ul, .message.assistant ol {
  padding-left: 1.2em;
  margin: 0.4em 0;
}
.message.assistant strong { color: #c4b5fd; }
.message.assistant a { color: var(--accent); text-decoration: underline; }

/* Typing indicator */
.typing-dots { display: flex; gap: 4px; padding: 0.5rem 0; }
.typing-dots span {
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.2s ease-in-out infinite;
}
.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(-8px); opacity: 1; }
}

/* Chat form — composable input pattern */
#chat-form-wrapper {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 1rem 1.5rem 1.25rem;
}
#chat-form {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
}
.chat-input-container {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  display: flex;
  flex-direction: column;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.chat-input-container:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Attachment chip */
.chat-attachment-chip[hidden] {
  display: none;
}
.chat-attachment-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  margin: 0.5rem 0.75rem 0;
  background: rgba(144, 70, 255, 0.08);
  border: 1px solid rgba(144, 70, 255, 0.2);
  border-radius: 8px;
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 500;
}
.chat-attachment-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}
.chip-remove-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  min-width: 24px;
  background: none;
  border: none;
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  margin-left: auto;
  padding: 0;
  transition: all 0.2s;
}
.chip-remove-btn:hover {
  color: #f87171;
  background: rgba(248, 113, 113, 0.1);
}
.chip-remove-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Textarea */
#user-input {
  width: 100%;
  padding: 0.85rem 1rem;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  resize: none;
  min-height: 44px;
  max-height: 160px;
  line-height: 1.5;
  overflow-y: auto;
}
#user-input:focus { outline: none; }
#user-input::placeholder { color: var(--text-muted); }

/* Toolbar inside input container */
.chat-toolbar {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.4rem 0.5rem;
  border-top: 1px solid var(--border);
}
.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.65rem;
  min-height: 36px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
  transition: all 0.15s;
}
.toolbar-btn:hover {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border);
}
.toolbar-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.toolbar-btn[aria-checked="true"],
.toolbar-btn.active {
  background: rgba(144, 70, 255, 0.12);
  color: var(--accent);
  border-color: rgba(144, 70, 255, 0.3);
}
.toolbar-btn-label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* Send button */
#send-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.7rem 1.1rem;
  min-height: 44px;
  background: linear-gradient(135deg, #9046FF, #7c3aed);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
  flex-shrink: 0;
}
.send-btn-label {
  font-size: 0.85rem;
  font-weight: 600;
}
/* Scrollbar */
#messages::-webkit-scrollbar { width: 6px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== Model Button in Header ===== */
.header-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  z-index: 2;
}
#model-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 1.1rem;
  background: linear-gradient(135deg, rgba(144, 70, 255, 0.15), rgba(59, 130, 246, 0.1));
  color: var(--text);
  border: 1px solid rgba(144, 70, 255, 0.4);
  border-radius: 20px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.25s, border-color 0.25s;
  animation: modelBtnGlow 4s ease-in-out infinite;
  z-index: 2;
}
#model-btn:hover {
  background: linear-gradient(135deg, rgba(144, 70, 255, 0.25), rgba(59, 130, 246, 0.2));
  border-color: var(--accent);
}
@keyframes modelBtnGlow {
  0%, 100% { box-shadow: 0 0 8px rgba(144, 70, 255, 0.2); border-color: rgba(144, 70, 255, 0.4); }
  33% { box-shadow: 0 0 12px rgba(59, 130, 246, 0.25); border-color: rgba(59, 130, 246, 0.5); }
  66% { box-shadow: 0 0 10px rgba(168, 85, 247, 0.2); border-color: rgba(168, 85, 247, 0.4); }
}
#model-btn-name { font-weight: 600; }

/* ===== Cache Readiness Pill ===== */
.cache-pill {
  padding: 0.25rem 0.7rem;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  transition: all 0.3s;
}
.cache-pill[hidden] { display: none; }
.cache-pill.status-filling {
  color: var(--text-muted);
  border-color: var(--border);
}
.cache-pill.status-ready {
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.3);
  background: rgba(251, 191, 36, 0.08);
}
.cache-pill.status-active {
  color: #4ade80;
  border-color: rgba(74, 222, 128, 0.3);
  background: rgba(74, 222, 128, 0.08);
}
.cache-pill.status-unsupported {
  color: var(--text-muted);
  opacity: 0.6;
}

/* ===== Model Picker Modal ===== */
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem;
  width: 90%;
  max-width: 360px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5), 0 0 30px var(--accent-glow);
  transform: scale(0.9) translateY(20px);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-overlay.open .modal-card {
  transform: scale(1) translateY(0);
}
.modal-card h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-muted);
}
#model-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 0.25rem;
}
.model-option {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text);
  font-size: 0.9rem;
}
.model-option:hover {
  border-color: var(--accent);
  background: var(--surface2);
}
.model-option.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
  background: var(--surface2);
}
.model-option .model-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}
.model-option.active .model-dot {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}

/* ===== Custom Model Badge ===== */
.custom-badge {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.1rem 0.4rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  border-radius: 4px;
}
.custom-badge.finetuned {
  background: linear-gradient(135deg, #10b981, #059669);
}

/* ===== Provider Badge (managed / self-hosted) ===== */
.provider-badge {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.1rem 0.4rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #fff;
  border-radius: 4px;
}
.provider-badge.managed {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
}
.provider-badge.self-hosted {
  background: linear-gradient(135deg, #0ea5e9, #0284c7);
}

/* ===== Backend Reachability Indicator (self-hosted up/down) ===== */
.backend-status {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-left: 0.4rem;
  padding: 0.1rem 0.4rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.backend-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}
.backend-status.status-up {
  color: #059669;
  border-color: rgba(16, 185, 129, 0.4);
}
.backend-status.status-up .backend-status-dot {
  background: #10b981;
  box-shadow: 0 0 4px rgba(16, 185, 129, 0.7);
}
.backend-status.status-down {
  color: #dc2626;
  border-color: rgba(239, 68, 68, 0.4);
}
.backend-status.status-down .backend-status-dot {
  background: #ef4444;
}
.backend-status.status-unknown .backend-status-dot {
  animation: backend-status-pulse 1.2s ease-in-out infinite;
}
@keyframes backend-status-pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

/* ===== Cache Badge in Model Picker ===== */
.cache-badge {
  display: block;
  margin-top: 0.2rem;
  margin-left: auto;
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 500;
}
.cache-badge.no-cache {
  opacity: 0.5;
}
.model-option-name {
  flex: 1;
}

/* ===== Non-selectable self-hosted model (Req 5.2, 5.3) ===== */
/* A self-hosted model whose provider is off/starting/stopping/error/unknown,
   down, or stale is greyed and non-interactive; it carries no select handler. */
.model-option.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.model-option.disabled:hover {
  border-color: var(--border);
  background: transparent;
}
.model-unavailable {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.1rem 0.4rem;
  font-size: 0.65rem;
  font-weight: 600;
  border-radius: 4px;
  color: #dc2626;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.4);
}

/* ===== Metrics Badge ===== */
.metrics-badge {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--text-muted);
}
.metrics-badge span {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.45rem;
  background: var(--bg);
  border-radius: 4px;
  border: 1px solid var(--border);
}
.metrics-badge .model-tag {
  color: var(--accent);
  border-color: rgba(144, 70, 255, 0.3);
}
.metrics-badge .latency { color: #34d399; }
.metrics-badge .tokens { color: #60a5fa; }
.metrics-badge .cost { color: #fbbf24; }
.metrics-badge .cache { color: #f472b6; }
.metrics-badge .cache-hit { color: #4ade80; font-weight: 600; }
.metrics-badge .cache-write { color: #fbbf24; }
.metrics-badge .cache-miss { color: #94a3b8; }
.metrics-badge .cache-savings { color: #4ade80; font-weight: 600; }
.metrics-badge .cache-speedup { color: #38bdf8; font-style: italic; }

/* ===== Header Right Group ===== */
.header-right { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }

/* ===== Settings Button ===== */
#settings-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
#settings-btn:hover { color: var(--text); border-color: var(--accent); }

/* ===== Settings Modal Extras ===== */
.modal-hint {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-bottom: 0.75rem;
}
#system-prompt {
  width: 100%;
  padding: 0.75rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
  transition: border-color var(--transition);
}
#system-prompt:focus { outline: none; border-color: var(--accent); }
.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.btn-primary {
  flex: 1;
  padding: 0.5rem;
  background: linear-gradient(135deg, #9046FF, #7c3aed);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: opacity 0.2s;
}
.btn-primary:hover { opacity: 0.9; }
.btn-secondary {
  padding: 0.5rem 1rem;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}
.btn-secondary:hover { color: var(--text); border-color: var(--accent); }

/* ===== Settings Section & Toggle ===== */
.settings-section {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.settings-row-text h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 0.2rem;
}
.settings-row-text .modal-hint {
  margin-bottom: 0;
}
.toggle-switch {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 14px;
  flex-shrink: 0;
}
.toggle-switch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.toggle-track {
  display: block;
  width: 44px;
  height: 24px;
  background: var(--border);
  border-radius: 12px;
  position: relative;
  transition: background 0.2s;
}
.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.toggle-switch[aria-checked="true"] .toggle-track {
  background: var(--accent);
}
.toggle-switch[aria-checked="true"] .toggle-thumb {
  transform: translateX(20px);
  background: white;
}
.cache-model-info {
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ===== Inferentia Power Control ===== */
.settings-row.power-row {
  margin-top: 0.75rem;
}
.power-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}
.power-badge {
  display: inline-flex;
  align-items: center;
  min-width: 62px;
  justify-content: center;
  padding: 0.15rem 0.45rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.power-badge.status-on {
  color: #059669;
  border-color: rgba(16, 185, 129, 0.4);
  background: rgba(16, 185, 129, 0.1);
}
.power-badge.status-off {
  color: var(--text-muted);
}
.power-badge.status-starting,
.power-badge.status-stopping {
  color: #d97706;
  border-color: rgba(217, 119, 6, 0.4);
  background: rgba(217, 119, 6, 0.1);
}
.power-badge.status-error {
  color: #dc2626;
  border-color: rgba(239, 68, 68, 0.4);
  background: rgba(239, 68, 68, 0.1);
}
.power-badge.status-unknown {
  color: var(--text-muted);
  border-style: dashed;
}
.power-btn {
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: opacity 0.2s, border-color 0.2s;
}
.power-btn.power-on {
  background: linear-gradient(135deg, #9046FF, #7c3aed);
  color: white;
  border: none;
}
.power-btn.power-off {
  background: var(--surface2);
  color: var(--text);
}
.power-btn.power-off:hover:not(:disabled) {
  border-color: #ef4444;
  color: #ef4444;
}
.power-btn.power-on:hover:not(:disabled) {
  opacity: 0.9;
}
.power-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ===== Power_On_Confirmation ===== */
.power-cost-warning {
  border: 1px solid rgba(217, 119, 6, 0.4);
  background: rgba(217, 119, 6, 0.1);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  margin: 0.5rem 0 0.75rem;
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.4;
}
.power-cost-warning p { margin: 0 0 0.5rem; }
.power-cost-warning p:last-child { margin-bottom: 0; }
.power-cost-warning ul {
  margin: 0 0 0.5rem;
  padding-left: 1.1rem;
}
.power-cost-warning li { margin-bottom: 0.2rem; }
.power-on-error {
  margin: 0 0 0.5rem;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  font-size: 0.8rem;
  color: #dc2626;
  border: 1px solid rgba(239, 68, 68, 0.4);
  background: rgba(239, 68, 68, 0.1);
}

/* ===== Report Button ===== */
#report-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
#report-btn:hover { color: var(--text); border-color: #34d399; box-shadow: 0 0 8px rgba(52, 211, 153, 0.2); }

/* ===== Clear Button ===== */
#clear-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
#clear-btn:hover { color: #f87171; border-color: #f87171; box-shadow: 0 0 8px rgba(248, 113, 113, 0.2); }

/* ===== Compare Button ===== */
#compare-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== KB Toggle (now handled by toolbar-btn) ===== */

/* ===== Citations ===== */
.citations {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--border);
}
.citation-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.5rem;
  background: rgba(144, 70, 255, 0.1);
  border: 1px solid rgba(144, 70, 255, 0.3);
  border-radius: 12px;
  font-size: 0.68rem;
  color: var(--accent);
}
.citation-pill::before {
  content: '📄';
  font-size: 0.7rem;
}

/* ===== Compare Results ===== */
#compare-results {
  position: absolute;
  inset: 0;
  top: 0;
  z-index: 50;
  overflow-y: auto;
  padding: 1.5rem;
  background: var(--bg);
  transform: translateY(100%);
  opacity: 0;
  transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  pointer-events: none;
}
#compare-results.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}
#compare-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  position: sticky;
  top: -1.5rem;
  padding: 1.5rem 0 0.75rem;
  background: var(--bg);
  z-index: 2;
}
#compare-header h2 { font-size: 1.1rem; font-weight: 600; }
#compare-close {
  padding: 0.4rem 1rem;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s;
}
#compare-close:hover { color: var(--text); border-color: var(--accent); }
#compare-prompt {
  padding: 0.6rem 1rem;
  background: linear-gradient(135deg, #9046FF, #7c3aed);
  color: white;
  border-radius: 10px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
#compare-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}
@media (max-width: 768px) {
  #compare-grid { grid-template-columns: 1fr; }
}
.compare-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  animation: msgIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.compare-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.compare-card-header h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
}
.compare-card-body {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text);
  max-height: 300px;
  overflow-y: auto;
}
.compare-card-body p { margin-bottom: 0.4em; }
.compare-card-body p:last-child { margin-bottom: 0; }
.compare-card-metrics {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
}
.compare-card-metrics span {
  padding: 0.15rem 0.4rem;
  background: var(--bg);
  border-radius: 4px;
  border: 1px solid var(--border);
}
.compare-card.loading .compare-card-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60px;
}

/* ===== Language Selector ===== */
.lang-selector {
  display: flex;
  justify-content: center;
  gap: 0.4rem;
  margin-bottom: 1rem;
}
.lang-btn {
  padding: 0.25rem 0.6rem;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  transition: all 0.2s;
}
.lang-btn:hover { color: var(--text); border-color: var(--accent); }
.lang-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* ===== Evaluate Button ===== */
#eval-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
#eval-btn:hover { color: var(--text); border-color: #f59e0b; box-shadow: 0 0 8px rgba(245, 158, 11, 0.2); }

/* ===== Eval Results Table ===== */
.eval-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin-top: 0.5rem;
}
.eval-table th {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
}
.eval-table td {
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.eval-score {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.78rem;
}
.eval-score.high { background: rgba(52, 211, 153, 0.15); color: #34d399; }
.eval-score.mid { background: rgba(251, 191, 36, 0.15); color: #fbbf24; }
.eval-score.low { background: rgba(248, 113, 113, 0.15); color: #f87171; }
.eval-status { color: var(--text-muted); font-size: 0.82rem; text-align: center; padding: 1rem 0; }

/* ===== Sleep Mode Zzz Animation ===== */
.zzz-text {
  animation: zzzFloat 2s ease-in-out infinite;
  fill: #9046FF;
  font-family: -apple-system, sans-serif;
  font-weight: 700;
  filter: drop-shadow(0 0 4px #9046FF);
}
@keyframes zzzFloat {
  0%, 100% { opacity: 0.6; transform: translateY(0px); }
  50% { opacity: 1; transform: translateY(-20px); }
}

/* ===== Sleep Float (slower mascot bob) ===== */
.header-mascot.sleeping {
  animation: sleepFloat 5s ease-in-out infinite !important;
}
@keyframes sleepFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

/* ===== Header Title Group & Subtitle ===== */
.header-title-group { display: flex; flex-direction: column; gap: 0; line-height: 1; }
.header-subtitle { font-size: 0.55rem; color: var(--text-muted); font-weight: 400; opacity: 0.7; }

/* ===== Onboarding Tour ===== */
.tour-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 200;
  transition: opacity 0.3s ease;
}
.tour-overlay[hidden] {
  display: none !important;
}
.tour-spotlight {
  position: absolute;
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.7);
  border: 2px solid var(--accent);
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 201;
}
.tour-tooltip {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 14px;
  padding: 1.2rem;
  max-width: 300px;
  z-index: 202;
  box-shadow: 0 15px 40px rgba(0,0,0,0.4), 0 0 20px var(--accent-glow);
  animation: msgIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.tour-tooltip h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
  color: var(--accent);
}
.tour-tooltip p {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 0.8rem;
}
.tour-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.tour-btn-skip {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.78rem;
  padding: 0.3rem 0;
  transition: color 0.2s;
}
.tour-btn-skip:hover { color: var(--text); }
.tour-btn-next {
  padding: 0.4rem 1rem;
  background: linear-gradient(135deg, #9046FF, #7c3aed);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  transition: opacity 0.2s;
}
.tour-btn-next:hover { opacity: 0.9; }

/* ===== PDF Upload (now handled by toolbar-btn + chat-attachment-chip) ===== */
.pdf-loaded-msg {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: rgba(144, 70, 255, 0.08);
  border: 1px solid rgba(144, 70, 255, 0.2);
  border-radius: 10px;
  font-size: 0.85rem;
  color: var(--text);
}
