/* =============================================================================
   SalesPoint QA — Automation Health Dashboard
   Modern, professional, glanceable.
   ============================================================================= */

/* ---------- Design tokens ---------- */
:root {
  /* Surfaces */
  --bg:               #f1f5f9;
  --bg-deep:          #e2e8f0;
  --surface:          #ffffff;
  --surface-muted:    #f8fafc;

  /* Text */
  --text-strong:      #0f172a;
  --text:             #1e293b;
  --text-muted:       #64748b;
  --text-faint:       #94a3b8;
  --text-inverse:     #ffffff;

  /* Borders */
  --border:           #e2e8f0;
  --border-strong:    #cbd5e1;

  /* Status — primary swatches */
  --pass:             #16a34a;
  --pass-soft:        #dcfce7;
  --pass-soft-deep:   #bbf7d0;
  --warn:             #d97706;
  --warn-soft:        #fef3c7;
  --warn-soft-deep:   #fde68a;
  --fail:             #dc2626;
  --fail-soft:        #fee2e2;
  --fail-soft-deep:   #fecaca;
  --info:             #2563eb;
  --info-soft:        #dbeafe;
  --info-soft-deep:   #bfdbfe;
  --neutral:          #64748b;
  --neutral-soft:     #f1f5f9;

  /* Priority */
  --p0:               #b91c1c;
  --p0-bg:            #fee2e2;
  --p1:               #c2410c;
  --p1-bg:            #ffedd5;
  --p2:               #1d4ed8;
  --p2-bg:            #dbeafe;
  --p3:               #475569;
  --p3-bg:            #e2e8f0;

  /* Shape */
  --radius-sm:        6px;
  --radius:           12px;
  --radius-lg:        16px;

  /* Shadow */
  --shadow-sm:        0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow:           0 1px 3px rgba(15, 23, 42, 0.06),
                      0 4px 12px rgba(15, 23, 42, 0.04);
  --shadow-hover:     0 1px 3px rgba(15, 23, 42, 0.08),
                      0 8px 24px rgba(15, 23, 42, 0.08);

  /* Layout */
  --container:        1280px;
  --gap:              20px;
  --gap-sm:           12px;
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01', 'tnum';
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; color: var(--text-strong); letter-spacing: -0.011em; }
h1 { font-size: 1.25rem; }
h2 { font-size: 0.95rem; }
p { margin: 0; }
code { font-family: 'JetBrains Mono', monospace; font-size: 0.85em; background: var(--surface-muted); padding: 1px 6px; border-radius: 4px; }

.container { max-width: var(--container); margin: 0 auto; padding: 0 24px; }
.hidden { display: none !important; }

/* ---------- Header ---------- */
.page-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 20px 0;
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: blur(8px);
  background: rgba(255, 255, 255, 0.92);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  flex-wrap: wrap;
}
.header-brand { display: flex; align-items: center; gap: 14px; }
.header-logo {
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}
.header-logo img {
  width: 100%;
  height: 100%;
  display: block;
}
.header-titles h1 { font-size: 1.15rem; }
.header-subtitle { display: block; font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }

.header-meta { display: flex; gap: 28px; }
.meta-row { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.meta-label { font-size: 0.7rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.meta-value { font-size: 0.85rem; color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Page layout ---------- */
.page-content { padding: 28px 24px 48px; display: flex; flex-direction: column; gap: var(--gap); }

/* ---------- Hero tiles ---------- */
.hero-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap);
}
.hero-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
  display: flex; gap: 16px; align-items: flex-start;
  transition: box-shadow 0.2s ease, transform 0.15s ease;
  position: relative; overflow: hidden;
}
.hero-tile::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--border);
}
.hero-tile[data-status="excellent"]::before,
.hero-tile[data-status="all_passing"]::before { background: var(--pass); }
.hero-tile[data-status="ok"]::before,
.hero-tile[data-status="partial"]::before,
.hero-tile[data-status="flaky"]::before        { background: var(--warn); }
.hero-tile[data-status="poor"]::before,
.hero-tile[data-status="failing"]::before     { background: var(--fail); }
.hero-tile[data-status="none"]::before        { background: var(--neutral); }

.hero-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  background: var(--neutral-soft);
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.hero-tile[data-status="excellent"]    .hero-icon,
.hero-tile[data-status="all_passing"]  .hero-icon { background: var(--pass-soft); color: var(--pass); }
.hero-tile[data-status="ok"]           .hero-icon,
.hero-tile[data-status="partial"]      .hero-icon,
.hero-tile[data-status="flaky"]        .hero-icon { background: var(--warn-soft); color: var(--warn); }
.hero-tile[data-status="poor"]         .hero-icon,
.hero-tile[data-status="failing"]      .hero-icon { background: var(--fail-soft); color: var(--fail); }

.hero-body { flex: 1; min-width: 0; }
.hero-label { font-size: 0.7rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.hero-value {
  font-size: 2.2rem; font-weight: 800; color: var(--text-strong);
  line-height: 1.1; margin: 6px 0 10px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.hero-bar { height: 6px; background: var(--neutral-soft); border-radius: 999px; overflow: hidden; margin-bottom: 8px; }
.hero-bar-fill { height: 100%; background: var(--pass); width: 0%; transition: width 0.6s ease; border-radius: 999px; }
.hero-tile[data-status="ok"]      .hero-bar-fill,
.hero-tile[data-status="flaky"]   .hero-bar-fill { background: var(--warn); }
.hero-tile[data-status="poor"]    .hero-bar-fill { background: var(--fail); }
.hero-subline { font-size: 0.82rem; color: var(--text-muted); display: block; }

/* Secondary flaky indicator inside Pass Rate tile — only renders when flaky > 0 */
.hero-flaky-line {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.78rem;
  color: var(--warn);
  font-weight: 500;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
  width: 100%;
}
.hero-flaky-line.hidden { display: none; }
.hero-flaky-line svg { color: var(--warn); flex-shrink: 0; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
}
.card-title { font-size: 0.95rem; font-weight: 700; color: var(--text-strong); display: flex; align-items: center; gap: 10px; }
.card-subtitle { font-size: 0.78rem; color: var(--text-muted); }
.card-body { padding: 18px 20px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; font-size: 0.72rem; font-weight: 700;
  border-radius: 999px; letter-spacing: 0.02em;
}
.badge-count {
  background: var(--neutral-soft); color: var(--text-muted);
  min-width: 22px; justify-content: center;
}
.failing-card .badge-count { background: var(--fail-soft); color: var(--fail); }
.failing-card[data-empty="true"] .badge-count { background: var(--pass-soft); color: var(--pass); }
.badge-flaky { background: var(--warn-soft); color: var(--warn); }

.priority-badge {
  font-size: 0.65rem; font-weight: 700;
  padding: 2px 7px; border-radius: 4px;
  letter-spacing: 0.04em; text-transform: uppercase;
  font-family: 'JetBrains Mono', monospace;
}
.priority-badge.p0 { background: var(--p0-bg); color: var(--p0); }
.priority-badge.p1 { background: var(--p1-bg); color: var(--p1); }
.priority-badge.p2 { background: var(--p2-bg); color: var(--p2); }
.priority-badge.p3 { background: var(--p3-bg); color: var(--p3); }

/* ---------- Failing list ---------- */
.failing-list { display: flex; flex-direction: column; }
.failing-item {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 14px; align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.failing-item:last-child { border-bottom: 0; padding-bottom: 0; }
.failing-item:first-child { padding-top: 0; }
.failing-item .test-id { font-family: 'JetBrains Mono', monospace; font-size: 0.82rem; color: var(--text-muted); font-weight: 500; }
.failing-item .test-name { font-weight: 600; color: var(--text-strong); }
.failing-item .test-name-area { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }
.failing-item .test-meta { font-size: 0.78rem; color: var(--text-muted); text-align: right; white-space: nowrap; }

/* ---------- Empty states ---------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 28px 16px; gap: 8px;
  text-align: center; color: var(--text-muted);
}
.empty-state svg { color: var(--text-faint); }
.empty-state-success { color: var(--pass); }
.empty-state-success svg { color: var(--pass); }
.empty-state-success p { color: var(--text-strong); font-weight: 600; }

/* ---------- Two-column layout ---------- */
.two-col {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--gap);
}
.two-col > * { min-width: 0; }

/* ---------- Chart card ---------- */
.chart-canvas-wrap { height: 240px; position: relative; }

/* ---------- Recent runs ---------- */
.recent-runs { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; }
.recent-run-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px; align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.recent-run-item:last-child { border-bottom: 0; padding-bottom: 0; }
.recent-run-item:first-child { padding-top: 0; }
.recent-run-date { color: var(--text); font-weight: 500; font-variant-numeric: tabular-nums; }
.recent-run-counts { color: var(--text-muted); font-family: 'JetBrains Mono', monospace; font-size: 0.8rem; }
.recent-run-rate {
  font-weight: 700; font-variant-numeric: tabular-nums; min-width: 48px; text-align: right;
}
.recent-run-rate.excellent { color: var(--pass); }
.recent-run-rate.ok        { color: var(--warn); }
.recent-run-rate.poor      { color: var(--fail); }
.recent-run-rate.none      { color: var(--text-faint); }

/* ---------- Area grid ---------- */
.area-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.area-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  background: var(--surface);
  position: relative;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.area-card:hover { border-color: var(--border-strong); }
.area-card .area-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.area-card .area-name { font-weight: 700; font-size: 0.9rem; color: var(--text-strong); }
.area-card .area-prefix { font-family: 'JetBrains Mono', monospace; font-size: 0.7rem; color: var(--text-faint); }
.area-card .area-rate { font-size: 1.4rem; font-weight: 800; color: var(--text-strong); font-variant-numeric: tabular-nums; margin-bottom: 2px; letter-spacing: -0.01em; }
.area-card .area-counts { font-size: 0.78rem; color: var(--text-muted); }
.area-card .area-bar { height: 4px; background: var(--neutral-soft); border-radius: 999px; margin-top: 10px; overflow: hidden; }
.area-card .area-bar-fill { height: 100%; background: var(--pass); transition: width 0.5s ease; }

.area-card[data-coverage="strong"]  { border-left: 3px solid var(--pass); }
.area-card[data-coverage="partial"] { border-left: 3px solid var(--warn); }
.area-card[data-coverage="thin"]    { border-left: 3px solid var(--fail); }
.area-card[data-coverage="none"]    { border-left: 3px solid var(--border-strong); opacity: 0.65; }
.area-card[data-coverage="strong"]  .area-rate { color: var(--pass); }
.area-card[data-coverage="partial"] .area-rate { color: var(--warn); }
.area-card[data-coverage="thin"]    .area-rate { color: var(--fail); }
.area-card[data-coverage="none"]    .area-rate { color: var(--text-faint); font-size: 0.95rem; font-weight: 600; }
.area-card[data-coverage="partial"] .area-bar-fill { background: var(--warn); }
.area-card[data-coverage="thin"]    .area-bar-fill { background: var(--fail); }

/* ---------- Breakdown table ---------- */
.breakdown-table { width: 100%; border-collapse: collapse; }
.breakdown-table th, .breakdown-table td {
  padding: 9px 6px; text-align: left;
  border-bottom: 1px solid var(--border);
}
.breakdown-table th {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); font-weight: 600;
}
.breakdown-table th.num, .breakdown-table td.num {
  text-align: right; font-variant-numeric: tabular-nums;
}
.breakdown-table tbody tr:last-child td { border-bottom: 0; }
.breakdown-table td { font-size: 0.85rem; }
.breakdown-table .row-label { font-weight: 600; color: var(--text-strong); }
.breakdown-table .row-empty { color: var(--text-faint); }
.breakdown-table .rate-cell { font-weight: 700; }
.breakdown-table .rate-cell.excellent { color: var(--pass); }
.breakdown-table .rate-cell.ok        { color: var(--warn); }
.breakdown-table .rate-cell.poor      { color: var(--fail); }
.breakdown-table .rate-cell.none      { color: var(--text-faint); font-weight: 500; }

/* ---------- Footer ---------- */
.page-footer { border-top: 1px solid var(--border); margin-top: 16px; padding: 18px 0; background: var(--surface); }
.footer-inner { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 0.78rem; color: var(--text-muted); flex-wrap: wrap; }
.footer-sep { color: var(--border-strong); }

/* ---------- Error banner ---------- */
.error-banner {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--fail); color: white; padding: 12px 20px;
  border-radius: var(--radius-sm); box-shadow: var(--shadow-hover);
  font-weight: 600; max-width: 90vw;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .hero-grid       { grid-template-columns: 1fr; }
  .two-col         { grid-template-columns: 1fr; }
  .header-inner    { flex-direction: column; align-items: flex-start; gap: 14px; }
  .header-meta     { gap: 20px; align-self: stretch; justify-content: flex-start; }
  .meta-row        { align-items: flex-start; }
  .hero-value      { font-size: 1.8rem; }
}
@media (max-width: 520px) {
  .container       { padding: 0 16px; }
  .page-content    { padding: 20px 16px 32px; }
  .failing-item    { grid-template-columns: auto 1fr; }
  .failing-item .test-meta { grid-column: 1 / -1; text-align: left; }
}

/* ---------- Tiny entrance animation ---------- */
.card, .hero-tile { animation: fade-in 0.4s ease both; }
@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
