/* platformiq.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 {
  /* ── Shared inventory column widths ── */
  --col-dot: 14px;
  --col-id: 56px;
  --col-location: 90px;
  --col-vendor: 90px;
  --col-type: 90px;
  --col-cores: 52px;
  --col-ram: 56px;
  --col-notes: 52px;
  --col-flags: 110px;

  --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)
   ========================= */

/* Ensure the table container scrolls properly */
.soft-table .mud-table-container {
  position: relative;
  overflow: auto;
}

/* STICKY FIRST COLUMN */
.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 */
.soft-table .mud-table-root tbody tr:hover td {
  background: rgba(0, 209, 221, 0.08);
}

[data-theme='dark'] .soft-table .mud-table-root tbody tr:hover td {
  background: rgba(0, 209, 221, 0.12);
}

/* Table compactness helpers */
.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
   ========================= */
.piq-h-400 { height: 400px; }
.piq-h-500 { height: 500px; }
.piq-h-600 { height: 600px; }
.piq-h-700 { height: 700px; }
.piq-h-800 { height: 800px; }

/* =========================
   6) Muted text & badges
   ========================= */
.text-muted { opacity: 0.70; }

.badge + .badge { margin-left: 0.25rem; }

/* =========================
   7) Safe icon sizing helpers
   ========================= */
.piq-icon-sm { width: 16px; height: 16px; }
.piq-icon-md { width: 20px; height: 20px; }
.piq-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;
}

.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
   ========================= */
.mud-chip-filled.mud-chip-color-warning {
  color: #021D39 !important;
}

/* =========================
   11) Dark mode polish
   ========================= */
[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)
   ========================= */
body.production-mode #blazor-reconnect-modal,
body.production-mode #components-reconnect-modal {
  display: none !important;
}

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;
  color: #021D39;
  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
   ========================= */

@keyframes theme-toggle-bounce {
  0%, 100% {
    transform: translateY(0);
  }
  25% {
    transform: translateY(-8px);
  }
  50% {
    transform: translateY(0);
  }
  75% {
    transform: translateY(-4px);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .piq-theme-toggle {
    animation: theme-toggle-bounce 1.2s ease-in-out 3;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .piq-theme-toggle:hover {
    transform: scale(1.15);
    transition: transform 200ms ease-in-out;
  }
}

@media (prefers-reduced-motion: reduce) {
  .piq-theme-toggle {
    animation: none;
  }

  .piq-theme-toggle:hover {
    transform: none;
  }
}

/* =========================
   14) PlatformIQ Component Library - Layout Helpers
   ========================= */
.piq-row {
  display: grid;
  gap: var(--riq-card-gap);
  align-items: stretch;
}

.piq-row-2 {
  grid-template-columns: 1fr 1fr;
}

.piq-row-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.piq-row-3-weighted {
  grid-template-columns: 1fr 1.5fr 1fr;
}

.piq-row-4 {
  grid-template-columns: repeat(4, 1fr);
}

.piq-section {
  margin-bottom: var(--riq-space-lg);
}

/* MudTable compact overrides for component library */
.piq-table-compact th {
  font-size: var(--riq-font-sm) !important;
  font-weight: 600 !important;
  color: var(--riq-gray-600) !important;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: var(--riq-table-cell-padding) !important;
}

.piq-table-compact td {
  font-size: var(--riq-font-base) !important;
  padding: var(--riq-table-cell-padding) !important;
}

[data-theme='dark'] .piq-table-compact th {
  color: var(--riq-gray-400) !important;
}

/* Responsive breakpoints */
@media (max-width: 1200px) {
  .piq-row-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .piq-row-3 {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 768px) {
  .piq-row-4,
  .piq-row-3,
  .piq-row-2 {
    grid-template-columns: 1fr;
  }
}

/* =========================
   15) ApexCharts Theme Integration
   ========================= */

.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;
}

.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;
}

.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;
}

/* =========================
   16) PlatformIQ Component Library Styles
   ========================= */

/* PiqCard */
.piq-card {
  background: var(--riq-surface-default);
  border-radius: var(--riq-card-radius);
  box-shadow: var(--riq-shadow-sm);
  padding: var(--riq-card-padding);
}

.piq-card-title {
  font-size: var(--riq-font-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--riq-gray-600);
  margin-bottom: 12px;
}

.piq-card-content {
  /* Content area - no default styling, fully flexible */
}

[data-theme='dark'] .piq-card {
  box-shadow: var(--riq-shadow-md);
}

[data-theme='dark'] .piq-card-title {
  color: var(--riq-gray-400);
}

/* PiqMetricCard */
.piq-metric-card {
  background: var(--riq-surface-default);
  border-radius: var(--riq-card-radius);
  box-shadow: var(--riq-shadow-sm);
  padding: var(--riq-card-padding);
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.piq-metric-value {
  font-size: var(--riq-font-2xl);
  font-weight: 600;
  color: var(--riq-gray-900);
  line-height: 1.2;
}

.piq-metric-label {
  font-size: var(--riq-font-sm);
  color: var(--riq-gray-600);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.piq-metric-extra {
  margin-top: 8px;
  font-size: var(--riq-font-xs);
  color: var(--riq-gray-500);
}

.piq-metric-card.status-success .piq-metric-value {
  color: var(--riq-color-success);
}

.piq-metric-card.status-warning .piq-metric-value {
  color: var(--riq-color-warning);
}

.piq-metric-card.status-danger .piq-metric-value {
  color: var(--riq-color-error);
}

[data-theme='dark'] .piq-metric-card {
  box-shadow: var(--riq-shadow-md);
}

[data-theme='dark'] .piq-metric-value {
  color: var(--riq-gray-50);
}

[data-theme='dark'] .piq-metric-label {
  color: var(--riq-gray-400);
}

[data-theme='dark'] .piq-metric-extra {
  color: var(--riq-gray-500);
}

/* PiqTabPills */
.piq-tab-pills {
  display: flex;
  gap: 6px;
  background: var(--riq-surface-border);
  padding: 4px;
  border-radius: 8px;
  width: fit-content;
}

.piq-tab-pill {
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--riq-gray-700);
  font-size: var(--riq-font-sm);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.piq-tab-pill:hover:not(.active) {
  background: rgba(255, 255, 255, 0.5);
}

.piq-tab-pill.active {
  background: var(--riq-surface-default);
  color: var(--riq-color-primary);
  box-shadow: var(--riq-shadow-sm);
}

[data-theme='dark'] .piq-tab-pills {
  background: var(--riq-surface-raised);
}

[data-theme='dark'] .piq-tab-pill {
  color: var(--riq-gray-300);
}

[data-theme='dark'] .piq-tab-pill:hover:not(.active) {
  background: rgba(255, 255, 255, 0.05);
}

[data-theme='dark'] .piq-tab-pill.active {
  background: var(--riq-surface-default);
  color: var(--riq-color-primary);
}

/* PiqHorizontalBar */
.piq-horizontal-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
}

.piq-bar-label {
  flex: 0 0 160px;
  font-size: var(--riq-font-sm);
  color: var(--riq-gray-700);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.piq-bar-track {
  flex: 1;
  height: 6px;
  background: var(--riq-gray-200);
  border-radius: 3px;
  overflow: hidden;
  min-width: 0;
}

.piq-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}

.piq-bar-value {
  flex: 0 0 48px;
  text-align: right;
  font-size: var(--riq-font-sm);
  font-weight: 500;
  color: var(--riq-gray-700);
}

.piq-bar-fill.color-primary {
  background: var(--riq-color-primary);
}

.piq-bar-fill.color-success {
  background: var(--riq-color-success);
}

.piq-bar-fill.color-warning {
  background: var(--riq-color-warning);
}

.piq-bar-fill.color-danger {
  background: var(--riq-color-error);
}

.piq-bar-fill.color-info {
  background: var(--riq-color-info);
}

.piq-bar-fill.color-dark {
  background: var(--riq-gray-800);
}

.piq-bar-fill.color-muted {
  background: var(--riq-gray-500);
}

[data-theme='dark'] .piq-bar-label,
[data-theme='dark'] .piq-bar-value {
  color: var(--riq-gray-300);
}

[data-theme='dark'] .piq-bar-track {
  background: var(--riq-gray-700);
}

[data-theme='dark'] .piq-bar-fill.color-dark {
  background: var(--riq-gray-400);
}

/* PiqStatusBadge */
.piq-status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: var(--riq-font-xs);
  font-weight: 500;
  line-height: 1.5;
  white-space: nowrap;
}

.piq-status-badge.badge-default {
  background: var(--riq-gray-200);
  color: var(--riq-gray-700);
}

.piq-status-badge.badge-primary {
  background: rgba(0, 209, 221, 0.15);
  color: var(--riq-color-primary-active);
}

.piq-status-badge.badge-success {
  background: rgba(16, 185, 129, 0.15);
  color: #059669;
}

.piq-status-badge.badge-warning {
  background: rgba(245, 158, 11, 0.15);
  color: #D97706;
}

.piq-status-badge.badge-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #DC2626;
}

.piq-status-badge.badge-info {
  background: rgba(0, 209, 221, 0.15);
  color: var(--riq-color-info);
}

[data-theme='dark'] .piq-status-badge.badge-default {
  background: var(--riq-gray-700);
  color: var(--riq-gray-300);
}

[data-theme='dark'] .piq-status-badge.badge-primary {
  background: rgba(0, 209, 221, 0.2);
  color: var(--riq-color-primary);
}

[data-theme='dark'] .piq-status-badge.badge-success {
  background: rgba(16, 185, 129, 0.2);
  color: var(--riq-color-success);
}

[data-theme='dark'] .piq-status-badge.badge-warning {
  background: rgba(245, 158, 11, 0.2);
  color: var(--riq-color-warning);
}

[data-theme='dark'] .piq-status-badge.badge-danger {
  background: rgba(239, 68, 68, 0.2);
  color: var(--riq-color-error);
}

[data-theme='dark'] .piq-status-badge.badge-info {
  background: rgba(0, 209, 221, 0.2);
  color: var(--riq-color-info);
}

/* =========================
   Release Notes commit cards (.rn-*)
   ========================= */
.rn-commit-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 4px 0 8px 0;
}

.rn-commit {
    padding: 10px 12px;
    border-radius: 6px;
    background: var(--mud-palette-background-grey);
    border-left: 3px solid var(--mud-palette-primary);
}

.rn-commit-header {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 4px;
}

.rn-sha {
    font-family: ui-monospace, monospace;
    font-size: 11px;
    color: var(--mud-palette-text-secondary);
    text-decoration: none;
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.07);
    border: 1px solid rgba(0, 0, 0, 0.1);
    padding: 1px 6px;
    border-radius: 4px;
}

a.rn-sha:hover {
    color: var(--mud-palette-primary);
    text-decoration: underline;
}

[data-theme='dark'] .rn-sha {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.15);
}

.rn-summary {
    font-size: 13px;
    font-weight: 500;
    color: var(--mud-palette-text-primary);
    line-height: 1.4;
}

.rn-bullets {
    margin: 6px 0 8px 0;
    padding-left: 18px;
    list-style-type: disc !important;
}

.rn-bullets li {
    font-size: 12.5px;
    color: var(--mud-palette-text-secondary);
    line-height: 1.5;
    margin-bottom: 2px;
    list-style-type: disc !important;
}

.rn-authors {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.rn-author-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px 2px 3px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

.rn-author-initials {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    font-size: 9px;
    font-weight: 700;
    flex-shrink: 0;
}

/* Human author — teal */
.rn-author-human {
    background: #0097a722;
    color: #0097a7;
    border: 1px solid #0097a744;
}
.rn-author-human .rn-author-initials {
    background: #0097a7;
    color: #fff;
}

/* Claude AI co-author — purple */
.rn-author-claude {
    background: #7c3aed22;
    color: #7c3aed;
    border: 1px solid #7c3aed44;
}
.rn-author-claude .rn-author-initials {
    background: #7c3aed;
    color: #fff;
}

/* ===== Friendly (AI-generated) release note card ===== */
.rn-friendly-note {
    border-left: 4px solid var(--mud-palette-primary);
    background: var(--mud-palette-background-grey);
    border-radius: 6px;
    padding: 14px 16px 10px 16px;
}
.rn-friendly-note-body {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--mud-palette-text-primary);
}
.rn-friendly-note-footer {
    margin-top: 8px;
    font-size: 0.75rem;
    color: var(--mud-palette-text-secondary);
    font-style: italic;
}
