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

:root {
  --bg: #0b0e14;
  --sidebar: #12161f;
  --surface: #1a1f2b;
  --surface-hover: #242b3d;
  --border: #2d3548;
  --border-light: #3d475e;
  --text: #cbd5e1;
  --text-bright: #f8fafc;
  --text-dim: #94a3b8;
  --text-muted: #64748b;
  --accent: #8b5cf6; /* Vibrant Violet */
  --accent-glow: rgba(139, 92, 246, 0.3);
  --accent-bright: #a78bfa;
  --blue: #3b82f6;
  --green: #10b981;
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
}

html { height: 100%; }
body {
  height: 100%; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14px; -webkit-font-smoothing: antialiased;
}

#app { display: flex; height: 100vh; overflow: hidden; }

/* ========= SIDEBAR ========= */
#sidebar {
  width: 260px; min-width: 260px; background: var(--sidebar);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
}
.sidebar-inner { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.sidebar-top { border-bottom: 1px solid var(--border); }
.logo-area {
  display: flex; align-items: center; gap: 10px; padding: 16px;
}
.logo-icon {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  display: flex; align-items: center; justify-content: center; color: #fff;
  box-shadow: 0 4px 12px var(--accent-glow);
}
.logo-icon svg { width: 20px; height: 20px; }
.logo-title { font-size: 16px; font-weight: 700; color: var(--text-bright); letter-spacing: -0.5px; }
.logo-badge {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  background: rgba(255,255,255,0.1); color: var(--text-dim); padding: 2px 6px; border-radius: 4px; margin-left: auto;
}

.search-box {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; margin: 0 12px 12px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-dim); font-size: 13px; transition: all 0.2s;
}
.search-box:focus-within { border-color: var(--accent); background: var(--surface); }
.search-box svg { width: 14px; height: 14px; flex-shrink: 0; opacity: 0.6; }

.section-label {
  display: flex; align-items: center; gap: 8px; padding: 12px 16px 6px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--text-muted);
}

#feature-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px;
  border: none; background: none; color: var(--text); font-size: 13.5px; cursor: pointer;
  text-align: left; border-radius: var(--radius-sm); transition: all 0.2s;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text-bright); }
.nav-item.active {
  background: var(--accent-glow); color: var(--accent-bright); font-weight: 500;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.8; }
.nav-item .badge {
  margin-left: auto; font-size: 10px; background: var(--accent); color: #fff;
  padding: 1px 5px; border-radius: 4px; opacity: 0.8;
}

.model-selector { padding: 12px 16px; margin-top: auto; border-top: 1px solid var(--border); }
.model-selector label { display: block; font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }
.model-selector select {
  width: 100%; padding: 8px 12px; background: var(--surface); color: var(--text-bright);
  border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; outline: none;
  cursor: pointer; transition: all 0.2s;
}
.model-selector select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }

#conversation-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.conv-item {
  padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13px;
  color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: all 0.2s;
}
.conv-item:hover { background: var(--surface-hover); color: var(--text-bright); }
.conv-item.active { background: var(--surface); color: var(--accent-bright); font-weight: 500; }

.sidebar-footer {
  padding: 16px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-muted);
}

/* ========= MAIN ========= */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); position: relative; }

.tab-content { display: none; flex-direction: column; height: 100%; }
.tab-content.active { display: flex; }

.chat-container { display: flex; flex-direction: column; height: 100%; }

/* ========= MESSAGES ========= */
.messages {
  flex: 1; overflow-y: auto; padding: 24px 0; display: flex; flex-direction: column;
  background-image: radial-gradient(circle at 50% 0%, rgba(139, 92, 246, 0.05) 0%, transparent 50%);
}

.msg {
  max-width: 800px; width: 100%; margin: 0 auto; padding: 16px 24px; line-height: 1.7;
  font-size: 15px; word-wrap: break-word; white-space: pre-wrap; animation: msgIn 0.3s ease-out;
}
.msg.user {
  background: var(--surface); color: var(--text-bright); border-radius: 18px;
  margin-top: 8px; margin-bottom: 8px; border: 1px solid var(--border);
}
.msg.assistant {
  background: transparent; color: var(--text); border-bottom: 1px solid rgba(255,255,255,0.02);
  margin-top: 12px; margin-bottom: 12px;
}
.msg.system {
  text-align: center; color: var(--text-muted); font-size: 13px; font-style: italic;
  max-width: 500px; margin: 16px auto;
}

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

.typing {
  max-width: 800px; margin: 0 auto; padding: 16px 24px; display: flex; gap: 6px;
}
.typing span {
  width: 8px; height: 8px; background: var(--accent); border-radius: 50%;
  animation: bounce 1.4s infinite; opacity: 0.6;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { 0%,60%,100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-6px); } }

/* Welcome Screen */
.welcome {
  text-align: center; padding: 60px 20px; max-width: 600px; margin: auto;
}
.welcome-icon {
  width: 64px; height: 64px; margin: 0 auto 24px; border-radius: 20px;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  display: flex; align-items: center; justify-content: center; color: #fff;
  font-size: 32px; box-shadow: 0 12px 40px var(--accent-glow);
}
.welcome h1 { font-size: 32px; font-weight: 800; color: var(--text-bright); margin-bottom: 12px; letter-spacing: -1px; }
.welcome p { color: var(--text-dim); font-size: 16px; margin-bottom: 32px; }
.welcome-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; max-width: 500px; margin: 0 auto; }
.welcome-chip {
  padding: 12px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 14px; cursor: pointer;
  text-align: left; transition: all 0.2s;
}
.welcome-chip:hover {
  background: var(--surface-hover); border-color: var(--accent); color: var(--text-bright);
  transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* ========= INPUT ========= */
.input-area {
  padding: 20px 24px 32px; background: transparent;
}
.input-wrap {
  max-width: 800px; margin: 0 auto; display: flex; gap: 0; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 8px 8px 8px 16px; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 8px 40px rgba(0,0,0,0.4), 0 0 0 2px var(--accent-glow); }
.input-wrap textarea {
  flex: 1; resize: none; padding: 10px 0; background: transparent; color: var(--text-bright);
  border: none; font-size: 15px; font-family: var(--font); outline: none; line-height: 1.5;
  max-height: 200px;
}
.input-wrap textarea::placeholder { color: var(--text-muted); }

.send-btn {
  width: 40px; height: 40px; border-radius: 12px; border: none;
  background: var(--accent); color: #fff; cursor: pointer; display: flex;
  align-items: center; justify-content: center; flex-shrink: 0; transition: all 0.2s;
}
.send-btn:hover:not(:disabled) { background: var(--accent-bright); transform: scale(1.05); }
.send-btn:disabled { opacity: 0.2; cursor: default; }
.send-btn svg { width: 20px; height: 20px; }

.input-hint { max-width: 800px; margin: 12px auto 0; font-size: 12px; color: var(--text-muted); text-align: center; }

/* ========= BUILDER ========= */
.builder-container { display: flex; flex-direction: column; height: 100%; }
.builder-body { flex: 1; padding: 24px; overflow-y: auto; max-width: 900px; width: 100%; margin: 0 auto; }
.builder-controls { display: flex; flex-direction: column; gap: 16px; margin-bottom: 24px; }
.builder-row { display: flex; gap: 16px; }
.builder-field { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.builder-field label { font-size: 13px; color: var(--text-dim); font-weight: 500; }
.builder-field select, .builder-field input {
  padding: 10px 12px; background: var(--surface); color: var(--text-bright);
  border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; outline: none;
}
.builder-field textarea {
  width: 100%; padding: 12px; background: var(--surface); color: var(--text-bright);
  border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px;
  outline: none; font-family: var(--font); resize: vertical;
}
.builder-field select:focus, .builder-field input:focus, .builder-field textarea:focus { border-color: var(--accent); }

.primary-btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 12px 24px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), var(--blue)); color: #fff; border: none; cursor: pointer;
  font-size: 14px; font-weight: 600; transition: all 0.2s; align-self: flex-start;
  box-shadow: 0 4px 15px var(--accent-glow);
}
.primary-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px var(--accent-glow); opacity: 0.9; }
.primary-btn.sm { padding: 6px 12px; font-size: 12px; }

.builder-status { font-size: 13px; min-height: 22px; margin-bottom: 12px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.builder-status.building { color: var(--accent-bright); }
.builder-status.success { color: var(--green); }
.builder-status.error { color: #ef4444; }
.build-spinner {
  display: inline-block; width: 14px; height: 14px; border: 2px solid var(--accent-glow);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.builder-output { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: #0d1117; }
.output-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--text-dim); font-weight: 500;
}
.output-info { display: flex; align-items: center; gap: 6px; }
.output-actions { display: flex; align-items: center; gap: 4px; }
.code-stats { color: var(--text-muted); font-weight: 400; font-size: 11px; }
.icon-btn {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  padding: 5px; border-radius: 4px; display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text-bright); }
.icon-btn.active { color: var(--accent-bright); background: rgba(139, 92, 246, 0.12); }

.output-view { position: relative; min-height: 200px; }
.code-block {
  padding: 20px; font-family: var(--mono); font-size: 13px; line-height: 1.7; overflow: auto; max-height: 520px;
  white-space: pre-wrap; color: #e6edf3; background: #0d1117; margin: 0;
}
.code-block .placeholder { color: var(--text-muted); font-family: var(--font); }

.preview-pane {
  position: absolute; inset: 0; display: none; flex-direction: column;
  background: #fff; overflow: hidden;
}
.preview-pane.open { display: flex; }
.preview-web { display: flex; flex: 1; }
.preview-mobile { display: none; flex: 1; align-items: center; justify-content: center; background: #0d1117; padding: 20px; }
.preview-frame {
  width: 100%; flex: 1; border: none; background: #fff; min-height: 400px;
}
.preview-error {
  padding: 20px; text-align: center; color: #ef4444;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  font-size: 13px;
}

.phone-frame {
  position: relative; width: 300px; min-width: 300px; height: 540px;
  background: #1a1a2e; border-radius: 40px; padding: 12px;
  box-shadow: 0 0 0 2px #333, 0 20px 60px rgba(0,0,0,0.5),
    inset 0 0 0 2px rgba(255,255,255,0.05);
}
.phone-notch {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 120px; height: 28px; background: #1a1a2e; border-radius: 0 0 16px 16px;
  z-index: 2;
}
.phone-notch::after {
  content: ''; position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  width: 10px; height: 10px; border-radius: 50%; background: #0f0f23;
  border: 2px solid #2a2a4a;
}
.phone-screen {
  width: 100%; height: 100%; background: #0d1117; border-radius: 28px;
  overflow: hidden; display: flex;
}
.phone-code {
  flex: 1; margin: 0; padding: 28px 16px 16px; overflow: auto;
  font-family: var(--mono); font-size: 10.5px; line-height: 1.6;
  color: #e6edf3; white-space: pre; tab-size: 2;
}
.phone-code code { font-family: inherit; }
.phone-hint {
  margin-top: 12px; text-align: center; font-size: 12px; color: var(--text-muted);
  max-width: 320px; line-height: 1.5;
}

/* ========= RAG ========= */
.rag-bar {
  display: flex; gap: 12px; align-items: center; padding: 16px 24px;
  border-bottom: 1px solid var(--border); flex-wrap: wrap; background: var(--surface);
}
.file-btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-bright); font-size: 13px; cursor: pointer; transition: all 0.2s;
}
.file-btn:hover { border-color: var(--accent); background: var(--surface-hover); }
.rag-bar select {
  padding: 8px 12px; background: var(--bg); color: var(--text-bright);
  border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px;
  flex: 1; min-width: 140px; cursor: pointer; outline: none;
}

/* ========= SCROLLBAR ========= */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ========= RESPONSIVE ========= */
@media (max-width: 720px) {
  #sidebar { width: 100%; min-width: unset; position: fixed; z-index: 100; height: 100vh; display: none; }
  #sidebar.open { display: flex; }
  .msg { padding: 12px 16px; }
  .welcome h1 { font-size: 24px; }
  .welcome-grid { grid-template-columns: 1fr; }
}
