/* ============================================================
   COMPONENTS.CSS — Header, table, modal, buttons, form, footer
   ============================================================ */

/* ── HEADER ── */
.cluster-header {
  background: var(--c-bg-elevated);
  border-bottom: 1px solid var(--c-border);
  padding: var(--sp-3) var(--sp-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-3);
  position: sticky;
  top: 0;
  z-index: 100;
}

.cluster-header__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.cluster-header__logo {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--c-cyan-dim);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-md);
  font-weight: 700;
  color: var(--c-bg);
}

.cluster-header__title {
  font-size: var(--font-size-md);
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--c-text-heading);
}

.cluster-header__title span {
  color: var(--c-cyan);
}

.cluster-header__meta {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  font-size: var(--font-size-sm);
}

.cluster-status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: var(--font-size-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid transparent;
  transition: all var(--duration-normal) var(--ease-out);
}

.cluster-status-badge--operational {
  color: var(--c-green);
  background: rgba(63, 185, 80, 0.1);
  border-color: rgba(63, 185, 80, 0.25);
}

.cluster-status-badge--degraded {
  color: var(--c-yellow);
  background: rgba(210, 153, 34, 0.1);
  border-color: rgba(210, 153, 34, 0.25);
}

.cluster-status-badge--fatal {
  color: var(--c-red);
  background: rgba(248, 81, 73, 0.12);
  border-color: rgba(248, 81, 73, 0.3);
  box-shadow: var(--shadow-glow-red);
}

.cluster-status-badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.cluster-header__clock {
  color: var(--c-text-muted);
  font-variant-numeric: tabular-nums;
}

.cluster-header__partition-count {
  color: var(--c-text-muted);
}
.cluster-header__partition-count strong {
  color: var(--c-cyan);
}

/* ── TOOLBAR ── */
.toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}

.toolbar__group {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.toolbar__spacer {
  flex: 1;
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  font-weight: 500;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  background: var(--c-bg-surface);
  color: var(--c-text);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  white-space: nowrap;
  user-select: none;
}

.btn:hover {
  background: var(--c-bg-hover);
  border-color: var(--c-text-muted);
}

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

.btn--primary {
  background: rgba(57, 210, 224, 0.12);
  border-color: var(--c-cyan-dim);
  color: var(--c-cyan);
}
.btn--primary:hover {
  background: rgba(57, 210, 224, 0.2);
  border-color: var(--c-cyan);
}

.btn--danger {
  background: rgba(248, 81, 73, 0.08);
  border-color: var(--c-red-dim);
  color: var(--c-red);
}
.btn--danger:hover {
  background: rgba(248, 81, 73, 0.18);
  border-color: var(--c-red);
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--c-text-muted);
}
.btn--ghost:hover {
  color: var(--c-text);
  background: var(--c-bg-hover);
}

.btn--sm {
  padding: var(--sp-1) var(--sp-2);
  font-size: var(--font-size-xs);
}

.btn__icon {
  font-size: 1em;
  line-height: 1;
}

/* ── JOB TABLE ── */
.job-table-container {
  background: var(--c-bg-elevated);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.job-table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--c-border);
  background: var(--c-bg-surface);
}

.job-table-header__title {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--c-text-heading);
  letter-spacing: 0.03em;
}

.job-table-header__count {
  font-size: var(--font-size-xs);
  color: var(--c-text-muted);
}

.job-table-wrapper {
  overflow-x: auto;
}

.job-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
  font-variant-numeric: tabular-nums;
}

.job-table thead th {
  position: sticky;
  top: 0;
  background: var(--c-bg-surface);
  color: var(--c-text-muted);
  font-weight: 500;
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--sp-2) var(--sp-3);
  text-align: left;
  border-bottom: 1px solid var(--c-border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: color var(--duration-fast) var(--ease-out);
}

.job-table thead th:hover {
  color: var(--c-cyan);
}

.job-table thead th.sort-active {
  color: var(--c-cyan);
}

.job-table thead th .sort-indicator {
  display: inline-block;
  margin-left: var(--sp-1);
  font-size: 0.7em;
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease-out);
}

.job-table thead th.sort-active .sort-indicator {
  opacity: 1;
}

.job-table tbody tr {
  border-bottom: 1px solid rgba(48, 54, 61, 0.5);
  transition: background var(--duration-fast) var(--ease-out);
}

.job-table tbody tr:hover {
  background: var(--c-bg-hover);
}

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

.job-table tbody td {
  padding: var(--sp-2) var(--sp-3);
  vertical-align: middle;
  white-space: nowrap;
}

/* Job ID column */
.td-jobid {
  color: var(--c-magenta);
  font-weight: 500;
}

/* State badge */
.state-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 1px var(--sp-2);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  border: 1px solid transparent;
}

.state-badge--PD {
  color: var(--c-yellow);
  background: rgba(210, 153, 34, 0.1);
  border-color: rgba(210, 153, 34, 0.2);
}

.state-badge--R {
  color: var(--c-cyan);
  background: rgba(57, 210, 224, 0.1);
  border-color: rgba(57, 210, 224, 0.2);
}

.state-badge--CG {
  color: var(--c-magenta);
  background: rgba(210, 168, 255, 0.1);
  border-color: rgba(210, 168, 255, 0.2);
}

.state-badge--CD {
  color: var(--c-green);
  background: rgba(63, 185, 80, 0.08);
  border-color: rgba(63, 185, 80, 0.15);
}

.state-badge--NF {
  color: var(--c-red);
  background: rgba(248, 81, 73, 0.1);
  border-color: rgba(248, 81, 73, 0.25);
}

/* Progress cell */
.td-progress {
  min-width: 120px;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--c-bg);
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
}

.progress-bar__fill {
  height: 100%;
  border-radius: var(--radius-sm);
  transition: width 1s linear;
  position: relative;
}

.progress-bar__fill--PD { background: var(--c-yellow-dim); }
.progress-bar__fill--R  { background: var(--c-cyan); }
.progress-bar__fill--CG { background: var(--c-magenta); }
.progress-bar__fill--CD { background: var(--c-green); }
.progress-bar__fill--NF { background: var(--c-red); }

.progress-bar__pct {
  font-size: var(--font-size-xs);
  color: var(--c-text-muted);
  margin-top: 2px;
  text-align: right;
}

/* Action cell */
.td-actions {
  display: flex;
  gap: var(--sp-1);
}

/* Empty state */
.job-table-empty {
  padding: var(--sp-8) var(--sp-4);
  text-align: center;
  color: var(--c-text-muted);
  font-size: var(--font-size-md);
}
.job-table-empty__icon {
  font-size: 2rem;
  margin-bottom: var(--sp-2);
  opacity: 0.4;
}

/* ── SIDEBAR / STATS PANEL ── */
.stats-panel {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.stat-card {
  background: var(--c-bg-elevated);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-3) var(--sp-4);
  box-shadow: var(--shadow-sm);
}

.stat-card__title {
  font-size: var(--font-size-xs);
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--sp-2);
}

.stat-card__value {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--c-text-heading);
  font-variant-numeric: tabular-nums;
}

.stat-card__sub {
  font-size: var(--font-size-xs);
  color: var(--c-text-muted);
  margin-top: var(--sp-1);
}

.stat-card__bar {
  margin-top: var(--sp-2);
  height: 4px;
  background: var(--c-bg);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.stat-card__bar-fill {
  height: 100%;
  border-radius: var(--radius-sm);
  background: var(--c-cyan);
  transition: width var(--duration-slow) var(--ease-out);
}

/* Node utilization grid */
.node-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
  margin-top: var(--sp-2);
}

.node-grid__cell {
  aspect-ratio: 1;
  border-radius: 2px;
  background: var(--c-bg);
  transition: background var(--duration-normal) var(--ease-out);
}

.node-grid__cell--idle    { background: var(--c-green-dim); }
.node-grid__cell--running { background: var(--c-cyan); }
.node-grid__cell--failed  { background: var(--c-red); }

/* ── MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--duration-normal) var(--ease-out),
              visibility var(--duration-normal);
}

.modal-overlay--active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--c-bg-elevated);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
  transform: translateY(8px);
  transition: transform var(--duration-normal) var(--ease-out);
}

.modal-overlay--active .modal {
  transform: translateY(0);
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--c-border);
}

.modal__title {
  font-size: var(--font-size-md);
  font-weight: 600;
  color: var(--c-text-heading);
}

.modal__close {
  background: none;
  border: none;
  color: var(--c-text-muted);
  font-size: var(--font-size-lg);
  cursor: pointer;
  padding: var(--sp-1);
  line-height: 1;
  transition: color var(--duration-fast);
}
.modal__close:hover { color: var(--c-text); }

.modal__body {
  padding: var(--sp-4);
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--c-border);
}

/* Error modal specifics */
.error-detail {
  font-size: var(--font-size-sm);
  line-height: 1.7;
}

.error-detail__label {
  color: var(--c-text-muted);
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.error-detail__value {
  color: var(--c-red);
  font-weight: 500;
}

.error-detail__trace {
  margin-top: var(--sp-3);
  padding: var(--sp-3);
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  font-size: var(--font-size-xs);
  color: var(--c-text-muted);
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 160px;
  overflow-y: auto;
}

/* ── FORM ── */
.form-group {
  margin-bottom: var(--sp-3);
}

.form-group label {
  display: block;
  font-size: var(--font-size-xs);
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--sp-1);
  font-weight: 500;
}

.form-input {
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  color: var(--c-text);
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  transition: border-color var(--duration-fast) var(--ease-out);
}

.form-input:focus {
  border-color: var(--c-cyan);
  outline: none;
  box-shadow: 0 0 0 3px rgba(57, 210, 224, 0.1);
}

.form-input::placeholder {
  color: var(--c-text-muted);
  opacity: 0.5;
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238b949e'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

/* ── FOOTER ── */
.cluster-footer {
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--c-border);
  background: var(--c-bg-elevated);
  font-size: var(--font-size-xs);
  color: var(--c-text-muted);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.cluster-footer__link {
  color: var(--c-cyan-dim);
  cursor: pointer;
}
.cluster-footer__link:hover {
  color: var(--c-cyan);
}

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .cluster-header {
    flex-direction: column;
    align-items: flex-start;
    padding: var(--sp-3);
  }
  .cluster-header__meta {
    flex-wrap: wrap;
  }
  .job-table {
    font-size: var(--font-size-xs);
  }
  .modal {
    max-width: 100%;
    margin: var(--sp-2);
  }
  .node-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

