/* ===================================================================
   Dash Split Demo — Design System
   Ported from ui_core.css with sanitized class names
   =================================================================== */

:root {
  --bg-primary: #f3f4f6;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f9fafb;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --border-primary: #e5e7eb;
  --border-secondary: #d1d5db;
  --accent-blue: #3b82f6;
  --accent-green: #22c55e;
  --accent-red: #ef4444;
  --accent-yellow: #f59e0b;
  --accent-purple: #8b5cf6;
  --accent-indigo: #6366f1;
  --accent-teal: #14b8a6;
  --accent-orange: #f97316;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-1: 0 1px 2px rgba(0,0,0,.05), 0 1px 1px rgba(0,0,0,.03);
  --shadow-2: 0 6px 16px rgba(0,0,0,.08), 0 2px 8px rgba(0,0,0,.06);
  --shadow-3: 0 16px 40px rgba(0,0,0,.12);
  --ring: 0 0 0 3px rgba(59,130,246,.35);
}

.theme-dark {
  --bg-primary: #111827;
  --bg-secondary: #1f2937;
  --bg-tertiary: #374151;
  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --border-primary: #374151;
  --border-secondary: #4b5563;
}

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

html { -webkit-tap-highlight-color: transparent; }
::selection { background: rgba(59,130,246,.22); color: var(--text-primary); }
:root { scrollbar-color: var(--border-secondary) transparent; scrollbar-width: thin; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  transition: background-color 0.2s ease, color 0.2s ease;
  letter-spacing: .005em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  margin: 0;
  padding: 0.5rem;
  min-height: 100vh;
}

@media (min-width: 640px) { body { padding: 1.5rem; } }
@media (min-width: 1024px) { body { padding: 2rem; } }

/* Focus rings */
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ===== Layout ===== */
#demo-app {
  max-width: 80rem;
  margin: 0 auto;
  background-color: var(--bg-secondary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  padding: 1rem;
  min-height: calc(100vh - 4rem);
}

@media (min-width: 640px) { #demo-app { padding: 1.5rem; } }

/* ===== Demo Banner ===== */
.demo-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 50%, #6366f1 100%);
  color: white;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  font-size: 0.875rem;
  font-weight: 500;
  margin: -1rem -1rem 1rem -1rem;
  flex-wrap: wrap;
  gap: 8px;
}

@media (min-width: 640px) { .demo-banner { margin: -1.5rem -1.5rem 1.5rem -1.5rem; } }

.demo-banner a {
  color: white;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 600;
  white-space: nowrap;
}

.demo-banner a:hover { opacity: 0.85; }

/* ===== Header ===== */
.demo-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-primary);
  margin-bottom: 16px;
}

@media (min-width: 640px) {
  .demo-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.demo-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

@media (min-width: 640px) { .demo-header h1 { font-size: 1.75rem; } }

.demo-header-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.demo-select {
  padding: 8px 12px;
  font-size: 0.875rem;
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-sm);
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  min-height: 40px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.demo-select:focus {
  border-color: var(--accent-blue);
  box-shadow: var(--ring);
}

.demo-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-primary);
  background-color: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.demo-icon-btn:hover {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
}

/* ===== Date Presets ===== */
.date-presets {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
}

.date-preset-btn {
  padding: 6px 14px;
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: 9999px;
  border: 1px solid var(--border-primary);
  background-color: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.date-preset-btn:hover {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
}

.date-preset-btn.active {
  background-color: var(--accent-blue) !important;
  color: white !important;
  border-color: var(--accent-blue) !important;
}

/* ===== KPI Tiles ===== */
.kpi-tile {
  padding: 16px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  text-align: center;
  transition: box-shadow 0.2s, transform 0.15s;
}

.kpi-tile:hover { box-shadow: var(--shadow-2); transform: translateY(-1px); }

.kpi-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.kpi-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-wrap: wrap;
}

/* ===== Tables ===== */
.demo-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
}

.demo-table {
  width: 100%;
  text-align: left;
  font-size: 0.875rem;
  border-collapse: collapse;
}

.demo-table thead {
  background-color: var(--bg-tertiary);
  position: sticky;
  top: 0;
  z-index: 5;
}

.demo-table th {
  padding: 10px 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.75rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-primary);
}

.demo-table tbody tr {
  border-bottom: 1px solid var(--border-primary);
  transition: background-color 0.12s;
}

.demo-table tbody tr:last-child { border-bottom: none; }
.demo-table tbody tr:nth-child(even) { background-color: var(--bg-tertiary); }
.demo-table tbody tr:hover { background-color: rgba(59,130,246,.06); }
.demo-table td { padding: 10px 14px; }

/* ===== Badges ===== */
.role-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border-primary);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

/* ===== Trend Badges ===== */
.trend-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 9999px;
  font-size: 0.6875rem;
  font-weight: 600;
}

.trend-up { background-color: #dcfce7; color: #15803d; }
.trend-down { background-color: #fee2e2; color: #b91c1c; }
.trend-flat { background-color: #fefce8; color: #a16207; }

/* ===== Charts ===== */
.chart-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-1);
}

.chart-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
}

/* ===== Insights Tabs ===== */
.insight-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border-primary);
  padding-bottom: 0;
  overflow-x: auto;
}

.insight-tab {
  padding: 10px 16px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.insight-tab:hover { color: var(--text-primary); }
.insight-tab.active {
  color: var(--accent-blue);
  border-bottom-color: var(--accent-blue);
  font-weight: 600;
}

.insight-section { /* no extra styles needed, hidden class handles visibility */ }

/* ===== Spotlights ===== */
.spotlight-card {
  padding: 16px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
}

/* ===== Anomalies ===== */
.anomaly-card {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  border: 1px solid;
}

.anomaly-high {
  background-color: rgba(34,197,94,0.06);
  border-color: rgba(34,197,94,0.2);
  color: #15803d;
}

.anomaly-low {
  background-color: rgba(239,68,68,0.06);
  border-color: rgba(239,68,68,0.2);
  color: #b91c1c;
}

/* ===== Associate Cards ===== */
.associate-card {
  padding: 14px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  transition: box-shadow 0.2s;
}

.associate-card:hover { box-shadow: var(--shadow-2); }

.rank-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--text-primary);
  flex-shrink: 0;
}

/* ===== Challenges ===== */
.challenge-card {
  padding: 16px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  transition: box-shadow 0.2s;
}

.challenge-card:hover { box-shadow: var(--shadow-2); }
.challenge-active { border-color: var(--accent-blue); }

/* ===== Podium ===== */
.podium-section {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-1);
}

.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 16px;
  min-height: 180px;
}

.podium-place {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100px;
}

.podium-avatar { font-size: 2rem; margin-bottom: 8px; }
.podium-name { font-size: 0.875rem; font-weight: 600; color: var(--text-primary); margin-bottom: 2px; }
.podium-score { font-size: 1.25rem; font-weight: 800; color: var(--accent-blue); margin-bottom: 8px; }

.podium-bar {
  width: 100%;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  min-height: 40px;
}

/* ===== Data Entry ===== */
.data-entry-input {
  width: 60px;
  padding: 6px 8px;
  text-align: center;
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-sm);
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}

.data-entry-input::-webkit-outer-spin-button,
.data-entry-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.data-entry-input[readonly] {
  cursor: default;
  opacity: 0.7;
}

.completion-badge {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  font-size: 0.875rem;
}

/* ===== Back Button ===== */
.demo-btn-back {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-primary);
  background-color: var(--bg-secondary);
  color: var(--accent-blue);
  cursor: pointer;
  transition: all 0.15s;
}

.demo-btn-back:hover {
  background-color: var(--bg-tertiary);
}

/* ===== Command Palette ===== */
#demo-cmd-palette {
  position: fixed;
  inset: 0;
  background-color: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 20vh;
  z-index: 100;
}

#demo-cmd-palette .cmd-content {
  width: 100%;
  max-width: 520px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  overflow: hidden;
}

#demo-cmd-input {
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-bottom: 1px solid var(--border-primary);
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: 'Inter', sans-serif;
}

#demo-cmd-input:focus { outline: none; }
#demo-cmd-input::placeholder { color: var(--text-secondary); }

#demo-cmd-results {
  list-style: none;
  max-height: 300px;
  overflow-y: auto;
  padding: 8px;
}

.cmd-result-item {
  padding: 10px 12px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  color: var(--text-primary);
  transition: background-color 0.1s;
}

.cmd-result-item:hover {
  background-color: var(--accent-blue);
  color: white;
}

/* ===== Toast ===== */
#demo-toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 110;
  display: none;
}

/* ===== Loader ===== */
#demo-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 50vh;
}

.demo-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border-primary);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: demo-spin 0.8s linear infinite;
}

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

/* ===== Utilities ===== */
.hidden { display: none !important; }

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
  .demo-header { padding-bottom: 12px; }
  .demo-header h1 { font-size: 1.25rem; }

  .podium { gap: 8px; }
  .podium-place { width: 80px; }
  .podium-avatar { font-size: 1.5rem; }
  .podium-score { font-size: 1rem; }

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

  .date-presets { overflow-x: auto; padding-bottom: 4px; }

  .chart-card div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  .insight-tabs { gap: 0; }
  .insight-tab { padding: 8px 12px; font-size: 0.8125rem; }

  .demo-table th, .demo-table td { padding: 8px 10px; font-size: 0.8125rem; }
  .data-entry-input { width: 50px; font-size: 0.8125rem; }

  button, select, input { min-height: 44px; }
}
