/* ========================================
   StudyGen — Ultimate Cheat Sheet Generator
   Premium Dark Theme Design System
   ======================================== */

@import url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap");

/* --- CSS CUSTOM PROPERTIES --- */
:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.95); /* Increased opacity for readability */
  --bg-card-solid: #1a2234;
  --bg-glass: rgba(255, 255, 255, 0.03);
  --bg-glass-hover: rgba(255, 255, 255, 0.06);
  --bg-input: rgba(255, 255, 255, 0.05);
  --bg-input-focus: rgba(255, 255, 255, 0.08);

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.1);
  --border-hover: rgba(255, 255, 255, 0.15);
  --border-accent: rgba(99, 102, 241, 0.4);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-accent: #a5b4fc;

  --accent-primary: #6366f1;
  --accent-secondary: #8b5cf6;
  --accent-tertiary: #06b6d4;
  --accent-gradient: linear-gradient(
    135deg,
    #6366f1 0%,
    #8b5cf6 50%,
    #06b6d4 100%
  );
  --accent-glow:
    0 0 20px rgba(99, 102, 241, 0.3), 0 0 60px rgba(99, 102, 241, 0.1);

  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 16px 64px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.15);

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

/* --- RESET & BASE --- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
}

/* Background pattern */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(
      ellipse 80% 50% at 50% -20%,
      rgba(99, 102, 241, 0.15),
      transparent
    ),
    radial-gradient(
      ellipse 60% 40% at 80% 60%,
      rgba(139, 92, 246, 0.08),
      transparent
    ),
    radial-gradient(
      ellipse 50% 30% at 20% 80%,
      rgba(6, 182, 212, 0.06),
      transparent
    );
  pointer-events: none;
  z-index: 0;
}

/* --- SCROLLBAR --- */
::-webkit-scrollbar {
  width: 6px;
  height: 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.2);
}

/* --- ANIMATIONS --- */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse-glow {
  0%,
  100% {
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.2);
  }
  50% {
    box-shadow: 0 0 40px rgba(99, 102, 241, 0.4);
  }
}

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* --- VIEW MANAGEMENT --- */
.view {
  display: none !important;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.view.active {
  display: block !important;
  opacity: 1;
}

.view.flex-view.active {
  display: flex !important;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

@keyframes gradientShift {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

.animate-fade-in {
  animation: fadeIn 0.4s ease-out;
}
.animate-fade-in-up {
  animation: fadeInUp 0.5s ease-out;
}
.animate-slide-right {
  animation: slideInRight 0.3s ease-out;
}
.animate-slide-down {
  animation: slideInDown 0.3s ease-out;
}
.animate-float {
  animation: float 3s ease-in-out infinite;
}

/* --- LAYOUT --- */
#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  position: relative;
  z-index: 2;
}

.view {
  display: none;
  min-height: 100vh;
}

.view.active {
  display: flex;
  flex-direction: column;
}

/* --- GLASS CARD --- */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  transition: all var(--transition-base);
}

.glass-card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-md);
}

.glass-card-solid {
  background: var(--bg-card-solid);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  transition: all var(--transition-base);
}

/* --- BUTTONS --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  border: none;
  transition: all var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.4;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent-gradient);
  background-size: 200% 200%;
  color: white;
  box-shadow:
    var(--shadow-sm),
    0 0 20px rgba(99, 102, 241, 0.2);
}

.btn-primary:hover:not(:disabled) {
  box-shadow:
    var(--shadow-md),
    0 0 30px rgba(99, 102, 241, 0.3);
  transform: translateY(-1px);
  animation: gradientShift 3s ease infinite;
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--bg-glass);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-glass-hover);
  border-color: var(--border-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 12px;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-glass);
  color: var(--text-primary);
}

.btn-accent {
  background: rgba(99, 102, 241, 0.15);
  color: var(--text-accent);
  border: 1px solid rgba(99, 102, 241, 0.2);
}

.btn-accent:hover:not(:disabled) {
  background: rgba(99, 102, 241, 0.25);
  border-color: rgba(99, 102, 241, 0.4);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
}

.btn-outline:hover:not(:disabled) {
  background: var(--bg-glass);
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.btn.active, .btn-outline.active {
    background: var(--accent-primary) !important;
    border-color: var(--accent-primary) !important;
    color: white !important;
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.75rem;
}
.btn-lg {
  padding: 14px 28px;
  font-size: 1rem;
}
.btn-icon {
  padding: 8px;
  width: 36px;
  height: 36px;
}
.btn-icon-sm {
  padding: 6px;
  width: 28px;
  height: 28px;
  font-size: 0.75rem;
}

/* --- INPUTS --- */
.input,
.textarea,
select.input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  transition: all var(--transition-fast);
  outline: none;
}

.input:focus,
.textarea:focus {
  background: var(--bg-input-focus);
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-muted);
}

.textarea {
  resize: vertical;
  min-height: 100px;
  line-height: 1.5;
}

.input-inline {
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  padding: 4px 2px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  outline: none;
  transition: all var(--transition-fast);
}

.input-inline:focus {
  border-bottom-color: var(--accent-primary);
}

/* --- RANGE SLIDER --- */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent-primary);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.4);
  transition: all var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.6);
}

/* --- BADGES & CHIPS --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-accent {
  background: rgba(99, 102, 241, 0.15);
  color: var(--text-accent);
}

.badge-success {
  background: rgba(16, 185, 129, 0.15);
  color: #6ee7b7;
}

/* --- LOADING --- */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.spinner-lg {
  width: 40px;
  height: 40px;
  border-width: 3px;
}

.shimmer {
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.05),
    transparent
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 26, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease-out;
}

.loading-card {
  text-align: center;
  padding: 40px;
}

.loading-card h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-top: 20px;
  color: var(--text-primary);
}

.loading-card p {
  color: var(--text-secondary);
  margin-top: 8px;
  font-size: 0.875rem;
}

/* --- FORM ELEMENTS --- */
.select {
  width: 100%;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: var(--font-sans);
  outline: none;
  transition: all var(--transition-fast);
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3e%3cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3e%3c/path%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
}

.select:focus {
  border-color: var(--accent-primary);
  background-color: rgba(255, 255, 255, 0.05);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.select option {
  background: var(--bg-card-solid);
  color: var(--text-primary);
}

/* --- TOAST NOTIFICATIONS --- */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  backdrop-filter: blur(12px);
  animation: fadeInUp 0.3s ease-out;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.toast-success {
  background: rgba(16, 185, 129, 0.2);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #6ee7b7;
}

.toast-error {
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

.toast-info {
  background: rgba(99, 102, 241, 0.2);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: #a5b4fc;
}

/* ========================================
   HEADER / NAVIGATION
   ======================================== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10000;
  background: rgba(10, 14, 26, 0.8);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 24px;
}

.app-header-inner {
  max-width: 1400px;
  margin: 0 auto;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  flex-shrink: 0;
}

.app-logo-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.3));
}

.app-logo span {
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.5px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.app-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-sans);
}

.nav-btn:hover {
  color: var(--text-primary);
  background: var(--bg-glass);
}

.nav-btn.active {
  color: var(--text-accent);
  background: rgba(99, 102, 241, 0.1);
}

.nav-btn.active::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 2px;
  background: var(--accent-primary);
  border-radius: 1px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* User Profile & Dropdown */
.user-profile-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.user-profile-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  padding-right: 12px;
  background: var(--bg-glass);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.user-profile-trigger:hover {
  background: var(--bg-glass-hover);
  border-color: var(--border-hover);
  transform: translateY(-1px);
}

.user-avatar {
  width: 28px;
  height: 28px;
  background: var(--accent-gradient);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.75rem;
  color: white;
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.2);
}

.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 240px;
  background: var(--bg-card-solid);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: none;
  flex-direction: column;
  padding: 8px;
  z-index: 10001;
  animation: slideInDown 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: top right;
}

.user-dropdown.active {
  display: flex;
}

.dropdown-header {
  padding: 12px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 6px;
}

.dropdown-user-email {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.dropdown-user-plan {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 4px;
  letter-spacing: 0.5px;
  margin-top: 4px;
}

.btn-white {
  background: white;
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
}

.btn-white:hover {
  background: var(--bg-glass);
  border-color: var(--border-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-white i {
  color: var(--text-secondary);
}

.btn-white:hover i {
  color: var(--text-primary);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-sans);
}

.dropdown-item:hover {
  background: var(--bg-glass);
  color: var(--text-primary);
}

.dropdown-item i {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  transition: color var(--transition-fast);
}

.dropdown-item:hover i {
  color: var(--text-accent);
}

.dropdown-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 6px 0;
}

.dropdown-item.danger {
  color: #fca5a5;
}

.dropdown-item.danger:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.dropdown-item.danger i {
  color: #fca5a5;
}

.dropdown-item.danger:hover i {
  color: #ef4444;
}


/* ========================================
   HOME / LANDING VIEW
   ======================================== */
.home-view {
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
}

.home-hero {
  text-align: center;
  max-width: 800px;
  margin: 0 auto;
  animation: fadeInUp 0.6s ease-out;
  padding: 40px;
  background: rgba(10, 14, 26, 0.4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: var(--radius-xl);
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.hero-icon {
  width: 72px;
  height: 72px;
  background: var(--accent-gradient);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
  box-shadow: var(--accent-glow);
  animation: float 3s ease-in-out infinite;
}

.hero-icon svg {
  color: white;
  width: 36px;
  height: 36px;
}

.home-hero h1 {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin-bottom: 16px;
  background: linear-gradient(135deg, #f1f5f9, #a5b4fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.home-hero p {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
  line-height: 1.6;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: var(--radius-full);
  color: var(--text-accent);
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 40px;
}

.home-actions {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.home-paste-area {
  position: relative;
}

.home-paste-area .textarea {
  min-height: 120px;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  font-size: 0.9rem;
}

.home-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.home-btn-upload {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 18px;
  border: 2px dashed var(--border-default);
  border-radius: var(--radius-lg);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition-base);
}

.home-btn-upload:hover {
  border-color: var(--accent-primary);
  color: var(--text-accent);
  background: rgba(99, 102, 241, 0.05);
}

.home-btn-upload input[type="file"] {
  display: none;
}

.home-generate-section {
  margin-top: 12px;
  padding-top: 20px;
  border-top: 1px solid var(--border-subtle);
}

.home-generate-section h3 {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
  font-weight: 700;
}

.generate-row {
  display: flex;
  gap: 10px;
}

.generate-row .input {
  flex: 1;
}

.home-footer-links {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 24px;
}

/* ========================================
   REFINER VIEW
   ======================================== */
.refiner-view {
  display: none;
}

.refiner-view.active {
  display: flex;
  flex-direction: column;
}

/* --- EDITOR VIEW --- */
.editor-toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-default);
  border-bottom: 1px solid var(--border-default);
  padding: 10px 20px;
}

.editor-toolbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.editor-canvas-container {
  flex: 1;
  background: #f0f0f0; /* Contrast background */
  padding: 40px;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: calc(100vh - 60px);
}

.editor-canvas, .canvas-paper {
  background: white;
  width: 210mm; /* A4 width */
  min-height: 297mm; /* A4 height */
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  padding: 40px; /* Print margins */
  position: relative;
  transition: transform 0.2s;
  transform-origin: top center;
  color: #000; /* Ensure text is visible on white background */
}

.canvas-paper.landscape {
  width: 297mm;
  min-height: 210mm;
}

/* Mobile Editor Fixes */
@media (max-width: 768px) {
    .editor-canvas-container {
        padding: 20px 10px;
        align-items: flex-start;
        overflow-x: hidden; /* Prevent horiz scroll if we scale */
    }
    
    .editor-canvas {
        /* Scale down to fit screen width */
        width: 100%;
        max-width: 210mm;
        height: auto;
        min-height: 400px; /* minimal height */
        padding: 20px; /* Smaller margins on mobile */
        transform: none; /* Reset distinct scaling */
    }

    .canvas-columns {
        column-count: 1 !important; /* Force single column on mobile */
    }
}

.canvas-columns {
  display: grid;
  width: 100%;
  align-items: start;
}

/* Layout Mode Visuals */
.canvas-item-wrapper {
    transition: transform 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28), box-shadow 0.2s;
    position: relative;
}

.canvas-item-wrapper.layout-active {
    cursor: move;
    border: 1px dashed rgba(99, 102, 241, 0.3);
    border-radius: var(--radius-sm);
}

.canvas-item-wrapper.layout-active:hover {
    background: rgba(99, 102, 241, 0.05);
    border-color: var(--accent-primary);
}

.canvas-item-wrapper.dragging {
    opacity: 0.5;
    transform: scale(0.95);
    z-index: 1000;
}

.canvas-item[contenteditable="true"]:focus {
    outline: 2px solid var(--accent-primary);
    background: white;
    z-index: 10;
}

.refiner-toolbar {
  position: sticky;
  top: 60px;
  z-index: 50;
  background: rgba(10, 14, 26, 0.9);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 12px 24px;
}

.refiner-toolbar-inner {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.refiner-toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.refiner-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.refiner-content {
  flex: 1;
  overflow: auto;
  padding: 24px;
}

.refiner-chapters {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-bottom: 100px;
}

/* Chapter Card */
.chapter-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
  animation: fadeIn 0.3s ease-out;
  transition: all var(--transition-base);
}

.chapter-card:hover {
  border-color: var(--border-hover);
}

.chapter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border-subtle);
  gap: 12px;
  flex-wrap: wrap;
}

.chapter-title-input {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  padding: 4px 2px;
  outline: none;
  font-family: var(--font-sans);
  min-width: 200px;
  transition: all var(--transition-fast);
}

.chapter-title-input:focus {
  border-bottom-color: var(--accent-primary);
}

.chapter-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.chapter-actions .divider {
  width: 1px;
  height: 20px;
  background: var(--border-default);
  margin: 0 4px;
}

.chapter-body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Mobile Optimizations for Refiner */
@media (max-width: 768px) {
    .refiner-top-bar {
        padding: 10px 12px;
    }
    .refiner-title-edit {
        font-size: 1rem;
    }
    .desktop-only {
        display: none;
    }
}

/* Refiner Item Row */
.refiner-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  cursor: grab;
}

.refiner-item:hover {
  background: var(--bg-glass);
}

.refiner-item.dragging {
  opacity: 0.5;
  background: rgba(99, 102, 241, 0.1);
}

.drag-handle {
  color: var(--text-muted);
  cursor: grab;
  padding-top: 4px;
  flex-shrink: 0;
}

.drag-handle:active {
  cursor: grabbing;
}

.refiner-item-content {
  flex: 1;
  min-width: 0;
}

.refiner-term-row {
  display: flex;
  gap: 8px;
}

.refiner-term-input {
  width: 35%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.875rem;
  padding: 4px 2px;
  outline: none;
  font-family: var(--font-sans);
  transition: border-color var(--transition-fast);
}

.refiner-term-input:focus {
  border-bottom-color: var(--accent-primary);
}

.refiner-def-input {
  width: 65%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.875rem;
  padding: 4px 2px;
  outline: none;
  font-family: var(--font-sans);
  resize: none;
  overflow: hidden;
  transition: border-color var(--transition-fast);
}

.refiner-def-input:focus {
  border-bottom-color: var(--accent-primary);
  color: var(--text-primary);
}

.refiner-text-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.875rem;
  padding: 4px 2px;
  outline: none;
  font-family: var(--font-sans);
  resize: none;
  overflow: hidden;
  transition: border-color var(--transition-fast);
}

.refiner-text-input:focus {
  border-bottom-color: var(--accent-primary);
  color: var(--text-primary);
}

.refiner-image-preview {
  position: relative;
  display: inline-block;
}

.refiner-image-preview img {
  height: 64px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
}

.refiner-image-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.6rem;
}

/* Table editor in refiner */
.refiner-table-editor {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 10px;
  background: var(--bg-glass);
  position: relative;
}

.refiner-table-controls {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.refiner-table-editor:hover .refiner-table-controls {
  opacity: 1;
}

.table-header-row,
.table-data-row {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
}

.table-header-input,
.table-cell-input {
  flex: 1;
  min-width: 60px;
  padding: 4px 6px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  outline: none;
}

.table-header-input {
  font-weight: 700;
  background: rgba(255, 255, 255, 0.06);
}

.table-header-input:focus,
.table-cell-input:focus {
  border-color: var(--accent-primary);
}

/* Add Item Bar */
.add-item-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 0 4px;
  margin-top: 8px;
  border-top: 1px dashed var(--border-subtle);
  flex-wrap: wrap;
}

.add-item-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-right: 2px;
}

.add-item-type-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.add-item-type-btn:hover {
  border-color: var(--accent-primary);
  color: var(--text-accent);
  background: rgba(99, 102, 241, 0.08);
}

/* Chapter Header Left */
.chapter-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

/* Chapter Reorder */
.chapter-reorder {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.btn-icon-xs {
  padding: 2px;
  width: 20px;
  height: 20px;
  font-size: 0.65rem;
  border-radius: 4px;
}

.btn-icon-xs:disabled {
  opacity: 0.25;
  cursor: default;
}

/* Heading Item */
.refiner-heading-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 2px solid rgba(99, 102, 241, 0.3);
  color: var(--text-accent);
  font-weight: 800;
  font-size: 1rem;
  padding: 6px 2px;
  outline: none;
  font-family: var(--font-sans);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: border-color var(--transition-fast);
}

.refiner-heading-input:focus {
  border-bottom-color: var(--accent-primary);
}

/* Divider Item */
.refiner-divider-line {
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-default), var(--accent-primary), var(--border-default), transparent);
  margin: 8px 0;
}

/* List Editor */
.refiner-list-editor {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.refiner-list-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.delete-item-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.delete-item-btn:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

/* ========================================
   EDITOR / CANVAS VIEW
   ======================================== */
.editor-view {
  display: none;
}

.editor-view.active {
  display: flex;
  flex-direction: column;
}

.editor-toolbar {
  position: sticky;
  top: 60px;
  z-index: 50;
  background: rgba(10, 14, 26, 0.95);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 8px 24px;
}

.editor-toolbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.editor-toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.editor-controls-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.editor-toggles-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  border-top: 1px solid var(--border-subtle);
  padding-top: 6px;
}

.control-group {
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  min-width: 90px;
  flex: 1;
}

.control-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.control-label svg {
  width: 10px;
  height: 10px;
}

.editor-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Toggle Buttons */
.toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.toggle-btn:hover {
  border-color: var(--accent-primary);
  color: var(--text-secondary);
}

.toggle-btn.active {
  background: rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.4);
  color: var(--text-accent);
}

/* Canvas Area */
.editor-canvas-area {
  flex: 1;
  overflow: auto;
  background: var(--bg-primary);
  display: flex;
  justify-content: center;
  padding: 32px;
}

.canvas-zoom-wrapper {
  transition: transform 0.2s ease;
}

/* The a4 paper */
.canvas-paper {
  background: white;
  color: #111;
  width: 210mm;
  min-height: 297mm;
  padding: 10mm;
  box-sizing: border-box;
  box-shadow: var(--shadow-xl);
  border-radius: 2px;
  position: relative;
  font-family: var(--font-sans);
  transition: width 0.3s ease, min-height 0.3s ease;
}

/* Landscape orientation */
.canvas-paper.landscape {
  width: 297mm;
  min-height: 210mm;
}

/* Compact mode */
.canvas-paper.compact-mode .canvas-chapter {
  margin-bottom: 4px;
}

.canvas-paper.compact-mode .canvas-chapter-title {
  margin-bottom: 2px;
  padding-bottom: 1px;
}

.canvas-paper.compact-mode .canvas-title {
  margin-bottom: 4px;
  padding-bottom: 4px;
}

/* Show borders mode */
.canvas-paper.show-borders .canvas-item-term,
.canvas-paper.show-borders .canvas-item-text,
.canvas-paper.show-borders .canvas-item-list,
.canvas-paper.show-borders .canvas-item-heading {
  outline: 1px dashed rgba(0, 0, 0, 0.15);
  outline-offset: 1px;
}

/* Dark print mode */
.canvas-paper.dark-print {
  background: #1a1a2e;
  color: #e0e0e0;
}

.canvas-paper.dark-print .canvas-title h1 {
  color: #e0e0e0;
}

.canvas-paper.dark-print .canvas-title {
  border-bottom-color: #444;
}

.canvas-paper.dark-print .canvas-chapter-title {
  color: #a5b4fc;
  border-bottom-color: #444;
}

.canvas-paper.dark-print .canvas-item-term .term-label {
  color: #c4b5fd;
}

.canvas-paper.dark-print .canvas-item-term .term-def {
  color: #b0b0b0;
}

.canvas-paper.dark-print .canvas-item-text {
  color: #b0b0b0;
}

.canvas-paper.dark-print .canvas-item-text::before {
  color: #666;
}

.canvas-paper.dark-print .canvas-item-heading {
  color: #a5b4fc !important;
  border-bottom-color: #555 !important;
}

.canvas-paper.dark-print .canvas-item-table {
  border-color: #444;
}

.canvas-paper.dark-print .canvas-item-table th {
  background: #2a2a3e;
  color: #c4b5fd;
  border-color: #444;
}

.canvas-paper.dark-print .canvas-item-table td {
  border-color: #333;
  color: #b0b0b0;
}

.canvas-title {
  text-align: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid #111;
}

.canvas-title h1 {
  font-size: 16px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #111;
}

.canvas-chapter {
  margin-bottom: 12px;
  break-inside: avoid;
}

.canvas-chapter-title {
  font-weight: 700;
  text-transform: uppercase;
  color: #111;
  padding-bottom: 2px;
  margin-bottom: 4px;
  border-bottom: 1px solid #ccc;
  display: block; /* Ensure visibility */
  position: relative;
  z-index: 5; /* Ensure above background */
}

.canvas-columns {
  display: grid;
  align-items: start;
}

.canvas-column {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.canvas-item-term {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  margin-bottom: 2px;
  break-inside: avoid;
}

.canvas-item-term .term-label {
  font-weight: 700;
  color: #1a1a1a;
  flex-shrink: 0;
  overflow-wrap: break-word;
  line-height: 1.3;
}

.canvas-item-term .term-def {
  color: #444;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.canvas-item-text {
  color: #444;
  margin-bottom: 2px;
  break-inside: avoid;
  overflow-wrap: anywhere;
  line-height: 1.3;
}

.canvas-item-text::before {
  content: "•";
  margin-right: 4px;
  color: #888;
}

.canvas-item-image {
  margin-bottom: 4px;
  break-inside: avoid;
}

.canvas-item-image img {
  width: 100%;
  height: auto;
  border-radius: 2px;
  border: 1px solid #ddd;
}

.canvas-item-table {
  margin-bottom: 4px;
  break-inside: avoid;
  overflow: hidden;
  border-radius: 2px;
  border: 1px solid #ccc;
}

.canvas-item-table table {
  width: 100%;
  border-collapse: collapse;
}

.canvas-item-table th {
  background: #f0f0f0;
  font-weight: 700;
  text-align: left;
  padding: 2px 4px;
  border-right: 1px solid #ddd;
  border-bottom: 1px solid #ccc;
}

.canvas-item-table th:last-child {
  border-right: none;
}

.canvas-item-table td {
  padding: 2px 4px;
  border-right: 1px solid #eee;
  border-top: 1px solid #eee;
}

.canvas-item-table td:last-child {
  border-right: none;
}

/* Canvas list items */
.canvas-item-list {
  margin-bottom: 2px;
  break-inside: avoid;
}

.canvas-item-list ul {
  color: #444;
}

/* Canvas heading items */
.canvas-item-heading {
  break-inside: avoid;
}

/* Canvas divider items */
.canvas-item-divider {
  break-inside: avoid;
}

/* ========================================
   SELECTION POPUP
   ======================================== */
.selection-popup {
  position: fixed;
  z-index: 500;
  background: var(--bg-card-solid);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 4px;
  display: flex;
  gap: 2px;
  box-shadow: var(--shadow-lg);
  animation: fadeIn 0.15s ease-out;
  transform: translateX(-50%);
}

.selection-popup button {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-primary);
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: var(--font-sans);
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.selection-popup button:hover {
  background: var(--bg-glass-hover);
  color: var(--text-accent);
}

.selection-popup .divider {
  width: 1px;
  background: var(--border-default);
  margin: 4px 0;
}

/* ========================================
   AI CHAT PANEL
   ======================================== */
.chat-panel {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 380px;
  height: 520px;
  background: var(--bg-card-solid);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 200;
  animation: fadeInUp 0.3s ease-out;
}

.chat-header {
  padding: 16px 20px;
  background: var(--accent-gradient);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: white;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-header button {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: white;
  border-radius: var(--radius-sm);
  padding: 4px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chat-header button:hover {
  background: rgba(255, 255, 255, 0.25);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  line-height: 1.5;
  word-wrap: break-word;
  animation: fadeIn 0.2s ease-out;
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--accent-primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-msg.model {
  align-self: flex-start;
  background: var(--bg-glass);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  border-bottom-left-radius: 4px;
}

.chat-msg.system {
  align-self: center;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-align: center;
  padding: 4px;
}

.chat-msg .copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.65rem;
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chat-msg .copy-btn:hover {
  color: var(--text-primary);
  background: var(--bg-glass);
}

.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  gap: 8px;
}

.chat-input-area input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  outline: none;
  transition: all var(--transition-fast);
}

.chat-input-area input:focus {
  border-color: var(--accent-primary);
}

.chat-input-area input::placeholder {
  color: var(--text-muted);
}

.chat-send-btn {
  background: var(--accent-primary);
  border: none;
  color: white;
  padding: 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-send-btn:hover {
  background: var(--accent-secondary);
}

/* Chat toggle FAB */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 52px;
  height: 52px;
  background: var(--accent-gradient);
  border: none;
  border-radius: 50%;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--accent-glow);
  z-index: 190;
  transition: all var(--transition-base);
}

.chat-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 0 30px rgba(99, 102, 241, 0.5);
}

/* ========================================
   SETTINGS MODAL
   ======================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  animation: fadeIn 0.2s ease-out;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--bg-card-solid);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  width: 480px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  animation: fadeInUp 0.3s ease-out;
  position: relative;
}

.modal-premium {
    border: 1px solid var(--border-accent);
    background: linear-gradient(to bottom right, var(--bg-card-solid), #0a0e1a);
    box-shadow: 0 0 40px rgba(99, 102, 241, 0.15);
}


.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: var(--bg-glass);
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.setting-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.api-key-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: 8px;
}

.api-key-status.active {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.2);
  color: #6ee7b7;
}

.api-key-status.default {
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.2);
  color: var(--text-accent);
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ========================================
   COOKIE CONSENT BANNER
   ======================================== */
.cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 600;
  background: rgba(10, 14, 26, 0.97);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-default);
  padding: 20px 24px;
  animation: fadeInUp 0.3s ease-out;
}

.cookie-banner-inner {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.cookie-text {
  flex: 1;
  min-width: 250px;
}

.cookie-text strong {
  font-size: 0.95rem;
  color: var(--text-primary);
}

.cookie-text p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin: 4px 0 0;
  line-height: 1.5;
}

.cookie-text a {
  color: var(--text-accent);
}

.cookie-categories {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.cookie-cat {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.cookie-cat strong {
  color: var(--text-primary);
  font-size: 0.8rem;
}

.cookie-cat span {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.cookie-actions {
  display: flex;
  gap: 8px;
}

.btn-sm {
  padding: 6px 14px !important;
  font-size: 0.75rem !important;
}

/* ========================================
   SITE FOOTER
   ======================================== */
.site-footer {
  background: rgba(10, 14, 26, 0.95);
  border-top: 1px solid var(--border-default);
  padding: 40px 24px 20px;
}

.footer-inner {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 40px;
  flex-wrap: wrap;
}

.footer-brand {
  flex: 1;
  min-width: 200px;
}

.footer-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.footer-tagline {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* --- Editor Toolbar Premium --- */
.editor-controls-row {
  display: flex;
  align-items: stretch;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
  /* Hide scrollbar but keep functionality */
  scrollbar-width: thin;
}

.control-group-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 140px;
}

.control-header {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 800;
  color: #94a3b8;
  margin-bottom: -4px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.control-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: #475569;
}

.control-label i {
  width: 12px;
  height: 12px;
  color: #64748b;
}

/* Premium Slider Styling */
.premium-slider {
  -webkit-appearance: none;
  appearance: none; /* Fix lint: standard property */
  width: 100%;
  height: 4px;
  background: #e2e8f0;
  border-radius: 2px;
  outline: none;
  transition: all 0.2s;
}

.premium-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #4f46e5;
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  transition: transform 0.1s;
}

.premium-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  background: #4338ca;
}

.premium-slider:active::-webkit-slider-thumb {
  transform: scale(0.95);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.2);
}

.footer-links {
  display: flex;
  gap: 48px;
  flex-wrap: wrap;
}

.footer-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.footer-col h4 {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.footer-col a {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.footer-col a:hover {
  color: var(--text-accent);
}

.footer-bottom {
  max-width: 1000px;
  margin: 24px auto 0;
  padding-top: 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.footer-bottom p {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ========================================
   UTILITY CLASSES
   ======================================== */
.flex {
  display: flex;
}
.flex-col {
  flex-direction: column;
}
.items-center {
  align-items: center;
}
.justify-center {
  justify-content: center;
}
.justify-between {
  justify-content: space-between;
}
.gap-1 {
  gap: 4px;
}
.gap-2 {
  gap: 8px;
}
.join {
    display: inline-flex;
    background: var(--bg-glass);
    border-radius: var(--radius-md);
    padding: 2px;
    border: 1px solid var(--border-default);
}
.join-item {
    border: none !important;
    border-radius: var(--radius-sm) !important;
    font-size: 0.75rem !important;
    padding: 6px 12px !important;
    height: auto !important;
}
.join-item:hover {
    background: var(--bg-glass-hover) !important;
}
.join-item.active, .join-item.btn-primary {
    background: var(--accent-gradient) !important;
    color: white !important;
    box-shadow: var(--accent-glow);
}
.gap-3 {
  gap: 12px;
}
.gap-4 {
  gap: 16px;
}
.text-center {
  text-align: center;
}
.text-sm {
  font-size: 0.875rem;
}
.text-xs {
  font-size: 0.75rem;
}
.font-bold {
  font-weight: 700;
}
.w-full {
  width: 100%;
}
.hidden {
  display: none !important;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

/* ========================================
   PRINT STYLES
   ======================================== */
@media print {
  body::before {
    display: none;
  }
  body {
    background: white;
  }

  .app-header,
  .editor-toolbar,
  .refiner-toolbar,
  .chat-panel,
  .chat-fab,
  .selection-popup,
  .modal-overlay,
  .loading-overlay,
  .toast-container {
    display: none !important;
  }

  .editor-canvas-area {
    padding: 0;
    background: white;
    overflow: visible;
  }

  .canvas-zoom-wrapper {
    transform: none !important;
  }

  .canvas-paper {
    box-shadow: none;
    width: 100%;
    min-height: auto;
    padding: 0;
  }

  .canvas-paper.landscape {
    width: 100%;
  }

  .canvas-paper.dark-print {
    background: #1a1a2e;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  @page {
    margin: 5mm;
    size: auto;
  }
}

/* ========================================
   RESPONSIVE
   ======================================== */
/* ========================================
   MOBILE BOTTOM NAV (Hidden on Desktop)
   ======================================== */
.mobile-bottom-nav {
  display: none; /* Hidden on desktop */
}

@media (max-width: 768px) {

  /* --- MOBILE BOTTOM NAV --- */
  .mobile-bottom-nav {
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: rgba(10, 14, 26, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-subtle);
    padding: 6px 0;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    justify-content: space-around;
    align-items: center;
  }

  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 12px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 0.6rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    border-radius: var(--radius-sm);
    min-width: 56px;
  }

  .mobile-nav-item:hover,
  .mobile-nav-item:active {
    color: var(--text-secondary);
    background: var(--bg-glass);
  }

  .mobile-nav-item.active {
    color: var(--accent-primary);
  }

  .mobile-nav-item.active::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 2px;
    background: var(--accent-primary);
    border-radius: 1px;
  }

  /* --- HEADER: Compact on Mobile --- */
  .app-header {
    padding: 0 12px;
  }

  .app-header-inner {
    height: 48px;
  }

  .app-nav {
    display: none !important;  /* Hide desktop nav — replaced by bottom nav */
  }

  .app-logo span {
    font-size: 1rem;
  }

  .app-logo-img {
    width: 26px;
    height: 26px;
  }

  /* Profile trigger stays compact on mobile */
  .user-profile-trigger {
    padding: 3px 6px;
    padding-right: 8px;
  }

  .user-profile-trigger .usage-badge {
    display: none; /* Hide plan badge on tiny screens */
  }

  /* Profile dropdown positioned for mobile */
  .user-dropdown {
    position: fixed !important;
    top: auto !important;
    bottom: calc(70px + env(safe-area-inset-bottom, 0px));
    right: 12px !important;
    left: 12px !important;
    width: auto !important;
    max-height: 70vh;
    overflow-y: auto;
    border-radius: var(--radius-xl);
    animation: fadeInUp 0.25s ease-out;
  }

  /* --- HOME VIEW --- */
  .home-hero h1 {
    font-size: 1.75rem;
  }

  .home-hero p {
    font-size: 0.85rem;
  }

  .home-buttons {
    grid-template-columns: 1fr;
  }

  .home-view {
    padding-bottom: 80px; /* Space for bottom nav */
  }

  /* --- GENERATE ROW --- */
  .generate-row {
    flex-direction: column;
  }

  /* --- EDITOR --- */
  .editor-controls-row {
    flex-direction: column;
    gap: 4px;
  }

  .editor-toggles-row {
    flex-wrap: wrap;
    gap: 4px;
  }

  /* Canvas area: scale to fit mobile */
  .canvas-zoom-wrapper {
    padding: 8px;
  }

  .canvas-paper {
    width: 100% !important;
    min-width: 0;
    transform: none !important;
  }

  #view-editor {
    padding-bottom: 80px;
  }

  /* Layout toolbar: full width at bottom */
  #editorLayoutToolbar {
    left: 8px !important;
    right: 8px !important;
    bottom: calc(70px + env(safe-area-inset-bottom, 0px)) !important;
    transform: none !important;
    width: auto !important;
    max-width: 100% !important;
    overflow-x: auto;
  }

  /* --- REFINER --- */
  .refiner-toolbar-inner {
    flex-direction: column;
    align-items: stretch;
  }

  .chapter-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .chapter-actions {
    flex-wrap: wrap;
    gap: 4px;
  }

  #view-refiner {
    padding-bottom: 80px;
  }

  /* --- CHAT PANEL --- */
  .chat-panel {
    width: calc(100vw - 16px);
    right: 8px;
    bottom: calc(70px + env(safe-area-inset-bottom, 0px));
    height: 420px;
    max-height: calc(100vh - 140px);
  }

  .chat-fab {
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
    right: 16px;
  }

  /* --- MODALS: Full-screen on mobile --- */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 90vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    margin: 0;
  }

  .modal-body {
    max-height: calc(90vh - 120px);
    overflow-y: auto;
  }

  /* --- DASHBOARD --- */
  .dashboard-container {
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); 
  }

  .quick-actions-row {
    grid-template-columns: 1fr;
  }

  /* --- FOOTER: Ensure not hidden by bottom nav --- */
  footer, .site-footer {
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }

  /* --- HIDE CHAT TRIGGER IN HEADER (it's in FAB now) --- */
  #aiChatTriggerBtn {
    display: none !important;
  }

  /* --- NEXT GEN DASHBOARD STYLES --- */
  .dashboard-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 30px 24px;
    padding-bottom: 100px; /* Space for bottom nav */
  }

  .dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
    flex-wrap: wrap;
    gap: 20px;
  }
  
  .header-content h1 {
      font-size: 2rem;
      font-weight: 800;
      background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
      margin-bottom: 4px;
  }
  
  .header-content p {
      color: var(--text-secondary);
  }

  .usage-stats-card {
      display: flex;
      align-items: center;
      gap: 16px;
      padding: 12px 20px;
      background: var(--bg-card);
      border: 1px solid var(--border-default);
      border-radius: var(--radius-lg);
      box-shadow: var(--shadow-sm);
  }
  
  .stat-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 2px;
  }
  
  .stat-label {
      font-size: 0.65rem;
      text-transform: uppercase;
      font-weight: 700;
      color: var(--text-muted);
      letter-spacing: 0.5px;
  }
  
  .stat-value {
      font-size: 0.9rem;
      font-weight: 700;
      color: var(--text-primary);
  }
  
  .stat-divider {
      width: 1px;
      height: 24px;
      background: var(--border-subtle);
  }

  .quick-actions-row {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
      gap: 16px;
      margin-bottom: 40px;
  }
  
  .action-card {
      display: flex;
      align-items: center;
      gap: 16px;
      padding: 20px;
      background: var(--bg-card);
      border: 1px solid var(--border-default);
      border-radius: var(--radius-lg);
      cursor: pointer;
      text-align: left;
      transition: all 0.2s;
  }
  
  .action-card:hover {
      transform: translateY(-2px);
      box-shadow: var(--shadow-md);
      border-color: var(--accent-primary);
  }
  
  .action-card.primary {
      background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(168, 85, 247, 0.1));
      border: 1px solid rgba(99, 102, 241, 0.3);
  }
  
  .icon-box {
      width: 40px;
      height: 40px;
      background: var(--bg-secondary);
      border-radius: 10px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-accent);
  }
  
  .action-card.primary .icon-box {
      background: var(--accent-primary);
      color: white;
  }
  
  .action-text h3 {
      font-size: 0.95rem;
      font-weight: 700;
      margin-bottom: 2px;
      color: var(--text-primary);
  }
  
  .action-text p {
      font-size: 0.8rem;
      color: var(--text-secondary);
  }

  .section-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 16px;
      flex-wrap: wrap;
      gap: 12px;
  }
  
  .section-header h3 {
      font-size: 1.1rem;
      font-weight: 700;
      display: flex;
      align-items: center;
      gap: 8px;
  }

  .draft-card {
      background: var(--bg-card);
      border: 1px solid var(--border-accent);
      border-radius: var(--radius-lg);
      padding: 16px 20px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      background: linear-gradient(to right, rgba(99, 102, 241, 0.05), transparent);
  }
  
  .draft-info {
      display: flex;
      align-items: center;
      gap: 16px;
  }
  
  .draft-icon {
      width: 36px;
      height: 36px;
      background: rgba(99, 102, 241, 0.1);
      color: var(--text-accent);
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
  }
  
  .draft-meta {
      font-size: 0.75rem;
      color: var(--text-muted);
      display: block;
      margin-top: 2px;
  }

  .sheets-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
      gap: 20px;
  }
  
  .sheet-card {
      background: var(--bg-card);
      border: 1px solid var(--border-default);
      border-radius: var(--radius-lg);
      overflow: hidden;
      transition: all 0.2s;
      position: relative;
      display: flex;
      flex-direction: column;
  }
  
  .sheet-card:hover {
      transform: translateY(-4px);
      box-shadow: var(--shadow-lg);
      border-color: var(--text-muted);
  }
  
  .sheet-preview {
      height: 120px;
      background: var(--bg-secondary);
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-muted);
      position: relative;
      overflow: hidden;
  }
  
  .sheet-preview::after {
      content: '';
      position: absolute;
      inset: 0;
      background: linear-gradient(45deg, transparent 40%, rgba(255,255,255,0.05) 50%, transparent 60%);
      background-size: 200% 200%;
      animation: shimmer 3s infinite;
  }
  
  .sheet-content {
      padding: 16px;
      flex: 1;
      display: flex;
      flex-direction: column;
  }
  
  .sheet-title {
      font-weight: 700;
      font-size: 0.95rem;
      margin-bottom: 6px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      color: var(--text-primary);
  }
  
  .sheet-date {
      font-size: 0.75rem;
      color: var(--text-muted);
      margin-bottom: 12px;
  }
  
  .sheet-tags {
      margin-top: auto;
      display: flex;
      gap: 6px;
  }
  
  .sheet-tag {
      font-size: 0.65rem;
      padding: 2px 8px;
      background: var(--bg-secondary);
      border-radius: 12px;
      color: var(--text-secondary);
  }

  .loading-state {
      grid-column: 1 / -1;
      text-align: center;
      padding: 60px;
      color: var(--text-muted);
      background: var(--bg-glass);
      border-radius: var(--radius-lg);
      border: 1px dashed var(--border-default);
  }
  
  /* --- MOBILE BOTTOM NAVIGATION --- */
  .app-nav {
    display: flex; /* Show it! */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: rgba(10, 14, 26, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-default);
    padding: 8px 12px;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.4);
  }

  .nav-btn {
    flex-direction: column;
    gap: 4px;
    font-size: 0.65rem;
    padding: 6px;
    color: var(--text-muted);
    background: transparent !important; /* Override hover/active bg */
    border-radius: 8px;
    width: auto;
    flex: 1;
    max-width: 80px;
    justify-content: center;
  }

  .nav-btn i {
    width: 20px;
    height: 20px;
    margin-bottom: 2px;
  }

  .nav-btn.active {
    color: var(--text-accent);
  }
  
  .nav-btn.active::after {
    display: none; /* Remove bottom bar indicator */
  }

  /* Adjust main container to not be covered by nav */
  #view-home, #view-dashboard, #view-refiner, #view-editor {
    padding-bottom: 80px !important; 
  }

  /* Hide specialized buttons on mobile to save space if needed */
  /* .nav-btn[onclick="showPricing()"], .nav-btn[href*="docs"] { display: none; } */

  .add-item-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .footer-inner {
    flex-direction: column;
    gap: 24px;
  }
  .footer-links {
    gap: 24px;
  }
  .cookie-banner-inner {
    flex-direction: column;
    align-items: stretch;
  }
}

/* ========================================
   ADDITIONAL UTILITIES & ANIMATIONS
   ======================================== */
.w-full {
  width: 100%;
}

.usage-badge {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 10px;
  background: var(--bg-glass);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  line-height: 1.2;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
/* --- BRANDING VIDEO SECTION --- */
.branding-video-wrap {
  width: 100%;
  max-width: 1000px;
  /* max-height removed to allow full 16:9 aspect ratio */
  margin: 20px auto 10px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.02);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl), 0 0 30px rgba(99, 102, 241, 0.1);
  overflow: hidden;
  position: relative;
  z-index: 5;
}

.branding-video-inner {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-primary);
}

.branding-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0.9;
}

.branding-vignette {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: radial-gradient(
    circle,
    transparent 40%,
    rgba(10, 14, 26, 0.4) 80%,
    rgba(10, 14, 26, 0.8) 100%
  );
  z-index: 1;
}

/* --- SUBSCRIPTION UI --- */
.subscription-status-card {
  border: 1px solid var(--border-accent);
  background: rgba(99, 102, 241, 0.05);
  display: flex;
  flex-direction: column;
}

.plan-feature-item {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.plan-feature-item i {
  color: var(--text-accent);
  flex-shrink: 0;
}

/* Cleanup old video styles */
.home-bg-video-container { display: none; }

/* ——————————————————————————————————————
   USER PROFILE DROPDOWN
   —————————————————————————————————————— */
.user-profile-wrapper {
  position: relative;
}

.user-profile-trigger {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background 0.2s;
}

.user-profile-trigger:hover {
  background: rgba(255,255,255,0.06);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.75rem;
  color: #fff;
  flex-shrink: 0;
}

.user-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 240px;
  max-width: 280px;
  max-height: 70vh;
  overflow-y: auto;
  background: rgba(24, 24, 32, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 6px 0;
  z-index: 9999;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.05);
  animation: dropdownSlideIn 0.15s ease-out;
}

.user-dropdown.visible {
  display: block;
}

@keyframes dropdownSlideIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Scrollbar styling */
.user-dropdown::-webkit-scrollbar {
  width: 4px;
}
.user-dropdown::-webkit-scrollbar-track {
  background: transparent;
}
.user-dropdown::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 4px;
}

@media (max-width: 768px) {
    .user-dropdown {
        position: fixed !important;
        bottom: 80px !important;
        left: 10px !important;
        right: 10px !important;
        top: auto !important;
        width: auto !important;
        max-width: none !important;
        transform-origin: bottom center;
        animation: slideUpMobile 0.2s ease-out;
    }
    
    @keyframes slideUpMobile {
        from { transform: translateY(20px); opacity: 0; }
        to { transform: translateY(0); opacity: 1; }
    }
}

.dropdown-header {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dropdown-user-email {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropdown-user-plan {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.dropdown-item:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text-primary);
}

.dropdown-item i {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.7;
}

.dropdown-item.danger {
  color: #f87171;
}
.dropdown-item.danger:hover {
  background: rgba(248, 113, 113, 0.1);
  color: #fca5a5;
}

.dropdown-item.upgrade {
  color: #a5b4fc;
  font-weight: 600;
}
.dropdown-item.upgrade:hover {
  background: rgba(99, 102, 241, 0.12);
  color: #c4b5fd;
}

.dropdown-divider {
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 4px 0;
}

/* ========================================
   DASHBOARD STYLES (Refined)
   ======================================== */
.dashboard-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 60px 24px; /* Slightly more padding */
  display: flex;
  flex-direction: column;
  gap: 56px; /* Increased gap between major segments */
}

.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 20px;
}

.header-content h1 {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 8px;
  background: var(--text-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-content p {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-top: 4px; /* Reduce gap to title */
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.section-header h3 {
  font-size: 1.25rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 12px; /* Space between icon and text */
  color: var(--text-primary);
}

.section-header h3 i {
  color: var(--accent-primary);
  width: 20px;
  height: 20px;
}

.usage-stats-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  box-shadow: var(--shadow-sm);
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-divider {
  width: 1px;
  height: 30px;
  background: var(--border-subtle);
}

/* Dashboard Content Grid */
.dashboard-main-grid {
    display: grid;
    grid-template-columns: 2fr 1.1fr; /* Adjusted ratio */
    gap: 40px; /* Increased gap */
    margin-top: 10px;
}

@media (max-width: 900px) {
    .dashboard-main-grid {
        grid-template-columns: 1fr;
    }
}

.quick-actions-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr); 
    gap: 16px;
}
@media (max-width: 600px) {
    .quick-actions-grid {
        grid-template-columns: 1fr;
    }
}

.action-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 12px;
  cursor: pointer;
  transition: all var(--transition-base);
  text-align: left;
  height: 100%;
}

.action-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-primary);
  box-shadow: var(--accent-glow);
}

.action-card.primary {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(168, 85, 247, 0.1));
  border-color: rgba(99, 102, 241, 0.3);
}

.action-text h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 2px;
  color: var(--text-primary);
}

.action-text p {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.icon-box {
  width: 44px; /* Slightly larger */
  height: 44px;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-primary);
  margin-bottom: 4px; /* Add bottom margin for title spacing */
}

.file-icon {
    width: 44px;
    height: 44px;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-primary);
    margin-bottom: 12px; /* Gap to title */
}

.file-icon i {
    width: 20px;
    height: 20px;
}

/* Templates */
.templates-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.template-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 10px;
}

.template-card:hover {
    border-color: var(--accent-secondary);
    background: var(--bg-surface);
}

.template-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.template-card h4 {
    font-size: 0.9rem;
    font-weight: 600;
}

/* Draft Card */
.draft-card {
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-left: 4px solid var(--accent-primary);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.draft-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.draft-icon {
    width: 40px;
    height: 40px;
    background: var(--bg-surface);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-primary);
}

.draft-info h4 {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 2px;
}

.draft-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Projects Grid (Refined) */
.sheets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
  position: relative;
  z-index: 1; /* Below search bar */
}

.sheet-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 24px; /* Increased padding */
    display: flex;
    flex-direction: column;
    height: 190px;
    justify-content: space-between;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
    z-index: 1;
}

.sheet-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent-primary);
    z-index: 10; /* Bring to front on hover */
}

.card-actions {
  display: flex;
  gap: 8px;
  opacity: 0; 
  transition: opacity 0.2s;
  pointer-events: none; /* Prevent accidental clicks when hidden */
}

.sheet-card:hover .card-actions,
.sheet-card:focus-within .card-actions {
    opacity: 1; 
    pointer-events: auto; /* Enable clicks on hover */
}

/* Ensure buttons are visible/clickable on mobile */
@media (max-width: 768px) {
    .card-actions {
        opacity: 1;
        pointer-events: auto;
    }
}

.card-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  cursor: pointer;
  transition: all 0.2s;
  position: relative; 
  z-index: 20; /* Ensure clickable */
}

/* Search Bar Fix */
.search-bar {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 300px;
  z-index: 50;
  background: var(--bg-surface) !important; /* Ensure background matches theme */
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 0 12px; /* Container padding */
  overflow: hidden; 
}

.search-bar input {
    background: transparent !important;
    border: none !important;
    color: var(--text-primary) !important;
    width: 100%;
    padding: 10px 0 10px 8px; /* Offset for icon */
    outline: none;
    font-size: 0.95rem;
}

.search-bar i {
    color: var(--text-muted);
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* Empty State */
.loading-state, .empty-state {
  text-align: center;
  padding: 60px 20px;
  grid-column: 1 / -1;
  color: var(--text-muted);
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 2px dashed var(--border-subtle);
}

.empty-state-icon {
    width: 48px;
    height: 48px;
    color: var(--text-muted);
    margin-bottom: 16px;
    opacity: 0.5;
}

.card-info h3.sheet-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.card-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ========================================
   DEDICATED PAGE VIEWS (Import & AI Gen)
   ======================================== */
.page-view-container {
    max-width: 900px;
    margin: 60px auto;
    padding: 0 24px;
    animation: fadeInUp 0.6s ease-out;
}

.page-header {
    text-align: center;
    margin-bottom: 48px;
}

.page-header h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-top: 16px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.page-header p {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-top: 8px;
}

/* Import Card Design */
.import-zone-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 32px;
}

.import-card {
    width: 100%;
    max-width: 600px;
    padding: 60px 40px;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 2px dashed var(--border-default);
    border-radius: var(--radius-xl);
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-base);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.import-card:hover {
    border-color: var(--accent-primary);
    background: var(--bg-glass-hover);
    transform: translateY(-4px);
    box-shadow: var(--shadow-xl), var(--accent-glow);
}

.import-icon {
    width: 64px;
    height: 64px;
    color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.1);
    padding: 16px;
    border-radius: var(--radius-lg);
    margin-bottom: 8px;
}

.import-card h3 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.import-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    margin-top: 24px;
}

/* AI Generation Card Design */
.ai-gen-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 48px;
}

.ai-gen-card {
    width: 100%;
    max-width: 640px;
    padding: 40px;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    display: flex;
    flex-direction: column;
    gap: 24px;
    box-shadow: var(--shadow-lg);
}

.ai-gen-card .input-group {
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all var(--transition-fast);
}

.ai-gen-card .input-group:focus-within {
    border-color: var(--accent-primary);
    background: var(--bg-input-focus);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.ai-gen-card .input-group i {
    color: var(--accent-primary);
    flex-shrink: 0;
}

.ai-gen-card .input {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    font-size: 1.1rem;
    color: var(--text-primary);
    width: 100%;
}

.ai-gen-tips {
    max-width: 600px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 24px 32px;
}

.ai-gen-tips h4 {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 16px;
    font-weight: 700;
}

.ai-gen-tips ul {
    list-style: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-gen-tips li {
    font-size: 0.95rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-gen-tips li::before {
    content: "✦";
    color: var(--accent-primary);
    font-size: 0.8rem;
}

/* Responsive centering fixes */
@media (max-width: 768px) {
    .page-view-container {
        margin: 32px auto;
    }
    .page-header h1 {
        font-size: 2rem;
    }
    .import-card {
        padding: 40px 24px;
    }
}

/* ========================================
   EDITOR TOOLBAR & CONTROLS
   ======================================== */
.editor-toolbar {
  background: rgba(10, 14, 26, 0.98);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-default);
  position: sticky;
  top: 0; /* Pin to top of the view */
  z-index: 5000;
  box-shadow: var(--shadow-lg);
  padding: 12px 24px;
}

.editor-toolbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.editor-toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.editor-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --- CONTROLS ROW --- */
.editor-controls-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 4px;
  overflow-x: auto;
}

.control-group-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 12px;
  min-width: 140px;
}

.control-header {
  font-size: 0.65rem;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  user-select: none;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.control-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.control-label i {
  width: 12px;
  height: 12px;
  opacity: 0.7;
}

.control-label span {
  color: var(--text-primary);
  font-family: monospace;
}

/* --- EDITOR TOGGLE SWITCHES --- */
.editor-toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
  user-select: none;
}

.editor-toggle-label:hover {
  background: var(--bg-glass);
}

.editor-toggle {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.editor-toggle-track {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-default);
  border-radius: 9px;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.editor-toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: all var(--transition-fast);
}

.editor-toggle:checked + .editor-toggle-track {
  background: rgba(99, 102, 241, 0.3);
  border-color: var(--accent-primary);
}

.editor-toggle:checked + .editor-toggle-track::after {
  transform: translateX(14px);
  background: var(--accent-primary);
  box-shadow: 0 0 6px rgba(99, 102, 241, 0.5);
}

.editor-toggle-text {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.editor-toggle:checked ~ .editor-toggle-text {
  color: var(--text-primary);
}

/* --- PREMIUM SLIDER --- */
.premium-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  margin-top: 4px;
}

.premium-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--text-primary);
  border: 2px solid var(--bg-primary);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--border-hover);
  transition: all var(--transition-fast);
}

.premium-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  background: var(--accent-primary);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
}

.premium-slider:active::-webkit-slider-thumb {
  transform: scale(0.95);
  background: var(--accent-secondary);
}

/* --- EDITOR CANVAS AREA --- */
.editor-canvas-area {
  flex: 1;
  background: #0f172a; 
  overflow: hidden;
  position: relative;
  display: flex !important; 
  align-items: center;
  justify-content: center;
  min-height: 0;
  width: 100%;
}

.canvas-zoom-wrapper {
  width: 100%;
  height: 100%;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px;
}

.canvas-paper {
  background: white;
  min-height: 1056px; 
  width: 816px; 
  box-shadow: 0 0 20px rgba(0,0,0,0.5);
  transform-origin: top center;
  transition: transform 0.2s;
  display: block !important;
  position: relative;
}

.canvas-paper.snap-active {
    background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
    background-size: 20px 20px;
}

/* ========================================
   ENHANCED LAYOUT MODE (Consolidated)
   ======================================== */

#canvasPaper.layout-mode {
  outline: 2px dashed rgba(99, 102, 241, 0.4);
  outline-offset: 4px;
}

/* Wrapper holds the item, the handles, and the logic */
.canvas-item-wrapper {
    position: relative;
    width: 100%;
    transition: none !important; 
    touch-action: none;
    user-select: none;
}

.canvas-item-wrapper.layout-active {
    cursor: grab;
    outline: 1px solid transparent;
    transition: outline 0.2s;
}

.canvas-item-wrapper.layout-active:hover {
    outline: 1px solid var(--accent-primary);
}

.canvas-item-wrapper.dragging {
    cursor: grabbing !important;
    z-index: 5000 !important;
    opacity: 0.8;
    transform: scale(1.02);
    box-shadow: 0 20px 50px rgba(0,0,0,0.4) !important;
}

/* THE FLOATING HANDLE — Visible only on hover */
.layout-drag-handle {
    position: absolute;
    top: -34px;
    right: 0;
    left: auto;
    background: #0f172a; 
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 8px;
    display: flex;
    align-items: center;
    padding: 4px 10px;
    gap: 8px;
    z-index: 6000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    transform: translateY(5px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    min-width: max-content;
}

.canvas-item-wrapper:hover .layout-drag-handle {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.layout-drag-handle span {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.05em;
    color: var(--accent-primary);
}

.layout-controls {
    display: flex;
    gap: 2px;
}

.layout-controls button {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: none;
    background: transparent;
    color: #94a3b8;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.layout-controls button:hover {
    background: rgba(255,255,255,0.1);
    color: white;
    transform: scale(1.1);
}

.layout-controls button.btn-danger:hover {
    background: #ef4444;
}

/* RE-SIZE HANDLES (Only in Layout Mode) */
.resize-handle {
    position: absolute;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    background: rgba(99, 102, 241, 0.4);
}

.rh-se { 
    bottom: 0px; 
    right: 0px; 
    width: 20px; 
    height: 20px; 
    border-radius: 4px 0 8px 0; 
    cursor: se-resize; 
    border-bottom: 3px solid var(--accent-primary);
    border-right: 3px solid var(--accent-primary);
}

.canvas-item-wrapper:hover .resize-handle {
    opacity: 1;
}

.resize-handle:hover {
    background: var(--accent-primary) !important;
}

/* POINTER EVENT TRICK: Wrapper catches drag, item blocks it unless editing */
.layout-mode .canvas-item {
    pointer-events: none;
}

.layout-mode.edit-mode-active .canvas-item {
    pointer-events: auto;
    cursor: text;
}

.layout-mode.edit-mode-active .canvas-item-wrapper {
    cursor: default;
}

/* THE FIXED TOOLBAR */
#editorLayoutToolbar {
    z-index: 9000;
    animation: slideUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes slideUp {
    from { transform: translate(-50%, 20px); opacity: 0; }
    to { transform: translate(-50%, 0); opacity: 1; }
}

/* PRINT CLEANUP */
@media print {
    .layout-drag-handle, .layout-controls, .resize-handle, #editorLayoutToolbar, .alignment-guide {
        display: none !important;
    }
    .canvas-item-wrapper { outline: none !important; box-shadow: none !important; }
}
