/* ============================================================
   TST Cluster Dashboard — Stylesheet
   Dark theme, Grafana/Datadog aesthetic
   No external dependencies — fully self-contained
   ============================================================ */

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

/* ── CSS Custom Properties ────────────────────────────────── */
:root {
  /* Background layers */
  --bg-base:        #0d1117;
  --bg-surface:     #161b22;
  --bg-elevated:    #1c2330;
  --bg-card:        #1e2636;
  --bg-card-hover:  #242e42;

  /* Brand / accent */
  --accent-blue:    #388bfd;
  --accent-blue-dim:#1f6feb;

  /* Status colours */
  --status-ok:      #3fb950;
  --status-ok-bg:   rgba(63, 185, 80, 0.10);
  --status-ok-border: rgba(63, 185, 80, 0.30);

  --status-warn:    #d29922;
  --status-warn-bg: rgba(210, 153, 34, 0.10);
  --status-warn-border: rgba(210, 153, 34, 0.35);

  --status-crit:    #f85149;
  --status-crit-bg: rgba(248, 81, 73, 0.10);
  --status-crit-border: rgba(248, 81, 73, 0.35);

  --status-error:   #f85149;
  --status-error-bg: rgba(248, 81, 73, 0.08);
  --status-error-border: rgba(248, 81, 73, 0.50);

  /* Text */
  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-muted:     #6e7681;
  --text-code:      #79c0ff;

  /* Borders */
  --border-subtle:  #21262d;
  --border-default: #30363d;
  --border-muted:   #3d444d;

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  /* Radius */
  --radius-sm:  4px;
  --radius-md:  6px;
  --radius-lg:  10px;

  /* Transition */
  --transition: 150ms ease;
}

/* ── Base Typography ─────────────────────────────────────── */
html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-base);
  min-height: 100vh;
}

/* ── Layout Shell ────────────────────────────────────────── */
.dashboard-wrapper {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 var(--space-6) var(--space-8);
}

/* ── Header ──────────────────────────────────────────────── */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) 0 var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-6);
  gap: var(--space-4);
  flex-wrap: wrap;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.header-logo {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent-blue-dim), var(--accent-blue));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.header-logo svg {
  width: 18px;
  height: 18px;
  fill: #ffffff;
}

.header-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.header-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.last-collected {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.last-collected-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--status-ok);
  animation: pulse-dot 2s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* Auto-refresh toggle */
.autorefresh-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  user-select: none;
}

.autorefresh-label input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 28px;
  height: 16px;
  background: var(--border-muted);
  border-radius: 8px;
  position: relative;
  cursor: pointer;
  transition: background var(--transition);
  flex-shrink: 0;
}

.autorefresh-label input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: left var(--transition), background var(--transition);
}

.autorefresh-label input[type="checkbox"]:checked {
  background: var(--accent-blue-dim);
}

.autorefresh-label input[type="checkbox"]:checked::after {
  left: 14px;
  background: #ffffff;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 14px;
  font-size: 13px;
  font-family: var(--font-sans);
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
  line-height: 1.4;
  text-decoration: none;
  user-select: none;
}

.btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--accent-blue-dim);
  border-color: var(--accent-blue-dim);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
}

.btn-primary:active {
  transform: scale(0.97);
}

.btn-secondary {
  background: transparent;
  border-color: var(--border-muted);
  color: var(--text-secondary);
}
.btn-secondary:hover {
  background: var(--bg-elevated);
  border-color: var(--border-default);
  color: var(--text-primary);
}
.btn-secondary:active { transform: scale(0.97); }

.btn-primary.loading svg {
  animation: spin 0.8s linear infinite;
}

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

/* ── Summary Bar ─────────────────────────────────────────── */
.summary-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--stat-accent, var(--border-muted));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.stat-card--total  { --stat-accent: var(--accent-blue-dim); }
.stat-card--ok     { --stat-accent: var(--status-ok); }
.stat-card--behind { --stat-accent: var(--status-warn); }
.stat-card--failures { --stat-accent: var(--status-crit); }
.stat-card--failures .stat-value { color: var(--status-crit); }

.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  color: var(--text-primary);
  letter-spacing: -1px;
}

.stat-card--ok     .stat-value { color: var(--status-ok); }
.stat-card--behind .stat-value { color: var(--status-warn); }

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

/* ── Toolbar (Sort / Filter) ─────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.toolbar-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

/* Pill button group */
.btn-group {
  display: flex;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.btn-group .pill {
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-sans);
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-right: 1px solid var(--border-default);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}

.btn-group .pill:last-child {
  border-right: none;
}

.btn-group .pill:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.btn-group .pill.active {
  background: var(--accent-blue-dim);
  color: #ffffff;
}

/* App count badge */
.app-count-badge {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: 10px;
  padding: 2px 8px;
}

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

/* ── App Card ────────────────────────────────────────────── */
.app-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
  position: relative;
  overflow: hidden;
}

.app-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-muted);
  transform: translateY(-1px);
}

/* Left-side accent bar */
.app-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 3px;
  background: var(--card-accent, var(--border-muted));
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
}

.app-card--ok     { --card-accent: var(--status-ok); }
.app-card--warn   { --card-accent: var(--status-warn); }
.app-card--crit   { --card-accent: var(--status-crit); }
.app-card--error  {
  --card-accent: var(--status-error);
  background: var(--status-error-bg);
  border-color: var(--status-error-border);
}

/* Card header row */
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.card-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.2px;
  word-break: break-word;
  line-height: 1.3;
}

/* Status badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  white-space: nowrap;
  flex-shrink: 0;
}

.status-badge svg {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
}

.status-badge--ok {
  background: var(--status-ok-bg);
  color: var(--status-ok);
  border: 1px solid var(--status-ok-border);
}

.status-badge--warn {
  background: var(--status-warn-bg);
  color: var(--status-warn);
  border: 1px solid var(--status-warn-border);
}

.status-badge--crit {
  background: var(--status-crit-bg);
  color: var(--status-crit);
  border: 1px solid var(--status-crit-border);
}

/* Card meta rows */
.card-meta {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.meta-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 12px;
}

.meta-icon {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.meta-icon svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.meta-label {
  color: var(--text-muted);
  min-width: 70px;
  flex-shrink: 0;
}

.meta-value {
  color: var(--text-secondary);
  word-break: break-all;
}

.meta-value--code {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-code);
}

.meta-value a {
  color: var(--text-code);
  text-decoration: none;
  transition: color var(--transition);
}

.meta-value a:hover {
  color: var(--accent-blue);
  text-decoration: underline;
}

/* Branch pill */
.branch-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
}

.branch-pill svg {
  width: 11px;
  height: 11px;
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Commits-behind indicator */
.commits-behind-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 12px;
}

.commits-behind-text {
  font-weight: 600;
}

.commits-behind-text--warn { color: var(--status-warn); }
.commits-behind-text--crit { color: var(--status-crit); }
.commits-behind-text--ok   { color: var(--status-ok); }

/* SHA display */
.sha-pair {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 11.5px;
  font-family: var(--font-mono);
}

.sha-deployed {
  color: var(--text-code);
}

.sha-separator {
  color: var(--text-muted);
}

.sha-head {
  color: var(--text-muted);
}

/* Tooltip wrapper */
[data-tooltip] {
  position: relative;
  cursor: default;
}

[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;
}

[data-tooltip]:hover::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 1px);
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: var(--border-muted);
  pointer-events: none;
  z-index: 101;
}

/* Card footer — image tag */
.card-footer {
  border-top: 1px solid var(--border-subtle);
  padding-top: var(--space-3);
  margin-top: auto;
}

.image-tag {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-muted);
  word-break: break-all;
  line-height: 1.4;
}

.image-tag-label {
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: block;
  margin-bottom: 2px;
  font-family: var(--font-sans);
}

/* Error block */
.error-block {
  background: var(--status-error-bg);
  border: 1px solid var(--status-error-border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  font-size: 12px;
  color: var(--status-error);
}

.error-block svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  margin-top: 1px;
  stroke: var(--status-error);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

/* ── CI/CD Section ───────────────────────────────────────── */
.ci-section {
  border-top: 1px solid var(--border-subtle);
  padding-top: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.ci-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 12px;
  flex-wrap: wrap;
}
.ci-row-label {
  color: var(--text-muted);
  min-width: 80px;
  flex-shrink: 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.ci-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid transparent;
}
.ci-badge--success { background: var(--status-ok-bg);   color: var(--status-ok);   border-color: var(--status-ok-border); }
.ci-badge--failure { background: var(--status-crit-bg); color: var(--status-crit); border-color: var(--status-crit-border); }
.ci-badge--pending { background: var(--status-warn-bg); color: var(--status-warn); border-color: var(--status-warn-border); }
.ci-badge--unknown { background: var(--bg-elevated);    color: var(--text-muted);  border-color: var(--border-default); }
.ci-pipeline-link {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition);
}
.ci-pipeline-link:hover { color: var(--accent-blue); text-decoration: underline; }
.job-pills {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  padding-top: var(--space-1);
}
.job-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-size: 10.5px;
  font-family: var(--font-sans);
  border: 1px solid var(--border-default);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  white-space: nowrap;
}
.job-pill--success { border-color: var(--status-ok-border);   color: var(--status-ok); }
.job-pill--failure { border-color: var(--status-crit-border); color: var(--status-crit); }
.job-pill--skipped { opacity: 0.55; }
.job-pill--pending { border-color: var(--status-warn-border); color: var(--status-warn); }

/* ── Loading / Empty / Error States ─────────────────────── */
.state-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 40vh;
  gap: var(--space-4);
  color: var(--text-secondary);
  text-align: center;
  padding: var(--space-8);
}

.state-icon {
  width: 48px;
  height: 48px;
  color: var(--text-muted);
}

.state-icon svg {
  width: 48px;
  height: 48px;
  stroke: currentColor;
  stroke-width: 1.25;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.state-sub {
  font-size: 13px;
  color: var(--text-secondary);
  max-width: 380px;
  line-height: 1.6;
}

/* Spinner */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-default);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-base);
}

::-webkit-scrollbar-thumb {
  background: var(--border-muted);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .dashboard-wrapper {
    padding: 0 var(--space-4) var(--space-6);
  }

  .summary-bar {
  grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
  }

  .stat-value {
    font-size: 24px;
  }

  .app-grid {
    grid-template-columns: 1fr;
  }

  .site-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .toolbar {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 480px) {
  .summary-bar {
    grid-template-columns: 1fr;
  }

  .btn-group {
    flex-wrap: wrap;
  }
}

/* ── Footer ──────────────────────────────────────────────── */
.site-footer {
  margin-top: var(--space-8);
  padding: var(--space-5) 0;
  border-top: 1px solid var(--border-subtle);
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Utility ─────────────────────────────────────────────── */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.fade-in {
  animation: fadeIn 200ms ease forwards;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
