/* routeiq.ui.css
   Purpose: tiny, consistent UI helpers that complement MudBlazor (v8).
   Scope: conservative; avoids overriding Mud defaults and Bootstrap globally.
   Safe to use across all pages.
*/

/* =========================
   0) Page Headers & Tables - Prevent focus/selection during Blazor hydration
   ========================= */
h1, h2, h3, h4, h5, h6 {
  outline: none;
}

/* =========================
   1) Typography Override - Force Inter font across all MudBlazor components
   ========================= */
:root {
  --mud-typography-default-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mud-typography-h1-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mud-typography-h2-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mud-typography-h3-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mud-typography-h4-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mud-typography-h5-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mud-typography-h6-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mud-typography-subtitle1-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mud-typography-subtitle2-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mud-typography-body1-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mud-typography-body2-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mud-typography-button-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mud-typography-caption-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mud-typography-overline-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* Direct font-family override for all elements (overrides MudBlazor's Roboto) */
html, body {
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
  background-color: var(--mud-palette-background) !important;
}

/* Override MudBlazor components specifically */
.mud-typography,
.mud-button-root,
.mud-input,
.mud-select,
.mud-text,
.mud-table,
[class*="mud-"] {
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
}

/* Ensure MudLayout and main content use theme background */
.mud-layout,
.mud-main-content {
  background-color: var(--mud-palette-background);
}

/* =========================
   1) Scrollbars (subtle, neutral)
   ========================= */
::-webkit-scrollbar { width: 8px; height: 8px; z-index: 1; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c4c4c4; border-radius: 1px; }
::-webkit-scrollbar-thumb:hover { background: #a6a6a6; }
/* Firefox */
html, body * { scrollbar-color: #c4c4c4 transparent; scrollbar-width: thin; }

/* =========================
   2) Cards (soft surfaces)
   ========================= */
.soft-card {
  background: var(--riq-surface-default);
  border-radius: 12px;
  box-shadow: var(--riq-shadow-sm);
  padding: 0.75rem;
}

/* Add a little inner breathing room when used with MudPaper etc. */
.soft-card > .pa-4,
.soft-card > .pa-3,
.soft-card > .pa-2 {
  padding: inherit; /* inherit soft-card padding */
}

/* =========================
   3) Table helpers (sticky header & first column)
   Usage:
     - Use MudTable's FixedHeader="true" + Height="600px" for sticky headers
     - Add .sticky-first-col to wrapper for frozen first column
     - Or add .sticky-col class to individual cells
   ========================= */

/* Ensure the table container scrolls properly */
.soft-table .mud-table-container {
  position: relative;
  overflow: auto;
}

/* STICKY FIRST COLUMN (optional, for custom first-column stickiness) */
.sticky-first-col .mud-table-root th:first-child,
.sticky-first-col .mud-table-root td:first-child {
  position: sticky;
  left: 0;
  z-index: 6;
  background: var(--riq-surface-default);
  box-shadow: 2px 0 0 0 var(--riq-surface-border);
  background-clip: padding-box;
}

/* Keep the header cell above the first column cells */
.sticky-first-col .mud-table-root thead th:first-child {
  z-index: 7;
}

/* Table row hover (kept subtle and aligned with Mud palette) */
.soft-table .mud-table-root tbody tr:hover td {
  background: rgba(0, 209, 221, 0.08); /* Light teal hover */
}

[data-theme='dark'] .soft-table .mud-table-root tbody tr:hover td {
  background: rgba(0, 209, 221, 0.12); /* Slightly stronger in dark mode */
}

/* Table compactness helpers (optional; apply on .soft-table) */
.soft-table.soft-compact .mud-table-root th,
.soft-table.soft-compact .mud-table-root td {
  padding-top: 0.4rem;
  padding-bottom: 0.4rem;
}

/* Header styling */
.soft-table .mud-table-root thead th {
  background: var(--riq-surface-default);
  position: sticky;
  top: 0;
  z-index: 5;
  border-bottom: 1px solid var(--riq-surface-border);
  font-weight: 600;
}

.soft-table .mud-table-root {
  background: var(--riq-surface-default);
}

/* =========================
   4) Alignment utilities
   ========================= */
.ta-center   { text-align: center; }
.ta-right    { text-align: right; }
.ta-left     { text-align: left; }

/* =========================
   5) Height utilities for scrollable tables
   (Use exactly one of these on the MudTable container wrapper if needed)
   Example: wrap table with a div.riq-h-600
   ========================= */
.riq-h-400 { height: 400px; }
.riq-h-500 { height: 500px; }
.riq-h-600 { height: 600px; }
.riq-h-700 { height: 700px; }
.riq-h-800 { height: 800px; }

/* =========================
   6) Muted text & badges (neutral, not overriding Mud colors)
   ========================= */
.text-muted { opacity: 0.70; }

/* Badges when using Bootstrap classes but want consistent spacing in Mud cards */
.badge + .badge { margin-left: 0.25rem; }

/* =========================
   7) Safe icon sizing helpers
   ========================= */
.riq-icon-sm { width: 16px; height: 16px; }
.riq-icon-md { width: 20px; height: 20px; }
.riq-icon-lg { width: 24px; height: 24px; }

/* =========================
   8) App footer consistency (non-intrusive)
   ========================= */
.app-footer {
  position: fixed;
  bottom: 0;
  right: 0;
  padding: 0.5rem 1rem;
  background: transparent;
  z-index: 1000;
  pointer-events: none; /* footer floats above content but stays passive */
}

.app-footer small {
  font-size: 0.75rem;
  opacity: 0.6;
}

/* =========================
   9) "Pills" (MudChip) sizing: compact badge feel
   ========================= */
.pill-xs .mud-chip,
.mud-chip.pill-xs {
  height: 22px;
  padding: 0 .5rem;
  font-size: .75rem;
  border-radius: 9999px;
}

/* =========================
   10) Fix any legacy overrides that erased chip backgrounds
   ========================= */
/* Force text contrast for Warning chips if your theme makes them too light */
.mud-chip-filled.mud-chip-color-warning {
  color: #021D39 !important; /* Ready Dark for readability on warning background */
}

/* =========================
   11) Dark mode polish (respects theme variables)
   Only tweaks borders/shadows to remain visible in dark palettes.
   ========================= */
[data-theme='dark'] .soft-card {
  box-shadow: var(--riq-shadow-md);
}

[data-theme='dark'] .soft-table.sticky-first-col .mud-table-root th:first-child,
[data-theme='dark'] .soft-table.sticky-first-col .mud-table-root td:first-child,
[data-theme='dark'] .soft-table .sticky-col {
  box-shadow: 2px 0 0 0 var(--riq-surface-border);
}

/* =========================
   12) Blazor reconnection UI overrides (Production only)
   Hide the intrusive blocking modal; replaced with subtle status chip.
   Set via JS based on environment.
   ========================= */
body.production-mode #blazor-reconnect-modal,
body.production-mode #components-reconnect-modal {
  display: none !important;
}

/* Keep error UI hidden in production unless explicitly shown */
body.production-mode #blazor-error-ui {
  display: none !important;
}

/* Reconnection status chip (subtle, top-right) */
.reconnect-status-chip {
  position: fixed;
  top: 80px;
  right: 24px;
  z-index: 9999;
  background: #F59E0B; /* Warning color */
  color: #021D39; /* Ready Dark for readability */
  padding: 8px 16px;
  border-radius: 20px;
  box-shadow: var(--riq-shadow-lg);
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.reconnect-status-chip.visible {
  opacity: 1;
  transform: translateY(0);
}

.reconnect-status-chip .spinner {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* =========================
   13) Theme Toggle Animation
   ========================= */

/* Bounce animation for sun icon (plays 3 times on page load) */
@keyframes theme-toggle-bounce {
  0%, 100% {
    transform: translateY(0);
  }
  25% {
    transform: translateY(-8px);
  }
  50% {
    transform: translateY(0);
  }
  75% {
    transform: translateY(-4px);
  }
}

/* Apply bounce animation on page load (only when motion is allowed) */
@media (prefers-reduced-motion: no-preference) {
  .riq-theme-toggle {
    animation: theme-toggle-bounce 1.2s ease-in-out 3;
  }
}

/* Hover effect (subtle scale) */
@media (prefers-reduced-motion: no-preference) {
  .riq-theme-toggle:hover {
    transform: scale(1.15);
    transition: transform 200ms ease-in-out;
  }
}

/* Fallback for reduced motion users (no animation) */
@media (prefers-reduced-motion: reduce) {
  .riq-theme-toggle {
    animation: none;
  }

  .riq-theme-toggle:hover {
    transform: none;
  }
}

/* =========================
   14) ApexCharts Theme Integration
   Using EXPLICIT colors from ApplicationTheme.cs for reliable theming.
   ApexCharts Theme.Mode doesn't integrate well with MudBlazor.

   Colors matched to ApplicationTheme.cs:
   Light: Surface=#EBF3FB, Background=#D6E4F0, TextPrimary=#021D39, TextSecondary=#4A6176, Lines=#A8C5DC
   Dark:  Surface=#0A1F54, Background=#04123F, TextPrimary=#F5F7F7, TextSecondary=#94A3B8, Lines=#1A3266
   ========================= */

/* Light mode tooltip (default) */
.apexcharts-tooltip {
  background: #EBF3FB !important;
  color: #021D39 !important;
  border: 1px solid #A8C5DC !important;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.apexcharts-tooltip-title {
  background: #D6E4F0 !important;
  color: #021D39 !important;
  border-bottom: 1px solid #A8C5DC !important;
}

.apexcharts-tooltip-text,
.apexcharts-tooltip-text-y-value,
.apexcharts-tooltip-text-y-label {
  color: #021D39 !important;
}

/* Light mode toolbar menu */
.apexcharts-menu {
  background: #EBF3FB !important;
  border: 1px solid #A8C5DC !important;
  color: #021D39 !important;
}

.apexcharts-menu-item {
  color: #021D39 !important;
}

.apexcharts-menu-item:hover {
  background: #D6E4F0 !important;
}

/* Dark mode overrides - using MudBlazor's dark mode class */
.mud-theme-dark .apexcharts-tooltip {
  background: #0A1F54 !important;
  color: #F5F7F7 !important;
  border: 1px solid #1A3266 !important;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.mud-theme-dark .apexcharts-tooltip-title {
  background: #04123F !important;
  color: #F5F7F7 !important;
  border-bottom: 1px solid #1A3266 !important;
}

.mud-theme-dark .apexcharts-tooltip-text,
.mud-theme-dark .apexcharts-tooltip-text-y-value,
.mud-theme-dark .apexcharts-tooltip-text-y-label {
  color: #F5F7F7 !important;
}

.mud-theme-dark .apexcharts-menu {
  background: #0A1F54 !important;
  border: 1px solid #1A3266 !important;
  color: #F5F7F7 !important;
}

.mud-theme-dark .apexcharts-menu-item {
  color: #F5F7F7 !important;
}

.mud-theme-dark .apexcharts-menu-item:hover {
  background: #04123F !important;
}
