/* ============================================
   MAP-RCS — Design System
   Brand tokens: css/brand-tokens.css (load first)
   Guidelines: docs/BRAND-GUIDELINES.md
   ============================================ */

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-glass: rgba(0,0,0,0.03);
    --text-primary: #1a1a2e;
    --text-secondary: #4a4a6a;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  }
}

:root {
  /* Colors — defined in brand-tokens.css; extended below */

  /* Backgrounds — dark mode (Trust Blue infrastructure) */
  --bg-primary: var(--trust-blue);
  --bg-secondary: #0A1628;
  --bg-tertiary: #0D1F33;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-surface: rgba(255, 255, 255, 0.06);
  --bg-card-hover: rgba(255, 255, 255, 0.08);
  --bg-glass: rgba(255, 255, 255, 0.06);
  --bg-input: rgba(255, 255, 255, 0.05);
  --bg-sidebar: rgba(15, 43, 70, 0.98);
  --bg-sand: rgba(219, 205, 186, 0.08);

  /* Text */
  --text-primary: var(--brand-white);
  --text-secondary: rgba(255, 255, 255, 0.75);
  --text-muted: rgba(219, 205, 186, 0.55);
  --text-inverse: #FFFFFF;

  /* Borders — --border-active in brand-tokens.css */
  --border-color: rgba(255, 255, 255, 0.12);
  --border-subtle: rgba(255, 255, 255, 0.1);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.15);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.35);

  /* Chart colors - light-safe */
  --chart-text: rgba(255,255,255,0.55);
  --chart-grid: rgba(255,255,255,0.05);
  --chart-label: #fff;

  /* Radii */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 18px;
  --radius-full: 9999px;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;

  /* Typography */
  --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-serif: 'Cormorant Garamond', Georgia, serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', ui-monospace, monospace;
  --font-display: 'Poppins', 'Plus Jakarta Sans', sans-serif;
  --font-xs: clamp(0.625rem, 1.5vw, 0.75rem);
  --font-sm: clamp(0.75rem, 1.8vw, 0.875rem);
  --font-md: clamp(0.875rem, 2vw, 1rem);
  --font-lg: clamp(1rem, 2.5vw, 1.125rem);
  --font-xl: clamp(1.125rem, 3vw, 1.25rem);
  --font-2xl: clamp(1.25rem, 3.5vw, 1.5rem);
  --font-3xl: clamp(1.5rem, 4vw, 1.875rem);
  --font-4xl: clamp(1.875rem, 5vw, 2.25rem);
  --font-5xl: clamp(2rem, 5.5vw, 3.5rem);

  /* Layout */
  --sidebar-width: 252px;
  --sidebar-collapsed: 72px;
  --header-height: 64px;
  --bottom-nav-height: 56px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   Light Theme
   ============================================ */
[data-theme="dark"] {
  --bg-surface: rgba(255, 255, 255, 0.06);
  --border-subtle: rgba(255, 255, 255, 0.1);
}

[data-theme="light"] {
  --bg-primary: #FFFBF7;
  --bg-secondary: var(--brand-white);
  --bg-tertiary: #F5F0EA;
  --bg-card: var(--brand-white);
  --bg-surface: var(--brand-white);
  --bg-card-hover: #FFFBF7;
  --bg-glass: rgba(var(--brand-rgb), 0.04);
  --bg-input: #FFFBF7;
  --bg-sidebar: var(--brand-white);
  --bg-sand: var(--warm-sand);
  --text-primary: var(--trust-blue);
  --text-secondary: var(--slate-gray);
  --text-muted: var(--slate-gray);
  --primary-light: var(--badge-primary-text);
  --border-color: rgba(var(--slate-gray-rgb), 0.22);
  --border-subtle: rgba(var(--slate-gray-rgb), 0.12);
  --text-inverse: var(--brand-white);
  --shadow-sm: 0 2px 8px rgba(var(--trust-blue-rgb), 0.06);
  --shadow-md: 0 4px 16px rgba(var(--trust-blue-rgb), 0.08);
  --shadow-lg: 0 16px 32px rgba(var(--trust-blue-rgb), 0.12);
  --shadow-glow: 0 0 20px rgba(var(--brand-rgb), 0.15);
  --shadow-glow-sm: 0 0 10px rgba(var(--brand-rgb), 0.08);
  --chart-text: rgba(0,0,0,0.55);
  --chart-grid: rgba(0,0,0,0.06);
  --chart-label: var(--trust-blue);
}
[data-theme="light"] ::-webkit-scrollbar-thumb { background: rgba(var(--slate-gray-rgb), 0.25); }
[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: rgba(var(--slate-gray-rgb), 0.4); }
[data-theme="light"] .hero-title {
  background: var(--brand-gradient);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
[data-theme="light"] .landing-hero-title,
[data-theme="light"] .landing-page .cta-title {
  background: none;
  -webkit-text-fill-color: unset;
  color: var(--brand-white);
}
[data-theme="light"] .btn-primary { box-shadow: 0 4px 15px rgba(var(--brand-rgb), 0.28); }
[data-theme="light"] .badge-primary { background: rgba(var(--brand-rgb), 0.1); color: var(--badge-primary-text); }
[data-theme="light"] .badge-success { background: rgba(var(--verify-rgb), 0.1); color: var(--badge-success-text); }
[data-theme="light"] .badge-warning { background: rgba(var(--amber-rgb), 0.1); color: var(--badge-warning-text); }
[data-theme="light"] .badge-danger { background: rgba(var(--crimson-rgb), 0.1); color: var(--badge-danger-text); }
[data-theme="light"] .badge-info { background: rgba(var(--trust-blue-rgb), 0.08); color: var(--badge-info-text); }
[data-theme="light"] .stat-card { background: var(--bg-secondary); box-shadow: var(--shadow-sm); }
[data-theme="light"] .card { background: var(--bg-secondary); box-shadow: var(--shadow-sm); }
[data-theme="light"] .modal { background: var(--bg-secondary); }
[data-theme="light"] .nav-item:hover { background: rgba(var(--slate-gray-rgb), 0.06); color: var(--trust-blue); }
[data-theme="light"] .nav-item.active { background: rgba(var(--brand-rgb), 0.08); color: var(--nav-accent-text); border-color: rgba(var(--brand-rgb), 0.2); }
[data-theme="light"] .nav-tile { background: none; color: var(--trust-blue); }
[data-theme="light"] .nav-item:hover .nav-tile,
[data-theme="light"] .nav-item.active .nav-tile { background: none; color: var(--nav-accent-text); }
[data-theme="light"] .sidebar-user-trigger:hover { background: rgba(var(--brand-rgb), 0.05); }
[data-theme="dark"] .nav-tile { background: none; color: rgba(255,255,255,0.72); }
[data-theme="dark"] .nav-item.active .nav-tile,
[data-theme="dark"] .nav-item:hover .nav-tile { background: none; color: var(--primary-light); }
[data-theme="light"] .sidebar { background: var(--bg-sidebar); box-shadow: 2px 0 8px rgba(0,0,0,0.04); }
[data-theme="light"] .main-header {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
}
[data-theme="light"] .nav-item.active {
  background: rgba(var(--brand-rgb), 0.08) !important;
  color: var(--nav-accent-text) !important;
  border-color: transparent !important;
}
[data-theme="light"] .landing-nav {
  background: var(--brand-black);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
[data-theme="light"] .landing-nav .nav-link {
  color: rgba(255, 255, 255, 0.75);
}
[data-theme="light"] .landing-nav .nav-link:hover,
[data-theme="light"] .landing-nav .nav-link.active {
  color: var(--brand-white);
}
[data-theme="light"] .landing-nav .btn-ghost {
  color: rgba(255, 255, 255, 0.85) !important;
  border-color: rgba(255, 255, 255, 0.25) !important;
}
[data-theme="light"] .landing-nav .btn-ghost:hover {
  color: var(--brand-white) !important;
  background: rgba(255, 255, 255, 0.1) !important;
}
[data-theme="light"] .hero-bg {
  background: radial-gradient(ellipse at 30% 20%, rgba(var(--brand-rgb), 0.06) 0%, transparent 50%),
              radial-gradient(ellipse at 70% 80%, rgba(var(--brand-red-rgb), 0.04) 0%, transparent 50%);
}
[data-theme="light"] .hero-grid-overlay {
  background-image: linear-gradient(rgba(0,0,0,0.03) 1px, transparent 1px),
                     linear-gradient(90deg, rgba(0,0,0,0.03) 1px, transparent 1px);
}
[data-theme="light"] .hero-orb { opacity: 0.15; }
[data-theme="light"] .dropdown-menu { background: var(--bg-secondary); box-shadow: var(--shadow-lg); }

/* ============================================
   Reset & Base
   ============================================ */

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-family);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
  min-height: 100vh;
}

#app {
  min-height: 100vh;
}

a {
  color: var(--primary-light);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: var(--secondary); }

img { max-width: 100%; display: block; }

button {
  font-family: var(--font-family);
  cursor: pointer;
  border: none;
  outline: 2px solid transparent;
  outline-offset: 2px;
}

input, textarea, select {
  font-family: var(--font-family);
  outline: 2px solid transparent;
  outline-offset: 2px;
  border: none;
}

ul, ol { list-style: none; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

/* Selection */
::selection { background: var(--primary); color: white; }

/* ============================================
   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-xs { gap: var(--space-xs); }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.gap-xl { gap: var(--space-xl); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.w-full { width: 100%; }
.relative { position: relative; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-10px); }
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes ripple {
  0% { transform: scale(0); opacity: 0.6; }
  100% { transform: scale(2.5); opacity: 0; }
}
.animate-fade-in { animation: fadeIn 0.5s ease forwards; }
.animate-fade-in-up { animation: fadeInUp 0.6s ease forwards; }
.animate-slide-left { animation: slideInLeft 0.4s ease forwards; }
.animate-slide-right { animation: slideInRight 0.4s ease forwards; }
.animate-scale-in { animation: scaleIn 0.3s ease forwards; }

.stagger-1 { animation-delay: 0.1s; opacity: 0; }
.stagger-2 { animation-delay: 0.2s; opacity: 0; }
.stagger-3 { animation-delay: 0.3s; opacity: 0; }
.stagger-4 { animation-delay: 0.4s; opacity: 0; }
.stagger-5 { animation-delay: 0.5s; opacity: 0; }
.stagger-6 { animation-delay: 0.6s; opacity: 0; }

.btn:disabled,
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
  transform: none !important;
}

.btn--loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn--loading::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px;
  height: 18px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: btnSpin 0.6s linear infinite;
}

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

/* Prestigious Editorial Typography Mapping */
h1, h2, h3, h4, .page-title, .section-title, .pricing-name, .hero-title, .modal-title, .card-title, .logo-text, .nav-logo-text {
  font-family: var(--font-family);
}
h1, .hero-title, .page-title {
  font-weight: 500 !important;
  letter-spacing: -0.5px;
}
h2, .section-title {
  font-weight: 600 !important;
  letter-spacing: -0.2px;
}

/* Legal practitioner typography utilities */
.text-label {
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
  line-height: 1.4;
}
.text-helper {
  font-size: var(--font-xs);
  color: var(--text-muted);
  line-height: 1.55;
}
.page-lead,
.page-desc {
  line-height: 1.6;
}
[data-theme="light"] .text-helper,
[data-theme="light"] .text-label {
  color: var(--text-secondary);
}
[data-theme="light"] .comp-glass-card .text-helper {
  color: var(--text-muted);
}

/* H2 — Role-appropriate surface banner */
.role-surface-banner {
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  margin-bottom: var(--space-md);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-glass);
  font-size: var(--font-sm);
  line-height: 1.5;
}
.role-surface-banner__icon {
  flex-shrink: 0;
  color: var(--primary);
  margin-top: 2px;
}
.role-surface-banner__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.role-surface-banner__body strong {
  font-weight: 700;
  color: var(--text-primary);
}
.role-surface-banner__body span {
  color: var(--text-secondary);
  font-size: var(--font-xs);
}
.role-surface-banner--viewer {
  border-color: rgba(var(--brand-rgb), 0.25);
  background: rgba(var(--brand-rgb), 0.06);
}
.role-surface-banner--auditor {
  border-color: rgba(46, 133, 85, 0.35);
  background: rgba(46, 133, 85, 0.08);
}
.role-surface-banner--platform {
  border-color: rgba(255, 123, 34, 0.35);
  background: rgba(255, 123, 34, 0.08);
}
.role-surface-banner__cta {
  flex-shrink: 0;
  align-self: center;
}

/* Mobile — scrollable complex grids */
.responsive-grid-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: var(--space-md);
}
.responsive-grid-scroll > .dashboard-grid,
.responsive-grid-scroll.dashboard-grid {
  min-width: min(100%, 640px);
}

.modal.modal--library-detail {
  width: min(94vw, 1200px);
  max-width: min(94vw, 1200px);
  max-height: 90vh;
}

@media (max-width: 768px) {
  .modal--library-detail {
    width: 95vw !important;
    max-width: none !important;
    max-height: 92vh !important;
  }
  .tabs-scroll-mobile {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  .tabs-scroll-mobile .tab {
    flex-shrink: 0;
  }
  .responsive-grid-scroll .dashboard-grid {
    grid-template-columns: 1fr !important;
    min-width: 0 !important;
  }
  .search-layout-grid {
    grid-template-columns: 1fr !important;
  }
  .search-layout-grid .card {
    position: static !important;
  }
  .notif-premium-card:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
  }
  .search-result-card:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (forced-colors: active) {
  .btn,
  .btn-primary,
  .btn-ghost {
    border: 2px solid ButtonText;
  }
  .btn:focus-visible {
    outline: 3px solid Highlight;
    outline-offset: 2px;
  }
  .card, .comp-glass-card, .modal-overlay {
    border: 2px solid ButtonText;
  }
  .nav-tile, .nav-tile.active {
    border: none;
  }
}
