/* ══════════════════════════════════════════════════════════════
   Lost Data Finder — Material Design 3 Dashboard
   Design Tokens + Component Styles
   ══════════════════════════════════════════════════════════════ */

/* ── MD3 Design Tokens (Dark Theme) ─────────────────────────── */
:root {
  /* Primary */
  --md-sys-color-primary: #A0CFCF;
  --md-sys-color-on-primary: #003737;
  --md-sys-color-primary-container: #004F4F;
  --md-sys-color-on-primary-container: #BCEBEB;
  /* Secondary */
  --md-sys-color-secondary: #B1CCD0;
  --md-sys-color-on-secondary: #1C3438;
  --md-sys-color-secondary-container: #334B4F;
  --md-sys-color-on-secondary-container: #CDE8EC;
  /* Tertiary */
  --md-sys-color-tertiary: #B5C6EA;
  --md-sys-color-on-tertiary: #1F304D;
  --md-sys-color-tertiary-container: #364764;
  --md-sys-color-on-tertiary-container: #D5E3FF;
  /* Error */
  --md-sys-color-error: #FFB4AB;
  --md-sys-color-on-error: #690005;
  --md-sys-color-error-container: #93000A;
  --md-sys-color-on-error-container: #FFDAD6;
  /* Surface hierarchy */
  --md-sys-color-surface: #0E1415;
  --md-sys-color-on-surface: #DEE3E3;
  --md-sys-color-surface-dim: #0E1415;
  --md-sys-color-surface-container-lowest: #090F10;
  --md-sys-color-surface-container-low: #161C1D;
  --md-sys-color-surface-container: #1A2021;
  --md-sys-color-surface-container-high: #252B2C;
  --md-sys-color-surface-container-highest: #303637;
  --md-sys-color-on-surface-variant: #BEC8C9;
  --md-sys-color-outline: #899393;
  --md-sys-color-outline-variant: #3F4949;
  --md-sys-color-inverse-surface: #DEE3E3;
  --md-sys-color-inverse-on-surface: #2B3132;
  /* Extended semantic colors */
  --md-extended-color-success: #81D994;
  --md-extended-color-success-container: #004E1A;
  --md-extended-color-warning: #F0C05A;
  --md-extended-color-warning-container: #4A3800;
  /* Elevation tint */
  --md-sys-elevation-1: 0 1px 3px 1px rgba(0,0,0,.15), 0 1px 2px rgba(0,0,0,.3);
  --md-sys-elevation-2: 0 2px 6px 2px rgba(0,0,0,.15), 0 1px 2px rgba(0,0,0,.3);
  --md-sys-elevation-3: 0 4px 8px 3px rgba(0,0,0,.15), 0 1px 3px rgba(0,0,0,.3);
  /* Shape */
  --md-sys-shape-xs: 4px;
  --md-sys-shape-sm: 8px;
  --md-sys-shape-md: 12px;
  --md-sys-shape-lg: 16px;
  --md-sys-shape-xl: 28px;
  /* Typography */
  --md-sys-typescale-display: 'Google Sans', 'Segoe UI', system-ui, sans-serif;
  --md-sys-typescale-body: 'Google Sans Text', 'Segoe UI', system-ui, sans-serif;
  --md-sys-typescale-code: 'Google Sans Mono', 'SF Mono', 'Cascadia Code', monospace;
  /* Motion */
  --md-sys-motion-duration-short: 150ms;
  --md-sys-motion-duration-medium: 300ms;
  --md-sys-motion-easing-standard: cubic-bezier(0.2, 0, 0, 1);
}

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--md-sys-typescale-body);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
.material-symbols-rounded {
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  vertical-align: middle;
}

/* ── Top App Bar ────────────────────────────────────────────── */
.top-app-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; height: 64px;
  background: var(--md-sys-color-surface);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  position: sticky; top: 0; z-index: 10;
}
.top-app-bar__leading { display: flex; align-items: center; gap: 12px; }
.top-app-bar__title {
  font-family: var(--md-sys-typescale-display);
  font-size: 22px; font-weight: 500;
  color: var(--md-sys-color-on-surface);
}
.top-app-bar__trailing { display: flex; align-items: center; gap: 12px; }
.top-app-bar__status {
  font-size: 12px; color: var(--md-sys-color-on-surface-variant);
  letter-spacing: 0.4px;
}
.live-indicator {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--md-sys-color-outline);
  transition: background var(--md-sys-motion-duration-medium);
}
.live-indicator.connected { background: var(--md-extended-color-success); box-shadow: 0 0 6px var(--md-extended-color-success); }
.icon-button {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: transparent; color: var(--md-sys-color-on-surface-variant);
  cursor: pointer; display: grid; place-items: center;
  transition: background var(--md-sys-motion-duration-short);
}
.icon-button:hover { background: var(--md-sys-color-surface-container-high); }
.icon-button:active { background: var(--md-sys-color-surface-container-highest); }


/* ── KPI Strip ──────────────────────────────────────────────── */
.kpi-strip {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
  padding: 20px 24px;
  max-width: 1200px; margin: 0 auto;
}
.kpi-card {
  display: flex; align-items: center; gap: 16px;
  padding: 20px; border-radius: var(--md-sys-shape-md);
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  transition: box-shadow var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard);
}
.kpi-card:hover { box-shadow: var(--md-sys-elevation-1); }
.kpi-icon { font-size: 32px; }
.kpi-data { display: flex; flex-direction: column; }
.kpi-value {
  font-family: var(--md-sys-typescale-display);
  font-size: 28px; font-weight: 700; line-height: 1.1;
  color: var(--md-sys-color-on-surface);
}
.kpi-label {
  font-size: 12px; color: var(--md-sys-color-on-surface-variant);
  letter-spacing: 0.5px; margin-top: 2px;
}

/* ── Tab Bar ────────────────────────────────────────────────── */
.tab-bar {
  display: flex; gap: 0; justify-content: center;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  max-width: 1200px; margin: 0 auto;
  padding: 0 24px;
}
.tab {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 24px; border: none; background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font-family: var(--md-sys-typescale-body); font-size: 14px; font-weight: 500;
  cursor: pointer; position: relative;
  transition: color var(--md-sys-motion-duration-short);
  letter-spacing: 0.1px;
}
.tab .material-symbols-rounded { font-size: 20px; }
.tab:hover { color: var(--md-sys-color-on-surface); background: var(--md-sys-color-surface-container); }
.tab.active { color: var(--md-sys-color-primary); }
.tab.active .material-symbols-rounded { font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24; }
.tab.active::after {
  content: ''; position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 48px; height: 3px; border-radius: 3px 3px 0 0;
  background: var(--md-sys-color-primary);
}

/* ── Content Area ───────────────────────────────────────────── */
.content { max-width: 1200px; margin: 0 auto; padding: 24px; }
.panel { display: none; }
.panel.active { display: block; animation: fadeIn var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Run Cards ──────────────────────────────────────────────── */
.run-card {
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-md);
  padding: 20px 24px; margin-bottom: 12px;
  border: 1px solid var(--md-sys-color-outline-variant);
  transition: box-shadow var(--md-sys-motion-duration-medium), border-color var(--md-sys-motion-duration-short);
}
.run-card:hover { box-shadow: var(--md-sys-elevation-1); border-color: var(--md-sys-color-outline); }
.run-card__header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.run-card__query {
  font-family: var(--md-sys-typescale-display);
  font-size: 16px; font-weight: 500; color: var(--md-sys-color-on-surface);
  display: flex; align-items: center; gap: 8px;
}
.run-card__meta {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--md-sys-color-on-surface-variant);
}
.run-card__stats {
  display: flex; gap: 24px; flex-wrap: wrap;
}
.run-stat {
  display: flex; flex-direction: column;
}
.run-stat__value {
  font-family: var(--md-sys-typescale-display);
  font-size: 20px; font-weight: 600; color: var(--md-sys-color-on-surface);
}
.run-stat__label { font-size: 11px; color: var(--md-sys-color-on-surface-variant); letter-spacing: 0.5px; }

/* ── Status Chips (MD3 Assist Chip style) ───────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: var(--md-sys-shape-sm);
  font-size: 12px; font-weight: 500; letter-spacing: 0.1px;
  border: 1px solid transparent;
}
.chip .material-symbols-rounded { font-size: 16px; }
.chip--completed { background: rgba(129,217,148,0.12); color: var(--md-extended-color-success); border-color: rgba(129,217,148,0.25); }
.chip--running { background: rgba(160,207,207,0.12); color: var(--md-sys-color-primary); border-color: rgba(160,207,207,0.25); }
.chip--failed { background: rgba(255,180,171,0.12); color: var(--md-sys-color-error); border-color: rgba(255,180,171,0.25); }

/* ── Export Cards ───────────────────────────────────────────── */
.export-group { margin-bottom: 24px; }
.export-group__title {
  font-family: var(--md-sys-typescale-display);
  font-size: 14px; font-weight: 500; color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 8px; padding-left: 4px;
  display: flex; align-items: center; gap: 8px;
}
.export-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; margin-bottom: 4px;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-sm);
  border: 1px solid var(--md-sys-color-outline-variant);
  transition: background var(--md-sys-motion-duration-short);
}
.export-item:hover { background: var(--md-sys-color-surface-container-high); }
.export-item__info { display: flex; align-items: center; gap: 12px; }
.export-item__icon { color: var(--md-sys-color-on-surface-variant); }
.export-item__name { font-size: 14px; color: var(--md-sys-color-on-surface); }
.export-item__size { font-size: 12px; color: var(--md-sys-color-on-surface-variant); margin-left: 8px; }
.export-item__date { font-size: 12px; color: var(--md-sys-color-on-surface-variant); }
.btn-download {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--md-sys-shape-xl);
  background: transparent; border: 1px solid var(--md-sys-color-outline);
  color: var(--md-sys-color-primary); font-size: 13px; font-weight: 500;
  cursor: pointer; text-decoration: none;
  transition: background var(--md-sys-motion-duration-short);
}
.btn-download:hover { background: var(--md-sys-color-surface-container-high); }
.btn-download .material-symbols-rounded { font-size: 18px; }


/* ── System Panel ──────────────────────────────────────────── */
.system-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.system-card {
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-md);
  padding: 24px; border: 1px solid var(--md-sys-color-outline-variant);
}
.system-card__title {
  font-family: var(--md-sys-typescale-display);
  font-size: 14px; font-weight: 500; color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 16px; display: flex; align-items: center; gap: 8px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.system-card__title .material-symbols-rounded { font-size: 20px; color: var(--md-sys-color-primary); }
.system-stat-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--md-sys-color-outline-variant);
}
.system-stat-row:last-child { border-bottom: none; }
.system-stat-row__label { font-size: 14px; color: var(--md-sys-color-on-surface); }
.system-stat-row__value {
  font-family: var(--md-sys-typescale-display);
  font-size: 16px; font-weight: 600; color: var(--md-sys-color-primary);
}

/* ── Metrics Breakdown ─────────────────────────────────────── */
.metrics-bar {
  display: flex; align-items: flex-end; gap: 8px; height: 160px;
  padding: 16px 0; margin-top: 12px;
}
.metrics-bar__col {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.metrics-bar__bar {
  width: 100%; border-radius: var(--md-sys-shape-xs) var(--md-sys-shape-xs) 0 0;
  min-height: 4px; background: var(--md-sys-color-primary-container);
  transition: height var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard);
}
.metrics-bar__value { font-size: 12px; font-weight: 600; color: var(--md-sys-color-on-surface); }
.metrics-bar__label { font-size: 10px; color: var(--md-sys-color-on-surface-variant); text-align: center; max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Skeleton Loader ───────────────────────────────────────── */
.skeleton-loader {
  height: 120px; border-radius: var(--md-sys-shape-md);
  background: linear-gradient(90deg, var(--md-sys-color-surface-container) 25%, var(--md-sys-color-surface-container-high) 50%, var(--md-sys-color-surface-container) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Empty State ───────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px 24px; text-align: center;
  color: var(--md-sys-color-on-surface-variant);
}
.empty-state .material-symbols-rounded { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty-state__title { font-size: 16px; font-weight: 500; margin-bottom: 4px; }
.empty-state__subtitle { font-size: 14px; opacity: 0.7; }

/* ── Error State ───────────────────────────────────────────── */
.error-state {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-radius: var(--md-sys-shape-sm);
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
  font-size: 14px;
}
.error-state .material-symbols-rounded { font-size: 20px; }

/* ── Footer ────────────────────────────────────────────────── */
.app-footer {
  text-align: center; padding: 32px 24px;
  font-size: 12px; color: var(--md-sys-color-on-surface-variant);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  opacity: 0.6;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 900px) {
  .kpi-strip { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .system-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .kpi-strip { grid-template-columns: 1fr; }
  .top-app-bar { padding: 12px 16px; }
  .top-app-bar__title { font-size: 18px; }
  .content { padding: 16px; }
  .run-card__stats { gap: 16px; }
  .export-item { flex-direction: column; align-items: flex-start; gap: 8px; }
}
