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

:root {
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --green: #10b981;
  --green-bg: #ecfdf5;
  --green-text: #065f46;
  --yellow: #f59e0b;
  --yellow-bg: #fffbeb;
  --yellow-text: #92400e;
  --red: #ef4444;
  --red-bg: #fef2f2;
  --red-text: #991b1b;
  --gray: #9ca3af;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  font-size: 14px;
}

/* ===== Login ===== */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-header h1 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.login-header p { color: var(--text-muted); font-size: 0.9rem; }

.form-group { margin-bottom: 1.25rem; }
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
}
.form-group input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}
.form-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.error-message {
  color: var(--red);
  font-size: 0.85rem;
  margin-bottom: 1rem;
  padding: 0.5rem 0.75rem;
  background: var(--red-bg);
  border-radius: var(--radius);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-primary { background: var(--primary); color: white; width: 100%; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { background: var(--gray); cursor: not-allowed; }
.btn-secondary {
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  width: 100%;
  margin-top: 0.75rem;
}
.btn-secondary:hover { background: var(--bg); }
.btn-small {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.btn-small:hover { background: var(--bg); color: var(--text); }
.btn-sync-stub { opacity: 0.55; cursor: not-allowed; }
.btn-sync-stub:hover { background: transparent; color: var(--text-muted); }

/* ===== Navbar ===== */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1.5rem;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}
.nav-left { display: flex; align-items: center; gap: 0.75rem; }
.nav-left h2 { font-size: 1rem; }
.nav-account {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg);
  padding: 0.15rem 0.5rem;
  border-radius: 12px;
}
.nav-right { display: flex; align-items: center; gap: 0.5rem; }

/* ===== Layout ===== */
.container { max-width: 1100px; margin: 0 auto; padding: 1.25rem; }
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card h3 {
  font-size: 0.8rem;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ===== Health Card ===== */
.health-card {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.health-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.1rem;
  font-weight: 600;
  min-width: 140px;
}
.health-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--gray);
  flex-shrink: 0;
}
.health-badge.healthy .health-dot { background: var(--green); }
.health-badge.degraded .health-dot { background: var(--yellow); }
.health-badge.failing .health-dot { background: var(--red); }
.health-badge.unknown .health-dot { background: var(--gray); }
.health-details { display: flex; gap: 1.5rem; flex-wrap: wrap; flex: 1; }
.stat { display: flex; flex-direction: column; }
.stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stat-value { font-size: 1rem; font-weight: 600; }

/* ===== Run List ===== */
.runs-list { display: flex; flex-direction: column; gap: 0; }
.loading-text {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem;
}

/* Run row (clickable) */
.run-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background 0.1s;
  border-radius: var(--radius-sm);
}
.run-row:hover { background: #f9fafb; }
.run-row.expanded { background: #f0f0ff; border-bottom-color: transparent; }
.run-row .run-date { min-width: 160px; font-weight: 500; font-size: 0.85rem; }
.run-row .run-meta {
  display: flex;
  gap: 1.25rem;
  flex: 1;
  align-items: center;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.run-row .run-meta span { white-space: nowrap; }
.run-row .run-chevron {
  color: var(--gray);
  font-size: 0.75rem;
  transition: transform 0.15s;
}
.run-row.expanded .run-chevron { transform: rotate(90deg); }

/* Run detail (expandable) */
.run-detail {
  display: none;
  padding: 0 0.75rem 0.75rem 0.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
}
.run-detail.open { display: block; }

/* ===== Tables ===== */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
th {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 2px solid var(--border);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
td {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
}
tbody tr:hover { background: #fafafa; }

/* Collection row (expandable to show tables) */
tr.collection-row { cursor: pointer; }
tr.collection-row:hover { background: #f5f5ff; }
tr.collection-row td:first-child { font-weight: 500; }
tr.collection-row .coll-chevron {
  display: inline-block;
  font-size: 0.7rem;
  color: var(--gray);
  margin-right: 0.35rem;
  transition: transform 0.15s;
}
tr.collection-row.expanded .coll-chevron { transform: rotate(90deg); }

/* Sub-table rows (individual BQ tables under a collection) */
tr.table-sub-row { display: none; }
tr.table-sub-row.visible { display: table-row; }
tr.table-sub-row td {
  padding-left: 2rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  background: #fafbfc;
  border-bottom-color: #f0f1f3;
}
tr.table-sub-row td:first-child { font-weight: 400; }

/* ===== Status Badges ===== */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.45rem;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 500;
}
.status-badge.success { background: var(--green-bg); color: var(--green-text); }
.status-badge.failed { background: var(--red-bg); color: var(--red-text); }

/* Write strategy badges */
.strategy-badge {
  display: inline-flex;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 500;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  letter-spacing: 0.02em;
}
.strategy-badge.truncate { background: #eef2ff; color: #4338ca; }
.strategy-badge.append { background: var(--yellow-bg); color: var(--yellow-text); }

.error-text {
  color: var(--red);
  font-size: 0.78rem;
  max-width: 280px;
  word-break: break-word;
}

.muted { color: var(--text-muted); }
.section-desc { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.75rem; }
.mono { font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace; font-size: 0.78rem; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .health-card { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
  .health-details { gap: 0.75rem; }
  .run-row { flex-wrap: wrap; }
  .run-row .run-date { min-width: 100%; }
  .run-row .run-meta { flex-wrap: wrap; gap: 0.5rem; }
  .navbar { flex-direction: column; gap: 0.4rem; align-items: flex-start; }
  .nav-right { width: 100%; justify-content: flex-end; }
}

#load-more-container { text-align: center; padding: 0.5rem; }

/* ===== Tooltips ===== */
[data-tip] {
  position: relative;
  cursor: help;
}
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #f1f5f9;
  font-size: 0.72rem;
  font-weight: 400;
  line-height: 1.4;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  white-space: normal;
  width: max-content;
  max-width: 260px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 100;
  text-transform: none;
  letter-spacing: normal;
}
[data-tip]:hover::after { opacity: 1; }
/* Tooltip arrow */
[data-tip]::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: #1e293b;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 100;
}
[data-tip]:hover::before { opacity: 1; }
/* Info icon for inline help */
.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  font-size: 0.6rem;
  font-weight: 700;
  font-style: normal;
  margin-left: 0.3rem;
  cursor: help;
  vertical-align: middle;
  flex-shrink: 0;
}
/* Collection description in row counts */
.coll-desc {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: 1px;
}
