:root {
  /* Colors - Light Theme (default fallback, but we use dark mode by default) */
  --bg-color: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --secondary: #e2e8f0;
  --secondary-hover: #cbd5e1;
  --border: #e2e8f0;
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.5);
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 24px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg-color: #020617;
  --surface: #0f172a;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --secondary: #1e293b;
  --secondary-hover: #334155;
  --border: #1e293b;
  --glass-bg: rgba(15, 23, 42, 0.6);
  --glass-border: rgba(255, 255, 255, 0.05);
}

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

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-color);
  color: var(--text);
  display: flex;
  height: 100vh;
  overflow: hidden;
  transition: background-color var(--transition), color var(--transition);
}

/* Glassmorphism utils */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
}

/* ── Sidebar ───────────────────────────────────────────────────────────── */
.sidebar {
  width: 260px;
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  border-right: 1px solid var(--border);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 40px;
  padding-left: 8px;
}

.brand-logo {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  color: white;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.nav-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.nav-links li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  cursor: pointer;
  font-weight: 500;
  transition: all var(--transition);
}

.nav-links li:hover {
  background: var(--secondary);
  color: var(--text);
  transform: translateX(4px);
}

.nav-links li.active {
  background: var(--secondary);
  color: var(--primary);
}

.theme-toggle {
  margin-top: auto;
  display: flex;
  justify-content: center;
}

/* ── Main Content Area ─────────────────────────────────────────────────── */
.content-area {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.view {
  display: none;
  flex-direction: column;
  height: 100%;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
  padding: 32px 40px;
  overflow-y: auto;
  animation: fadeIn 0.3s ease;
}

.view.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.view-header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.chat-controls {
  display: flex;
  gap: 12px;
}

/* ── Chat Container ────────────────────────────────────────────────────── */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  gap: 20px;
  position: relative;
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding-bottom: 24px;
  scroll-behavior: smooth;
}

.message {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 85%;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  align-self: flex-end;
}

.message.assistant {
  align-self: flex-start;
}

.msg-bubble {
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.message.user .msg-bubble {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant .msg-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  padding: 0 4px;
}

.message.user .msg-meta {
  justify-content: flex-end;
}

/* Input Area */
.chat-input-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border);
}

textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  resize: none;
  padding: 4px;
  max-height: 200px;
  overflow-y: auto;
}

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

.chat-input-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-input-left {
  display: flex;
  align-items: center;
}

.chat-input-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-selector-pill {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 16px;
  padding: 4px 8px;
  font-size: 13px;
  border: 1px solid var(--border);
  gap: 4px;
}

.dropdown-minimal, .input-minimal {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  outline: none;
  font-family: inherit;
}

.dropdown-minimal:focus, .input-minimal:focus {
  color: var(--text);
}

.dropdown-minimal option {
  background: var(--surface);
  color: var(--text);
}

.icon-btn-minimal {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.icon-btn-minimal:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.send-btn {
  background: var(--primary) !important;
  color: white !important;
}

.send-btn:hover {
  background: var(--primary-hover) !important;
  opacity: 0.9;
}

/* ── UI Elements ───────────────────────────────────────────────────────── */
.btn {
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn:active {
  transform: scale(0.96);
}

.btn.primary {
  background: var(--primary);
  color: white;
}

.btn.primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn.secondary {
  background: var(--secondary);
  color: var(--text);
}

.btn.secondary:hover {
  background: var(--secondary-hover);
}

.icon-btn {
  padding: 10px;
  border-radius: var(--radius-md);
}

.dropdown, .input-inline {
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
}

.dropdown:focus, .input-inline:focus {
  border-color: var(--primary);
}

/* ── Gallery ───────────────────────────────────────────────────────────── */
.generate-image-box {
  padding: 24px;
  border-radius: var(--radius-lg);
  margin-bottom: 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.flex-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.flex-1 {
  flex: 1;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
  padding-bottom: 40px;
}

.img-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
  display: flex;
  flex-direction: column;
}

.img-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.1);
}

.img-card img {
  width: 100%;
  aspect-ratio: 1/1;
  object-fit: cover;
  background: #000;
}

.img-card-info {
  padding: 16px;
  font-size: 13px;
}

.img-card-info .prompt {
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.img-card-info .meta {
  color: var(--text-muted);
  font-size: 12px;
}

/* ── Settings Form ─────────────────────────────────────────────────────── */
.settings-container {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.settings-card {
  padding: 32px;
  border-radius: var(--radius-lg);
}

.settings-card h3 {
  margin-bottom: 24px;
}

.settings-card h4 {
  margin: 24px 0 16px 0;
  color: var(--text-muted);
}

.form-group {
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
}

.form-group input {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color var(--transition);
}

.form-group input:focus {
  border-color: var(--primary);
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 32px;
}

.status-msg {
  font-size: 14px;
  color: #10b981; /* green */
  opacity: 0;
  transition: opacity 0.3s ease;
}

.status-msg.show {
  opacity: 1;
}

/* ── Auth Modal ────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.active {
  display: flex;
}

.modal-content {
  padding: 40px;
  border-radius: var(--radius-lg);
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}

.modal-content h2 {
  margin-bottom: 12px;
}

.modal-content p {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 24px;
}

.modal-content input {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-color);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  outline: none;
  margin-bottom: 20px;
  text-align: center;
}

.modal-content input:focus {
  border-color: var(--primary);
}

.modal-content button {
  width: 100%;
  padding: 12px;
}

/* Typewriter animation cursor */
.cursor {
  display: inline-block;
  width: 8px;
  height: 16px;
  background-color: var(--text);
  margin-left: 2px;
  vertical-align: middle;
  animation: blink 1s step-end infinite;
}

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

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ── Custom Dropdown ───────────────────────────────────────────────────── */
.custom-select-wrapper {
  position: relative;
  width: 100%;
}

.custom-select-list {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  max-height: 250px;
  overflow-y: auto;
  z-index: 100;
  margin-top: 4px;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  padding: 4px 0;
}

.custom-select-option {
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  color: var(--text);
}

.custom-select-option:hover {
  background: var(--primary);
  color: white;
}

/* ── API Docs ──────────────────────────────────────────────────────────── */
.docs-section {
  margin-bottom: 32px;
}

.docs-section-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  letter-spacing: -0.3px;
}

.docs-section-title .icon {
  font-size: 20px;
}

.docs-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px 24px;
  margin-bottom: 12px;
  transition: border-color var(--transition);
}

.docs-card:hover {
  border-color: var(--primary);
}

.docs-endpoint-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.docs-method {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.docs-method.get { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.docs-method.post { background: rgba(59, 130, 246, 0.15); color: #3b82f6; }
.docs-method.delete { background: rgba(239, 68, 68, 0.15); color: #ef4444; }

.docs-path {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.docs-access {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  margin-left: auto;
  flex-shrink: 0;
}

.docs-desc {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

.docs-body-table {
  width: 100%;
  margin-top: 12px;
  font-size: 13px;
  border-collapse: collapse;
}

.docs-body-table th {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.docs-body-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: top;
}

.docs-body-table tr:last-child td {
  border-bottom: none;
}

.docs-code {
  background: var(--bg-color);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-top: 12px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
  color: var(--text);
}

.docs-provider-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.docs-provider-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  transition: border-color var(--transition);
}

.docs-provider-card:hover {
  border-color: var(--primary);
}

.docs-provider-name {
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

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

.docs-status-dot.active { background: #10b981; box-shadow: 0 0 6px rgba(16, 185, 129, 0.4); }
.docs-status-dot.inactive { background: #64748b; }

.docs-provider-detail {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.docs-provider-detail code {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  color: var(--text);
  font-size: 12px;
}

.docs-fallback-chain {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.docs-fallback-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  position: relative;
}

.docs-fallback-step:not(:last-child) {
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.docs-fallback-step:not(:first-child) {
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.docs-fallback-step:not(:first-child):not(:last-child) {
  border-radius: 0;
}

.docs-fallback-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.docs-auth-method {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin-bottom: 8px;
}

.docs-auth-method-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
  color: var(--text);
}

.docs-auth-method code {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  color: var(--primary);
}

.docs-tabs {
  display: flex;
  gap: 4px;
  margin-top: 12px;
  margin-bottom: 0;
  border-bottom: 1px solid var(--border);
}

.docs-tab-btn {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
}

.docs-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.docs-tab-btn:hover {
  color: var(--text);
}
