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

:root {
  --bg-primary: #0a0e27;
  --bg-secondary: #0d1230;
  --bg-card: #131837;
  --border: #1e2450;
  --border-hover: #2d3363;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-glow: rgba(99, 102, 241, 0.2);
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  height: 100vh;
  overflow: hidden;
}

/* ── Navbar ──────────────────────────────────────────────────────────────── */

.navbar {
  height: 52px;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  z-index: 100;
  gap: 12px;
}

.navbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.navbar-logo {
  font-weight: 700;
  font-size: 16px;
  color: white;
  text-decoration: none;
  white-space: nowrap;
}

.navbar-brand {
  font-size: 12px;
  color: var(--text-muted);
  padding: 2px 8px;
  background: var(--bg-card);
  border-radius: 4px;
}

.navbar-links {
  display: flex;
  gap: 8px;
}

.navbar-links a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.2s;
}

.navbar-links a:hover { color: var(--text-primary); }

.navbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
  min-width: 0;
}

.project-name {
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  padding: 4px 8px;
  border-bottom: 1px dashed var(--border-hover);
  outline: none;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: text;
}

.project-name:focus {
  border-bottom-color: var(--accent);
}

.navbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  white-space: nowrap;
}

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

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

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

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

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  font-size: 16px;
  transition: color 0.2s;
}

.btn-icon:hover { color: var(--text-primary); }

/* ── Main Layout ─────────────────────────────────────────────────────────── */

.main-layout {
  display: flex;
  height: calc(100vh - 52px);
  overflow: hidden;
}

/* ── Chat Panel ──────────────────────────────────────────────────────────── */

.chat-panel {
  width: 340px;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg-primary);
}

.chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-header h3 i { color: var(--accent); }

.mobile-close { display: none; }

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: all 0.2s ease;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--text-primary);
  background: rgba(99, 102, 241, 0.1);
}

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

.message {
  display: flex;
  gap: 10px;
  max-width: 95%;
  animation: fadeIn 0.3s ease;
}

.message.ai-message { align-self: flex-start; }
.message.user-message { align-self: flex-end; flex-direction: row-reverse; }

.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 13px;
  color: white;
}

.message-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
}

.message-content p { margin: 0; }

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

.message.ai-message .message-content {
  border-bottom-left-radius: 4px;
}

/* ── Generating indicator ────────────────────────────────────────────────── */

.chat-generating {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  color: var(--accent);
  font-size: 13px;
}

.chat-generating.hidden { display: none; }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ── Chat Input ──────────────────────────────────────────────────────────── */

.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.chat-input-area textarea {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text-primary);
  resize: none;
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 42px;
}

.chat-input-area textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.btn-send {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 15px;
  padding: 0;
}

.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Chat Overlay (mobile) ───────────────────────────────────────────────── */

.chat-overlay {
  display: none;
}

/* ── Editor Panel ────────────────────────────────────────────────────────── */

.editor-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.editor-tabs {
  display: flex;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 10px 20px;
  cursor: pointer;
  color: var(--text-muted);
  border: none;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  font-size: 13px;
  font-weight: 500;
  background: none;
  font-family: 'Inter', sans-serif;
  display: flex;
  align-items: center;
  gap: 6px;
}

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

.tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}

.editor-content {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.tab-pane {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.tab-pane.hidden { display: none; }

#preview-frame {
  flex: 1;
  border: none;
  width: 100%;
  height: 100%;
  background: white;
}

#monaco-container {
  flex: 1;
  min-height: 0;
}

.status-bar {
  height: 28px;
  background: var(--bg-secondary);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* ── Modals ───────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--bg-card);
  border-radius: 16px;
  max-width: 500px;
  width: 90%;
  border: 1px solid var(--border);
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.modal-lg { max-width: 700px; }

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-body { padding: 20px; }

.modal-body p {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 12px;
}

.modal-body label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-textarea {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  color: var(--text-primary);
  font-family: 'Inter', monospace;
  font-size: 13px;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}

.modal-textarea:focus { border-color: var(--accent); }

/* ── Share Modal ─────────────────────────────────────────────────────────── */

.share-url-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.share-url-input {
  flex: 1;
  min-width: 0;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: 12px;
  font-family: monospace;
  outline: none;
}

.qr-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px;
  color: var(--text-muted);
  font-size: 13px;
}

.qr-placeholder i { font-size: 40px; opacity: 0.3; }

/* ── Import Summary ──────────────────────────────────────────────────────── */

.import-summary {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg-primary);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.import-summary.hidden { display: none; }

.import-summary h4 {
  font-size: 13px;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.summary-stats {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-secondary);
}

/* ── Template Grid ───────────────────────────────────────────────────────── */

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

.template-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 16px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
  font-family: 'Inter', sans-serif;
  color: var(--text-primary);
}

.template-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.template-card i {
  font-size: 28px;
  display: block;
  margin-bottom: 10px;
  color: var(--accent);
}

.template-card h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.template-card p {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ── Empty Preview State ──────────────────────────────────────────────────── */

.empty-preview {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  color: var(--text-muted);
  z-index: 1;
}

.empty-preview.hidden { display: none; }

.empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
  opacity: 0.6;
}

.empty-preview h3 {
  font-size: 18px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-preview p {
  font-size: 14px;
  max-width: 300px;
  text-align: center;
  line-height: 1.6;
}

.empty-actions {
  margin-top: 20px;
}

.empty-actions .btn {
  padding: 10px 20px;
  font-size: 14px;
  box-shadow: 0 4px 16px var(--accent-glow);
  transition: all 0.2s ease;
}

.empty-actions .btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.3);
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #3d4373; }

/* ── Animations ──────────────────────────────────────────────────────────── */

.fade-in { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.hidden { display: none !important; }

/* ── Mobile Chat Toggle ──────────────────────────────────────────────────── */

.mobile-chat-toggle { display: none; }

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .navbar-links { display: none; }
  .navbar-brand { display: none; }
  .navbar-center { display: none; }
  .navbar-right .btn-secondary { display: none; }
  .navbar-right .btn-primary { display: none; }
  .mobile-chat-toggle { display: flex !important; }

  .main-layout { flex-direction: column; }

  .chat-panel {
    position: fixed;
    top: 52px;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .chat-panel.mobile-open {
    transform: translateX(0);
  }

  .mobile-close { display: flex; }

  .chat-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 199;
  }

  .chat-overlay:not(.hidden) { display: block; }

  .editor-panel {
    width: 100%;
    height: calc(100vh - 52px);
  }

  .template-grid { grid-template-columns: repeat(2, 1fr); }

  .modal { width: 95%; }
}

@media (max-width: 480px) {
  .navbar { padding: 0 10px; }
  .template-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .template-card { padding: 14px 10px; }
}
