/* ===================================
   ADMIN SCENARIO EDITOR STYLES (DARK THEME)
   Matches consistency with /embed/ and Zenobits brand
   =================================== */

:root {
  /* Core brand colors */
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-sidebar: rgba(15, 23, 42, 0.6);

  /* Text colors */
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  /* Accent colors */
  --accent-primary: #6CBEDA;
  --accent-hover: #5aadca;
  --accent-light: rgba(108, 190, 218, 0.1);
  --accent-glow: rgba(108, 190, 218, 0.3);

  /* Semantic colors */
  --danger: #DD4730;
  --danger-hover: #c23d28;
  --success: #10b981;
  --warning: #f59e0b;

  /* Borders & Surfaces */
  --border: rgba(255, 255, 255, 0.1);
  --border-hover: rgba(255, 255, 255, 0.2);
  --border-focus: rgba(108, 190, 218, 0.5);

  --surface: rgba(30, 41, 59, 0.4);
  --surface-hover: rgba(30, 41, 59, 0.6);
  --glass-bg: rgba(15, 23, 42, 0.7);

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

  /* Dimensions & Spacing */
  --sidebar-width: 280px;
  --header-height: 70px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;
}

/* ===================================
   RESET & BASE
   =================================== */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at 50% 0%, #334155 0%, #1e293b 40%, #0f172a 100%);
  background-attachment: fixed;
  color: var(--text-primary);
  font-family: 'Inter', 'Gravity', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  height: 100vh;
  overflow: hidden;
  /* Main scroll is handled by layout containers */
  -webkit-font-smoothing: antialiased;
}

/* Use imported fonts from styles.css */

/* ===================================
   LAYOUT STRUCTURE
   =================================== */
.admin-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* --- SIDEBAR --- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 10;
}

.sidebar__header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 var(--spacing-lg);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-primary);
}

.brand__logo {
  color: var(--accent-primary);
  display: flex;
  align-items: center;
}

.brand__name {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
}

.sidebar__content {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-lg);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-lg);
}

.sidebar__separator {
  height: 1px;
  background: var(--border);
  width: 100%;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  background: transparent;
  border: none;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  font-family: inherit;
}

.nav-item:hover {
  background: var(--surface);
  color: var(--text-primary);
}

.nav-item--active {
  background: var(--accent-light);
  color: var(--accent-primary);
  font-weight: 600;
}

.sidebar__section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--spacing-sm);
}

.sidebar__section-title {
  text-transform: uppercase;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* Scenario List in Sidebar */
.scenario-list-container {
  flex: 1;
  overflow-y: auto;
  min-height: 200px;
  margin: 0 -8px;
  /* Negative margin for scroll area */
  padding: 0 8px;
}

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

.scenario-item {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.scenario-item:hover {
  background: var(--surface);
}

.scenario-item--active {
  background: var(--surface-hover);
  border-color: var(--border-focus);
  box-shadow: 0 0 0 1px var(--border-focus);
}

.scenario-item__name {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scenario-item__meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.sidebar__footer {
  padding: var(--spacing-md) var(--spacing-lg);
  border-top: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.8);
}

/* User Profile */
.user-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-profile__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary) 0%, #3b82f6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 0.9rem;
}

.user-profile__info {
  flex: 1;
  min-width: 0;
}

.user-profile__email {
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.user-profile__role {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.user-profile__logout {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.user-profile__logout:hover {
  background: rgba(221, 71, 48, 0.1);
  color: var(--danger);
  border-color: var(--danger);
}


/* --- MAIN CONTENT --- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: transparent;
  min-width: 0;
  /* Prevent flex overflow */
}

.top-bar {
  height: var(--header-height);
  padding: 0 var(--spacing-xl);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(10px);
}

.page-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.version-badge {
  font-size: 0.75rem;
  background: var(--surface);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  margin-left: 12px;
  border: 1px solid var(--border);
}

.top-bar__left {
  display: flex;
  align-items: center;
}

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

.content-scrollable {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-xl);
}

/* --- EMPTY STATE --- */
.scenario-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--spacing-xl);
  min-height: 400px;
  color: var(--text-muted);
}

.scenario-empty-state svg {
  opacity: 0.3;
  margin-bottom: var(--spacing-lg);
}

.scenario-empty-state__title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--spacing-sm);
}

.scenario-empty-state__description {
  font-size: 0.9rem;
  color: var(--text-muted);
  max-width: 360px;
}

/* --- FORMS & CARDS --- */
.scenario-form {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-lg);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--spacing-lg);
}

.form-column {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-lg);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-lg);
}

.card--featured {
  border-color: var(--accent-light);
  background: linear-gradient(to bottom, rgba(30, 41, 59, 0.6), rgba(30, 41, 59, 0.4));
}

.card__header {
  padding: var(--spacing-md) var(--spacing-lg);
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.3);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.card__description {
  margin: 4px 0 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.card__body {
  padding: var(--spacing-lg);
}

.card__body.p-0 {
  padding: 0;
}

/* Form Groups */
.form-group {
  margin-bottom: var(--spacing-md);
}

.form-group:last-child {
  margin-bottom: 0;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--spacing-md);
}

.col {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-divider {
  height: 1px;
  background: var(--border);
  margin: var(--spacing-lg) 0;
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.required {
  color: var(--danger);
}

.form-hint {
  display: block;
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Inputs */
input[type="text"],
input[type="number"],
input[type="email"],
textarea,
select {
  width: 100%;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  transition: all 0.2s;
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: rgba(15, 23, 42, 0.8);
}

input::placeholder,
textarea::placeholder {
  color: rgba(148, 163, 184, 0.5);
}

/* Read-only input styling (for auto-generated fields) */
input.input-readonly,
input:disabled {
  background: rgba(15, 23, 42, 0.3);
  color: rgba(148, 163, 184, 0.8);
  cursor: not-allowed;
  opacity: 0.8;
}

input.input-readonly:focus,
input:disabled:focus {
  border-color: var(--border);
  box-shadow: none;
  background: rgba(15, 23, 42, 0.3);
}

.select-sm {
  padding: 6px 10px;
  font-size: 0.85rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
  font-family: inherit;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--accent-primary);
  color: #fff;
  border-color: var(--accent-primary);
  box-shadow: 0 4px 12px rgba(108, 190, 218, 0.3);
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(108, 190, 218, 0.4);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--text-secondary);
}

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

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(221, 71, 48, 0.3);
}

.btn-danger-ghost:hover {
  background: rgba(221, 71, 48, 0.1);
  border-color: var(--danger);
}

/* Quill Editor Overrides for Dark Theme */
.quill-editor {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  /* Default radius for small editors */
  display: flex;
  flex-direction: column;
}

/* Special styling for the large prompt editor */
.quill-editor--large {
  border: none;
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
  /* Match card bottom radius */
  min-height: 400px;
}

.quill-editor .ql-toolbar {
  border: none;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  padding: 8px;
}

.quill-editor .ql-container {
  border: none;
  flex: 1;
  font-size: 0.95rem;
  font-family: 'Inter', sans-serif;
  color: var(--text-primary);
  min-height: 150px;
  /* Minimum height for small editors */
}

.quill-editor--large .ql-container {
  font-size: 1rem;
  line-height: 1.6;
}

.ql-snow .ql-stroke {
  stroke: var(--text-secondary);
}

.ql-snow .ql-fill {
  fill: var(--text-secondary);
}

.ql-snow .ql-picker {
  color: var(--text-secondary);
}

.ql-snow .ql-picker-options {
  background-color: var(--bg-secondary) !important;
  border-color: var(--border) !important;
  color: var(--text-primary) !important;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 9999;
}

.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  min-width: 320px;
  box-shadow: var(--shadow-xl);
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: slideInRight 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  color: var(--text-primary);
}

.toast--success {
  border-left: 4px solid var(--success);
}

.toast--error {
  border-left: 4px solid var(--danger);
}

.toast--info {
  border-left: 4px solid var(--accent-primary);
}

.toast__icon {
  flex-shrink: 0;
  margin-top: 2px;
}

.toast__content {
  flex: 1;
}

.toast__title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.toast__message {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.toast__close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  flex-shrink: 0;
  transition: color 0.2s;
}

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

.toast--hiding {
  animation: slideOutRight 0.3s cubic-bezier(0.4, 0, 0.6, 1) forwards;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOutRight {
  from {
    transform: translateX(0);
    opacity: 1;
  }

  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal__backdrop,
.modal__overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal__content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 90%;
  max-width: 500px;
  position: relative;
  z-index: 1001;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  padding: 0;
  overflow: hidden;
}

.modal__header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.03);
}

.modal__header h2,
.modal__header h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.modal__close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
  padding: 4px;
}

.modal__body {
  padding: 24px;
}

.modal__description {
  margin: 0 0 24px 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.6;
}

.modal__footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  background: rgba(255, 255, 255, 0.03);
}

/* Embed Modal Styles */
.embed-section {
  margin-bottom: 20px;
}

.embed-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.embed-input-group {
  display: flex;
  gap: 8px;
}

.embed-input,
.embed-textarea {
  flex: 1;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  resize: none;
}

.embed-input:focus,
.embed-textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.embed-warning {
  margin-top: 20px;
  padding: 12px;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.2);
  border-radius: var(--radius-md);
  color: var(--warning);
  font-size: 0.85rem;
}

/* Responsive */
@media (max-width: 1024px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

/* ===================================
   MOBILE MENU SYSTEM
   =================================== */
.mobile-menu-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: var(--radius-md);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
  margin-right: 12px;
}

.mobile-menu-toggle:hover {
  background: var(--surface);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.mobile-menu-close {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.mobile-menu-close:hover {
  background: var(--surface);
  color: var(--text-primary);
}

.mobile-menu-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.mobile-menu-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 768px) {
  /* Show hamburger menu button on mobile */
  .mobile-menu-toggle {
    display: flex;
  }

  .mobile-menu-close {
    display: flex;
  }

  /* =============================================
     MOBILE SCROLLING FIX
     On mobile, we want the ENTIRE PAGE to scroll,
     not a nested container. This requires:
     1. Remove fixed heights
     2. Remove overflow:hidden from containers
     3. Let content flow naturally

     NOTE: styles.css sets html,body { overflow:hidden }
     We must override with !important
     ============================================= */

  html {
    height: auto !important;
    overflow: visible !important;
    overflow-y: scroll !important;
  }

  body {
    height: auto !important;
    min-height: 100% !important;
    overflow: visible !important;
    overflow-x: hidden !important;
    overflow-y: scroll !important;
    -webkit-overflow-scrolling: touch !important;
    position: relative !important;
  }

  /* Break the flex layout that constrains scrolling */
  .admin-layout {
    display: block !important;
    height: auto !important;
    min-height: 100vh;
    overflow: visible !important;
    position: relative;
  }

  .main-content {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    min-height: auto !important;
    overflow: visible !important;
    position: relative;
  }

  /* Top bar - make it static, not part of flex */
  .top-bar {
    position: relative;
    width: 100%;
  }

  /* Content area - NO internal scrolling on mobile */
  /* NOTE: #usageContent has class content-scrollable but its display is controlled by JS */
  /* We use :not(#usageContent) to avoid overriding the JS-controlled display property */
  .content-scrollable:not(#usageContent),
  #scenariosContent {
    display: block !important;
    height: auto !important;
    min-height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    flex: none !important;
    position: relative;
  }

  /* usageContent: only override layout properties, NOT display */
  /* The display property is controlled by JavaScript based on user role and tab selection */
  #usageContent {
    height: auto !important;
    min-height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    flex: none !important;
    position: relative;
  }

  /* When usageContent IS shown (by JS), ensure it displays as block */
  #usageContent[style*="display: block"],
  #usageContent[style*="display:block"] {
    display: block !important;
  }

  /* Mobile sidebar behavior - fixed position overlay */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--bg-sidebar);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
  }

  .sidebar__content {
    display: flex !important;
  }

  .sidebar__header {
    justify-content: space-between;
  }


  /* Top bar adjustments for mobile */
  .top-bar {
    padding: 0 var(--spacing-md);
  }

  .top-bar__left {
    gap: 8px;
    flex: 1;
    min-width: 0;
  }

  .page-title {
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .top-bar__right {
    gap: 8px;
  }

  /* Simplify buttons on mobile */
  .top-bar__right .btn span {
    display: none;
  }

  .top-bar__right .btn {
    padding: 10px 12px;
    min-width: auto;
  }

  .version-badge {
    display: none;
  }

  /* Content area padding - scrolling is handled by body now */
  .content-scrollable {
    padding: var(--spacing-md);
  }

  /* Form adjustments */
  .card__body {
    padding: var(--spacing-md);
  }

  .scenario-form {
    gap: var(--spacing-md);
  }

  /* Toast notifications on mobile */
  .toast-container {
    bottom: 12px;
    right: 12px;
    left: 12px;
  }

  .toast {
    min-width: auto;
    width: 100%;
  }

  /* Modal adjustments for mobile */
  .modal__content {
    width: 95%;
    margin: 0 12px;
  }

  .embed-input-group {
    flex-direction: column;
  }

  .embed-input-group .btn {
    width: 100%;
  }

  /* Usage dashboard mobile */
  .usage-dashboard__header {
    flex-direction: column;
    gap: var(--spacing-md);
  }

  .usage-dashboard__actions {
    width: 100%;
  }

  .btn-refresh {
    width: 100%;
    justify-content: center;
  }

  /* Make usage table scrollable on mobile */
  .usage-dashboard__table-wrapper {
    overflow-x: auto;
  }

  .usage-table {
    min-width: 800px;
  }

  .usage-table th,
  .usage-table td {
    padding: 12px;
    font-size: 0.85rem;
  }
}

/* ===================================
   MISSING UTILITIES & COMPONENTS
   =================================== */

/* Usage Dashboard */
.usage-dashboard {
  max-width: 1400px;
  margin: 0 auto;
}

.usage-dashboard__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--spacing-lg);
  gap: var(--spacing-md);
}

.usage-dashboard__header-content h2 {
  margin: 0 0 8px 0;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
}

.usage-dashboard__header-content p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.usage-dashboard__actions {
  display: flex;
  gap: 12px;
}

.btn-refresh {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
  font-size: 0.9rem;
  font-family: inherit;
}

.btn-refresh:hover {
  background: var(--surface-hover);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.btn-refresh.loading .btn-refresh__icon {
  animation: spin 1s linear infinite;
}

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

.usage-dashboard__table-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
}

.usage-table {
  width: 100%;
  border-collapse: collapse;
}

.usage-table thead {
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border);
}

.usage-table th {
  padding: 12px 16px;
  text-align: left;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.usage-table td {
  padding: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--text-primary);
}

.usage-table tbody tr {
  transition: background 0.2s;
}

.usage-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

/* Usage Table Status Colors */
.usage-table__balance--critical {
  color: var(--danger);
  font-weight: 700;
}

.usage-table__balance--low {
  color: var(--warning);
  font-weight: 600;
}

.usage-table__balance--healthy {
  color: var(--success);
}

.usage-table__loading,
.usage-table__empty {
  text-align: center;
  padding: 3rem;
  color: var(--text-secondary);
  font-style: italic;
}

/* Customer Balance Display */
.customer-balance {
  margin-bottom: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.customer-balance__label {
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
}

.customer-balance__value {
  font-family: monospace;
  font-weight: 700;
  font-size: 1rem;
}

.customer-balance--critical {
  color: var(--danger);
}

.customer-balance--low {
  color: var(--warning);
}

/* Simple Tooltip */
[data-tooltip] {
  position: relative;
  cursor: help;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 1000;
  box-shadow: var(--shadow-md);
}

[data-tooltip]:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

/* ===================================
   ANALYTICS DASHBOARD STYLES
   =================================== */

/* Dashboard Layout */
.analytics-dashboard {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--spacing-lg);
}

.analytics-dashboard__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--spacing-lg);
  gap: var(--spacing-md);
  flex-wrap: wrap;
}

.analytics-dashboard__header-content h2 {
  margin: 0 0 8px 0;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
}

.analytics-dashboard__header-content p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

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

/* Summary Cards */
.analytics-summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-lg);
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  transition: all 0.2s;
}

.summary-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.summary-card__icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.summary-card__icon--attempts {
  background: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
}

.summary-card__icon--completion {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.summary-card__icon--score {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.summary-card__icon--users {
  background: rgba(139, 92, 246, 0.15);
  color: #8b5cf6;
}

.summary-card__icon--duration {
  background: rgba(236, 72, 153, 0.15);
  color: #ec4899;
}

.summary-card__icon--visits {
  background: rgba(108, 190, 218, 0.15);
  color: var(--accent-primary);
}

.summary-card__icon--signups {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.summary-card__icon--sessions {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.summary-card__content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.summary-card__value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}

.summary-card__label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Funnel Cards */
.summary-card--funnel {
  position: relative;
}

.funnel-arrow {
  position: absolute;
  left: -20px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  display: none;
}

@media (min-width: 769px) {
  .summary-card--funnel:not(:first-child) .funnel-arrow {
    display: block;
  }
}

/* Chart Cards */
.analytics-chart-card {
  margin-bottom: var(--spacing-lg);
}

.chart-container {
  position: relative;
  height: 300px;
  width: 100%;
}

.chart-container--funnel {
  height: 200px;
}

/* Analytics Tables */
.analytics-table-card {
  margin-bottom: var(--spacing-lg);
}

.analytics-table-wrapper {
  overflow-x: auto;
}

.analytics-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 700px;
}

.analytics-table thead {
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border);
}

.analytics-table th {
  padding: 12px 16px;
  text-align: left;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.analytics-table th.sortable {
  cursor: pointer;
  user-select: none;
}

.analytics-table th.sortable:hover {
  color: var(--accent-primary);
}

.analytics-table th.sortable.sorted-asc .sort-icon::after {
  content: " ▲";
  font-size: 0.6rem;
}

.analytics-table th.sortable.sorted-desc .sort-icon::after {
  content: " ▼";
  font-size: 0.6rem;
}

.analytics-table td {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--text-primary);
}

.analytics-table tbody tr {
  transition: background 0.2s;
}

.analytics-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.analytics-table__loading,
.analytics-table__empty {
  text-align: center;
  padding: 3rem !important;
  color: var(--text-secondary);
  font-style: italic;
}

.analytics-table__error {
  text-align: center;
  padding: 3rem !important;
  color: var(--danger);
}

/* Score Badge */
.score-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.score-badge--high {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.score-badge--medium {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.score-badge--low {
  background: rgba(221, 71, 48, 0.15);
  color: var(--danger);
}

.score-badge--na {
  background: var(--surface);
  color: var(--text-muted);
}

/* Rate Badge */
.rate-badge {
  font-weight: 600;
}

.rate-badge--high {
  color: #10b981;
}

.rate-badge--medium {
  color: #f59e0b;
}

.rate-badge--low {
  color: var(--danger);
}

/* View Students Button */
.btn-view-students {
  padding: 6px 12px;
  font-size: 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-view-students:hover {
  background: rgba(108, 190, 218, 0.1);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

/* Analytics Badges */
.analytics-badge {
  display: inline-block;
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 20px;
  background: var(--surface);
  color: var(--text-secondary);
}

.analytics-badge--success {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.analytics-badge--warning {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.analytics-badge--danger {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

/* Marketing Section Divider */
.analytics-section-divider {
  display: flex;
  align-items: center;
  margin: var(--spacing-xl) 0;
  gap: var(--spacing-md);
}

.analytics-section-divider::before,
.analytics-section-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}

.analytics-section-divider span {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

/* Wide Modal */
.modal__content--wide {
  max-width: 900px;
  width: 90%;
}

/* P-0 utility */
.p-0 {
  padding: 0 !important;
}

/* Responsive */
@media (max-width: 768px) {
  .analytics-dashboard {
    padding: var(--spacing-md);
  }

  .analytics-dashboard__header {
    flex-direction: column;
  }

  .analytics-dashboard__controls {
    width: 100%;
    flex-wrap: wrap;
  }

  .analytics-dashboard__controls .select-sm {
    flex: 1;
    min-width: 120px;
  }

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

  .summary-card {
    padding: var(--spacing-md);
  }

  .summary-card__value {
    font-size: 1.5rem;
  }

  .chart-container {
    height: 250px;
  }

  .analytics-table {
    min-width: 600px;
  }
}

@media (max-width: 480px) {
  .analytics-summary-cards {
    grid-template-columns: 1fr;
  }

  .summary-card__icon {
    width: 40px;
    height: 40px;
  }

  .summary-card__value {
    font-size: 1.25rem;
  }
}

/* ===================================
   TEMPLATE BUTTONS
   =================================== */

/* Large template button (for System Prompt card header) */
.btn-template {
  background: linear-gradient(135deg, rgba(108, 190, 218, 0.1) 0%, rgba(108, 190, 218, 0.05) 100%);
  border: 1px solid rgba(108, 190, 218, 0.3);
  color: var(--accent-primary);
  padding: 8px 14px;
  font-size: 0.85rem;
  transition: all 0.2s ease;
}

.btn-template:hover {
  background: linear-gradient(135deg, rgba(108, 190, 218, 0.2) 0%, rgba(108, 190, 218, 0.1) 100%);
  border-color: var(--accent-primary);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(108, 190, 218, 0.2);
}

.btn-template .btn__icon {
  color: var(--accent-primary);
}

/* Small template button (for Rubric field) */
.btn-template-sm {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: transparent;
  border: 1px solid rgba(108, 190, 218, 0.3);
  border-radius: var(--radius-sm);
  color: var(--accent-primary);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.btn-template-sm:hover {
  background: rgba(108, 190, 218, 0.1);
  border-color: var(--accent-primary);
}

.btn-template-sm svg {
  color: var(--accent-primary);
}

/* Form group header (for label + button alignment) */
.form-group__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.form-group__header label {
  margin-bottom: 0;
}

/* Quill editor template content styling */
.quill-editor h2 {
  color: var(--accent-primary);
  font-size: 1.1rem;
  font-weight: 700;
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--border);
}

.quill-editor h2:first-child {
  margin-top: 0;
}

.quill-editor h3 {
  color: var(--text-primary);
  font-size: 0.95rem;
  font-weight: 600;
  margin-top: 1.25em;
  margin-bottom: 0.5em;
}

.quill-editor em {
  color: var(--text-secondary);
  font-style: italic;
}

.quill-editor strong {
  color: var(--text-primary);
  font-weight: 600;
}

.quill-editor ul,
.quill-editor ol {
  padding-left: 1.5em;
  margin: 0.5em 0;
}

.quill-editor li {
  margin: 0.3em 0;
  line-height: 1.6;
}

.quill-editor blockquote {
  border-left: 3px solid var(--accent-primary);
  padding-left: 1em;
  margin: 1em 0;
  background: rgba(108, 190, 218, 0.05);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.quill-editor table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75em 0;
  font-size: 0.85rem;
}

.quill-editor table th,
.quill-editor table td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}

.quill-editor table th {
  background: rgba(255, 255, 255, 0.05);
  font-weight: 600;
  color: var(--text-secondary);
}

.quill-editor table td {
  color: var(--text-primary);
}

.quill-editor table tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.02);
}

/* ===================================
   PROMPT COACH PANEL
   =================================== */

.card__header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.prompt-editor-layout {
  display: flex;
  min-height: 400px;
}

.prompt-editor-layout__editor {
  flex: 1 1 65%;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.prompt-editor-layout__editor .quill-editor--large {
  flex: 1;
  min-height: 400px;
}

.prompt-coach {
  flex: 0 0 35%;
  max-width: 35%;
  border-left: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.4);
  overflow-y: auto;
  max-height: 600px;
  display: flex;
  flex-direction: column;
}

.prompt-coach__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  position: sticky;
  top: 0;
  z-index: 1;
}

.prompt-coach__title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.prompt-coach__score {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  background: rgba(108, 190, 218, 0.15);
  color: var(--accent-primary);
  transition: all 0.3s ease;
}

.prompt-coach__score--good {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
}

.prompt-coach__score--fair {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}

.prompt-coach__score--poor {
  background: rgba(221, 71, 48, 0.15);
  color: var(--danger);
}

.prompt-coach__checklist {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.prompt-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
  transition: background 0.2s;
}

.prompt-check:hover {
  background: rgba(255, 255, 255, 0.05);
}

.prompt-check__icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin-top: 1px;
}

.prompt-check__icon--pass { color: var(--success); }
.prompt-check__icon--warn { color: var(--warning); }
.prompt-check__icon--miss { color: var(--text-muted); opacity: 0.5; }

.prompt-check__text {
  font-size: 0.8rem;
  line-height: 1.4;
}

.prompt-check__label {
  font-weight: 600;
  color: var(--text-primary);
  display: block;
}

.prompt-check__hint {
  color: var(--text-muted);
  font-size: 0.72rem;
}

.prompt-coach__divider {
  height: 1px;
  background: var(--border);
  margin: 0;
}

.prompt-coach__ai-section {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.prompt-coach__ai-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-feedback-card {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.ai-feedback-card__header {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.ai-feedback-card__header--strengths { color: var(--success); }
.ai-feedback-card__header--improvements { color: var(--warning); }
.ai-feedback-card__header--suggestions { color: var(--accent-primary); }

.ai-feedback-card__list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.ai-feedback-card__list li {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.5;
  padding: 2px 0 2px 14px;
  position: relative;
}

.ai-feedback-card__list li::before {
  content: "\2022";
  position: absolute;
  left: 0;
  color: var(--text-muted);
}

.ai-quality-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.ai-quality-badge--good { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.ai-quality-badge--fair { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.ai-quality-badge--needs-work { background: rgba(221, 71, 48, 0.15); color: var(--danger); }

#analyzePromptBtn.is-loading {
  opacity: 0.7;
  pointer-events: none;
}

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

#analyzePromptBtn .spin {
  animation: spin 1s linear infinite;
}

/* Responsive: stack panel below editor on smaller screens */
@media (max-width: 1024px) {
  .prompt-editor-layout {
    flex-direction: column;
  }

  .prompt-coach {
    flex: none;
    max-width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 350px;
  }
}

/* Mobile responsive for template buttons */
@media (max-width: 768px) {
  .btn-template span {
    display: none;
  }

  .btn-template {
    padding: 8px;
  }

  .card__header {
    flex-wrap: wrap;
    gap: 12px;
  }

  .card__header-content {
    flex: 1;
    min-width: 200px;
  }
}