@import url('./styles/high-contrast.css');

:root {
  --bg: #020617;
  --bg-elevated: #020617;
  --card-bg: #020617;
  --border-subtle: rgba(148, 163, 184, 0.25);
  --accent: #22c55e;
  --accent-soft: rgba(34, 197, 94, 0.1);
  --text-main: #e5e7eb;
  --text-muted: #9ca3af;
  --text-soft: #6b7280;
}

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

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: radial-gradient(circle at top, #0b1120 0, #020617 52%, #020617 100%);
  color: var(--text-main);
}

/* Layout */

.app-header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.5rem;
  background: rgba(15, 23, 42, 0.95);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: blur(8px);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: radial-gradient(circle, var(--accent) 0, #22c55e 40%, #22c55e 100%);
}

.brand-name {
  font-weight: 600;
  letter-spacing: 0.02em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-meta {
  font-size: 0.85rem;
  color: var(--text-soft);
}

.app-main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.app-footer {
  border-top: 1px solid var(--border-subtle);
  padding: 0.75rem 1.5rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-soft);
}

/* Language toggle */

.lang-toggle {
  display: inline-flex;
  border-radius: 999px;
  padding: 2px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-subtle);
}

.lang-btn {
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-size: 0.8rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  cursor: pointer;
}

.lang-btn--active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Cache indicator */

.cache-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.3);
  font-size: 0.75rem;
  color: #93c5fd;
}

.cache-indicator[hidden] {
  display: none;
}

.cache-indicator__icon::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #60a5fa;
  animation: cache-pulse 2s ease-in-out infinite;
}

@keyframes cache-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

.cache-indicator--stale {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.3);
  color: #fcd34d;
}

.cache-indicator--stale .cache-indicator__icon::before {
  background: #f59e0b;
}

/* Refresh button */

.refresh-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.65rem;
  border-radius: 0.4rem;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.refresh-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.refresh-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.refresh-btn__icon {
  width: 14px;
  height: 14px;
  transition: transform 0.3s ease;
}

.refresh-btn--loading .refresh-btn__icon {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* PWA Install button */

.install-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.65rem;
  border-radius: 0.4rem;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.15s;
}

.install-btn:hover {
  background: var(--accent);
  color: #0f172a;
  transform: scale(1.02);
}

.install-btn__icon {
  width: 14px;
  height: 14px;
}

.install-btn__text {
  font-weight: 500;
}

/* Filters / overview */

.filters h2 {
  margin: 0 0 0.3rem 0;
}

.filters-text {
  margin: 0.2rem 0 1rem;
  color: var(--text-muted);
  max-width: 720px;
}

.filter-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  font-size: 0.9rem;
}

.filter-controls select {
  margin-left: 0.35rem;
  padding: 0.2rem 0.5rem;
  border-radius: 0.4rem;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text-main);
}

.filter-controls button {
  padding: 0.3rem 0.7rem;
  border-radius: 0.4rem;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text-main);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.filter-controls button:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.filter-controls button .btn-icon {
  vertical-align: -3px;
  margin-right: 0.35rem;
}

/* KPI cards */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.9rem;
}

.kpi-card {
  padding: 1rem 1.1rem;
  border-radius: 0.9rem;
  border: 1px solid var(--border-subtle);
  background: linear-gradient(
    135deg,
    rgba(15, 23, 42, 0.95),
    rgba(15, 23, 42, 0.98)
  );
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.8);
}

.kpi-card h3 {
  margin: 0 0 0.3rem;
  font-size: 0.95rem;
  font-weight: 500;
}

.kpi-value {
  margin: 0.2rem 0;
  font-size: 1.6rem;
  font-weight: 600;
}

.kpi-subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.85rem;
  color: var(--text-soft);
}

/* Country Comparison */

.comparison-section {
  margin: 1.5rem 0;
  padding: 1.25rem;
  border-radius: 0.9rem;
  border: 1px solid var(--border-subtle);
  background: linear-gradient(
    135deg,
    rgba(15, 23, 42, 0.95),
    rgba(15, 23, 42, 0.98)
  );
}

.comparison-section h2 {
  margin: 0 0 0.3rem 0;
  font-size: 1.1rem;
}

.comparison-subtitle {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.comparison-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.comparison-table th,
.comparison-table td {
  padding: 0.6rem 0.8rem;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}

.comparison-table th {
  font-weight: 600;
  color: var(--text-main);
  background: rgba(15, 23, 42, 0.5);
}

.comparison-table th:first-child {
  border-radius: 0.4rem 0 0 0;
}

.comparison-table th:last-child {
  border-radius: 0 0.4rem 0 0;
}

.comparison-table td {
  color: var(--text-muted);
}

.comparison-table td:not(:first-child) {
  font-family: "SF Mono", "Monaco", "Inconsolata", monospace;
  text-align: right;
}

.comparison-table th:not(:first-child) {
  text-align: right;
}

.comparison-table tbody tr:hover {
  background: rgba(34, 197, 94, 0.05);
}

.comparison-table tbody tr:last-child td {
  border-bottom: none;
}

.comparison-value-better {
  color: var(--accent);
}

.comparison-value-worse {
  color: #f87171;
}

.clear-comparison-btn {
  color: #f87171;
}

.clear-comparison-btn:hover {
  background: rgba(248, 113, 113, 0.1);
  border-color: #f87171;
}

/* Charts */

.charts-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.1rem;
}

@media (min-width: 900px) {
  .charts-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.chart-card {
  padding: 1rem 1.1rem 0.9rem;
  border-radius: 0.9rem;
  border: 1px solid var(--border-subtle);
  background: radial-gradient(circle at top left, #0f172a 0, #020617 50%);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.85);
}

.chart-header h3 {
  margin: 0 0 0.25rem;
  font-size: 0.95rem;
}

.chart-header p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-soft);
}

.chart-container {
  margin-top: 0.75rem;
  height: 260px;
}

.chart-note {
  margin: 0.4rem 0 0;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--text-soft);
}

/* Sources */

.sources h2 {
  margin-bottom: 0.4rem;
}

.sources ul {
  list-style: none;
  padding: 0;
  margin: 0 0 0.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-size: 0.86rem;
}

.sources a {
  color: var(--accent);
  text-decoration: none;
}

.sources a:hover {
  text-decoration: underline;
}

.sources-note {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  color: var(--text-soft);
}

/* About section */

.about {
  padding: 1rem 1.25rem;
  border-radius: 0.9rem;
  border: 1px solid var(--border-subtle);
  background: linear-gradient(
    135deg,
    rgba(15, 23, 42, 0.9),
    rgba(15, 23, 42, 0.95)
  );
}

.about h2 {
  margin: 0 0 0.5rem;
}

.about p {
  margin: 0 0 0.6rem;
  line-height: 1.55;
  color: var(--text-muted);
  max-width: 720px;
}

.about p:last-child {
  margin-bottom: 0;
}

/* Status banner */

.status-banner {
  max-width: 1120px;
  margin: 0.75rem auto 0;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.85rem;
  text-align: center;
}

.status-banner[hidden] {
  display: none;
}

.status-banner--info {
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.4);
  color: #93c5fd;
}

.status-banner--warning {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: #fcd34d;
}

.status-banner--error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

/* General */

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  font-size: 0.83rem;
}

/* ==========================================================================
   Loading States & Skeleton UI
   ========================================================================== */

/* Skeleton shimmer animation */
@keyframes skeleton-shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* Base skeleton class */
.skeleton {
  background: linear-gradient(
    90deg,
    rgba(148, 163, 184, 0.1) 25%,
    rgba(148, 163, 184, 0.2) 50%,
    rgba(148, 163, 184, 0.1) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: 0.4rem;
}

/* Skeleton text line */
.skeleton-text {
  height: 1em;
  margin-bottom: 0.5rem;
}

.skeleton-text--short {
  width: 40%;
}

.skeleton-text--medium {
  width: 70%;
}

.skeleton-text--long {
  width: 90%;
}

/* Skeleton for KPI values */
.skeleton-kpi-value {
  height: 1.6rem;
  width: 80%;
  margin: 0.2rem 0;
}

.skeleton-kpi-subtitle {
  height: 0.85rem;
  width: 60%;
  margin-top: 0.5rem;
}

/* Skeleton for chart containers */
.skeleton-chart {
  height: 100%;
  width: 100%;
  min-height: 200px;
}

/* Loading spinner */
@keyframes spinner-rotate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(148, 163, 184, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spinner-rotate 0.8s linear infinite;
}

/* Loading overlay for charts section */
.charts-loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(2, 6, 23, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  border-radius: 0.9rem;
  z-index: 10;
  opacity: 1;
  transition: opacity 0.3s ease-out;
}

.charts-loading-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

.charts-loading-overlay span {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Container for chart cards needs relative positioning for overlay */
.chart-card {
  position: relative;
}

/* Charts grid needs relative positioning for the loading overlay */
.charts-grid {
  position: relative;
}

/* Smooth fade-in for loaded content */
.fade-in {
  animation: fade-in 0.4s ease-out forwards;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Hide skeleton content when data is loaded */
.skeleton-hidden {
  display: none;
}

/* ==========================================================================
   Export Modal
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.modal-overlay[hidden] {
  opacity: 0;
  visibility: hidden;
  display: none;
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 420px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95);
  transition: transform 0.2s ease;
}

.modal-overlay:not([hidden]) .modal {
  transform: scale(1);
}

.modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.modal__title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-main);
  margin: 0;
}

.modal__close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem;
  transition: color 0.15s ease;
}

.modal__close:hover {
  color: var(--text-main);
}

.modal__body {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.modal__description {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0;
}

.export-options {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.export-options__title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 0.5rem;
}

.export-options__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
}

.export-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 0.75rem;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text-main);
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  text-align: center;
}

.export-option:hover {
  background: rgba(15, 23, 42, 0.9);
  border-color: var(--accent);
}

.export-option:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.export-option:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.export-option__icon {
  width: 28px;
  height: 28px;
  color: var(--accent);
  flex-shrink: 0;
}

.export-option__label {
  font-weight: 600;
  font-size: 0.95rem;
}

.export-option__desc {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.export-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-subtle);
  margin-top: 0.75rem;
}

.export-meta__info {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0;
}

.export-meta__info strong {
  color: var(--text-main);
}

.export-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.5rem 0;
  font-size: 0.8rem;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.export-divider::before,
.export-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}

/* Export button on chart cards */
.chart-card .card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.export-chart-btn {
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.export-chart-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* KPI card copy button */
.kpi-card {
  position: relative;
}

.kpi-copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: transparent;
  border: none;
  color: var(--text-soft);
  cursor: pointer;
  padding: 0.25rem;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.kpi-card:hover .kpi-copy-btn {
  opacity: 1;
}

.kpi-copy-btn:hover {
  color: var(--accent);
}

.kpi-copy-btn svg {
  width: 16px;
  height: 16px;
}

.kpi-value--copied {
  color: var(--accent) !important;
  transition: color 0.2s ease;
}

/* Copy success toast */
.copy-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  background: var(--accent);
  color: #020617;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  z-index: 200;
}

.copy-toast.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* ==========================================================================
   Mobile Responsiveness (screens under 640px)
   ========================================================================== */

@media (max-width: 640px) {
  /* Header - stack vertically on mobile */
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
  }

  .brand-name {
    font-size: 0.95rem;
  }

  .header-right {
    width: 100%;
    justify-content: space-between;
  }

  .header-meta {
    font-size: 0.8rem;
  }

  /* Language toggle - touch-friendly tap targets */
  .lang-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Cache indicator - smaller on mobile */
  .cache-indicator {
    padding: 0.2rem 0.5rem;
    font-size: 0.7rem;
  }

  .cache-indicator__text {
    display: none;
  }

  /* Refresh button - icon only on mobile */
  .refresh-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 0.5rem;
    justify-content: center;
  }

  .refresh-btn__text {
    display: none;
  }

  .refresh-btn__icon {
    width: 18px;
    height: 18px;
  }

  /* Main content - tighter padding on mobile */
  .app-main {
    padding: 1rem 0.75rem 2rem;
    gap: 1.25rem;
  }

  /* Filter controls - stack vertically */
  .filter-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .filter-controls label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
  }

  .filter-controls select {
    margin-left: 0;
    width: 100%;
    min-height: 44px;
    padding: 0.5rem 0.75rem;
    font-size: 1rem;
  }

  .filter-controls button {
    width: 100%;
    min-height: 44px;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
  }

  /* KPI cards - single column on mobile */
  .kpi-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .kpi-card {
    padding: 0.9rem 1rem;
  }

  .kpi-card h3 {
    font-size: 0.9rem;
  }

  .kpi-value {
    font-size: 1.4rem;
  }

  .kpi-subtitle {
    font-size: 0.8rem;
  }

  /* Charts - reduced height on mobile */
  .charts-grid {
    gap: 1rem;
  }

  .chart-card {
    padding: 0.9rem 0.9rem 0.75rem;
  }

  .chart-header h3 {
    font-size: 0.9rem;
  }

  .chart-header p {
    font-size: 0.75rem;
  }

  .chart-container {
    height: 200px;
    margin-top: 0.5rem;
  }

  .chart-note {
    font-size: 0.75rem;
    margin-top: 0.35rem;
  }

  /* About section */
  .about {
    padding: 0.9rem 1rem;
  }

  .about h2 {
    font-size: 1.1rem;
  }

  .about p {
    font-size: 0.9rem;
    line-height: 1.5;
  }

  /* Filters section */
  .filters h2 {
    font-size: 1.1rem;
  }

  .filters-text {
    font-size: 0.9rem;
    line-height: 1.5;
  }

  /* Sources - stack links vertically */
  .sources h2 {
    font-size: 1.1rem;
  }

  .sources ul {
    flex-direction: column;
    gap: 0.5rem;
  }

  .sources a {
    display: inline-block;
    padding: 0.5rem 0;
    min-height: 44px;
    line-height: 1.8;
  }

  .sources-note {
    font-size: 0.75rem;
  }

  /* Status banner */
  .status-banner {
    margin: 0.5rem 0.75rem 0;
    padding: 0.75rem 1rem;
    font-size: 0.8rem;
    line-height: 1.4;
  }

  /* Footer */
  .app-footer {
    padding: 0.75rem 1rem;
    font-size: 0.8rem;
  }

  /* Loading states adjustments for mobile */
  .skeleton-chart {
    min-height: 180px;
  }

  .loading-spinner {
    width: 32px;
    height: 32px;
  }

  .charts-loading-overlay span {
    font-size: 0.85rem;
  }

  /* Export modal mobile adjustments */
  .modal {
    width: 95%;
    padding: 1rem;
  }

  .modal__title {
    font-size: 1rem;
  }

  .export-options__grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .export-option {
    padding: 0.75rem 0.5rem;
    font-size: 0.9rem;
  }

  .export-option__icon {
    width: 24px;
    height: 24px;
  }

  .export-option__label {
    font-size: 0.85rem;
  }

  .export-option__desc {
    font-size: 0.7rem;
  }

  .kpi-copy-btn {
    opacity: 1;
  }

  .copy-toast {
    bottom: 1rem;
    font-size: 0.8rem;
  }
}

/* Extra small screens (under 360px) */
@media (max-width: 360px) {
  .app-main {
    padding: 0.75rem 0.5rem 1.5rem;
  }

  .brand-name {
    font-size: 0.85rem;
  }

  .kpi-value {
    font-size: 1.25rem;
  }

  .chart-container {
    height: 180px;
  }

  .filter-controls select,
  .filter-controls button {
    font-size: 0.9rem;
  }
}

/* Ensure horizontal scroll for any potential data tables */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Touch-friendly focus states */
@media (hover: none) and (pointer: coarse) {
  .lang-btn:active {
    background: var(--accent-soft);
  }

  .filter-controls button:active {
    background: var(--accent-soft);
    border-color: var(--accent);
  }

  .sources a:active {
    opacity: 0.7;
  }
}

/* ==========================================================================
   Chart Controls (Zoom, Pan, Type Toggle)
   ========================================================================== */

/* Chart header layout with controls */
.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.chart-header__title-group {
  flex: 1;
  min-width: 200px;
}

.chart-header__title-group h3 {
  margin: 0 0 0.25rem;
  font-size: 0.95rem;
}

.chart-header__title-group p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-soft);
}

/* Chart controls container */
.chart-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* Chart type toggle buttons */
.chart-type-toggle {
  display: inline-flex;
  border-radius: 0.4rem;
  padding: 2px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-subtle);
}

.chart-type-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  border-radius: 0.3rem;
  transition: all 0.15s ease;
}

.chart-type-btn:hover {
  color: var(--text-main);
  background: rgba(148, 163, 184, 0.1);
}

.chart-type-btn--active {
  background: var(--accent-soft);
  color: var(--accent);
}

.chart-type-btn--active:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.chart-type-btn svg {
  width: 16px;
  height: 16px;
}

/* Reset zoom button */
.reset-zoom-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.6rem;
  border-radius: 0.4rem;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.6);
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.reset-zoom-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.reset-zoom-btn[hidden] {
  display: none;
}

.reset-zoom-btn svg {
  width: 14px;
  height: 14px;
}

/* Crosshair cursor for charts when zooming */
.chart-container canvas {
  cursor: crosshair;
}

/* Zoom hint tooltip */
.zoom-hint {
  position: absolute;
  bottom: 0.5rem;
  right: 0.5rem;
  padding: 0.25rem 0.5rem;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--border-subtle);
  border-radius: 0.3rem;
  font-size: 0.7rem;
  color: var(--text-soft);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 5;
}

.chart-card:hover .zoom-hint {
  opacity: 1;
}

/* Event annotation styles */
.chart-annotation-label {
  font-size: 10px;
  font-weight: 500;
}

/* YoY change indicator in tooltip */
.yoy-change {
  font-size: 0.85em;
  margin-left: 0.5em;
}

.yoy-change--positive {
  color: var(--accent);
}

.yoy-change--negative {
  color: #f87171;
}

/* Mobile adjustments for chart controls */
@media (max-width: 640px) {
  .chart-header {
    flex-direction: column;
    gap: 0.5rem;
  }

  .chart-controls {
    width: 100%;
    justify-content: flex-start;
  }

  .chart-type-btn {
    width: 32px;
    height: 32px;
  }

  .reset-zoom-btn {
    padding: 0.4rem 0.7rem;
  }

  .zoom-hint {
    display: none;
  }
}

/* Annotation line styles (for event markers) */
.chartjs-annotation-line {
  pointer-events: none;
}

/* ==========================================================================
   Forecast Controls and Display
   ========================================================================== */

/* Forecast controls section */
.forecast-controls {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-subtle);
}

.forecast-controls__title {
  margin: 0 0 0.75rem 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

.forecast-controls__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.forecast-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.forecast-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.forecast-toggle__label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.forecast-dependent-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding-left: 1rem;
  border-left: 2px solid var(--accent-soft);
}

.forecast-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.forecast-control select {
  padding: 0.25rem 0.5rem;
  border-radius: 0.4rem;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text-main);
  font-size: 0.85rem;
}

/* Slider controls for forecast settings */
.forecast-control--slider {
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
}

.forecast-control--slider input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 140px;
  height: 6px;
  border-radius: 3px;
  background: rgba(148, 163, 184, 0.25);
  cursor: pointer;
}

.forecast-control--slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 4px rgba(34, 197, 94, 0.4);
  transition: transform 0.1s ease;
}

.forecast-control--slider input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.forecast-control--slider input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
  box-shadow: 0 0 4px rgba(34, 197, 94, 0.4);
}

.forecast-slider-value {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
  min-width: 55px;
}

/* Forecast model badge on charts */
.forecast-model-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.5rem;
  border-radius: 0.3rem;
  background: rgba(34, 197, 94, 0.15);
  border: 1px solid rgba(34, 197, 94, 0.3);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.forecast-model-badge--arima {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.3);
  color: #3b82f6;
}

.forecast-model-badge--exponential {
  background: rgba(168, 85, 247, 0.15);
  border-color: rgba(168, 85, 247, 0.3);
  color: #a855f7;
}

.forecast-model-badge--holt_winters {
  background: rgba(236, 72, 153, 0.15);
  border-color: rgba(236, 72, 153, 0.3);
  color: #ec4899;
}

/* Forecast diagnostics tooltip */
.forecast-diagnostics-tooltip {
  position: absolute;
  z-index: 100;
  padding: 0.6rem 0.8rem;
  border-radius: 0.5rem;
  background: rgba(15, 23, 42, 0.98);
  border: 1px solid var(--border-subtle);
  font-size: 0.75rem;
  color: var(--text-muted);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  max-width: 220px;
}

.forecast-diagnostics-tooltip__title {
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.3rem;
}

.forecast-diagnostics-tooltip__row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.2rem;
}

.forecast-diagnostics-tooltip__label {
  color: var(--text-soft);
}

.forecast-diagnostics-tooltip__value {
  font-family: "SF Mono", "Monaco", "Inconsolata", monospace;
  color: var(--text-main);
}

/* Forecast table section */
.forecast-section {
  margin: 1.5rem 0;
  padding: 1.25rem;
  border-radius: 0.9rem;
  border: 1px solid var(--border-subtle);
  background: linear-gradient(
    135deg,
    rgba(15, 23, 42, 0.95),
    rgba(15, 23, 42, 0.98)
  );
}

.forecast-section h2 {
  margin: 0 0 0.3rem 0;
  font-size: 1.1rem;
}

.forecast-subtitle {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.forecast-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.forecast-table th,
.forecast-table td {
  padding: 0.6rem 0.8rem;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}

.forecast-table th {
  font-weight: 600;
  color: var(--text-main);
  background: rgba(15, 23, 42, 0.5);
}

.forecast-table th:first-child {
  border-radius: 0.4rem 0 0 0;
}

.forecast-table th:last-child {
  border-radius: 0 0.4rem 0 0;
}

.forecast-table td {
  color: var(--text-muted);
}

.forecast-table td:not(:first-child) {
  font-family: "SF Mono", "Monaco", "Inconsolata", monospace;
  text-align: right;
}

.forecast-table th:not(:first-child) {
  text-align: right;
}

.forecast-table tbody tr:hover {
  background: rgba(34, 197, 94, 0.05);
}

.forecast-table tbody tr:last-child td {
  border-bottom: none;
}

/* Forecast quality indicators */
.forecast-quality--good {
  color: var(--accent);
}

.forecast-quality--weak {
  color: #f59e0b;
}

/* Forecast disclaimer */
.forecast-disclaimer {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.forecast-disclaimer h4 {
  margin: 0 0 0.4rem 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: #fcd34d;
}

.forecast-disclaimer p {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.5;
  color: #fcd34d;
  opacity: 0.9;
}

/* Mobile adjustments for forecast controls */
@media (max-width: 640px) {
  .forecast-controls__row {
    flex-direction: column;
    align-items: flex-start;
  }

  .forecast-dependent-controls {
    flex-direction: column;
    align-items: flex-start;
    padding-left: 0.75rem;
    gap: 0.75rem;
  }

  .forecast-control {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }

  .forecast-control select {
    width: 100%;
    min-height: 44px;
  }

  .forecast-toggle {
    min-height: 44px;
  }

  .forecast-table {
    font-size: 0.8rem;
  }

  .forecast-table th,
  .forecast-table td {
    padding: 0.5rem 0.4rem;
  }

  .forecast-disclaimer {
    padding: 0.6rem 0.75rem;
  }

  .forecast-disclaimer h4 {
    font-size: 0.85rem;
  }

  .forecast-disclaimer p {
    font-size: 0.75rem;
  }
}

/* ==========================================================================
   Correlation Matrix
   ========================================================================== */

.correlation-section {
  margin: 1.5rem 0;
  padding: 1.25rem;
  border-radius: 0.9rem;
  border: 1px solid var(--border-subtle);
  background: linear-gradient(
    135deg,
    rgba(15, 23, 42, 0.95),
    rgba(15, 23, 42, 0.98)
  );
}

.correlation-section h2 {
  margin: 0 0 0.3rem 0;
  font-size: 1.1rem;
}

.correlation-subtitle {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.correlation-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.correlation-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.correlation-control select {
  padding: 0.3rem 0.6rem;
  border-radius: 0.4rem;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text-main);
  font-size: 0.85rem;
}

.correlation-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.correlation-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.correlation-hint {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  opacity: 0.8;
  font-style: italic;
}

.correlation-matrix-wrapper {
  overflow-x: auto;
  margin-bottom: 1rem;
}

.correlation-matrix-container {
  min-width: fit-content;
}

.correlation-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem;
}

/* Correlation Table */
.correlation-table {
  border-collapse: separate;
  border-spacing: 2px;
  font-size: 0.8rem;
}

.correlation-table th,
.correlation-table td {
  padding: 0.4rem 0.5rem;
  text-align: center;
  min-width: 55px;
}

.correlation-corner {
  background: transparent;
}

.correlation-header {
  font-weight: 600;
  color: var(--text-main);
  background: rgba(15, 23, 42, 0.5);
  border-radius: 0.3rem;
  writing-mode: vertical-lr;
  text-orientation: mixed;
  transform: rotate(180deg);
  white-space: nowrap;
  padding: 0.5rem 0.3rem;
  height: 80px;
}

.correlation-row-header {
  font-weight: 600;
  color: var(--text-main);
  background: rgba(15, 23, 42, 0.5);
  border-radius: 0.3rem;
  text-align: right;
  padding-right: 0.6rem;
  white-space: nowrap;
}

.correlation-cell {
  border-radius: 0.3rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  font-family: "SF Mono", "Monaco", "Inconsolata", monospace;
  font-size: 0.75rem;
}

.correlation-cell:hover:not(.correlation-cell--diagonal) {
  transform: scale(1.1);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
  z-index: 1;
  position: relative;
}

.correlation-cell--diagonal {
  cursor: default;
  opacity: 0.5;
}

.correlation-cell--strong {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.6);
}

/* Correlation Legend */
.correlation-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

.correlation-legend__item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.correlation-legend__color {
  width: 20px;
  height: 14px;
  border-radius: 3px;
}

.correlation-legend__color--positive {
  background: rgba(34, 197, 94, 0.6);
}

.correlation-legend__color--negative {
  background: rgba(239, 68, 68, 0.6);
}

.correlation-legend__color--strong {
  background: rgba(100, 100, 100, 0.4);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.6);
}

/* Correlation Explanation */
.correlation-explanation {
  margin-top: 0.5rem;
  padding: 0.75rem;
  border-radius: 0.5rem;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.correlation-explanation summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  color: #93c5fd;
}

.correlation-explanation summary:hover {
  color: #bfdbfe;
}

.correlation-explanation p {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  line-height: 1.6;
  color: #93c5fd;
  opacity: 0.9;
}

/* Scatter Plot Modal */
.modal-content--chart {
  max-width: 700px;
  width: 95%;
}

.scatter-plot-container {
  height: 400px;
  margin-top: 1rem;
}

#scatter-plot-title {
  margin: 0;
  font-size: 1rem;
  color: var(--text-main);
}

/* Mobile adjustments for correlation matrix */
@media (max-width: 768px) {
  .correlation-controls {
    flex-direction: column;
    align-items: flex-start;
  }

  .correlation-control {
    width: 100%;
  }

  .correlation-control select {
    flex: 1;
    min-height: 44px;
  }

  .correlation-toggle {
    min-height: 44px;
  }

  .correlation-table {
    font-size: 0.7rem;
  }

  .correlation-table th,
  .correlation-table td {
    padding: 0.3rem 0.35rem;
    min-width: 45px;
  }

  .correlation-header {
    height: 65px;
    font-size: 0.65rem;
  }

  .correlation-row-header {
    font-size: 0.65rem;
  }

  .correlation-cell {
    font-size: 0.65rem;
  }

  .correlation-legend {
    flex-direction: column;
    gap: 0.5rem;
  }

  .scatter-plot-container {
    height: 300px;
  }
}

@media (max-width: 480px) {
  .correlation-table th,
  .correlation-table td {
    min-width: 38px;
    padding: 0.25rem;
  }

  .correlation-header {
    height: 55px;
    font-size: 0.6rem;
  }

  .correlation-cell {
    font-size: 0.6rem;
  }
}

/* ==========================================================================
   Year-over-Year Analysis
   ========================================================================== */

/* YoY Controls */
.yoy-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
}

.yoy-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.yoy-toggle-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.yoy-toggle-btn.yoy-toggle--active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.yoy-toggle-btn__icon {
  width: 16px;
  height: 16px;
}

.yoy-mode-btn {
  padding: 0.35rem 0.6rem;
  border-radius: 0.4rem;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.yoy-mode-btn:hover {
  background: rgba(34, 197, 94, 0.1);
  border-color: var(--accent);
}

/* YoY Section */
.yoy-section {
  margin: 1.5rem 0;
  padding: 1.25rem;
  border-radius: 0.9rem;
  border: 1px solid var(--border-subtle);
  background: linear-gradient(
    135deg,
    rgba(15, 23, 42, 0.95),
    rgba(15, 23, 42, 0.98)
  );
}

.yoy-section h2 {
  margin: 0 0 0.3rem 0;
  font-size: 1.1rem;
}

.yoy-subtitle {
  margin: 0 0 1.25rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* YoY Card Grid */
.yoy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.yoy-card {
  padding: 1rem;
  border-radius: 0.6rem;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.6);
  transition: border-color 0.2s ease;
}

.yoy-card:hover {
  border-color: rgba(148, 163, 184, 0.3);
}

.yoy-card__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.yoy-card__title {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.sparkline {
  flex-shrink: 0;
}

.yoy-card__body {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 0.75rem;
}

.yoy-card__current {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
}

.yoy-card__value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
  font-family: "SF Mono", "Monaco", "Inconsolata", monospace;
}

.yoy-card__unit {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.yoy-card__change {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 0.35rem 0.6rem;
  border-radius: 0.4rem;
}

.yoy-card__change-value {
  font-size: 1rem;
  font-weight: 600;
  font-family: "SF Mono", "Monaco", "Inconsolata", monospace;
}

.yoy-card__change-label {
  font-size: 0.65rem;
  opacity: 0.8;
}

/* YoY Color Classes */
.yoy-positive {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}

.yoy-negative {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.yoy-neutral {
  background: rgba(148, 163, 184, 0.15);
  color: #9ca3af;
}

/* YoY Card Footer */
.yoy-card__footer {
  display: flex;
  justify-content: space-between;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.75rem;
}

.yoy-card__best,
.yoy-card__worst {
  display: flex;
  gap: 0.3rem;
}

.yoy-card__best-label,
.yoy-card__worst-label {
  color: var(--text-muted);
}

.yoy-card__best-value {
  color: #22c55e;
  font-family: "SF Mono", "Monaco", "Inconsolata", monospace;
}

.yoy-card__worst-value {
  color: #ef4444;
  font-family: "SF Mono", "Monaco", "Inconsolata", monospace;
}

/* YoY Bar Chart Section */
.yoy-chart-section {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-subtle);
}

.yoy-chart-section h3 {
  margin: 0 0 1rem 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

.yoy-chart-container {
  height: 250px;
  position: relative;
}

/* Mobile adjustments for YoY */
@media (max-width: 768px) {
  .yoy-controls {
    flex-wrap: wrap;
  }

  .yoy-grid {
    grid-template-columns: 1fr;
  }

  .yoy-card__value {
    font-size: 1.3rem;
  }

  .yoy-card__change-value {
    font-size: 0.9rem;
  }

  .yoy-chart-container {
    height: 200px;
  }
}

@media (max-width: 480px) {
  .yoy-toggle-btn,
  .yoy-mode-btn {
    min-height: 44px;
  }

  .yoy-card__footer {
    flex-direction: column;
    gap: 0.4rem;
  }
}

/* ==========================================================================
   Real-time Data Styles
   ========================================================================== */

/* Real-time container in header */
.realtime-container {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-left: auto;
  margin-right: 1rem;
}

/* Live badge */
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: all 0.3s ease;
}

.live-badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  transition: all 0.3s ease;
}

.live-badge--connected {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.live-badge--connected .live-badge__dot {
  background: #22c55e;
  box-shadow: 0 0 8px #22c55e;
  animation: pulse-live 2s ease-in-out infinite;
}

.live-badge--disconnected {
  background: rgba(107, 114, 128, 0.15);
  color: #9ca3af;
  border: 1px solid rgba(107, 114, 128, 0.3);
}

.live-badge--disconnected .live-badge__dot {
  background: #6b7280;
}

.live-badge--connecting {
  background: rgba(234, 179, 8, 0.15);
  color: #eab308;
  border: 1px solid rgba(234, 179, 8, 0.3);
}

.live-badge--connecting .live-badge__dot {
  background: #eab308;
  animation: pulse-connecting 1s ease-in-out infinite;
}

.live-badge--error {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.live-badge--error .live-badge__dot {
  background: #ef4444;
}

@keyframes pulse-live {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.6;
    transform: scale(1.2);
  }
}

@keyframes pulse-connecting {
  0%, 100% {
    opacity: 0.4;
  }
  50% {
    opacity: 1;
  }
}

/* Forex ticker */
.forex-ticker {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.75rem;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: "SF Mono", "Fira Code", monospace;
  transition: all 0.3s ease;
}

.forex-ticker--updated {
  animation: ticker-pulse 1s ease-out;
}

@keyframes ticker-pulse {
  0% {
    background: rgba(34, 197, 94, 0.2);
    border-color: rgba(34, 197, 94, 0.4);
  }
  100% {
    background: rgba(15, 23, 42, 0.8);
    border-color: var(--border-subtle);
  }
}

.forex-ticker__pair {
  color: var(--text-muted);
  font-weight: 500;
}

.forex-ticker__rate {
  color: var(--text-main);
  font-weight: 600;
}

.forex-ticker__change {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-weight: 500;
}

.forex-ticker__change--up {
  color: #22c55e;
  background: rgba(34, 197, 94, 0.15);
}

.forex-ticker__change--down {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
}

/* Toast notifications */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(8px);
  font-size: 0.85rem;
  max-width: 400px;
  opacity: 0;
  transform: translateX(100%);
  transition: all 0.3s ease;
  pointer-events: auto;
}

.toast--visible {
  opacity: 1;
  transform: translateX(0);
}

.toast--hiding {
  opacity: 0;
  transform: translateX(100%);
}

.toast__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  border-radius: 50%;
}

.toast--info .toast__icon {
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
}

.toast--success .toast__icon {
  background: linear-gradient(135deg, #22c55e, #16a34a);
}

.toast--warning .toast__icon {
  background: linear-gradient(135deg, #eab308, #ca8a04);
}

.toast--error .toast__icon {
  background: linear-gradient(135deg, #ef4444, #dc2626);
}

.toast__message {
  flex: 1;
  color: var(--text-main);
}

.toast__close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.toast__close:hover {
  opacity: 1;
  color: var(--text-main);
}

/* Responsive adjustments for real-time UI */
@media (max-width: 768px) {
  .realtime-container {
    gap: 0.5rem;
    margin-right: 0.5rem;
  }

  .live-badge {
    padding: 0.2rem 0.5rem;
    font-size: 0.65rem;
  }

  .forex-ticker {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
  }

  .forex-ticker__change {
    display: none;
  }

  .toast-container {
    left: 1rem;
    right: 1rem;
  }

  .toast {
    max-width: none;
  }
}

@media (max-width: 480px) {
  .forex-ticker {
    display: none;
  }

  .live-badge__text {
    display: none;
  }

  .live-badge {
    padding: 0.35rem;
    border-radius: 50%;
  }

  .live-badge__dot {
    width: 8px;
    height: 8px;
  }
}

/* ==========================================================================
   AI Insights Panel Styles
   ========================================================================== */

/* Overlay */
.insights-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 998;
}

.insights-overlay--visible {
  opacity: 1;
  visibility: visible;
}

/* Panel */
.insights-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 100%;
  background: linear-gradient(180deg, #0f172a 0%, #020617 100%);
  border-left: 1px solid var(--border-subtle);
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.4);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.insights-panel--open {
  transform: translateX(0);
}

.insights-panel--loading {
  pointer-events: none;
}

.insights-panel--loading .insights-query-submit,
.insights-panel--loading .insights-summary-btn {
  opacity: 0.5;
}

/* Panel Header */
.insights-panel__header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.8);
  flex-shrink: 0;
}

.insights-panel__title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.insights-panel__title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.insights-panel__icon {
  font-size: 1.2rem;
}

.insights-panel__subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.75rem;
  color: var(--text-soft);
}

.insights-panel__close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 8px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.insights-panel__close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

/* Panel Content */
.insights-panel__content {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Sections */
.insights-section {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 1rem;
}

.insights-section__title {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Query Form */
.insights-query-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.insights-query-input-wrapper {
  display: flex;
  gap: 0.5rem;
}

.insights-query-input {
  flex: 1;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  color: var(--text-main);
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.insights-query-input::placeholder {
  color: var(--text-soft);
}

.insights-query-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1);
}

.insights-query-submit {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 0.75rem;
  color: #020617;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.insights-query-submit:hover:not(:disabled) {
  background: #16a34a;
  transform: scale(1.05);
}

.insights-query-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.insights-query-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.insights-query-suggestion {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.2);
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  color: var(--accent);
  cursor: pointer;
  transition: all 0.2s ease;
}

.insights-query-suggestion:hover {
  background: rgba(34, 197, 94, 0.2);
  border-color: var(--accent);
}

/* Response Section */
.insights-section--response {
  flex: 1;
  min-height: 200px;
  display: flex;
  flex-direction: column;
}

.insights-response {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.insights-response__empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  color: var(--text-soft);
  font-size: 0.9rem;
}

/* Loading State */
.insights-loading {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 2rem;
}

.insights-loading__spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(34, 197, 94, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: insights-spin 1s linear infinite;
}

@keyframes insights-spin {
  to {
    transform: rotate(360deg);
  }
}

.insights-loading__text {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Insight Response */
.insights-insight {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.insights-insight__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.insights-insight__type {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.insights-insight__time {
  font-size: 0.7rem;
  color: var(--text-soft);
}

.insights-insight__content {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text-main);
}

.insights-insight__content p {
  margin: 0 0 0.75rem;
}

.insights-insight__content p:last-child {
  margin-bottom: 0;
}

.insights-insight__content strong {
  color: var(--accent);
}

.insights-insight__content code {
  background: rgba(0, 0, 0, 0.3);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: "SF Mono", "Fira Code", monospace;
}

/* Error State */
.insights-error {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  gap: 0.75rem;
}

.insights-error__icon {
  font-size: 2rem;
}

.insights-error__message {
  margin: 0;
  color: #ef4444;
  font-size: 0.9rem;
}

.insights-error__hint {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.8rem;
}

/* Actions */
.insights-section--actions {
  padding: 0.75rem 1rem;
  background: transparent;
  border: none;
}

.insights-actions {
  display: flex;
  gap: 0.75rem;
}

.insights-action-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.insights-action-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

.insights-action-btn--success {
  background: rgba(34, 197, 94, 0.2) !important;
  border-color: var(--accent) !important;
  color: var(--accent) !important;
}

/* Summary Button */
.insights-summary-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.15), rgba(34, 197, 94, 0.05));
  border: 1px solid rgba(34, 197, 94, 0.3);
  border-radius: 10px;
  padding: 0.875rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  transition: all 0.2s ease;
}

.insights-summary-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.25), rgba(34, 197, 94, 0.1));
  border-color: var(--accent);
  transform: translateY(-1px);
}

.insights-summary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.insights-summary-btn__icon {
  font-size: 1.1rem;
}

/* Rate Limit */
.insights-rate-limit {
  padding: 0.75rem;
  text-align: center;
  border-top: 1px solid var(--border-subtle);
  margin-top: auto;
}

.insights-rate-limit__text {
  font-size: 0.75rem;
  color: var(--text-soft);
}

.insights-rate-limit__text strong {
  color: var(--text-muted);
}

/* Explain Button (added to charts) */
.chart-explain-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.2);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  transition: all 0.2s ease;
}

.chart-explain-btn:hover {
  background: rgba(34, 197, 94, 0.2);
  border-color: var(--accent);
}

.chart-explain-btn__icon {
  font-size: 0.85rem;
}

/* AI Insights Toggle Button (header) */
.ai-insights-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(34, 197, 94, 0.15));
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: #a78bfa;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ai-insights-toggle:hover {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.25), rgba(34, 197, 94, 0.2));
  border-color: #a78bfa;
  transform: translateY(-1px);
}

.ai-insights-toggle__icon {
  font-size: 1rem;
}

/* Responsive */
@media (max-width: 480px) {
  .insights-panel {
    width: 100%;
  }

  .insights-panel__content {
    padding: 1rem;
    gap: 1rem;
  }

  .insights-query-suggestions {
    display: none;
  }

  .ai-insights-toggle span:not(.ai-insights-toggle__icon) {
    display: none;
  }

  .ai-insights-toggle {
    padding: 0.5rem;
  }
}

/* =============================================================================
   ERROR HANDLING UI COMPONENTS
   ============================================================================= */

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
  max-width: 400px;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  background: var(--card-bg, rgba(30, 41, 59, 0.98));
  border: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.1));
  border-radius: 0.75rem;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4), 0 0 1px rgba(255, 255, 255, 0.1);
  pointer-events: auto;
  opacity: 0;
  transform: translateX(100%);
  transition: opacity 0.3s ease, transform 0.3s ease;
  backdrop-filter: blur(12px);
}

.toast--visible {
  opacity: 1;
  transform: translateX(0);
}

.toast--leaving {
  opacity: 0;
  transform: translateX(100%);
}

.toast-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
}

.toast-message {
  flex: 1;
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--text-main, #e2e8f0);
}

.toast-action {
  flex-shrink: 0;
  padding: 0.25rem 0.5rem;
  background: rgba(59, 130, 246, 0.2);
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 0.375rem;
  color: #60a5fa;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s;
}

.toast-action:hover {
  background: rgba(59, 130, 246, 0.3);
}

.toast-dismiss {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: transparent;
  border: none;
  border-radius: 0.375rem;
  color: var(--text-muted, #64748b);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.toast-dismiss:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main, #e2e8f0);
}

/* Toast severity variants */
.toast--info {
  border-left: 3px solid #3b82f6;
}

.toast--info .toast-icon {
  color: #3b82f6;
}

.toast--warning {
  border-left: 3px solid #f59e0b;
}

.toast--warning .toast-icon {
  color: #f59e0b;
}

.toast--error {
  border-left: 3px solid #ef4444;
}

.toast--error .toast-icon {
  color: #ef4444;
}

.toast--critical {
  border-left: 3px solid #dc2626;
  background: rgba(127, 29, 29, 0.95);
}

.toast--critical .toast-icon {
  color: #fca5a5;
}

/* Error Modal */
.error-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.error-modal-overlay--visible {
  opacity: 1;
  visibility: visible;
}

.error-modal {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--card-bg, rgba(30, 41, 59, 0.98));
  border: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.15));
  border-radius: 1rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.error-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.1));
}

.error-modal-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-main, #e2e8f0);
}

.error-modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: 0.5rem;
  color: var(--text-muted, #64748b);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.error-modal-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main, #e2e8f0);
}

.error-modal-body {
  padding: 1.5rem;
}

.error-modal-message {
  margin: 0 0 1rem;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-soft, #94a3b8);
}

.error-modal-details {
  margin-top: 1rem;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 0.5rem;
}

.error-modal-details summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted, #64748b);
}

.error-modal-details pre {
  margin: 0.75rem 0 0;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 0.375rem;
  font-family: "SF Mono", "Monaco", "Inconsolata", monospace;
  font-size: 0.8rem;
  color: var(--text-soft, #94a3b8);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.error-modal-footer {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.1));
}

.error-modal-action {
  padding: 0.625rem 1.25rem;
  border-radius: 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.error-modal-action:active {
  transform: scale(0.98);
}

.error-modal-action--primary {
  background: var(--accent-green, #22c55e);
  border: none;
  color: #0f172a;
}

.error-modal-action--primary:hover {
  background: #16a34a;
}

.error-modal-action--secondary {
  background: transparent;
  border: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.2));
  color: var(--text-soft, #94a3b8);
}

.error-modal-action--secondary:hover {
  background: rgba(255, 255, 255, 0.05);
}

/* Error modal severity variants */
.error-modal--error .error-modal-header {
  border-bottom-color: rgba(239, 68, 68, 0.3);
}

.error-modal--critical {
  border-color: rgba(220, 38, 38, 0.5);
}

.error-modal--critical .error-modal-header {
  background: rgba(127, 29, 29, 0.3);
  border-bottom-color: rgba(220, 38, 38, 0.3);
}

.error-modal--critical .error-modal-title {
  color: #fca5a5;
}

/* Error Boundary Fallback */
.error-boundary-fallback {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.5rem;
  background: rgba(30, 41, 59, 0.5);
  border: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.15));
  border-radius: 0.75rem;
}

.error-boundary-icon {
  font-size: 1.5rem;
}

.error-boundary-content {
  flex: 1;
}

.error-boundary-title {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main, #e2e8f0);
}

.error-boundary-message {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  color: var(--text-soft, #94a3b8);
}

.error-boundary-retry {
  padding: 0.5rem 1rem;
  background: rgba(59, 130, 246, 0.2);
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 0.5rem;
  color: #60a5fa;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.2s;
}

.error-boundary-retry:hover {
  background: rgba(59, 130, 246, 0.3);
}

/* Error boundary severity variants */
.error-boundary-fallback--warning {
  border-color: rgba(245, 158, 11, 0.3);
}

.error-boundary-fallback--error {
  border-color: rgba(239, 68, 68, 0.3);
}

.error-boundary-fallback--critical {
  background: rgba(127, 29, 29, 0.2);
  border-color: rgba(220, 38, 38, 0.4);
}

/* Chart Error Boundary */
.chart-error-boundary {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  padding: 2rem;
  text-align: center;
}

.chart-error-icon {
  margin-bottom: 1rem;
  color: var(--text-muted, #64748b);
  opacity: 0.5;
}

.chart-error-title {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main, #e2e8f0);
}

.chart-error-message {
  margin: 0 0 1.5rem;
  font-size: 0.9rem;
  color: var(--text-soft, #94a3b8);
}

.chart-error-actions {
  display: flex;
  gap: 0.75rem;
}

.chart-error-retry,
.chart-error-use-cached {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.2s;
}

.chart-error-retry {
  background: rgba(59, 130, 246, 0.2);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: #60a5fa;
}

.chart-error-retry:hover {
  background: rgba(59, 130, 246, 0.3);
}

.chart-error-use-cached {
  background: rgba(148, 163, 184, 0.1);
  border: 1px solid rgba(148, 163, 184, 0.2);
  color: var(--text-soft, #94a3b8);
}

.chart-error-use-cached:hover {
  background: rgba(148, 163, 184, 0.2);
}

/* Inline Error */
.inline-error {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: rgba(30, 41, 59, 0.5);
  border: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.15));
  border-radius: 0.5rem;
}

.inline-error--compact {
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
}

.inline-error-icon {
  flex-shrink: 0;
}

.inline-error-message {
  flex: 1;
  color: var(--text-soft, #94a3b8);
}

.inline-error-retry {
  flex-shrink: 0;
  padding: 0.25rem 0.5rem;
  background: rgba(59, 130, 246, 0.2);
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 0.375rem;
  color: #60a5fa;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s;
}

.inline-error-retry:hover {
  background: rgba(59, 130, 246, 0.3);
}

.inline-error--warning {
  border-color: rgba(245, 158, 11, 0.3);
}

.inline-error--error {
  border-color: rgba(239, 68, 68, 0.3);
}

.inline-error--critical {
  background: rgba(127, 29, 29, 0.2);
  border-color: rgba(220, 38, 38, 0.4);
}

/* Status Indicator */
.status-indicator {
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.875rem;
  background: var(--card-bg, rgba(30, 41, 59, 0.98));
  border: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.15));
  border-radius: 2rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  font-size: 0.8rem;
  transition: opacity 0.3s, transform 0.3s;
}

.status-indicator--hidden {
  opacity: 0;
  transform: translateY(1rem);
  pointer-events: none;
}

.status-indicator-icon {
  font-size: 0.7rem;
}

.status-indicator-text {
  color: var(--text-soft, #94a3b8);
}

.status-indicator--online .status-indicator-text {
  color: #22c55e;
}

.status-indicator--offline {
  border-color: rgba(239, 68, 68, 0.3);
}

.status-indicator--offline .status-indicator-text {
  color: #ef4444;
}

.status-indicator--queued {
  border-color: rgba(245, 158, 11, 0.3);
}

.status-indicator--queued .status-indicator-text {
  color: #f59e0b;
}

.status-indicator--error {
  border-color: rgba(239, 68, 68, 0.3);
}

.status-indicator--error .status-indicator-text {
  color: #ef4444;
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .toast-container {
    top: auto;
    bottom: 4rem;
    left: 1rem;
    right: 1rem;
    max-width: none;
  }

  .toast {
    border-radius: 0.625rem;
  }

  .error-modal {
    max-width: none;
    border-radius: 0.75rem;
  }

  .status-indicator {
    bottom: 0.75rem;
    left: 0.75rem;
  }
}

/* =============================================================================
   DATA QUALITY UI COMPONENTS
   ============================================================================= */

/* Quality Badge */
.quality-badge-container {
  margin-left: auto;
}

.quality-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.5rem;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.15));
  border-radius: 1rem;
  font-size: 0.75rem;
  transition: all 0.2s ease;
}

.quality-badge:hover {
  background: rgba(30, 41, 59, 0.95);
  transform: translateY(-1px);
}

.quality-badge--small {
  padding: 0.125rem 0.375rem;
  font-size: 0.7rem;
  gap: 0.25rem;
}

.quality-badge--large {
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  gap: 0.5rem;
}

.quality-badge__icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.quality-badge__score {
  font-weight: 600;
  font-family: "SF Mono", "Monaco", "Inconsolata", monospace;
}

.quality-badge__label {
  color: var(--text-soft, #94a3b8);
  text-transform: capitalize;
}

.quality-badge__issues {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.25rem;
  background: rgba(239, 68, 68, 0.2);
  border-radius: 0.625rem;
  color: #f87171;
  font-size: 0.65rem;
  font-weight: 600;
}

/* Quality badge color variants */
.quality-badge--excellent {
  border-color: rgba(34, 197, 94, 0.3);
}

.quality-badge--excellent .quality-badge__score {
  color: #22c55e;
}

.quality-badge--good {
  border-color: rgba(132, 204, 22, 0.3);
}

.quality-badge--good .quality-badge__score {
  color: #84cc16;
}

.quality-badge--fair {
  border-color: rgba(245, 158, 11, 0.3);
}

.quality-badge--fair .quality-badge__score {
  color: #f59e0b;
}

.quality-badge--poor {
  border-color: rgba(249, 115, 22, 0.3);
}

.quality-badge--poor .quality-badge__score {
  color: #f97316;
}

.quality-badge--critical {
  border-color: rgba(239, 68, 68, 0.3);
  background: rgba(127, 29, 29, 0.2);
}

.quality-badge--critical .quality-badge__score {
  color: #ef4444;
}

/* Anomaly Marker */
.anomaly-marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: bold;
  cursor: help;
}

.anomaly-marker--outlier {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.anomaly-marker--change {
  background: rgba(245, 158, 11, 0.2);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

/* Quality Modal */
.quality-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10001;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

.quality-modal-overlay--visible {
  opacity: 1;
  visibility: visible;
}

.quality-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  z-index: 10002;
  width: 90%;
  max-width: 700px;
  max-height: 85vh;
  background: var(--card-bg, rgba(30, 41, 59, 0.98));
  border: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.15));
  border-radius: 1rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s, transform 0.3s;
}

.quality-modal--visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
}

.quality-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.1));
}

.quality-modal__title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-main, #e2e8f0);
}

.quality-modal__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: 0.5rem;
  color: var(--text-muted, #64748b);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.quality-modal__close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main, #e2e8f0);
}

.quality-modal__body {
  padding: 1.5rem;
  max-height: calc(85vh - 140px);
  overflow-y: auto;
}

.quality-modal__summary {
  display: flex;
  gap: 2rem;
  margin-bottom: 1.5rem;
}

.quality-modal__overview {
  display: flex;
  gap: 2rem;
  align-items: center;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.1));
}

/* Quality Score Ring */
.quality-score-ring {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: conic-gradient(
    var(--score-color, #22c55e) var(--score-percent, 0%),
    rgba(148, 163, 184, 0.2) var(--score-percent, 0%)
  );
  flex-shrink: 0;
}

.quality-score-ring::before {
  content: '';
  position: absolute;
  inset: 8px;
  background: var(--card-bg, rgba(30, 41, 59, 0.98));
  border-radius: 50%;
}

.quality-score-ring__value {
  position: relative;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-main, #e2e8f0);
}

.quality-score-ring__label {
  position: relative;
  font-size: 0.75rem;
  color: var(--text-muted, #64748b);
  text-transform: capitalize;
}

/* Quality Stats */
.quality-stats {
  display: flex;
  gap: 1.5rem;
}

.quality-stat {
  text-align: center;
}

.quality-stat__value {
  display: block;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-main, #e2e8f0);
}

.quality-stat__label {
  font-size: 0.75rem;
  color: var(--text-muted, #64748b);
}

.quality-stat--warning .quality-stat__value {
  color: #f59e0b;
}

.quality-stat--error .quality-stat__value {
  color: #ef4444;
}

/* Quality Breakdown */
.quality-breakdown {
  flex: 1;
}

.quality-breakdown__title {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main, #e2e8f0);
}

.quality-breakdown__item {
  margin-bottom: 0.75rem;
}

.quality-breakdown__label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.25rem;
  font-size: 0.8rem;
  color: var(--text-soft, #94a3b8);
}

.quality-breakdown__bar {
  height: 6px;
  background: rgba(148, 163, 184, 0.2);
  border-radius: 3px;
  overflow: hidden;
}

.quality-breakdown__fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* Quality Issues */
.quality-issues {
  margin-top: 1.5rem;
}

.quality-issues__title {
  margin: 0 0 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main, #e2e8f0);
}

.quality-issues__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.quality-issue {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.625rem 0.75rem;
  margin-bottom: 0.5rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 0.5rem;
  border-left: 3px solid transparent;
}

.quality-issue--warning {
  border-left-color: #f59e0b;
}

.quality-issue--error {
  border-left-color: #ef4444;
}

.quality-issue--critical {
  border-left-color: #dc2626;
  background: rgba(127, 29, 29, 0.2);
}

.quality-issue__icon {
  flex-shrink: 0;
}

.quality-issue__text {
  font-size: 0.85rem;
  color: var(--text-soft, #94a3b8);
}

.quality-no-issues {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.5rem;
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.2);
  border-radius: 0.75rem;
  color: #22c55e;
  font-size: 0.9rem;
}

.quality-no-issues__icon {
  font-size: 1.25rem;
}

/* Quality Anomalies Table */
.quality-anomalies {
  margin-top: 1.5rem;
}

.quality-anomalies__title {
  margin: 0 0 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main, #e2e8f0);
}

.quality-anomalies__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.quality-anomalies__table th,
.quality-anomalies__table td {
  padding: 0.625rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.1));
}

.quality-anomalies__table th {
  font-weight: 600;
  color: var(--text-soft, #94a3b8);
  background: rgba(0, 0, 0, 0.2);
}

.quality-anomalies__table td {
  color: var(--text-main, #e2e8f0);
}

.anomaly-type-badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: capitalize;
}

.anomaly-type-badge--outlier {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
}

.anomaly-type-badge--sudden_change {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
}

/* Quality Indicators Grid */
.quality-indicators {
  margin-top: 1.5rem;
}

.quality-indicators__title {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main, #e2e8f0);
}

.quality-indicators__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}

.quality-indicator-card {
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.1));
  border-radius: 0.5rem;
  transition: border-color 0.2s;
}

.quality-indicator-card:hover {
  border-color: rgba(148, 163, 184, 0.25);
}

.quality-indicator-card__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.quality-indicator-card__name {
  font-size: 0.8rem;
  color: var(--text-soft, #94a3b8);
}

.quality-indicator-card__score {
  font-size: 0.875rem;
  font-weight: 600;
}

.quality-indicator-card__bar {
  height: 4px;
  background: rgba(148, 163, 184, 0.2);
  border-radius: 2px;
  overflow: hidden;
}

.quality-indicator-card__fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.5s ease;
}

.quality-indicator-card__issues {
  margin-top: 0.5rem;
  font-size: 0.7rem;
  color: #f59e0b;
}

/* Quality Correlations Table */
.quality-correlations {
  margin-top: 1.5rem;
}

.quality-correlations__title {
  margin: 0 0 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main, #e2e8f0);
}

.quality-correlations__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.quality-correlations__table th,
.quality-correlations__table td {
  padding: 0.625rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.1));
}

.quality-correlations__table th {
  font-weight: 600;
  color: var(--text-soft, #94a3b8);
  background: rgba(0, 0, 0, 0.2);
}

.correlation-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  font-size: 0.875rem;
}

.correlation-status--ok {
  background: rgba(34, 197, 94, 0.2);
  color: #22c55e;
}

.correlation-status--warning {
  background: rgba(245, 158, 11, 0.2);
  color: #f59e0b;
}

/* Quality Modal Footer */
.quality-modal__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.1));
}

.quality-modal__timestamp {
  font-size: 0.75rem;
  color: var(--text-muted, #64748b);
}

.quality-modal__btn {
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.quality-modal__btn:active {
  transform: scale(0.98);
}

.quality-modal__btn--primary {
  background: var(--accent-green, #22c55e);
  border: none;
  color: #0f172a;
}

.quality-modal__btn--primary:hover {
  background: #16a34a;
}

.quality-modal__btn--secondary {
  background: transparent;
  border: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.2));
  color: var(--text-soft, #94a3b8);
}

.quality-modal__btn--secondary:hover {
  background: rgba(255, 255, 255, 0.05);
}

/* Quality Warning Banner */
.quality-warning-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: rgba(127, 29, 29, 0.95);
  border-bottom: 1px solid rgba(239, 68, 68, 0.3);
  transform: translateY(-100%);
  transition: transform 0.3s ease;
}

.quality-warning-banner--visible {
  transform: translateY(0);
}

.quality-warning-banner__content {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.quality-warning-banner__icon {
  font-size: 1.25rem;
}

.quality-warning-banner__message {
  font-size: 0.9rem;
  color: #fecaca;
}

.quality-warning-banner__score {
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #0f172a;
}

.quality-warning-banner__issues {
  padding: 0.25rem 0.5rem;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 0.25rem;
  font-size: 0.8rem;
  color: #fecaca;
}

.quality-warning-banner__actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.quality-warning-banner__btn {
  padding: 0.375rem 0.75rem;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 0.375rem;
  color: #fecaca;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s;
}

.quality-warning-banner__btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.quality-warning-banner__dismiss {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: transparent;
  border: none;
  color: #fca5a5;
  font-size: 1.25rem;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.quality-warning-banner__dismiss:hover {
  opacity: 1;
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .quality-modal {
    width: 95%;
    max-height: 90vh;
  }

  .quality-modal__summary {
    flex-direction: column;
    gap: 1.5rem;
  }

  .quality-modal__overview {
    flex-direction: column;
  }

  .quality-stats {
    justify-content: center;
  }

  .quality-indicators__grid {
    grid-template-columns: 1fr;
  }

  .quality-warning-banner {
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
  }

  .quality-warning-banner__content {
    flex-wrap: wrap;
    justify-content: center;
    text-align: center;
  }
}

/* Quality Report Button in Header */
.quality-report-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.75rem;
  background: rgba(34, 197, 94, 0.15);
  border: 1px solid rgba(34, 197, 94, 0.25);
  border-radius: 0.5rem;
  color: #22c55e;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.quality-report-btn:hover {
  background: rgba(34, 197, 94, 0.25);
  transform: translateY(-1px);
}

.quality-report-btn svg {
  flex-shrink: 0;
}

@media (max-width: 640px) {
  .quality-report-btn span {
    display: none;
  }

  .quality-report-btn {
    padding: 0.5rem;
  }
}

/* ============================================================================
   Dashboard Builder Styles
   ============================================================================ */

/* Theme Variables for Light Mode */
[data-theme="light"] {
  --db-bg: #ffffff;
  --db-bg-elevated: #f8fafc;
  --db-card-bg: #ffffff;
  --db-border: #e2e8f0;
  --db-border-hover: #cbd5e1;
  --db-text: #1e293b;
  --db-text-muted: #64748b;
  --db-accent: #3b82f6;
  --db-accent-hover: #2563eb;
  --db-shadow: rgba(0, 0, 0, 0.1);
  --db-overlay: rgba(0, 0, 0, 0.5);
}

/* Theme Variables for Dark Mode (default) */
:root,
[data-theme="dark"] {
  --db-bg: #0f172a;
  --db-bg-elevated: #1e293b;
  --db-card-bg: #1e293b;
  --db-border: rgba(148, 163, 184, 0.2);
  --db-border-hover: rgba(148, 163, 184, 0.4);
  --db-text: #e2e8f0;
  --db-text-muted: #94a3b8;
  --db-accent: #3b82f6;
  --db-accent-hover: #60a5fa;
  --db-shadow: rgba(0, 0, 0, 0.3);
  --db-overlay: rgba(0, 0, 0, 0.7);
}

/* Dashboard Toolbar */
.dashboard-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--db-bg-elevated);
  border-bottom: 1px solid var(--db-border);
  gap: 1rem;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toolbar-center {
  flex: 1;
  justify-content: center;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.75rem;
  background: transparent;
  border: 1px solid var(--db-border);
  border-radius: 0.5rem;
  color: var(--db-text);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.toolbar-btn:hover:not(:disabled) {
  background: var(--db-bg-elevated);
  border-color: var(--db-border-hover);
}

.toolbar-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.toolbar-btn.primary {
  background: var(--db-accent);
  border-color: var(--db-accent);
  color: white;
}

.toolbar-btn.primary:hover {
  background: var(--db-accent-hover);
  border-color: var(--db-accent-hover);
}

.toolbar-btn svg {
  flex-shrink: 0;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--db-border);
  margin: 0 0.5rem;
}

/* Hide edit-only/view-only based on mode */
.dashboard-toolbar .edit-only {
  display: none;
}

.dashboard-toolbar.edit-mode .edit-only {
  display: flex;
}

.dashboard-toolbar.edit-mode .view-only {
  display: none;
}

/* Edit Mode Button Active State */
.dashboard-toolbar.edit-mode .edit-mode-btn {
  background: var(--db-accent);
  border-color: var(--db-accent);
  color: white;
}

/* Dashboard Grid Overlay */
.dashboard-grid-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 1;
}

.grid-line {
  position: absolute;
  background: var(--db-border);
  opacity: 0.3;
}

.grid-line.vertical {
  width: 1px;
  top: 0;
  bottom: 0;
}

.grid-line.horizontal {
  height: 1px;
  left: 0;
  right: 0;
}

/* Dashboard Container Edit Mode */
.charts-grid.edit-mode {
  position: relative;
  min-height: 600px;
  background:
    linear-gradient(90deg, var(--db-border) 1px, transparent 1px),
    linear-gradient(var(--db-border) 1px, transparent 1px);
  background-size: calc(100% / 12) 80px;
  background-position: 16px 16px;
}

.charts-grid.preview-mode .chart-card {
  pointer-events: none;
}

/* Widget Edit Container */
.widget-edit-container {
  position: absolute;
  background: var(--db-card-bg);
  border: 2px solid var(--db-border);
  border-radius: 0.75rem;
  cursor: move;
  overflow: hidden;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
  z-index: 5;
}

.widget-edit-container:hover {
  border-color: var(--db-accent);
  box-shadow: 0 4px 20px var(--db-shadow);
}

.widget-edit-container.selected {
  border-color: var(--db-accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.widget-edit-container.dragging {
  opacity: 0.8;
  z-index: 100;
  cursor: grabbing;
  box-shadow: 0 8px 30px var(--db-shadow);
}

.widget-edit-container.resizing {
  transition: none;
}

/* Widget Header */
.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--db-bg-elevated);
  border-bottom: 1px solid var(--db-border);
  cursor: grab;
}

.widget-header:active {
  cursor: grabbing;
}

.widget-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--db-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.widget-controls {
  display: flex;
  gap: 0.25rem;
}

.widget-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: transparent;
  border: none;
  border-radius: 0.375rem;
  color: var(--db-text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.widget-btn:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

/* Widget Preview */
.widget-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 1rem;
  color: var(--db-text-muted);
}

.widget-placeholder-icon {
  opacity: 0.3;
}

/* Resize Handles */
.resize-handle {
  position: absolute;
  z-index: 10;
}

.resize-handle.resize-e {
  right: -4px;
  top: 20%;
  width: 8px;
  height: 60%;
  cursor: ew-resize;
}

.resize-handle.resize-w {
  left: -4px;
  top: 20%;
  width: 8px;
  height: 60%;
  cursor: ew-resize;
}

.resize-handle.resize-n {
  top: -4px;
  left: 20%;
  width: 60%;
  height: 8px;
  cursor: ns-resize;
}

.resize-handle.resize-s {
  bottom: -4px;
  left: 20%;
  width: 60%;
  height: 8px;
  cursor: ns-resize;
}

.resize-handle.resize-se {
  right: -4px;
  bottom: -4px;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
}

.resize-handle.resize-sw {
  left: -4px;
  bottom: -4px;
  width: 16px;
  height: 16px;
  cursor: nesw-resize;
}

.resize-handle.resize-ne {
  right: -4px;
  top: -4px;
  width: 16px;
  height: 16px;
  cursor: nesw-resize;
}

.resize-handle.resize-nw {
  left: -4px;
  top: -4px;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
}

.widget-edit-container:hover .resize-handle::after,
.widget-edit-container.selected .resize-handle::after {
  content: '';
  position: absolute;
  background: var(--db-accent);
  border-radius: 2px;
}

.resize-handle.resize-e::after,
.resize-handle.resize-w::after {
  width: 4px;
  height: 24px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.resize-handle.resize-n::after,
.resize-handle.resize-s::after {
  width: 24px;
  height: 4px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.resize-handle.resize-se::after,
.resize-handle.resize-sw::after,
.resize-handle.resize-ne::after,
.resize-handle.resize-nw::after {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.resize-handle.resize-se::after {
  right: 2px;
  bottom: 2px;
}

.resize-handle.resize-sw::after {
  left: 2px;
  bottom: 2px;
}

.resize-handle.resize-ne::after {
  right: 2px;
  top: 2px;
}

.resize-handle.resize-nw::after {
  left: 2px;
  top: 2px;
}

/* Drop Placeholder */
.drop-placeholder {
  position: absolute;
  background: rgba(59, 130, 246, 0.1);
  border: 2px dashed var(--db-accent);
  border-radius: 0.75rem;
  pointer-events: none;
  z-index: 4;
}

/* Dashboard Sidebar */
.dashboard-sidebar {
  position: fixed;
  top: 0;
  right: -360px;
  width: 360px;
  height: 100vh;
  background: var(--db-bg);
  border-left: 1px solid var(--db-border);
  box-shadow: -4px 0 20px var(--db-shadow);
  overflow-y: auto;
  z-index: 1000;
  transition: right 0.3s ease;
}

.dashboard-sidebar.open {
  right: 0;
}

body.sidebar-open {
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: var(--db-bg-elevated);
  border-bottom: 1px solid var(--db-border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.sidebar-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--db-text);
}

.sidebar-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: 0.5rem;
  color: var(--db-text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.sidebar-close-btn:hover {
  background: var(--db-bg-elevated);
  color: var(--db-text);
}

.sidebar-content {
  padding: 1rem;
}

.sidebar-section {
  margin-bottom: 1.5rem;
}

.sidebar-section h4 {
  margin: 0 0 0.75rem 0;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--db-text-muted);
}

/* Widget Library */
.widget-library {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.widget-category h5 {
  margin: 0 0 0.5rem 0;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--db-text);
}

.widget-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 0.75rem;
  background: var(--db-bg-elevated);
  border: 1px solid var(--db-border);
  border-radius: 0.5rem;
  cursor: grab;
  transition: all 0.15s ease;
}

.widget-item:hover:not(.in-layout) {
  border-color: var(--db-accent);
  background: rgba(59, 130, 246, 0.05);
}

.widget-item.in-layout {
  opacity: 0.6;
  cursor: default;
}

.widget-name {
  font-size: 0.8125rem;
  color: var(--db-text);
}

.widget-status {
  font-size: 0.6875rem;
  color: var(--db-text-muted);
  font-style: italic;
}

.add-widget-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: var(--db-accent);
  border: none;
  border-radius: 0.375rem;
  color: white;
  font-size: 1.125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.add-widget-btn:hover {
  background: var(--db-accent-hover);
  transform: scale(1.1);
}

/* Preset List */
.preset-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.preset-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem;
  background: var(--db-bg-elevated);
  border: 1px solid var(--db-border);
  border-radius: 0.5rem;
  transition: all 0.15s ease;
}

.preset-item:hover {
  border-color: var(--db-border-hover);
}

.preset-info {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.preset-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--db-text);
}

.preset-description {
  font-size: 0.75rem;
  color: var(--db-text-muted);
}

.apply-preset-btn {
  padding: 0.375rem 0.75rem;
  background: transparent;
  border: 1px solid var(--db-border);
  border-radius: 0.375rem;
  color: var(--db-text);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.apply-preset-btn:hover {
  background: var(--db-accent);
  border-color: var(--db-accent);
  color: white;
}

/* Saved Layouts */
.saved-layouts-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.no-layouts {
  font-size: 0.8125rem;
  color: var(--db-text-muted);
  font-style: italic;
  text-align: center;
  padding: 1rem 0;
}

.saved-layout-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 0.75rem;
  background: var(--db-bg-elevated);
  border: 1px solid var(--db-border);
  border-radius: 0.5rem;
}

.layout-info {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.layout-name {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--db-text);
}

.layout-date {
  font-size: 0.6875rem;
  color: var(--db-text-muted);
}

.layout-actions {
  display: flex;
  gap: 0.375rem;
}

.load-layout-btn,
.delete-layout-btn {
  padding: 0.25rem 0.5rem;
  background: transparent;
  border: 1px solid var(--db-border);
  border-radius: 0.25rem;
  color: var(--db-text-muted);
  font-size: 0.6875rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.load-layout-btn:hover {
  background: var(--db-accent);
  border-color: var(--db-accent);
  color: white;
}

.delete-layout-btn:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: #ef4444;
  color: #ef4444;
}

.save-layout-btn {
  width: 100%;
  padding: 0.625rem;
  background: var(--db-accent);
  border: none;
  border-radius: 0.5rem;
  color: white;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.save-layout-btn:hover {
  background: var(--db-accent-hover);
}

/* Layout Settings */
.layout-settings {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.layout-settings label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8125rem;
  color: var(--db-text);
}

.layout-settings label span {
  flex-shrink: 0;
}

.layout-settings select {
  width: 140px;
  padding: 0.375rem 0.5rem;
  background: var(--db-bg-elevated);
  border: 1px solid var(--db-border);
  border-radius: 0.375rem;
  color: var(--db-text);
  font-size: 0.8125rem;
  cursor: pointer;
}

.layout-settings select:focus {
  outline: none;
  border-color: var(--db-accent);
}

.checkbox-label {
  justify-content: flex-start !important;
  gap: 0.5rem;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--db-accent);
  cursor: pointer;
}

/* Dashboard Dialog */
.dashboard-dialog {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--db-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 1rem;
  animation: fadeIn 0.2s ease;
}

.dialog-content {
  width: 100%;
  max-width: 480px;
  background: var(--db-bg);
  border: 1px solid var(--db-border);
  border-radius: 0.75rem;
  padding: 1.5rem;
  animation: slideUp 0.2s ease;
}

.dialog-content h3 {
  margin: 0 0 1rem 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--db-text);
}

.dialog-content p {
  margin: 0 0 1rem 0;
  font-size: 0.875rem;
  color: var(--db-text-muted);
}

.share-url-container {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.share-url-input {
  flex: 1;
  padding: 0.625rem 0.75rem;
  background: var(--db-bg-elevated);
  border: 1px solid var(--db-border);
  border-radius: 0.5rem;
  color: var(--db-text);
  font-size: 0.8125rem;
  font-family: monospace;
}

.share-url-input:focus {
  outline: none;
  border-color: var(--db-accent);
}

.copy-btn {
  padding: 0.625rem 1rem;
  background: var(--db-accent);
  border: none;
  border-radius: 0.5rem;
  color: white;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.copy-btn:hover {
  background: var(--db-accent-hover);
}

.dialog-close-btn {
  width: 100%;
  padding: 0.75rem;
  background: transparent;
  border: 1px solid var(--db-border);
  border-radius: 0.5rem;
  color: var(--db-text);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.dialog-close-btn:hover {
  background: var(--db-bg-elevated);
}

/* Export Dialog Sections */
.export-section,
.import-section {
  margin-bottom: 1.5rem;
}

.export-section h4,
.import-section h4 {
  margin: 0 0 0.5rem 0;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--db-text);
}

.export-json-btn,
.import-json-btn {
  width: 100%;
  padding: 0.625rem;
  background: var(--db-bg-elevated);
  border: 1px solid var(--db-border);
  border-radius: 0.5rem;
  color: var(--db-text);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.export-json-btn:hover,
.import-json-btn:hover {
  border-color: var(--db-accent);
  background: rgba(59, 130, 246, 0.05);
}

/* Dialog Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Theme Toggle Button */
.theme-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1px solid var(--db-border);
  border-radius: 0.5rem;
  color: var(--db-text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.theme-toggle-btn:hover {
  background: var(--db-bg-elevated);
  color: var(--db-text);
}

/* Language Toggle */
.language-toggle {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--db-bg-elevated);
  border: 1px solid var(--db-border);
  border-radius: 0.5rem;
}

.language-btn {
  padding: 0.375rem 0.5rem;
  background: transparent;
  border: none;
  border-radius: 0.375rem;
  color: var(--db-text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.language-btn.active {
  background: var(--db-accent);
  color: white;
}

.language-btn:hover:not(.active) {
  color: var(--db-text);
}

/* Responsive Adjustments for Dashboard Builder */
@media (max-width: 768px) {
  .dashboard-toolbar {
    flex-wrap: wrap;
    padding: 0.5rem 1rem;
    gap: 0.5rem;
  }

  .toolbar-left,
  .toolbar-center,
  .toolbar-right {
    flex: 1 1 auto;
    justify-content: center;
  }

  .toolbar-center {
    order: 3;
    width: 100%;
  }

  .toolbar-btn span {
    display: none;
  }

  .toolbar-btn {
    padding: 0.5rem;
  }

  .dashboard-sidebar {
    width: 100%;
    right: -100%;
  }

  .widget-edit-container {
    touch-action: none;
  }

  .resize-handle {
    width: 20px;
    height: 20px;
  }
}

@media (max-width: 480px) {
  .toolbar-divider {
    display: none;
  }

  .dialog-content {
    padding: 1rem;
  }

  .share-url-container {
    flex-direction: column;
  }

  .copy-btn {
    width: 100%;
  }
}

/* ==========================================================================
   PERFORMANCE OPTIMIZATIONS
   ========================================================================== */

/* CSS Containment for better rendering performance */
.chart-card,
.card,
.kpi-card {
  contain: layout style;
}

.charts-grid {
  contain: layout;
}

.kpi-grid {
  contain: layout;
}

/* Content-visibility for below-fold content */
.chart-card:not(.visible) {
  content-visibility: auto;
  contain-intrinsic-size: 0 400px;
}

.correlation-section,
.forecast-section,
.yoy-section {
  content-visibility: auto;
  contain-intrinsic-size: 0 500px;
}

/* GPU acceleration for animations */
.chart-card,
.card,
.modal,
.dialog,
.toast {
  will-change: transform, opacity;
  transform: translateZ(0);
}

/* Smooth scrolling */
.app-main,
.virtual-scroller__viewport {
  scroll-behavior: smooth;
}

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

/* Virtual Scroller Styles */
.virtual-scroller {
  position: relative;
  height: 100%;
  overflow: hidden;
}

.virtual-scroller__viewport {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

.virtual-scroller__content {
  position: relative;
}

.virtual-scroller__rows {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
}

.virtual-scroller__row {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--card-bg);
  transition: background-color 0.15s ease;
}

.virtual-scroller__row:hover {
  background: rgba(255, 255, 255, 0.02);
}

/* Virtual Table Styles */
.virtual-table__header {
  display: flex;
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(15, 23, 42, 0.95);
  border-bottom: 2px solid var(--border-subtle);
  backdrop-filter: blur(8px);
}

.virtual-table__header-cell {
  flex: 1;
  padding: 0.75rem 1rem;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: color 0.15s ease;
}

.virtual-table__header-cell:hover {
  color: var(--text-main);
}

.virtual-table__header-cell.sorted {
  color: var(--accent);
}

.virtual-table__header-cell .sort-indicator {
  font-size: 0.75rem;
}

.virtual-table__cell {
  flex: 1;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Lazy Loading Image Styles */
img[data-src] {
  opacity: 0;
  transition: opacity 0.3s ease;
}

img.loaded {
  opacity: 1;
}

img.error {
  opacity: 0.5;
  filter: grayscale(1);
}

/* Loading skeleton animation optimization */
@keyframes skeleton-pulse {
  0% {
    opacity: 0.5;
  }
  50% {
    opacity: 0.8;
  }
  100% {
    opacity: 0.5;
  }
}

.skeleton {
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05) 0%,
    rgba(255, 255, 255, 0.1) 50%,
    rgba(255, 255, 255, 0.05) 100%
  );
  background-size: 200% 100%;
  border-radius: 4px;
}

/* Performance indicator badge */
.performance-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}

.performance-badge--good {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}

.performance-badge--needs-improvement {
  background: rgba(234, 179, 8, 0.15);
  color: #eab308;
}

.performance-badge--poor {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

/* Web Vitals display */
.web-vitals-panel {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 1rem;
  font-size: 0.8rem;
  z-index: 9999;
  min-width: 200px;
  backdrop-filter: blur(8px);
}

.web-vitals-panel__title {
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.web-vitals-panel__close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  font-size: 1.2rem;
  line-height: 1;
}

.web-vitals-panel__metric {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-subtle);
}

.web-vitals-panel__metric:last-child {
  border-bottom: none;
}

.web-vitals-panel__label {
  color: var(--text-muted);
}

.web-vitals-panel__value {
  font-weight: 600;
  font-family: monospace;
}

.web-vitals-panel__value--good {
  color: #22c55e;
}

.web-vitals-panel__value--needs-improvement {
  color: #eab308;
}

.web-vitals-panel__value--poor {
  color: #ef4444;
}

.web-vitals-panel__score {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-subtle);
  text-align: center;
}

.web-vitals-panel__score-value {
  font-size: 2rem;
  font-weight: 700;
}

/* Worker status indicator */
.worker-status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.worker-status__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}

.worker-status--active .worker-status__dot {
  background: #22c55e;
  animation: pulse 1s ease-in-out infinite;
}

.worker-status--busy .worker-status__dot {
  background: #eab308;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* Resource hints indicator */
.resource-hint-indicator {
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  font-size: 0.7rem;
  color: var(--text-soft);
  opacity: 0.5;
}

/* Optimize font rendering */
body {
  text-rendering: optimizeSpeed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Optimize image rendering */
img {
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

canvas {
  image-rendering: optimizeSpeed;
}

/* Efficient box shadows */
.card,
.chart-card,
.modal,
.dialog {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}

/* Hardware acceleration for transforms */
.animated {
  transform: translate3d(0, 0, 0);
  backface-visibility: hidden;
  perspective: 1000px;
}

/* Efficient borders */
.border-optimized {
  border: 1px solid var(--border-subtle);
  outline: none;
}

/* Print optimizations */
@media print {
  .app-header,
  .app-footer,
  .header-right,
  .refresh-btn,
  .export-btn,
  .web-vitals-panel,
  .worker-status,
  .performance-badge {
    display: none !important;
  }

  .chart-card,
  .card {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  body {
    background: white;
    color: black;
  }

  .app-main {
    max-width: 100%;
    padding: 0;
  }
}

/* ==========================================================================
   ACCESSIBILITY STYLES
   ========================================================================== */

/* Ensure minimum touch target sizes */
button,
a,
select,
input,
[role="button"] {
  min-height: 44px;
}

/* Exception for inline elements */
.inline-btn,
.text-link,
a:not(.btn):not(.export-option):not(.skip-navigation__link) {
  min-height: auto;
}

/* Focus visibility enhancement */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Chart keyboard navigation indicator */
.chart-container canvas:focus {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ARIA live region positioning */
#a11y-live-polite,
#a11y-live-assertive {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
@import url('./styles/high-contrast.css');
