/* ── Google Font ─────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Design Tokens ───────────────────────────────────── */
:root {
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Surface palette */
  --bg:        #0d1117;
  --surface:   #161b22;
  --surface-2: #21262d;
  --surface-3: #30363d;
  --border:    #30363d;
  --border-subtle: #21262d;

  /* Text */
  --text:      #e6edf3;
  --text-muted:#8b949e;
  --text-faint:#6e7681;

  /* Brand */
  --brand:     #58a6ff;
  --brand-dim: #1f6feb;

  /* Semantic */
  --good:  #3fb950;
  --warn:  #d29922;
  --bad:   #f85149;
  --error-bg: #1c1313;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow: 0 4px 24px rgba(0,0,0,0.45);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
}

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

html { font-size: 16px; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── App Shell ───────────────────────────────────────── */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Topbar ──────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding: 0 24px;
  height: 56px;
  background: rgba(13, 17, 23, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  display: block;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  object-fit: contain;
  line-height: 1;
}

.brand-icon.large {
  width: 48px;
  height: 48px;
  margin: 0 auto 4px;
}

.brand-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  margin-right: 12px;
}

.topbar-nav .btn-ghost.nav-active {
  color: var(--brand);
  background: rgba(88, 166, 255, 0.12);
}

.topbar-user {
  font-size: 14px;
}

.flaky-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: rgba(210, 153, 34, 0.18);
  color: var(--warn);
}

.tc-link {
  color: var(--brand);
  text-decoration: none;
}

.tc-link:hover {
  text-decoration: underline;
}

.filter-input-sm {
  max-width: 88px;
}

.panel-subtitle {
  margin: -8px 0 16px;
  font-size: 13px;
}

.trend-filter-bar {
  flex-wrap: wrap;
}

/* ── Page layout ─────────────────────────────────────── */
.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 60px;
  width: 100%;
}

/* ── Login ───────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 0%, #1a2a4a 0%, var(--bg) 70%);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}

.login-brand {
  text-align: center;
  margin-bottom: 28px;
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}

.login-sub {
  font-size: 14px;
}

/* ── Forms ───────────────────────────────────────────── */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text);
  font-family: var(--font-sans);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

input::placeholder { color: var(--text-faint); }

/* ── Buttons ─────────────────────────────────────────── */
button { font-family: var(--font-sans); cursor: pointer; border: none; }

.btn-primary {
  background: var(--brand-dim);
  color: #fff;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  transition: background 0.15s, transform 0.1s;
}

.btn-primary:hover:not(:disabled) { background: var(--brand); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-outline {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: color 0.15s, border-color 0.15s;
}

.btn-outline:hover { color: var(--text); border-color: var(--text-muted); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: color 0.15s, background 0.15s;
}

.btn-ghost:hover { color: var(--text); background: var(--surface-3); }

.back-btn {
  background: transparent;
  color: var(--brand);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 0;
  margin-bottom: 20px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: opacity 0.15s;
}

.back-btn:hover { opacity: 0.75; }

/* ── Cards ───────────────────────────────────────────── */
.cards {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.card:hover { border-color: var(--surface-3); box-shadow: var(--shadow-sm); }

.card-label {
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.card-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
  line-height: 1.1;
}

.card-sub {
  font-size: 12px;
  margin-top: 4px;
}

/* ── Panels ──────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 16px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.panel-subtitle {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted);
}

/* ── Filter Bar ──────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-input {
  width: 200px;
  padding: 7px 10px;
  font-size: 13px;
}

/* ── Table ───────────────────────────────────────────── */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
}

.table td {
  border-bottom: 1px solid var(--border-subtle);
  padding: 11px 10px;
  vertical-align: top;
}

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

.run-row {
  cursor: pointer;
  transition: background 0.12s;
}

.run-row:hover { background: var(--surface-2); }
.run-row:hover .run-id-cell { color: var(--brand); }

.run-id-cell {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  transition: color 0.12s;
}

/* ── Branch Pill ─────────────────────────────────────── */
.branch-pill {
  display: inline-block;
  background: var(--surface-3);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

/* ── Pass Rate Pill ──────────────────────────────────── */
.rate-pill {
  display: inline-block;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  line-height: 1.5;
}

/* ── Run Detail ──────────────────────────────────────── */
.detail-view {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.detail-run-id {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.detail-meta {
  text-align: right;
}

.run-link {
  display: inline-block;
  margin-top: 6px;
  font-size: 13px;
  color: var(--brand);
}

.run-link:hover { text-decoration: underline; }

.detail-kpis {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
  line-height: 1;
}

/* ── Status Tabs ─────────────────────────────────────── */
.tc-filter-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tab-btn {
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  text-decoration: none;
}

.tab-btn:hover { color: var(--text); border-color: var(--surface-3); }
.tab-btn.active { color: #fff; border-color: transparent; }
.tab-btn.active.tab-all     { background: var(--brand-dim); }
.tab-btn.active.tab-passed  { background: #1a4a2a; color: var(--good); border-color: var(--good); }
.tab-btn.active.tab-failed  { background: #3a1515; color: var(--bad);  border-color: var(--bad); }
.tab-btn.active.tab-error   { background: #3a1515; color: var(--bad);  border-color: var(--bad); }
.tab-btn.active.tab-skipped { background: #3a2e10; color: var(--warn); border-color: var(--warn); }

.tab-count {
  background: var(--surface-3);
  border-radius: 20px;
  padding: 0 5px;
  font-size: 11px;
}

/* ── Test Case Table ─────────────────────────────────── */
.tc-table {
  table-layout: fixed;
}

.tc-table th:nth-child(1) { width: 90px;  }   /* Status badge */
.tc-table th:nth-child(2) { width: 45%;   }   /* Test Name — primary column */
.tc-table th:nth-child(3) { width: 35%;   }   /* Class / Suite */
.tc-table th:nth-child(4) { width: 80px;  }   /* Duration */

.tc-table td { padding: 10px; }

.tc-name {
  font-family: var(--font-mono);
  font-size: 13px;
  word-break: break-all;
  color: var(--text);
}

/* Class/Suite column: long fully-qualified names must wrap */
.tc-table td.mono {
  word-break: break-all;
  overflow-wrap: anywhere;
}

.tc-error-msg {
  margin-top: 6px;
  background: var(--error-bg);
  border: 1px solid #3a1515;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--bad);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 120px;
  overflow-y: auto;
}

.tc-row-error { background: rgba(248, 81, 73, 0.04); }

/* ── Status Badges ───────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

.badge-passed  { background: #1a4a2a; color: var(--good); }
.badge-failed  { background: #3a1515; color: var(--bad); }
.badge-error   { background: #3a1515; color: var(--bad); }
.badge-skipped { background: #3a2e10; color: var(--warn); }

/* ── Utilities ───────────────────────────────────────── */
.muted   { color: var(--text-muted); font-size: 13px; }
.mono    { font-family: var(--font-mono); font-size: 12px; }
.error   {
  color: var(--bad);
  background: var(--error-bg);
  border: 1px solid #3a1515;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  margin: 12px 0;
}

/* ── Anchor resets for elements styled as buttons/links ─ */
a.back-btn,
a.btn-ghost,
a.run-link {
  text-decoration: none;
}

a.topbar-brand {
  text-decoration: none;
  color: inherit;
}

/* ── Playwright report embed ─────────────────────────── */
.report-panel {
  margin-top: 20px;
}

.report-frame {
  width: 100%;
  min-height: 720px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
}

.tc-artifact-link {
  display: inline-block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--brand);
  text-decoration: none;
}

.tc-artifact-link:hover {
  text-decoration: underline;
}

/* ── Trend pages (Tests / Suites) ───────────────────── */
.trend-page {
  max-width: 1280px;
}

.page-header {
  margin-bottom: 18px;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.4px;
  margin-bottom: 4px;
}

.page-subtitle {
  font-size: 14px;
}

.trend-stats {
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 16px;
}

.trend-stats-3 {
  grid-template-columns: repeat(3, 1fr);
}

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

.page-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.apps-inactive-note {
  font-size: 13px;
  margin: -6px 0 14px;
}

.inactive-pill {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: rgba(110, 118, 129, 0.2);
  color: var(--text-muted);
  vertical-align: middle;
}

.app-overview-card-inactive {
  opacity: 0.82;
  border-style: dashed;
}

.filter-grid-flaky {
  grid-template-columns: 88px repeat(3, minmax(120px, 1fr)) repeat(2, 72px) auto;
}

.flip-rate-cell {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 88px;
}

/* ── App overview ────────────────────────────────────── */
.app-overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 16px;
}

.app-overview-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 0;
}

.app-ov-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.app-ov-title-block {
  min-width: 0;
  flex: 1;
}

.app-ov-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.app-ov-updated {
  font-size: 12px;
}

.app-ov-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  flex-wrap: wrap;
}

.app-ov-workflow {
  max-width: 180px;
}

.app-ov-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.stat-chip {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 500;
}

.stat-good { background: #1a4a2a; color: var(--good); }
.stat-bad  { background: #3a1515; color: var(--bad); }
.stat-warn { background: #3a2e10; color: var(--warn); }
.stat-neutral { background: #21262d; color: var(--text-muted); }

.app-ov-trend-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.app-ov-trend-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
  white-space: nowrap;
}

.app-ov-chart {
  height: 150px;
  margin-top: 0;
}

.app-ov-links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 4px;
  border-top: 1px solid var(--border-subtle);
}

.app-overview-card .pass-rate-cell {
  flex-shrink: 0;
  min-width: 96px;
}

.filters-panel {
  margin-bottom: 16px;
  padding: 18px 20px;
}

.filter-grid {
  display: grid;
  grid-template-columns: 1.4fr repeat(3, minmax(120px, 1fr)) repeat(2, 72px) auto;
  gap: 12px;
  align-items: end;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.filter-field-wide {
  grid-column: span 1;
}

.filter-field-sm {
  max-width: 88px;
}

.filter-field-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.filter-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 1px;
}

.btn-sm {
  padding: 8px 14px;
  font-size: 13px;
}

.table-wrap {
  overflow-x: auto;
  margin: 0 -4px;
  padding: 0 4px 4px;
}

.trend-table {
  table-layout: fixed;
  min-width: 980px;
}

.trend-table .col-test       { width: 22%; }
.trend-table .col-suite      { width: 20%; }
.trend-table .col-suite-wide { width: 28%; }
.trend-table .col-recent     { width: 110px; }
.trend-table .col-rate       { width: 120px; }
.trend-table .col-runs       { width: 88px; }
.trend-table .col-status     { width: 92px; }
.trend-table .col-failed     { width: 88px; }
.trend-table .col-time       { width: 108px; }

.cell-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.cell-primary {
  font-weight: 500;
  color: var(--text);
}

.cell-secondary {
  font-size: 12px;
  color: var(--text-muted);
}

.truncate-cell {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.nowrap {
  white-space: nowrap;
}

.runs-breakdown {
  display: block;
  font-weight: 600;
}

.runs-breakdown-sub {
  display: block;
  font-size: 11px;
  margin-top: 2px;
}

.pass-rate-cell {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 88px;
}

.pass-bar {
  height: 5px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}

.pass-bar-fill {
  height: 100%;
  border-radius: 999px;
  min-width: 2px;
}

.pass-bar-fill-good { background: var(--good); }
.pass-bar-fill-warn { background: var(--warn); }
.pass-bar-fill-bad  { background: var(--bad); }

.rate-pill-good { background: #1a4a2a; color: var(--good); }
.rate-pill-warn { background: #3a2e10; color: var(--warn); }
.rate-pill-bad  { background: #3a1515; color: var(--bad); }

.outcome-dots,
.rate-sparkline {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
}

.outcome-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.outcome-dot-passed  { background: var(--good); }
.outcome-dot-failed  { background: var(--bad); }
.outcome-dot-skipped { background: var(--warn); }

.rate-sparkline {
  align-items: flex-end;
  height: 28px;
  gap: 3px;
}

.rate-spark {
  display: block;
  width: 7px;
  min-height: 4px;
  border-radius: 2px 2px 0 0;
  align-self: flex-end;
}

.rate-spark-good { background: rgba(63, 185, 80, 0.85); }
.rate-spark-warn { background: rgba(210, 153, 34, 0.9); }
.rate-spark-bad  { background: rgba(248, 81, 73, 0.9); }

.empty-state {
  padding: 36px 12px;
  text-align: center;
}

.empty-state-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 6px;
}

.detail-header-main {
  flex: 1;
  min-width: 0;
}

.detail-title {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 8px;
  word-break: break-word;
}

.fingerprint-id {
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-all;
}

.chart-wrap {
  height: 240px;
  position: relative;
  margin-top: 8px;
}

@media (max-width: 1100px) {
  .trend-stats,
  .trend-stats-3,
  .trend-stats-4 { grid-template-columns: repeat(2, 1fr); }
  .filter-grid,
  .filter-grid-flaky {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .filter-field-wide { grid-column: 1 / -1; }
  .filter-actions { grid-column: 1 / -1; }
  .page-header-row { flex-direction: column; }
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 900px) {
  .cards        { grid-template-columns: repeat(2, 1fr); }
  .trend-stats  { grid-template-columns: repeat(2, 1fr); }
  .detail-kpis  { grid-template-columns: repeat(3, 1fr); }
  .filter-grid  { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .cards        { grid-template-columns: 1fr 1fr; }
  .detail-kpis  { grid-template-columns: repeat(2, 1fr); }
  .filter-input { width: 100%; }
  .panel-header { flex-direction: column; align-items: flex-start; }
}
