/* ============================================================
   ANALYTICS PORTAL — Design V5 Patch
   Fixes: contrast violations, missing prefers-reduced-motion,
   store-dropdown styles, OTP UX, icon-glow accessibility,
   sidebar hints visibility, table header readability.
   ============================================================ */

/* ── 1. CONTRAST FIXES ───────────────────────────────────────── */

/* Sub-menu hint text: was #2e3340 (~1.2:1) → now readable */
.sub-hint {
  color: #4b5563 !important;
}
.sub-hint.hint-ok    { color: #22863a !important; }
.sub-hint.hint-warn  { color: #b45309 !important; }
.sub-hint.hint-error { color: #b91c1c !important; }
.sub-hint.hint-live  { color: #22863a !important; }

/* Sub-nav item name: inactive state readability */
.sub-name {
  color: #6b7280 !important;
}
.sidebar-sub.active .sub-name {
  color: #e1e4eb !important;
  font-weight: 500 !important;
}

/* Table header: was #3a3a3e on near-black → barely visible */
.data-table thead th {
  color: #606878 !important;
}

/* Sidebar group label: was #4a4a52 (~2.1:1) → lifted */
.sidebar-nav .sidebar-group-label {
  color: #525868 !important;
}

/* Muted text minimum in data-heavy areas */
.kpi-sub,
.oc-compare,
.last-sync-label,
.seo-subtitle,
.detail-label,
.seo-position + * {
  color: #525868 !important;
}

/* ── 2. PREFERS-REDUCED-MOTION ───────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  /* Kill all decorative animations */
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  /* Keep functional transitions at meaningful durations */
  .sidebar,
  .app-main,
  .pill,
  .tab-btn,
  .btn-primary,
  .btn-secondary,
  .btn-icon,
  .kpi-card,
  .report-card,
  .seo-fix-card {
    transition-duration: 150ms !important;
  }

  /* Stop pulsing dots (status indicators stay visible as solid) */
  .status-live {
    animation: none !important;
    box-shadow: none !important;
  }

  /* Stop icon glow pulse */
  .icon-glow-wrapper::before,
  .icon-glow-wrapper::after {
    animation: none !important;
    opacity: 0 !important;
  }
  .sidebar-link.active .icon-glow-wrapper::before {
    opacity: 0.8 !important;
    animation: none !important;
  }
  .sidebar-link.active .icon-glow-wrapper::after {
    opacity: 0.6 !important;
    animation: none !important;
  }

  /* Stop login background canvas animation (handled in JS side)
     but at minimum freeze spinner */
  .spinner,
  .spinner-sm { animation-duration: 1s !important; }

  /* Stop loading banners shimmer */
  .login-card::before { animation: none !important; }
}

/* ── 3. STORE DROPDOWN ───────────────────────────────────────── */

.store-dropdown-wrap {
  padding: 6px 10px 2px !important;
  border-bottom: 1px solid rgba(255,255,255,0.05) !important;
}

.store-dropdown {
  position: relative !important;
}

.store-dropdown-btn {
  width: 100% !important;
  background: rgba(255,255,255,0.04) !important;
  border: 0.5px solid rgba(255,255,255,0.09) !important;
  border-radius: 8px !important;
  color: rgba(255,255,255,0.65) !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  padding: 7px 12px !important;
  text-align: left !important;
  cursor: pointer !important;
  transition: background 0.15s, border-color 0.15s !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
}

.store-dropdown-btn:hover {
  background: rgba(255,255,255,0.07) !important;
  border-color: rgba(255,255,255,0.15) !important;
  color: rgba(255,255,255,0.9) !important;
}

.store-dropdown-menu {
  position: absolute !important;
  top: calc(100% + 4px) !important;
  left: 0 !important;
  right: 0 !important;
  background: rgba(12,10,34,0.98) !important;
  backdrop-filter: blur(20px) !important;
  -webkit-backdrop-filter: blur(20px) !important;
  border: 0.5px solid rgba(255,255,255,0.1) !important;
  border-radius: 10px !important;
  box-shadow: 0 16px 48px rgba(0,0,0,0.65) !important;
  z-index: 300 !important;
  overflow: hidden !important;
  padding: 4px !important;
}

.store-dropdown-item {
  width: 100% !important;
  background: transparent !important;
  border: none !important;
  border-radius: 7px !important;
  color: rgba(255,255,255,0.55) !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  padding: 8px 12px !important;
  text-align: left !important;
  cursor: pointer !important;
  transition: background 0.1s, color 0.1s !important;
  display: block !important;
}

.store-dropdown-item:hover {
  background: rgba(147,81,222,0.18) !important;
  color: #fff !important;
}

/* Light mode store dropdown */
[data-theme=light] .store-dropdown-btn {
  background: rgba(255,255,255,0.12) !important;
  border-color: rgba(255,255,255,0.15) !important;
  color: rgba(255,255,255,0.8) !important;
}
[data-theme=light] .store-dropdown-menu {
  background: #1d1349 !important;
  border-color: rgba(255,255,255,0.12) !important;
}
[data-theme=light] .store-dropdown-item:hover {
  background: rgba(139,92,246,0.25) !important;
  color: #fff !important;
}

/* ── 4. OTP LOGIN IMPROVEMENTS ───────────────────────────────── */

/* Step indicator for email → code flow */
.otp-step-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 24px;
  font-family: monospace;
  font-size: 10px;
  letter-spacing: 2px;
  color: rgba(160,140,220,0.45);
}

.otp-step-indicator .step {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(160,140,220,0.2);
  transition: background 0.3s;
}

.otp-step-indicator .step.active {
  background: #7B5CF6;
  box-shadow: 0 0 8px rgba(123,92,246,0.6);
}

/* OTP code input — monospace digits, clear and legible */
.otp-input-wrap {
  position: relative;
}

.otp-input-wrap input {
  font-family: 'DM Mono', 'SF Mono', 'Courier New', monospace !important;
  font-size: 28px !important;
  letter-spacing: 0.35em !important;
  text-align: center !important;
  padding: 14px 16px !important;
  color: #e0d8ff !important;
  border-color: rgba(100,70,220,0.3) !important;
  background: rgba(10,4,40,0.7) !important;
  border-radius: 10px !important;
  width: 100% !important;
}

.otp-input-wrap input:focus {
  border-color: rgba(120,80,255,0.65) !important;
  box-shadow: 0 0 0 3px rgba(100,60,200,0.18), 0 0 20px rgba(100,60,200,0.08) !important;
}

/* "Check your email" helper state */
.otp-email-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(91,91,214,0.08);
  border: 0.5px solid rgba(91,91,214,0.25);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 18px;
  font-family: monospace;
  font-size: 11px;
  color: rgba(180,160,255,0.75);
}

.otp-email-hint svg {
  flex-shrink: 0;
  opacity: 0.6;
}

/* Countdown timer for OTP expiry */
.otp-timer {
  text-align: center;
  font-family: monospace;
  font-size: 11px;
  color: rgba(160,140,220,0.45);
  margin-top: 10px;
}

.otp-timer.warning { color: rgba(245,158,11,0.75); }
.otp-timer.expired { color: rgba(239,68,68,0.75); }

/* ── 5. ICON ACCESSIBILITY (collapsed sidebar) ───────────────── */

/* Tooltip for icon-only mode when sidebar is collapsed */
.sidebar-collapsed .sidebar-link {
  position: relative !important;
}

.sidebar-collapsed .sidebar-link:hover::after {
  content: attr(title);
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  background: rgba(12,10,34,0.97);
  border: 0.5px solid rgba(255,255,255,0.1);
  border-radius: 7px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 500;
  color: rgba(255,255,255,0.85);
  white-space: nowrap;
  pointer-events: none;
  z-index: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

/* ── 6. SKELETON LOADING STATES ──────────────────────────────── */

@keyframes skeleton-shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}

.skeleton {
  background: linear-gradient(
    90deg,
    rgba(255,255,255,0.04) 25%,
    rgba(255,255,255,0.08) 50%,
    rgba(255,255,255,0.04) 75%
  );
  background-size: 800px 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: 6px;
}

@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
    background: rgba(255,255,255,0.05);
  }
}

.skeleton-kpi {
  height: 80px;
  border-radius: 14px;
}

.skeleton-chart {
  height: 220px;
  border-radius: 14px;
}

.skeleton-row {
  height: 36px;
  border-radius: 6px;
  margin-bottom: 2px;
}

.skeleton-text {
  height: 14px;
  border-radius: 4px;
}

.skeleton-text.sm { height: 10px; }
.skeleton-text.lg { height: 18px; }

/* ── 7. FOCUS RING IMPROVEMENTS ──────────────────────────────── */

/* Ensure focus rings are visible against dark backgrounds */
:focus-visible {
  outline: 2px solid rgba(123,92,246,0.85) !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 4px rgba(123,92,246,0.15) !important;
}

/* Skip-to-main link (keyboard accessibility) */
.skip-to-main {
  position: fixed;
  top: -100%;
  left: 16px;
  z-index: 9999;
  background: #7B2FBE;
  color: #fff;
  padding: 8px 16px;
  border-radius: 0 0 8px 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: top 0.15s;
}

.skip-to-main:focus {
  top: 0;
  outline: none !important;
}

/* ── 8. BUTTON HOVER — NO LAYOUT SHIFT ──────────────────────── */

/* Remove transform: translateY from all hover states — causes layout shift */
.btn-primary:hover:not(:disabled),
.btn-login:hover:not(:disabled),
[data-theme=light] .btn-primary:hover:not(:disabled) {
  transform: none !important;
}

/* Replace with enhanced glow instead */
.btn-primary:hover:not(:disabled) {
  box-shadow: 0 6px 24px rgba(157,78,221,0.55) !important;
}

.btn-login:hover:not(:disabled) {
  box-shadow: 0 6px 28px rgba(100,40,255,0.6) !important;
}

/* KPI card — no translate on hover */
.kpi-card:hover {
  transform: none !important;
}

/* ── 9. SIDEBAR DOT-LINE VISIBILITY ─────────────────────────── */

/* Status line connector between sub-items */
.dot-line {
  background: rgba(255,255,255,0.06) !important;
}

/* ── 10. BADGE / STATUS BADGE CONTRAST ──────────────────────── */

/* Status badges need readable text on their colored backgrounds */
.status-scale   { color: #22c55e !important; background: rgba(34,197,94,0.12) !important; }
.status-monitor { color: #f59e0b !important; background: rgba(245,158,11,0.12) !important; }
.status-pause   { color: #f43f5e !important; background: rgba(244,63,94,0.12) !important; }

/* Severity badges */
.severity-critical { color: #f87171 !important; background: rgba(244,63,94,0.12) !important; }
.severity-warning  { color: #fbbf24 !important; background: rgba(245,158,11,0.12) !important; }
.severity-info     { color: #60a5fa !important; background: rgba(59,130,246,0.12) !important; }

/* ── 11. CHART IMPROVEMENTS ──────────────────────────────────── */

/* Ensure chart legends are visible */
._leg { color: rgba(255,255,255,0.55) !important; }

/* Grid lines — subtle but present */
.chart-card canvas {
  border-radius: 8px;
}

/* ── 12. MARKDOWN / AI REPORT READABILITY ────────────────────── */

.markdown-content {
  background: rgba(255,255,255,0.03) !important;
  border: 0.5px solid rgba(255,255,255,0.07) !important;
}

.markdown-content h2 {
  color: rgba(157,78,221,0.9) !important;
  border-bottom-color: rgba(255,255,255,0.06) !important;
}

.markdown-content p,
.markdown-content li {
  color: rgba(225,228,235,0.75) !important;
}

.markdown-content strong {
  color: #e1e4eb !important;
}

.markdown-content code {
  background: rgba(255,255,255,0.06) !important;
  color: rgba(157,78,221,0.9) !important;
  border-radius: 4px !important;
  padding: 2px 6px !important;
}

/* ── 13. MOBILE TOUCH TARGETS ────────────────────────────────── */

/* Ensure minimum 44×44px touch targets */
.btn-icon,
.modal-close,
.btn-delete,
.sidebar-toggle,
.sidebar-theme-btn,
.sidebar-logout,
.sidebar-pw-btn {
  min-width: 36px !important;
  min-height: 36px !important;
}

@media (max-width: 768px) {
  /* Larger touch targets on mobile */
  .btn-icon,
  .modal-close {
    min-width: 44px !important;
    min-height: 44px !important;
  }

  .pill {
    padding: 8px 14px !important;
    min-height: 36px !important;
  }

  /* Better spacing in toolbar on mobile */
  .quick-filters {
    gap: 8px !important;
  }
}

/* ── 14. SCROLL INERTIA & SMOOTHNESS ─────────────────────────── */

.sidebar-nav {
  -webkit-overflow-scrolling: touch !important;
  scroll-behavior: smooth !important;
  overscroll-behavior: contain !important;
}

.table-scroll {
  -webkit-overflow-scrolling: touch !important;
  overscroll-behavior-x: contain !important;
}

/* ── 15. TRANSITION CONSISTENCY ──────────────────────────────── */

/* Add missing transitions to interactive elements */
.sidebar-link,
.sidebar-sub,
.store-btn,
.tab-btn,
.pill,
.kpi-card,
.report-card,
.seo-fix-card,
.seo-card,
.seo-history-item,
.expandable-row,
.clickable-row {
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease !important;
}

/* ── 16. LIGHT MODE HINT COLORS ──────────────────────────────── */

[data-theme=light] .sub-hint        { color: #6b7280 !important; }
[data-theme=light] .hint-ok         { color: #16a34a !important; }
[data-theme=light] .hint-warn       { color: #ca8a04 !important; }
[data-theme=light] .hint-error      { color: #dc2626 !important; }
[data-theme=light] .hint-live       { color: #16a34a !important; }
[data-theme=light] .sub-name        { color: #6b7280 !important; }
[data-theme=light] .sidebar-sub.active .sub-name { color: #fff !important; }
[data-theme=light] .data-table thead th { color: #9b91c8 !important; }
[data-theme=light] .sidebar-nav .sidebar-group-label { color: rgba(255,255,255,0.5) !important; }

/* ── 17. EMPTY STATES ────────────────────────────────────────── */

/* Make empty states more informative visually */
.td-empty {
  color: rgba(255,255,255,0.25) !important;
  font-size: 13px !important;
}

[data-theme=light] .td-empty { color: #9b91c8 !important; }

/* ── 18. SCROLLBAR REFINEMENT ────────────────────────────────── */

::-webkit-scrollbar       { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.08);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.15);
}

[data-theme=light] ::-webkit-scrollbar-thumb {
  background: rgba(29,19,73,0.15);
}
[data-theme=light] ::-webkit-scrollbar-thumb:hover {
  background: rgba(29,19,73,0.25);
}

/* ── 19. LOADING BANNER IMPROVEMENT ─────────────────────────── */

.loading-banner {
  background: rgba(91,91,214,0.08) !important;
  border-color: rgba(91,91,214,0.2) !important;
  color: rgba(180,160,255,0.85) !important;
  border-radius: 10px !important;
}

/* ── 20. SEO PAGE SPECIFICS ──────────────────────────────────── */

.seo-fix-card {
  background: rgba(255,255,255,0.03) !important;
  border: 0.5px solid rgba(255,255,255,0.07) !important;
}

.seo-fix-card.done {
  border-color: rgba(34,197,94,0.25) !important;
  background: rgba(34,197,94,0.04) !important;
}

.seo-fix-card.errored {
  border-color: rgba(244,63,94,0.25) !important;
  background: rgba(244,63,94,0.04) !important;
}

.seo-card {
  background: rgba(255,255,255,0.03) !important;
  border: 0.5px solid rgba(255,255,255,0.07) !important;
}

/* ── 21. CROSS-ANALYSIS INFO BAR ─────────────────────────────── */

.cross-info-bar {
  background: linear-gradient(135deg, rgba(91,91,214,0.08), rgba(157,78,221,0.08)) !important;
  border-color: rgba(91,91,214,0.2) !important;
}
