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

:root {
  --bg-primary: #0a0b0f;
  --bg-secondary: #12141a;
  --bg-tertiary: #1a1d27;
  --bg-hover: #222632;
  --border: #2a2e3a;
  --border-light: #363b4a;
  --text-primary: #e8eaf0;
  --text-secondary: #9096a8;
  --text-muted: #5c6278;
  --accent-orange: #f97316;
  --accent-purple: #a78bfa;
  --accent-green: #34d399;
  --accent-red: #f87171;
  --accent-yellow: #fbbf24;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left { display: flex; align-items: baseline; gap: 0.75rem; }

header h1 {
  font-size: 1.15rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-orange), var(--accent-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
}

.header-right { display: flex; align-items: center; gap: 0.75rem; }

.ollama-status { display: flex; gap: 0.5rem; }

.status-badge {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.7rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-weight: 500;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.online { background: var(--accent-green); box-shadow: 0 0 6px rgba(52, 211, 153, 0.4); }
.status-dot.offline { background: var(--accent-red); }

/* ── Buttons ── */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-light);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-orange), #d946ef);
  color: #fff;
  box-shadow: 0 2px 12px rgba(249, 115, 22, 0.2);
}

.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--accent-red);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--bg-hover); border-color: var(--accent-red); }

/* ── Main ── */
main {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ── Input Section ── */
.input-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.model-picker {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.model-picker label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.model-select {
  flex: 1;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}

.model-select:hover { border-color: var(--border-light); }
.model-select:focus { border-color: var(--accent-purple); }
.model-select option { background: var(--bg-secondary); color: var(--text-primary); }

.prompt-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color 0.15s;
}

.prompt-box:focus-within {
  border-color: var(--accent-purple);
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.1);
}

#prompt {
  width: 100%;
  padding: 1rem 1.25rem 0.5rem;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  line-height: 1.6;
  resize: none;
  outline: none;
}

#prompt::placeholder { color: var(--text-muted); }

.prompt-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  border-top: 1px solid var(--border);
  background: rgba(0,0,0,0.15);
}

.hint { font-size: 0.7rem; color: var(--text-muted); }

.prompt-actions { display: flex; gap: 0.5rem; }

/* ── Presets ── */
.presets-panel { display: flex; flex-direction: column; gap: 0.5rem; }

.presets-tabs { display: flex; gap: 0.25rem; }

.preset-tab {
  padding: 0.3rem 0.75rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 0.15s;
}

.preset-tab:hover { color: var(--text-secondary); }
.preset-tab.active {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border);
}

.presets-list { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.preset-btn {
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

.preset-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--border-light);
  color: var(--text-primary);
}

.preset-btn.selected {
  background: var(--bg-hover);
  border-color: var(--accent-purple);
  color: var(--accent-purple);
}

/* ── Response ── */
.response-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.response-header {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0,0,0,0.15);
  gap: 1rem;
}

.response-model {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-purple);
}

.response-metrics {
  display: flex;
  gap: 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  flex: 1;
  justify-content: flex-end;
}

.metric {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.metric-value {
  color: var(--text-primary);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.metric-label { color: var(--text-muted); }

.response {
  padding: 1.25rem;
  min-height: 200px;
  font-size: 0.9rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-y: auto;
  max-height: 600px;
}

.response::-webkit-scrollbar { width: 4px; }
.response::-webkit-scrollbar-track { background: transparent; }
.response::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.empty-response {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 180px;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}

.response .cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--text-primary);
  animation: blink 0.7s ease infinite;
  vertical-align: text-bottom;
  margin-left: 1px;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ── Spinner ── */
.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent-purple);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── History ── */
.history-section {
  border-top: 1px solid var(--border);
  padding-top: 1.25rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.section-header h2 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.history-list { display: flex; flex-direction: column; gap: 0.4rem; }

.history-item {
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.history-item:hover {
  border-color: var(--border-light);
  background: var(--bg-tertiary);
}

.history-prompt {
  font-size: 0.82rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.history-meta {
  font-size: 0.68rem;
  color: var(--text-muted);
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.history-badge {
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: var(--bg-hover);
  color: var(--accent-purple);
  font-weight: 600;
  font-size: 0.65rem;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 0.6rem 1.25rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  border-radius: 999px;
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 500;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  z-index: 200;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Responsive ── */
@media (max-width: 640px) {
  header { padding: 0.6rem 1rem; }
  main { padding: 1rem; }
  .model-picker { flex-direction: column; align-items: stretch; gap: 0.4rem; }
  .prompt-actions { flex-wrap: wrap; }
  .response { max-height: 400px; }
  .response-metrics { gap: 0.5rem; font-size: 0.65rem; }
}
