﻿:root {
  --bg-primary: #f8fafc;
  --bg-card: #ffffff;
  --bg-glass: rgba(255, 255, 255, 0.88);
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-light: #3b82f6;
  --accent-glow: rgba(37, 99, 235, 0.18);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --nav-height: 64px;
  --header-height: 58px;
}

[data-theme="dark"] {
  --bg-primary: #090d16;
  --bg-card: #131b2e;
  --bg-glass: rgba(19, 27, 46, 0.92);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --border: #1e293b;
  --accent: #3b82f6;
  --accent-light: #60a5fa;
  --accent-glow: rgba(59, 130, 246, 0.25);
  --success: #10b981;
  --warning: #fbbf24;
  --danger: #f87171;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}

/* =========================================
   TOP HEADER & ACTIONS
   ========================================= */
.app-header {
  height: var(--header-height);
  background: var(--bg-glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  gap: 8px;
  z-index: 100;
  position: relative;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-size: 15.5px;
  color: var(--accent);
  letter-spacing: -0.3px;
  flex-shrink: 0;
  cursor: pointer;
}

.brand-logo .brand-icon {
  font-size: 18px;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-shrink: 1;
  justify-content: flex-end;
}

/* Model Selector Button on Header */
.model-picker-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.12), rgba(147, 51, 234, 0.12));
  border: 1px solid rgba(59, 130, 246, 0.35);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  cursor: pointer;
  max-width: 185px;
  height: 36px;
  flex-shrink: 1;
  min-width: 0;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.08);
}

.model-picker-btn:hover {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.2), rgba(147, 51, 234, 0.2));
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

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

.model-picker-icon {
  font-size: 13px;
  flex-shrink: 0;
}

#active-model-badge {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  color: var(--text-primary);
}

.model-chevron {
  font-size: 9px;
  opacity: 0.75;
  flex-shrink: 0;
}

/* User Account Icon Button */
.user-badge-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 20px;
  background: rgba(37, 99, 235, 0.08);
  border: 1px solid rgba(37, 99, 235, 0.25);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
  height: 36px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.user-badge-btn:hover {
  background: rgba(37, 99, 235, 0.15);
}

.user-badge-btn:active {
  transform: scale(0.94);
}

/* When logged in: sleek circular member avatar button */
.user-badge-btn.logged-in {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), rgba(6, 182, 212, 0.15));
  border: 1.5px solid rgba(16, 185, 129, 0.45);
  color: var(--success);
  font-size: 16px;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.18);
  position: relative;
}

.user-badge-btn.logged-in::after {
  content: '';
  position: absolute;
  top: 2px;
  right: 2px;
  width: 7px;
  height: 7px;
  background: #10b981;
  border-radius: 50%;
  border: 1.5px solid var(--bg-card);
}

.user-badge-btn.logged-in:hover {
  border-color: #10b981;
  box-shadow: 0 0 14px rgba(16, 185, 129, 0.35);
}

/* Round Icon Button */
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

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

.icon-btn:active {
  transform: scale(0.94);
}

/* =========================================
   MAIN VIEWPORT CONTAINER
   ========================================= */
.app-viewport {
  flex: 1;
  overflow-y: auto;
  position: relative;
  padding-bottom: calc(var(--nav-height) + 12px);
  -webkit-overflow-scrolling: touch;
}

.tab-pane {
  display: none;
  padding: 16px;
  min-height: 100%;
  animation: fadeIn 0.18s ease forwards;
}

.tab-pane.active {
  display: block;
}

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

/* =========================================
   BOTTOM NAVIGATION
   ========================================= */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s ease;
}

.nav-item.active {
  color: var(--accent);
}

.nav-item .nav-icon {
  font-size: 20px;
  transition: transform 0.15s ease;
}

.nav-item.active .nav-icon {
  transform: translateY(-2px) scale(1.08);
}

/* =========================================
   CARDS & COMMON UTILITIES
   ========================================= */
.app-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
}

.btn {
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #ffffff; }
.btn-secondary { background: var(--bg-card); border: 1px solid var(--border); color: var(--text-primary); }
.btn-success { background: var(--success); color: #ffffff; }
.btn-block { width: 100%; }

.input-area {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease;
}

.input-area:focus {
  border-color: var(--accent);
}

/* =========================================
   CHAT TAB
   ========================================= */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height) - var(--nav-height) - 32px);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-word;
}

.msg-user {
  align-self: flex-end;
  background: var(--accent);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.msg-ai {
  align-self: flex-start;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

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

.chat-input-box {
  flex: 1;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 13.5px;
  outline: none;
}

.chat-input-box:focus {
  border-color: var(--accent);
}

/* =========================================
   MODAL DRAWER / BOTTOM SHEET
   ========================================= */
.modal-sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 200;
  display: none;
  align-items: flex-end;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.modal-sheet.open {
  display: flex;
  opacity: 1;
}

.sheet-content {
  width: 100%;
  max-height: 85vh;
  background: var(--bg-card);
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  padding: 16px 20px 24px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.3);
}

.modal-sheet.open .sheet-content {
  transform: translateY(0);
}

/* Sheet Handle */
.sheet-handle {
  width: 38px;
  height: 4px;
  background: var(--text-secondary);
  opacity: 0.35;
  border-radius: 4px;
  margin: 0 auto 12px;
  flex-shrink: 0;
}

.modal-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.modal-title {
  font-size: 16.5px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-primary);
}

.modal-close-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.modal-close-btn:hover {
  color: var(--text-primary);
  background: var(--border);
}

/* =========================================
   MODEL SELECTOR STUDIO
   ========================================= */
.model-search-bar {
  position: relative;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.model-search-input {
  width: 100%;
  padding: 10px 14px 10px 36px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
}

.model-search-input:focus {
  border-color: var(--accent);
}

.model-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  opacity: 0.6;
  pointer-events: none;
}

.model-category-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 10px;
  margin-bottom: 8px;
  flex-shrink: 0;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.model-category-chips::-webkit-scrollbar {
  display: none;
}

.category-chip {
  padding: 5px 12px;
  border-radius: 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.category-chip:hover {
  color: var(--text-primary);
  border-color: var(--accent-light);
}

.category-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  box-shadow: 0 2px 8px var(--accent-glow);
}

/* Model Cards List */
.model-cards-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  max-height: 52vh;
  padding-right: 2px;
}

.model-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border-radius: 12px;
  background: var(--bg-primary);
  border: 1.5px solid var(--border);
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  text-align: left;
}

.model-card:hover {
  border-color: var(--accent-light);
  transform: translateY(-1px);
}

.model-card:active {
  transform: scale(0.985);
}

.model-card.active {
  background: rgba(37, 99, 235, 0.08);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 2px 10px var(--accent-glow);
}

.model-card-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.model-card-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.model-card.active .model-card-icon {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.model-card-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.model-card-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.model-card-desc {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-card-tags {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
}

.model-tag {
  font-size: 9.5px;
  padding: 1px 5px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-secondary);
  font-weight: 700;
}

[data-theme="dark"] .model-tag {
  background: rgba(255, 255, 255, 0.08);
}

.model-tag.tag-pro { color: #8b5cf6; background: rgba(139, 92, 246, 0.12); }
.model-tag.tag-fast { color: #f59e0b; background: rgba(245, 158, 11, 0.12); }
.model-tag.tag-free { color: #10b981; background: rgba(16, 185, 129, 0.12); }
.model-tag.tag-code { color: #06b6d4; background: rgba(6, 182, 212, 0.12); }

.model-check-icon {
  font-size: 15px;
  color: var(--accent);
  font-weight: 800;
  display: none;
  flex-shrink: 0;
  margin-left: 8px;
}

.model-card.active .model-check-icon {
  display: block;
}

/* =========================================
   AUTH MODAL & PROFILE
   ========================================= */
.auth-error {
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #ef4444;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 12px;
  display: none;
}

.auth-success {
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #10b981;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 12px;
  display: none;
}

/* Responsive tweaks */
@media (max-width: 360px) {
  .brand-logo span:last-child {
    display: none;
  }
}