/* ============================================
   AI Business Lab — ChatGPT/Claude-style UI
   Premium Dark Theme
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  /* Core palette */
  --bg-primary: #0d0d0d;
  --bg-sidebar: #171717;
  --bg-chat: #212121;
  --bg-user-msg: #2f2f2f;
  --bg-input: #2f2f2f;
  --bg-hover: #2a2a2a;
  --bg-surface: #1e1e1e;

  /* Accent */
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-soft: rgba(124, 58, 237, 0.12);
  --accent-glow: rgba(124, 58, 237, 0.25);

  /* Text */
  --text-primary: #ececec;
  --text-secondary: #8e8ea0;
  --text-tertiary: #6b6b7b;
  --text-link: #a78bfa;

  /* Borders & misc */
  --border: rgba(255,255,255,0.08);
  --border-light: rgba(255,255,255,0.05);
  --green: #10b981;
  --red: #ef4444;

  /* Sidebar width */
  --sidebar-width: 260px;
}

/* ============================================
   Light Theme
   ============================================ */
html.light {
  --bg-primary: #ffffff;
  --bg-sidebar: #f7f7f8;
  --bg-chat: #ffffff;
  --bg-user-msg: #f7f7f8;
  --bg-input: #f4f4f4;
  --bg-hover: #ececec;
  --bg-surface: #f7f7f8;

  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-soft: rgba(124, 58, 237, 0.08);
  --accent-glow: rgba(124, 58, 237, 0.15);

  --text-primary: #1a1a1a;
  --text-secondary: #6b6b7b;
  --text-tertiary: #9b9ba4;
  --text-link: #7c3aed;

  --border: rgba(0,0,0,0.08);
  --border-light: rgba(0,0,0,0.05);
  --green: #059669;
  --red: #dc2626;
}

html.light body { background: #ffffff; color: var(--text-primary); }

/* Theme toggle button */
.theme-toggle-btn {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: none; border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.theme-toggle-btn:hover { background: var(--bg-hover); }

/* Sun/moon icon visibility */
.icon-sun { display: none; }
.icon-moon { display: block; }
html.light .icon-sun { display: block; }
html.light .icon-moon { display: none; }

/* Theme label in sidebar */
html.light .theme-label::after { content: ''; }
html.light #themeToggleDesktop .theme-label { display: inline; }

/* Light mode scrollbar */
html.light ::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); }
html.light ::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.2); }
html.light * { scrollbar-color: rgba(0,0,0,0.12) transparent; }

/* Light mode code blocks */
html.light .message-text code {
  background: rgba(0,0,0,0.06);
}
html.light .message-text pre {
  background: #f7f7f8;
  border-color: rgba(0,0,0,0.1);
}

/* Light mode credits overlay */
html.light .credits-overlay { background: rgba(0,0,0,0.4); }

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

html, body {
  height: 100%; width: 100%; overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px; line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--text-link); text-decoration: none; }
a:hover { text-decoration: underline; }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.1) transparent; }

.hidden { display: none !important; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slideInLeft { from { transform: translateX(-100%); } to { transform: translateX(0); } }

/* ============================================
   Login Page (preserved)
   ============================================ */
:root {
  --tg-bg: #17212b;
  --tg-bg-secondary: #0e1621;
  --tg-bg-chat: #0e1621;
  --tg-bg-input: #242f3d;
  --tg-bubble-out: #2b5278;
  --tg-bubble-in: #182533;
  --tg-text: #f5f5f5;
  --tg-text-secondary: #6c7883;
  --tg-link: #6ab2f2;
  --tg-accent: #5288c1;
  --tg-accent-hover: #4a7db0;
  --tg-green: #4dcd5e;
  --tg-border: #0e1621;
  --tg-time: rgba(255,255,255,0.45);
  --tg-time-out: rgba(255,255,255,0.5);
  --tg-separator: #101921;
}

.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; min-height: 100dvh;
  padding: 24px; overflow: auto;
  background: var(--bg-primary);
}

.login-card {
  width: 100%; max-width: 380px;
  background: var(--bg-sidebar);
  border-radius: 16px;
  padding: 40px 32px;
  border: 1px solid var(--border);
}

.login-logo { text-align: center; margin-bottom: 8px; }

.login-logo-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 64px; height: 64px;
  background: var(--accent); border-radius: 16px;
  margin-bottom: 16px;
}
.login-logo-icon svg { width: 32px; height: 32px; fill: #fff; }
.login-logo h1 { font-size: 22px; font-weight: 700; color: var(--text-primary); }

.login-subtitle {
  text-align: center; color: var(--text-secondary);
  font-size: 14px; margin-bottom: 28px;
}

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

.form-input {
  width: 100%; padding: 12px 16px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 12px; color: var(--text-primary);
  font-size: 15px; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-input::placeholder { color: var(--text-tertiary); }

.phone-input-row { display: flex; gap: 8px; }
.phone-country-select {
  width: 100px; flex-shrink: 0; padding: 12px 8px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 12px; color: var(--text-primary); font-size: 14px; outline: none;
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='%236c7883' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 24px;
}
.phone-country-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.phone-input-row .form-input { flex: 1; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 24px; border: none; border-radius: 12px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: all 0.15s; gap: 8px; position: relative;
  font-family: inherit;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { width: 100%; background: var(--accent); color: #fff; margin-top: 8px; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-input); color: var(--text-primary); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-sm { padding: 6px 14px; font-size: 13px; border-radius: 8px; }

.btn-loading .btn-text { visibility: hidden; }
.btn-loading .btn-spinner { display: block; }
.btn-spinner {
  display: none; width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff;
  border-radius: 50%; animation: spin 0.6s linear infinite; position: absolute;
}

.login-helper { text-align: center; color: var(--text-secondary); font-size: 13px; margin-top: 16px; }
.login-error {
  background: rgba(239,68,68,0.12); border-radius: 10px;
  padding: 10px 14px; color: #ef5350; font-size: 14px;
  margin-bottom: 12px; display: none;
}
.login-error.visible { display: block; }

/* ============================================
   App Layout
   ============================================ */
.app-layout {
  display: flex;
  height: 100vh; height: 100dvh;
  background: var(--bg-primary);
  overflow: hidden;
}

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  height: 100%;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 32px; height: 32px;
  flex-shrink: 0;
}
.logo-icon svg { width: 100%; height: 100%; }

.logo-icon-sm {
  width: 28px; height: 28px;
}

.logo-text {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.sidebar-close-btn {
  display: none;
  width: 32px; height: 32px;
  border-radius: 8px;
  background: none; border: none;
  color: var(--text-secondary);
  cursor: pointer;
  align-items: center; justify-content: center;
}
.sidebar-close-btn:hover { background: var(--bg-hover); }

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 12px 8px;
  padding: 10px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}
.new-chat-btn:hover { background: var(--bg-hover); }
.new-chat-btn svg { color: var(--text-secondary); }

.sidebar-conversations {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px;
}

.sidebar-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
  padding: 12px 8px 6px;
}

.conversation-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conversation-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conversation-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.conversation-item.active { background: var(--bg-hover); color: var(--text-primary); }

.sidebar-footer {
  flex-shrink: 0;
  padding: 8px 12px 12px;
  border-top: 1px solid var(--border);
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

.sidebar-footer-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.1s;
  font-family: inherit;
  text-align: left;
}
.sidebar-footer-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.credits-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}
.credits-badge strong { color: var(--accent); font-weight: 700; }

.credits-topup-label {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 6px;
}

.sidebar-user-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ============================================
   Mobile Header
   ============================================ */
.mobile-header {
  display: none;
  align-items: center;
  padding: 10px 16px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
}

.hamburger-btn {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: none; border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.hamburger-btn:hover { background: var(--bg-hover); }

.mobile-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.mobile-header-spacer { width: 36px; }

/* Sidebar Overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 99;
}
.sidebar-overlay.visible { display: block; }

/* ============================================
   Main Content Area
   ============================================ */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-chat);
  position: relative;
}

/* ============================================
   Chat Messages (ChatGPT/Claude style)
   ============================================ */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  padding: 0;
}

/* Full-width message rows like ChatGPT */
.message-row {
  width: 100%;
  padding: 24px 0;
  animation: fadeIn 0.2s ease-out;
  border-bottom: 1px solid var(--border-light);
}

.message-row:last-child { border-bottom: none; }

.message-row.user {
  background: transparent;
}

.message-row.assistant {
  background: var(--bg-surface);
}

.message-row.system {
  background: transparent;
  padding: 12px 0;
}

/* Message inner container — centered like ChatGPT */
.message-inner {
  max-width: 768px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  gap: 16px;
  width: 100%;
}

/* Avatars */
.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}

.message-avatar svg {
  width: 28px;
  height: 28px;
}

.message-avatar.bot-avatar {
  background: none;
}

.message-avatar.user-avatar {
  background: #565869;
  border-radius: 50%;
}

.message-avatar.user-avatar svg {
  width: 16px; height: 16px;
  fill: #fff;
}

/* Message bubble (no actual bubble — clean layout) */
.message-bubble {
  flex: 1;
  min-width: 0;
  line-height: 1.6;
  font-size: 15px;
}

/* System messages centered */
.message-row.system .message-inner {
  justify-content: center;
}
.message-row.system .message-bubble {
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
  background: rgba(255,255,255,0.04);
  padding: 6px 16px;
  border-radius: 20px;
  flex: none;
}

/* ---- Message Content ---- */
.message-text {
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.message-text p { margin-bottom: 12px; }
.message-text p:last-child { margin-bottom: 0; }
.message-text a { color: var(--text-link); }
.message-text strong { font-weight: 600; }
.message-text em { font-style: italic; }
.message-text code {
  background: rgba(255,255,255,0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', 'Menlo', monospace;
}
.message-text pre {
  background: #0d0d0d;
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  margin: 12px 0;
  border: 1px solid var(--border);
}
.message-text pre code {
  background: none;
  padding: 0;
  font-size: 13px;
}
.message-text ul, .message-text ol {
  margin: 8px 0;
  padding-left: 24px;
}
.message-text li { margin-bottom: 4px; }

/* Timestamp — subtle */
.message-time {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 8px;
}
.message-row.system .message-time { display: none; }

/* ---- Typing Indicator ---- */
.typing-indicator {
  display: none;
  width: 100%;
  padding: 24px 0;
  background: var(--bg-surface);
}
.typing-indicator.visible { display: block; }

.typing-content {
  max-width: 768px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  gap: 16px;
}

.typing-bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 0;
}

.typing-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: typingPulse 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingPulse {
  0%, 60%, 100% { transform: scale(0.6); opacity: 0.3; }
  30% { transform: scale(1); opacity: 1; }
}

/* ============================================
   Quick Actions (Welcome screen)
   ============================================ */
.quick-actions-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.quick-actions-inner {
  text-align: center;
  max-width: 640px;
  width: 100%;
}

.welcome-heading {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 32px;
  line-height: 1.3;
}

.quick-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.quick-action-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  font-family: inherit;
}
.quick-action-card:hover {
  background: var(--bg-hover);
  border-color: rgba(255,255,255,0.12);
  color: var(--text-primary);
}
.quick-action-card svg { flex-shrink: 0; color: var(--text-tertiary); }

/* ============================================
   Input Bar (ChatGPT-style)
   ============================================ */
.chat-input-container {
  flex-shrink: 0;
  padding: 0 24px 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  background: var(--bg-chat);
}

.chat-input-inner {
  max-width: 768px;
  margin: 0 auto;
}

.chat-input-box {
  display: flex;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 4px 4px 4px 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chat-input-box:focus-within {
  border-color: rgba(255,255,255,0.2);
  box-shadow: 0 0 0 2px rgba(255,255,255,0.04);
}

.chat-input {
  flex: 1;
  padding: 10px 0;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  line-height: 1.5;
  outline: none;
  resize: none;
  max-height: 200px;
  min-height: 24px;
  overflow-y: auto;
}
.chat-input::placeholder { color: var(--text-tertiary); }

.send-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--accent);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
  margin-bottom: 2px;
}
.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:active:not(:disabled) { transform: scale(0.92); }
.send-btn:disabled { opacity: 0.3; cursor: default; background: var(--text-tertiary); }

.input-footer-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 8px;
}

/* ============================================
   Credits Overlay
   ============================================ */
.credits-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.2s ease-out;
}
.credits-overlay.hidden { display: none; }

.credits-panel {
  background: var(--bg-sidebar);
  border-radius: 20px;
  padding: 32px;
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid var(--border);
}

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

.credits-panel-header h2 {
  font-size: 22px;
  font-weight: 700;
}

.credits-close-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--bg-surface);
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.credits-close-btn:hover { background: var(--bg-hover); }

.credits-balance {
  text-align: center;
  padding: 24px;
  background: var(--bg-surface);
  border-radius: 16px;
  margin-bottom: 28px;
  border: 1px solid var(--border);
}

.credits-balance-label {
  font-size: 13px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.credits-balance-amount {
  font-size: 36px;
  font-weight: 700;
  color: var(--accent);
}

.credits-packages {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.credit-package-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px 20px;
  text-align: center;
  position: relative;
  transition: border-color 0.2s, transform 0.15s;
}
.credit-package-card:hover {
  border-color: rgba(255,255,255,0.15);
  transform: translateY(-2px);
}

.credit-package-card.popular {
  border-color: var(--accent);
  box-shadow: 0 0 30px var(--accent-glow);
}

.package-popular-tag {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 14px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.package-badge {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.package-credits {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.package-price {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.package-features {
  list-style: none;
  padding: 0;
  margin-bottom: 20px;
}

.package-features li {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 4px 0;
  position: relative;
}

.package-features li::before {
  content: '✓';
  color: var(--green);
  margin-right: 8px;
  font-weight: 700;
}

.package-buy-btn {
  width: 100%;
  padding: 12px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.package-buy-btn:hover { background: var(--bg-input); }

.package-buy-btn.btn-popular {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.package-buy-btn.btn-popular:hover { background: var(--accent-hover); }

/* ============================================
   Rich Message Components (preserved)
   ============================================ */
.rich-stats-card {
  background: rgba(255,255,255,0.04);
  border-radius: 12px; padding: 16px;
  margin-top: 12px;
  border: 1px solid var(--border);
}
.rich-stats-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.rich-stat-item { text-align: center; padding: 10px; }
.rich-stat-value { font-size: 22px; font-weight: 700; color: var(--text-primary); }
.rich-stat-label { font-size: 11px; color: var(--text-secondary); margin-top: 4px; }

.rich-upsell-card {
  background: linear-gradient(135deg, rgba(124,58,237,0.1), rgba(124,58,237,0.03));
  border: 1px solid rgba(124,58,237,0.2);
  border-radius: 12px; padding: 16px; margin-top: 12px;
}
.rich-upsell-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.rich-upsell-price { font-size: 22px; font-weight: 700; color: var(--green); margin-bottom: 8px; }
.rich-upsell-features { list-style: none; padding: 0; margin-bottom: 12px; }
.rich-upsell-features li {
  font-size: 13px; color: var(--text-secondary);
  padding: 3px 0; padding-left: 18px; position: relative;
}
.rich-upsell-features li::before {
  content: '✓'; position: absolute; left: 0; color: var(--green);
}
.rich-upsell-btn {
  width: 100%; padding: 10px; background: var(--accent);
  color: #fff; border: none; border-radius: 10px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  font-family: inherit;
}
.rich-upsell-btn:hover { background: var(--accent-hover); }

.rich-quick-replies {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px;
}
.rich-quick-reply-btn, .quick-reply-btn {
  padding: 8px 16px; background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px; color: var(--text-secondary);
  font-size: 13px; cursor: pointer; transition: all 0.15s;
  font-family: inherit;
}
.rich-quick-reply-btn:hover, .quick-reply-btn:hover {
  background: var(--bg-hover); border-color: rgba(255,255,255,0.15); color: var(--text-primary);
}

.rich-progress { margin-top: 12px; }
.rich-progress-label {
  font-size: 13px; color: var(--text-secondary); margin-bottom: 6px;
}
.rich-progress-bar {
  height: 6px; background: rgba(255,255,255,0.06);
  border-radius: 3px; overflow: hidden;
}
.rich-progress-fill {
  height: 100%; background: var(--accent);
  border-radius: 3px; transition: width 0.5s ease;
}

.rich-celebration {
  text-align: center; padding: 16px;
  margin-top: 12px;
}
.rich-celebration-emoji { font-size: 44px; margin-bottom: 8px; }
.rich-celebration-text { font-size: 16px; font-weight: 600; }

/* ============================================
   Onboarding Page (preserved)
   ============================================ */
.onboard-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; min-height: 100dvh;
  padding: 24px; background: var(--bg-primary);
}
.onboard-card { text-align: center; max-width: 360px; }
.onboard-spinner {
  width: 48px; height: 48px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 20px;
}
.onboard-title { font-size: 18px; font-weight: 600; color: var(--text-primary); margin-bottom: 8px; }
.onboard-subtitle { font-size: 14px; color: var(--text-secondary); }
.onboard-error { color: var(--red); font-size: 14px; margin-top: 16px; display: none; }
.onboard-error.visible { display: block; }

/* ============================================
   Admin Dashboard (preserved)
   ============================================ */
.admin-page {
  min-height: 100vh; background: var(--bg-primary); overflow: auto;
}
html.admin-mode, html.admin-mode body {
  overflow: auto !important; height: auto !important;
}

.admin-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.admin-header-left { display: flex; align-items: center; gap: 12px; }
.admin-back-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: transparent; border: none;
  color: var(--text-secondary); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.admin-back-btn:hover { background: var(--bg-hover); }
.admin-back-btn svg { width: 20px; height: 20px; }
.admin-title { font-size: 17px; font-weight: 600; color: var(--text-primary); }
.admin-subtitle { font-size: 12px; color: var(--text-secondary); }

.admin-tabs {
  display: flex; gap: 4px; padding: 8px 20px;
  background: var(--bg-sidebar); border-bottom: 1px solid var(--border);
  overflow-x: auto; position: sticky; top: 60px; z-index: 19;
}
.admin-tabs::-webkit-scrollbar { display: none; }

.admin-tab {
  padding: 8px 16px; border: none; border-radius: 8px;
  background: transparent; color: var(--text-secondary);
  font-size: 14px; font-weight: 500; cursor: pointer;
  white-space: nowrap; transition: all 0.15s;
  display: flex; align-items: center; gap: 6px;
  font-family: inherit;
}
.admin-tab:hover { background: var(--bg-hover); color: var(--text-primary); }
.admin-tab.active { background: var(--accent); color: #fff; }
.admin-tab svg { width: 16px; height: 16px; }

.admin-content { max-width: 1400px; margin: 0 auto; padding: 20px; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--bg-sidebar); border-radius: 12px; padding: 16px; border: 1px solid var(--border); }
.stat-card-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.stat-card-icon { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.stat-card-icon svg { width: 16px; height: 16px; }
.stat-card-label { font-size: 13px; color: var(--text-secondary); }
.stat-card-value { font-size: 28px; font-weight: 700; color: var(--text-primary); }

.admin-section {
  background: var(--bg-sidebar); border-radius: 12px;
  padding: 20px; margin-bottom: 16px;
  border: 1px solid var(--border);
}
.admin-section-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.admin-section-desc { font-size: 13px; color: var(--text-secondary); margin-bottom: 16px; }

.prompt-editor {
  width: 100%; min-height: 300px; padding: 14px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text-primary);
  font-size: 14px; font-family: 'SF Mono', 'Fira Code', monospace;
  line-height: 1.5; resize: vertical; outline: none;
}
.prompt-editor:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.prompt-actions { display: flex; gap: 8px; margin-top: 12px; justify-content: flex-end; }
.prompt-vars { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.prompt-vars-title { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.prompt-vars-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px; }
.prompt-var-item { background: var(--bg-input); border-radius: 6px; padding: 6px 10px; }
.prompt-var-key { font-size: 13px; font-family: monospace; color: var(--accent); }
.prompt-var-desc { font-size: 11px; color: var(--text-secondary); }

.admin-search {
  width: 100%; padding: 10px 14px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text-primary);
  font-size: 14px; outline: none; margin-bottom: 12px;
}
.admin-search::placeholder { color: var(--text-tertiary); }
.admin-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.users-table { width: 100%; border-collapse: collapse; }
.users-table th {
  text-align: left; padding: 8px 10px;
  font-size: 12px; font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}
.users-table td {
  padding: 10px; font-size: 14px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
.users-table tr:hover td { background: rgba(255,255,255,0.02); }

.badge {
  display: inline-block; padding: 2px 8px;
  border-radius: 4px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.3px;
}
.badge-starter { background: rgba(108,120,131,0.2); color: #8899a6; }
.badge-pro { background: rgba(124,58,237,0.2); color: #a78bfa; }
.badge-premium { background: rgba(171,104,232,0.2); color: #b078e8; }
.badge-upgrade { background: rgba(124,58,237,0.2); color: #a78bfa; }
.badge-addon { background: rgba(171,104,232,0.2); color: #b078e8; }

.status-badge { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; }
.status-badge .dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.status-badge .dot.live { background: var(--green); }
.status-badge .dot.building { background: #eab308; }
.status-badge .dot.pending { background: var(--text-secondary); }

.product-card {
  background: var(--bg-input); border-radius: 10px;
  padding: 14px; margin-bottom: 8px;
  display: flex; align-items: center; justify-content: space-between;
  border: 1px solid var(--border);
}
.product-info { flex: 1; }
.product-name { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.product-desc { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.product-price { font-size: 15px; font-weight: 700; color: var(--green); }
.product-actions { display: flex; gap: 6px; }

.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: 6px; margin-top: 12px;
}
.pagination-btn {
  padding: 6px 12px; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: 6px; color: var(--text-primary);
  font-size: 13px; cursor: pointer;
}
.pagination-btn:hover { background: var(--bg-hover); }
.pagination-btn:disabled { opacity: 0.3; cursor: default; }
.pagination-info { font-size: 13px; color: var(--text-secondary); }

.webhook-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 10px; }
.webhook-card { background: var(--bg-input); border-radius: 8px; padding: 12px; border: 1px solid var(--border); }
.webhook-card-title { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.webhook-card-url { font-size: 12px; font-family: monospace; color: var(--accent); word-break: break-all; margin-bottom: 4px; }
.webhook-card-desc { font-size: 11px; color: var(--text-secondary); }

/* Admin — Additional Styles */
.admin-section { display: none; }
.admin-section.active { display: block; }

.admin-section-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 20px; gap: 16px;
}

.admin-user-count {
  font-size: 13px; font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 12px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}

.admin-back-btn {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 8px;
  color: var(--text-secondary); text-decoration: none;
  transition: background 0.15s;
}
.admin-back-btn:hover { background: var(--bg-hover); text-decoration: none; }

.admin-table-wrap { overflow-x: auto; }

.users-table tr.clickable { cursor: pointer; transition: background 0.1s; }
.users-table tr.clickable:hover td { background: var(--bg-hover); }

.user-detail-row { display: none; }
.user-detail-row.visible { display: table-row; }

.user-detail-cell {
  padding: 16px !important;
  background: var(--bg-surface) !important;
  border-bottom: 2px solid var(--accent-soft) !important;
}

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

.user-detail-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.detail-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-tertiary);
}

.detail-value {
  font-size: 14px;
  color: var(--text-primary);
}

.admin-select {
  width: 100%; padding: 12px 16px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 12px; color: var(--text-primary);
  font-size: 14px; font-family: inherit; outline: none;
  margin-bottom: 16px;
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238e8ea0' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px;
}
.admin-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Fix admin-chat-select to use new style */
.admin-chat-select {
  width: 100%; padding: 12px 16px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 12px; color: var(--text-primary);
  font-size: 14px; font-family: inherit; outline: none;
  margin-bottom: 16px;
}

.admin-chat-view {
  background: var(--bg-chat);
  border: 1px solid var(--border);
  border-radius: 12px;
  min-height: 400px;
  max-height: 600px;
  overflow-y: auto;
  padding: 12px 0;
}

.admin-chat-empty {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: 300px;
  color: var(--text-secondary);
  font-size: 14px;
  text-align: center;
  padding: 24px;
}

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

.product-form {
  margin-top: 24px;
  padding: 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.product-form h3 {
  font-size: 16px; font-weight: 600; margin-bottom: 16px;
}

.product-form-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
@media (max-width: 480px) {
  .product-form-row { grid-template-columns: 1fr; }
}

.admin-form-actions {
  display: flex; gap: 8px; margin-top: 12px;
}

/* Admin textarea */
.admin-textarea {
  width: 100%; min-height: 300px; padding: 14px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text-primary);
  font-size: 14px; font-family: 'SF Mono', 'Fira Code', monospace;
  line-height: 1.5; resize: vertical; outline: none;
}
.admin-textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Badge colors */
.badge-green { background: rgba(16,185,129,0.15); color: #10b981; }
.badge-yellow { background: rgba(234,179,8,0.15); color: #eab308; }
.badge-blue { background: rgba(59,130,246,0.15); color: #3b82f6; }
.badge-red { background: rgba(239,68,68,0.15); color: #ef4444; }

/* Confetti */
.confetti-container {
  position: fixed; top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none; z-index: 9999; overflow: hidden;
}
.confetti-piece {
  position: absolute; width: 10px; height: 10px;
  animation: confettiFall 3s linear forwards;
}
@keyframes confettiFall {
  0% { transform: translateY(-10px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.4);
  }

  .sidebar-close-btn { display: flex; }

  .mobile-header { display: flex; }

  .chat-input-container { padding: 0 12px 12px; }
  .chat-input-inner { max-width: 100%; }

  .message-inner { padding: 0 16px; }

  .quick-actions-grid { grid-template-columns: 1fr; }

  .welcome-heading { font-size: 22px; }

  .credits-packages {
    grid-template-columns: 1fr;
  }

  .credits-panel {
    padding: 24px 20px;
    border-radius: 16px;
  }

  .admin-content { padding: 12px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 769px) {
  .mobile-header { display: none !important; }
  .sidebar-overlay { display: none !important; }
  .sidebar-close-btn { display: none !important; }
}


/* ============================================
   Templates Tab — Sidebar + Editor Layout
   ============================================ */
.tpl-layout {
  display: flex; height: calc(100vh - 140px); min-height: 500px;
  border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; background: var(--bg-primary);
}

/* ---- Sidebar ---- */
.tpl-sidebar {
  width: 260px; min-width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.tpl-sidebar-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.tpl-sidebar-header h3 {
  font-size: 15px; font-weight: 700;
  color: var(--text-primary); margin: 0;
}

/* Groups */
.tpl-group { border-bottom: 1px solid var(--border); }
.tpl-group-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
}
.tpl-group-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-secondary);
}
.tpl-add-btn {
  width: 26px; height: 26px; border-radius: 6px;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-secondary); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.tpl-add-btn:hover {
  background: var(--accent-soft); color: var(--accent);
  border-color: var(--accent);
}

/* Template list items */
.tpl-list { padding: 0 8px 8px; }
.tpl-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: 8px;
  cursor: pointer; transition: all 0.12s;
  margin-bottom: 2px;
}
.tpl-item:hover { background: var(--bg-hover); }
.tpl-item.active {
  background: var(--accent-soft);
}
.tpl-item-name {
  font-size: 13px; font-weight: 500;
  color: var(--text-primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  flex: 1;
}
.tpl-item.active .tpl-item-name { color: var(--accent); }
.tpl-item-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green); flex-shrink: 0; margin-left: 8px;
}
.tpl-item-empty {
  padding: 8px 10px;
  font-size: 12px; color: var(--text-tertiary);
  font-style: italic;
}

/* Variables panel in sidebar */
.tpl-vars-panel { padding-bottom: 12px; }
.tpl-vars-list {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 0 12px;
}
.tpl-var {
  padding: 3px 8px; border-radius: 4px;
  background: var(--bg-surface); border: 1px solid var(--border);
  font-size: 11px; font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--text-secondary); cursor: pointer;
  transition: all 0.12s;
}
.tpl-var:hover {
  background: var(--accent-soft); color: var(--accent);
  border-color: var(--accent);
}

/* ---- Main Editor ---- */
.tpl-main {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0;
}

/* Empty state */
.tpl-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px; color: var(--text-tertiary);
  text-align: center; padding: 40px;
}
.tpl-empty h3 { color: var(--text-secondary); font-size: 18px; font-weight: 600; }
.tpl-empty p { font-size: 14px; max-width: 320px; line-height: 1.5; }

/* Editor state */
.tpl-editor-state { flex: 1; display: flex; flex-direction: column; }

/* Toolbar */
.tpl-editor-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; gap: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sidebar);
  flex-wrap: wrap;
}
.tpl-editor-info {
  display: flex; align-items: center; gap: 10px; flex: 1; min-width: 200px;
}
.tpl-name-input {
  flex: 1; max-width: 280px;
  padding: 6px 10px; border-radius: 6px;
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text-primary); font-size: 14px; font-weight: 600;
  outline: none; transition: border-color 0.15s;
}
.tpl-name-input:focus { border-color: var(--accent); }
.tpl-type-badge {
  padding: 3px 10px; border-radius: 20px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
  white-space: nowrap;
}
.tpl-editor-btns { display: flex; gap: 6px; }
.tpl-toolbar-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 12px; border-radius: 6px;
  background: var(--bg-surface); border: 1px solid var(--border);
  color: var(--text-secondary); cursor: pointer;
  font-size: 12px; font-weight: 500;
  transition: all 0.15s;
}
.tpl-toolbar-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.tpl-toolbar-btn.primary {
  background: var(--accent); border-color: var(--accent);
  color: white;
}
.tpl-toolbar-btn.primary:hover { background: var(--accent-hover); }
.tpl-toolbar-btn.danger:hover { color: var(--red); border-color: var(--red); }

/* Code editor textarea */
.tpl-code-editor {
  flex: 1; width: 100%; padding: 16px 20px;
  background: var(--bg-primary); color: var(--text-primary);
  border: none; outline: none; resize: none;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 13px; line-height: 1.7;
  tab-size: 2;
}
.tpl-code-editor::placeholder { color: var(--text-tertiary); }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .tpl-layout { flex-direction: column; height: auto; min-height: 0; }
  .tpl-sidebar {
    width: 100%; min-width: 0;
    border-right: none; border-bottom: 1px solid var(--border);
    max-height: 300px;
  }
  .tpl-main { min-height: 400px; }
}


/* ============================================
   Template Preview — In-Page
   ============================================ */
.tpl-preview-panel {
  flex: 1; display: flex; flex-direction: column;
  background: var(--bg-primary);
}
.tpl-preview-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sidebar);
  flex-wrap: wrap; gap: 8px;
}
.tpl-preview-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; color: var(--text-primary);
}
.tpl-preview-controls {
  display: flex; align-items: center; gap: 4px;
}
.tpl-preview-sep {
  width: 1px; height: 20px;
  background: var(--border); margin: 0 6px;
}
.tpl-device-btn {
  width: 34px; height: 34px; border-radius: 8px;
  background: transparent; border: 1px solid transparent;
  color: var(--text-tertiary); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.tpl-device-btn:hover {
  background: var(--bg-hover); color: var(--text-primary);
}
.tpl-device-btn.active {
  background: var(--accent-soft); color: var(--accent);
  border-color: var(--accent);
}
.tpl-preview-viewport {
  flex: 1; display: flex; justify-content: center;
  padding: 16px;
  background: var(--bg-surface);
  overflow: auto;
  min-height: 400px;
}
.tpl-preview-frame {
  width: 100%; height: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  transition: width 0.3s ease, max-width 0.3s ease;
}
.tpl-preview-frame.desktop { max-width: 100%; }
.tpl-preview-frame.tablet { max-width: 768px; }
.tpl-preview-frame.mobile { max-width: 375px; }

/* Editor/preview split on templates */
.tpl-main { position: relative; }
.tpl-editor-state, .tpl-preview-panel { position: relative; }


/* Template default badge */
.tpl-item-default {
  font-size: 9px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  padding: 2px 6px; border-radius: 4px;
  background: var(--green); color: white;
  flex-shrink: 0; margin-left: 6px;
}
.tpl-toolbar-btn.is-default {
  background: var(--green); border-color: var(--green);
  color: white;
}
.tpl-toolbar-btn.is-default:hover {
  background: var(--green); opacity: 0.9;
}


/* ============================================
   Ad Code Tab — Simple Cards
   ============================================ */
.adslot-cards {
  display: flex; flex-direction: column; gap: 20px;
}
.adslot-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  transition: border-color 0.2s;
}
.adslot-card:hover {
  border-color: rgba(124, 58, 237, 0.3);
}
.adslot-header {
  padding: 20px 24px 16px;
}
.adslot-title {
  font-size: 18px; font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 6px;
}
.adslot-size {
  font-size: 13px; color: var(--text-secondary);
  display: block;
}
.adslot-editor {
  width: 100%; min-height: 120px; padding: 16px 24px;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: none;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  outline: none; resize: vertical;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 13px; line-height: 1.7;
  box-sizing: border-box;
}
.adslot-editor:focus {
  background: var(--bg-chat, var(--bg-primary));
}
.adslot-editor::placeholder {
  color: var(--text-tertiary);
}
.adslot-footer {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 24px;
}
.adslot-save-btn {
  padding: 8px 28px; border-radius: 10px;
  background: var(--accent); color: white;
  border: none; cursor: pointer;
  font-size: 13px; font-weight: 600;
  transition: all 0.2s;
}
.adslot-save-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.25);
}
.adslot-save-btn.saved {
  background: var(--green);
}
.adslot-status {
  font-size: 13px; font-weight: 600;
  color: var(--green);
}



/* ============================================
   Niches Tab
   ============================================ */
.niches-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.niche-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  transition: border-color 0.2s, transform 0.2s;
  position: relative;
}
.niche-card:hover {
  border-color: rgba(124,58,237,0.3);
  transform: translateY(-2px);
}
.niche-card-top {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 10px;
}
.niche-card-icon {
  width: 44px; height: 44px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}
.niche-card-name {
  font-size: 16px; font-weight: 700; color: var(--text-primary);
}
.niche-card-key {
  font-size: 11px; color: var(--text-tertiary);
  font-family: 'SF Mono', monospace;
}
.niche-card-desc {
  font-size: 13px; color: var(--text-secondary);
  line-height: 1.5; margin-bottom: 12px;
}
.niche-card-link {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-link);
  text-decoration: none; word-break: break-all;
}
.niche-card-link:hover { text-decoration: underline; }
.niche-card-actions {
  display: flex; gap: 8px;
  margin-top: 12px; padding-top: 12px;
  border-top: 1px solid var(--border);
}
.niche-card-actions button {
  padding: 5px 14px; border-radius: 8px;
  font-size: 12px; font-weight: 600;
  cursor: pointer; border: 1px solid var(--border);
  background: var(--bg-primary); color: var(--text-secondary);
  transition: all 0.15s;
}
.niche-card-actions button:hover {
  background: var(--bg-hover); color: var(--text-primary);
}
.niche-card-actions button.delete:hover {
  color: var(--red); border-color: var(--red);
}

/* Add form */
.niche-add-form {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 24px;
}
.niche-form-title {
  font-size: 16px; font-weight: 700; color: var(--text-primary);
  margin: 0 0 16px;
}
.niche-form-row {
  display: flex; gap: 12px; margin-bottom: 12px;
}
.niche-form-field {
  flex: 1;
}
.niche-form-field label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--text-secondary); margin-bottom: 4px;
}
.niche-form-actions {
  display: flex; gap: 8px; margin-top: 8px;
}
@media (max-width: 480px) {
  .niche-form-row { flex-direction: column; }
  .niches-grid { grid-template-columns: 1fr; }
}
