/* ============================================
   Amazon Affiliate Content Engine - Enhanced Design
   Modern SaaS "Docs-like" UI with Glassmorphism
   ============================================ */

/* ── Performance: smooth content reveal (perf-boost.js sets .ae-loading) ── */
html.ae-loading .dashboard,
html.ae-loading .main-content,
html.ae-loading main {
  opacity: 0;
  transition: none;
}
html:not(.ae-loading) .dashboard,
html:not(.ae-loading) .main-content,
html:not(.ae-loading) main {
  opacity: 1;
  transition: opacity 0.18s ease;
}

/* ── Performance: will-change only on animated elements ─────────────────── */
.sidebar { will-change: transform; contain: layout style; }
.topbar  { contain: layout style; }

/* ── Performance: reduce paint area for cards ───────────────────────────── */
.stat-card, .quick-action-card, .card {
  contain: layout style paint;
}

/* ── Skeleton loader pulse (for dynamic content) ─────────────────────────── */
@keyframes ae-skeleton-pulse {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}
.ae-skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: ae-skeleton-pulse 1.4s ease infinite;
  border-radius: 4px;
  color: transparent !important;
}
.ae-skeleton * { visibility: hidden; }

/* ============ CSS Variables ============ */
:root {
  /* Brand Colors - Blue→Violet→Pink Gradient Theme */
  --brand-blue: #2563EB;
  --brand-violet: #7C3AED;
  --brand-pink: #EC4899;
  --primary: #2563EB;
  --primary-dark: #1d4ed8;
  --primary-light: #3b82f6;
  --secondary: #7C3AED;
  --accent: #EC4899;
  
  /* Semantic Colors */
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
  --info: #3b82f6;
  
  /* Slate Color System - Light Mode */
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --slate-950: #020617;
  
  /* Surface Colors */
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #64748b;
  --border-color: #e2e8f0;
  
  /* Shadows - Soft Shadow System */
  --shadow-soft: 0 10px 30px rgba(2, 6, 23, 0.10);
  --shadow-sm: 0 1px 2px 0 rgba(2, 6, 23, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(2, 6, 23, 0.08);
  --shadow-lg: 0 10px 15px -3px rgba(2, 6, 23, 0.10);
  --shadow-xl: 0 20px 25px -5px rgba(2, 6, 23, 0.10);
  
  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  
  /* Border Radius - Rounded Friendly Geometry */
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.25rem;
  --radius-2xl: 1.5rem;
  
  /* Typography - Inter Font System */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Monaco', 'Courier New', monospace;
}

/* Dark Mode Variables */
[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-tertiary: #94a3b8;
  --border-color: #334155;
  --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
}

/* ============ Reset & Base Styles ============ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

/* ── Role-based nav: admin-only items hidden by default, shown for admin ── */
/* Items with .nav-admin-only are hidden until JS removes the class (admin role) */
.nav-admin-only { display: none !important; }

/* Once JS confirms admin role and sets data-was-admin-only,                  */
/* the item stays visible forever — CSS wins over any JS re-hide attempt      */
[data-was-admin-only] { display: block !important; }

/* On admin/settings pages the <html> tag gets class="is-admin-page"         */
/* This overrides the hide rule above — pure CSS, zero JS delay, zero flicker */
.is-admin-page .nav-admin-only { display: block !important; }

body {
  font-family: var(--font-sans);
  background: var(--slate-50);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.3s ease, color 0.3s ease;
  position: relative;
}

/* Light Mesh Background */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -1;
  background: 
    radial-gradient(circle at 20% 30%, rgba(37, 99, 235, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 80% 20%, rgba(124, 58, 237, 0.06) 0%, transparent 40%),
    radial-gradient(circle at 60% 80%, rgba(236, 72, 153, 0.05) 0%, transparent 40%),
    linear-gradient(180deg, #f8fafc 0%, #f9fafb 100%);
  pointer-events: none;
}

.mesh-bg {
  background: 
    radial-gradient(circle at 20% 30%, rgba(37, 99, 235, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 80% 20%, rgba(124, 58, 237, 0.06) 0%, transparent 40%),
    radial-gradient(circle at 60% 80%, rgba(236, 72, 153, 0.05) 0%, transparent 40%),
    linear-gradient(180deg, #f8fafc 0%, #f9fafb 100%);
}

/* ============ Typography ============ */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.2;
  color: var(--slate-900);
  margin-bottom: var(--space-md);
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }
h5 { font-size: 1.125rem; }
h6 { font-size: 1rem; }

p {
  margin-bottom: var(--space-md);
  color: var(--slate-600);
}

a {
  color: var(--brand-blue);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--brand-violet);
}

/* ============ Glassmorphism ============ */
.glass {
  background: rgba(255, 255, 255, 0.62);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: var(--shadow-soft);
}

.glass-dark {
  background: rgba(15, 23, 42, 0.62);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ============ Gradient Utilities ============ */
.gradient-primary {
  background: linear-gradient(135deg, var(--brand-blue) 0%, var(--brand-violet) 50%, var(--brand-pink) 100%);
}

.gradient-text {
  background: linear-gradient(135deg, var(--brand-blue) 0%, var(--brand-violet) 50%, var(--brand-pink) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.gradient-border {
  position: relative;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.gradient-border::before {
  content: '';
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  bottom: -2px;
  background: linear-gradient(135deg, var(--brand-blue) 0%, var(--brand-violet) 50%, var(--brand-pink) 100%);
  border-radius: inherit;
  z-index: -1;
}

/* ============ Layout Utilities ============ */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--space-lg);
}

.section {
  padding: var(--space-2xl) 0;
}

/* ============ Buttons - Gradient Enhanced ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 0.625rem 1.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-lg);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

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

.btn-primary {
  background: linear-gradient(135deg, #2563EB 0%, #7C3AED 50%, #EC4899 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.4);
  color: white !important;
}

a.btn-primary,
a.btn-primary:hover,
a.btn-primary:visited {
  color: white !important;
}

.btn-secondary {
  background: var(--slate-100);
  color: var(--slate-900);
  border: 1px solid var(--slate-200);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--slate-200);
}

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

.btn-success:hover:not(:disabled) {
  background: #059669;
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--slate-200);
  color: var(--slate-700);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--brand-blue);
  color: var(--brand-blue);
  background: rgba(37, 99, 235, 0.05);
}

.btn-lg {
  padding: 0.875rem 2rem;
  font-size: 1rem;
  border-radius: var(--radius-xl);
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.813rem;
}

.btn-icon {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border-radius: var(--radius-lg);
}

/* ============ Form Elements ============ */
.form-group {
  margin-bottom: var(--space-lg);
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--slate-900);
  margin-bottom: var(--space-sm);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
  font-family: var(--font-sans);
  color: var(--slate-900);
  background: var(--bg-primary);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-lg);
  transition: all 0.2s ease;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--brand-blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-textarea {
  resize: vertical;
  min-height: 120px;
}

.form-help {
  font-size: 0.813rem;
  color: var(--slate-500);
  margin-top: var(--space-xs);
}

.form-error {
  font-size: 0.813rem;
  color: var(--error);
  margin-top: var(--space-xs);
}

.form-checkbox,
.form-radio {
  width: 1.125rem;
  height: 1.125rem;
  cursor: pointer;
  accent-color: var(--brand-blue);
}

.form-checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--slate-700);
}

/* ============ Cards - Rounded 2xl Soft Style ============ */
.card {
  background: var(--bg-primary);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-2xl);
  padding: var(--space-xl);
  box-shadow: var(--shadow-soft);
  transition: all 0.3s ease;
}

.card:hover {
  box-shadow: 0 15px 35px rgba(2, 6, 23, 0.12);
  transform: translateY(-2px);
}

.card-header {
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--slate-200);
  margin-bottom: var(--space-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--slate-900);
  margin-bottom: 0;
}

.card-description {
  font-size: 0.875rem;
  color: var(--slate-600);
  margin-top: var(--space-xs);
  margin-bottom: 0;
}

.card-body {
  padding: 0;
}

.card-footer {
  padding-top: var(--space-lg);
  border-top: 1px solid var(--slate-200);
  margin-top: var(--space-lg);
}

/* ============ Grid System ============ */
.grid {
  display: grid;
  gap: var(--space-lg);
}

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

/* ============ Badges ============ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 9999px;
  white-space: nowrap;
}

.badge-primary {
  background: rgba(37, 99, 235, 0.1);
  color: var(--brand-blue);
}

.badge-success {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success);
}

.badge-warning {
  background: rgba(245, 158, 11, 0.1);
  color: var(--warning);
}

.badge-error {
  background: rgba(239, 68, 68, 0.1);
  color: var(--error);
}

.badge-info {
  background: rgba(59, 130, 246, 0.1);
  color: var(--info);
}

/* ============ Toast Notifications ============ */
.toast {
  position: fixed;
  top: var(--space-xl);
  right: var(--space-xl);
  min-width: 320px;
  max-width: 420px;
  padding: var(--space-lg);
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(14px);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-xl);
  z-index: 9999;
  animation: slideInRight 0.3s ease;
}

@keyframes slideInRight {
  from {
    transform: translateX(400px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

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

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

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

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

/* ============ Loading States ============ */
.loading {
  display: inline-block;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--slate-200);
  border-top-color: var(--brand-blue);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

.skeleton {
  background: linear-gradient(
    90deg,
    var(--slate-100) 25%,
    var(--slate-200) 50%,
    var(--slate-100) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-lg);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============ Tables ============ */
.table-container {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-2xl);
}

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

.table thead {
  background: var(--slate-50);
}

.table th {
  padding: 0.875rem;
  text-align: left;
  font-size: 0.813rem;
  font-weight: 600;
  color: var(--slate-600);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.table td {
  padding: 0.875rem;
  border-top: 1px solid var(--slate-200);
  font-size: 0.875rem;
  color: var(--slate-700);
}

.table tbody tr:hover {
  background: var(--slate-50);
}

/* ============ Modal ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  padding: var(--space-lg);
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--bg-primary);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-xl);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: scaleIn 0.2s ease;
}

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

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

.modal-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.modal-body {
  padding: var(--space-xl);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: var(--space-xs);
  border-radius: var(--radius-md);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
}

.modal-close:hover {
  background: var(--slate-100);
  color: var(--text-primary);
}

@keyframes scaleIn {
  from {
    transform: scale(0.95);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* ============ Progress Bar ============ */
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--slate-200);
  border-radius: 9999px;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary) 0%, var(--secondary) 100%);
  border-radius: 9999px;
  transition: width 0.4s ease;
  position: relative;
  overflow: hidden;
}

.progress-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.3) 50%,
    transparent 100%
  );
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

/* ============ Utility Classes ============ */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-medium { font-weight: 500; }

.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }
.text-2xl { font-size: 1.5rem; }
.text-3xl { font-size: 1.875rem; }
.text-4xl { font-size: 2.25rem; }

.text-slate-900 { color: var(--slate-900); }
.text-slate-700 { color: var(--slate-700); }
.text-slate-600 { color: var(--slate-600); }
.text-slate-500 { color: var(--slate-500); }
.text-success { color: var(--success); }
.text-error { color: var(--error); }
.text-warning { color: var(--warning); }

.bg-white { background: #ffffff; }
.bg-slate-50 { background: var(--slate-50); }
.bg-slate-100 { background: var(--slate-100); }

.rounded-lg { border-radius: var(--radius-lg); }
.rounded-xl { border-radius: var(--radius-xl); }
.rounded-2xl { border-radius: var(--radius-2xl); }
.rounded-full { border-radius: 9999px; }

.shadow-soft { box-shadow: var(--shadow-soft); }
.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }

.hidden { display: none; }
.block { display: block; }
.flex { display: flex; }
.inline-flex { display: inline-flex; }

.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }

.mt-lg { margin-top: var(--space-lg); }
.mb-lg { margin-bottom: var(--space-lg); }
.mb-0 { margin-bottom: 0; }
.ml-auto { margin-left: auto; }
.ml-sm { margin-left: var(--space-sm); }

.w-full { width: 100%; }
.h-full { height: 100%; }

/* ============ Responsive Design ============ */
@media (max-width: 1024px) {
  .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-cols-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  html { font-size: 14px; }
  
  h1 { font-size: 2rem; }
  h2 { font-size: 1.5rem; }
  h3 { font-size: 1.25rem; }
  
  .container {
    padding: 0 var(--space-md);
  }
  
  .grid-cols-4,
  .grid-cols-3,
  .grid-cols-2 {
    grid-template-columns: 1fr;
  }
  
  .toast {
    top: var(--space-md);
    right: var(--space-md);
    left: var(--space-md);
    min-width: auto;
  }
}
