/* =============================================================
   DESIGN TOKENS — All CSS custom properties for the app
   Import this FIRST in base.html before any other custom CSS
   ============================================================= */

:root {
  /* ── Spacing scale ── */
  --space-0: 0;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  /* ── Typography scale ── */
  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;
  --text-3xl:  1.875rem;
  --text-4xl:  2.25rem;

  /* ── Line heights ── */
  --leading-tight:   1.2;
  --leading-snug:    1.35;
  --leading-normal:  1.5;
  --leading-relaxed: 1.65;

  /* ── App layout tokens (light) ── */
  --app-sidebar-bg: #ffffff;
  --app-topbar-bg:  #ffffff;
  --app-content-bg: #f2f7ff;
  --app-border:     #e9ecef;
  --app-text-muted: #6c757d;
  --app-shadow:     0 2px 10px rgba(0, 0, 0, 0.06);
  --app-primary:    #435ebe;
  --sidebar-width:  260px;

  /* ── Status color tokens ── */
  --status-draft:        #6c757d;
  --status-draft-bg:     #e9ecef;
  --status-active:       #198754;
  --status-active-bg:    #d1e7dd;
  --status-pending:      #fd7e14;
  --status-pending-bg:   #fff3cd;
  --status-paused:       #6c757d;
  --status-paused-bg:    #f8f9fa;
  --status-error:        #dc3545;
  --status-error-bg:     #f8d7da;
  --status-completed:    #0d6efd;
  --status-completed-bg: #cfe2ff;

  /* ── AI confidence ── */
  --confidence-high:   #198754;
  --confidence-medium: #fd7e14;
  --confidence-low:    #dc3545;
}

/* ── Dark mode overrides ── */
[data-bs-theme="dark"] {
  --app-sidebar-bg: #1a1c23;
  --app-topbar-bg:  #22242c;
  --app-content-bg: #12141a;
  --app-border:     #2a2d36;
  --app-text-muted: #868e96;
  --app-shadow:     0 2px 10px rgba(0, 0, 0, 0.4);
  --app-primary:    #6571d1;

  --status-draft:        #adb5bd;
  --status-draft-bg:     #2a2d36;
  --status-active:       #4ade80;
  --status-active-bg:    #14532d;
  --status-pending:      #fb923c;
  --status-pending-bg:   #431407;
  --status-error:        #f87171;
  --status-error-bg:     #450a0a;
  --status-completed:    #60a5fa;
  --status-completed-bg: #1e3a5f;
}

/* ── Typography utilities ── */
.text-xs   { font-size: var(--text-xs);   line-height: var(--leading-snug); }
.text-sm   { font-size: var(--text-sm);   line-height: var(--leading-snug); }
.text-base { font-size: var(--text-base); line-height: var(--leading-normal); }
.text-lg   { font-size: var(--text-lg);   line-height: var(--leading-normal); }

.page-title {
  font-size: var(--text-3xl);
  font-weight: 600;
  line-height: var(--leading-tight);
  margin: 0;
}

.page-subtitle {
  font-size: var(--text-base);
  color: var(--app-text-muted);
  margin: var(--space-2) 0 0;
}

/* ── Status badge ── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: var(--text-xs);
  font-weight: 500;
  white-space: nowrap;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.status-badge[data-status="active"],
.status-badge[data-status="live"]       { background: var(--status-active-bg);    color: var(--status-active);    }
.status-badge[data-status="pending"]    { background: var(--status-pending-bg);   color: var(--status-pending);   }
.status-badge[data-status="error"],
.status-badge[data-status="failed"]     { background: var(--status-error-bg);     color: var(--status-error);     }
.status-badge[data-status="draft"]      { background: var(--status-draft-bg);     color: var(--status-draft);     }
.status-badge[data-status="paused"]     { background: var(--status-paused-bg);    color: var(--status-paused);    }
.status-badge[data-status="completed"]  { background: var(--status-completed-bg); color: var(--status-completed); }

.status-badge[data-status="active"] .status-dot,
.status-badge[data-status="live"] .status-dot  { background: var(--status-active);  box-shadow: 0 0 0 3px rgba(25,135,84,.15); }
.status-badge[data-status="pending"] .status-dot   { background: var(--status-pending);   }
.status-badge[data-status="error"] .status-dot,
.status-badge[data-status="failed"] .status-dot    { background: var(--status-error);     }
.status-badge[data-status="draft"] .status-dot     { background: var(--status-draft);     }
.status-badge[data-status="completed"] .status-dot { background: var(--status-completed); }

.status-badge[data-status="in_progress"] .status-dot {
  background: var(--status-pending);
  animation: status-pulse 1.5s ease infinite;
}

@keyframes status-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ── Stat card ── */
.stat-card {
  background: var(--app-sidebar-bg);
  border: 1px solid var(--app-border);
  border-radius: 10px;
  padding: var(--space-5);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--bs-primary, #435ebe);
}

.stat-card[data-trend="up"]::before   { background: var(--status-active); }
.stat-card[data-trend="down"]::before { background: var(--status-error);  }

.stat-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-3);
}

.stat-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--app-text-muted);
  font-weight: 600;
}

.stat-card-header i { font-size: 20px; opacity: 0.3; }

.stat-value {
  font-size: var(--text-3xl);
  font-weight: 700;
  line-height: 1.1;
  color: var(--bs-body-color, #212529);
  margin-bottom: var(--space-2);
}

.stat-meta {
  display: flex;
  gap: var(--space-3);
  font-size: var(--text-xs);
  color: var(--app-text-muted);
  flex-wrap: wrap;
}

.stat-trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
}

[data-trend="up"]   .stat-trend { color: var(--status-active); }
[data-trend="down"] .stat-trend { color: var(--status-error);  }

/* ── Dashboard grid ── */
.dashboard-grid {
  display: grid;
  gap: var(--space-5);
  grid-template-columns: repeat(12, 1fr);
}

.grid-stats        { grid-column: span 3; }
.grid-chart-full   { grid-column: span 12; }
.grid-chart-wide   { grid-column: span 8; }
.grid-chart-half   { grid-column: span 6; }
.grid-chart-narrow { grid-column: span 4; }

@media (max-width: 1200px) {
  .grid-stats { grid-column: span 6; }
  .grid-chart-wide,
  .grid-chart-half,
  .grid-chart-narrow { grid-column: span 12; }
}

@media (max-width: 768px) {
  .grid-stats { grid-column: span 12; }
  .dashboard-grid { gap: var(--space-3); }
}

/* ── Page actions ── */
.page-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ── Section form ── */
.section-form-header { margin-bottom: var(--space-5); }
.section-form-header h3 { margin: 0 0 var(--space-1); font-size: var(--text-xl); font-weight: 600; }
.section-form-header p  { margin: 0; color: var(--app-text-muted); font-size: var(--text-sm); }

.section-form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: var(--space-4);
  border-top: 1px solid var(--app-border);
  margin-top: var(--space-5);
}

.form-actions { display: flex; gap: var(--space-2); }

.dirty-indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--status-pending);
}

/* ── Data table toolbar ── */
.data-table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--app-border);
  gap: var(--space-3);
  flex-wrap: wrap;
}

.data-table-toolbar-left  { display: flex; align-items: center; gap: var(--space-3); flex: 1; min-width: 0; }
.data-table-toolbar-right { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }

.data-table-search { position: relative; min-width: 200px; max-width: 320px; flex: 1; }
.data-table-search i {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--app-text-muted);
  pointer-events: none;
}
.data-table-search input { padding-left: 34px; }

.data-table-bulk-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bs-primary-bg-subtle, #cfe2ff);
  border-radius: 6px;
  font-size: var(--text-sm);
}

.data-table-empty {
  padding: var(--space-8) var(--space-5);
  text-align: center;
  color: var(--app-text-muted);
}

.data-table-empty i    { font-size: 48px; display: block; margin-bottom: var(--space-3); opacity: 0.4; }
.data-table-empty h4   { margin: 0 0 var(--space-2); font-size: var(--text-xl); }
.data-table-empty p    { margin: 0 0 var(--space-4); }

/* ── Confirm dialog icon ── */
.confirm-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  font-size: 28px;
}

.confirm-icon.primary { background: var(--bs-primary-bg-subtle, #cfe2ff); color: var(--bs-primary, #435ebe); }
.confirm-icon.danger  { background: var(--bs-danger-bg-subtle,  #f8d7da); color: var(--bs-danger,  #dc3545); }

/* ── Drawer ── */
.drawer { position: fixed; inset: 0; z-index: 1055; display: none; }
.drawer.show { display: block; }

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.drawer.show .drawer-backdrop { opacity: 1; }

.drawer-panel {
  position: absolute;
  top: 0; right: 0;
  width: 100%;
  max-width: 500px;
  height: 100vh;
  background: var(--bs-body-bg, #fff);
  box-shadow: -10px 0 30px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

.drawer.show .drawer-panel { transform: translateX(0); }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5);
  border-bottom: 1px solid var(--app-border);
}

.drawer-title  { margin: 0; font-size: var(--text-xl); font-weight: 600; }
.drawer-close  { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--app-text-muted); padding: 4px; line-height: 1; }
.drawer-close:hover { color: var(--bs-body-color, #212529); }
.drawer-body   { flex: 1; padding: var(--space-5); overflow-y: auto; }
.drawer-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--app-border);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
}

/* ── Section loading overlay ── */
.section-loading { position: relative; }

.section-loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: inherit;
}

[data-bs-theme="dark"] .section-loading-overlay { background: rgba(0,0,0,0.5); }
.section-loading.is-loading .section-loading-overlay { display: flex; }

/* ── Error pages ── */
.error-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  text-align: center;
}

.error-code {
  font-size: 96px;
  font-weight: 700;
  line-height: 1;
  margin: 0;
  background: linear-gradient(135deg, var(--bs-primary, #435ebe), var(--bs-info, #0dcaf0));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.error-title   { margin: var(--space-3) 0; font-size: var(--text-2xl); }
.error-message { color: var(--app-text-muted); max-width: 500px; margin: 0 auto var(--space-5); }
.error-actions { display: flex; gap: var(--space-3); justify-content: center; margin-bottom: var(--space-5); flex-wrap: wrap; }
.error-request-id { font-size: var(--text-xs); color: var(--app-text-muted); }

/* ── Variation price grid ── */
.variation-grid-wrapper {
  background: var(--app-sidebar-bg);
  border: 1px solid var(--app-border);
  border-radius: 8px;
  overflow: hidden;
}

.variation-grid-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--app-border);
  background: #f8f9fa;
  flex-wrap: wrap;
}

[data-bs-theme="dark"] .variation-grid-toolbar { background: #22242c; }

.variation-grid { overflow: auto; max-height: 500px; }
.variation-prices-table { margin: 0; }
.variation-prices-table th,
.variation-prices-table td { padding: 6px; text-align: center; white-space: nowrap; }

.variation-colour-header {
  position: sticky; left: 0;
  background: #f8f9fa; z-index: 2;
  min-width: 160px; text-align: left !important;
}

[data-bs-theme="dark"] .variation-colour-header { background: #22242c; }

.variation-prices-table thead th { position: sticky; top: 0; background: #f8f9fa; z-index: 1; }
[data-bs-theme="dark"] .variation-prices-table thead th { background: #22242c; }

.variation-corner { position: sticky; top: 0; left: 0; z-index: 3; background: #f8f9fa; }
[data-bs-theme="dark"] .variation-corner { background: #22242c; }

.variation-price-cell input { width: 80px; text-align: right; }
.variation-price-cell input:focus { box-shadow: 0 0 0 2px var(--bs-primary-bg-subtle, #cfe2ff); background: var(--bs-primary-bg-subtle, #cfe2ff); }

.colour-swatch {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 1px solid var(--app-border);
  margin-right: 6px;
  vertical-align: middle;
}

/* ── Accessibility ── */
.skip-link {
  position: absolute;
  top: -40px; left: 0;
  padding: 8px 16px;
  background: var(--bs-primary, #435ebe);
  color: white;
  text-decoration: none;
  z-index: 9999;
  border-radius: 0 0 6px 0;
}

.skip-link:focus { top: 0; }

*:focus { outline: none; }
*:focus-visible {
  outline: 2px solid var(--bs-primary, #435ebe);
  outline-offset: 2px;
  border-radius: 4px;
}

kbd {
  background: #e9ecef;
  border: 1px solid var(--app-border);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: monospace;
  font-size: 12px;
}

[data-bs-theme="dark"] kbd { background: #2a2d36; }

/* ── Mobile ── */
@media (max-width: 768px) {
  .page-header-content { flex-direction: column; gap: var(--space-3); }
  .page-header-actions { width: 100%; }
  .data-table-toolbar  { flex-direction: column; align-items: stretch; }
  .data-table-toolbar-left,
  .data-table-toolbar-right { width: 100%; }
  .data-table-search { max-width: 100%; min-width: 0; }
}

@media (pointer: coarse) {
  .btn, .form-control, .form-select { min-height: 44px; }
  .dropdown-item { padding: 10px 16px; }
}
