/* Shipyard pages.css — page-specific tweaks.
 * Most styling lives in components.css; this file is for layout/positioning
 * adjustments that only apply to specific routes. Kept intentionally small
 * in Phase 1; Phases 2–4 expand it per-page.
 */

/* ----- Login ----- */
.login { max-width: 24rem; margin: var(--s-7) auto; }
.login form { display: flex; flex-direction: column; gap: var(--s-3); }
.login button { width: 100%; margin-top: var(--s-2); }

/* ----- Dashboard ----- */
p.actions { margin: var(--s-4) 0; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  flex-wrap: wrap;
  margin-bottom: var(--s-4);
}
.page-header h1 { margin: 0; }
.page-header p.actions { margin: 0; }

.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: var(--s-3);
  margin-bottom: var(--s-5);
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--s-3) var(--s-4);
  box-shadow: var(--shadow-sm);
}
.kpi-value {
  font-size: var(--text-2xl);
  font-weight: 600;
  line-height: 1.1;
  color: var(--fg);
}
.kpi-value.kpi-ok    { color: var(--success); }
.kpi-value.kpi-error { color: var(--danger); }
.kpi-value.kpi-muted { color: var(--fg-muted); }
.kpi-label {
  margin-top: var(--s-1);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-muted);
}

.dashboard-filters {
  display: flex;
  gap: var(--s-3);
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: var(--s-3);
}
.dashboard-filters input[type="search"] {
  flex: 1 1 16rem;
  max-width: 24rem;
}
.chips { display: flex; gap: var(--s-1); flex-wrap: wrap; }
.chip {
  padding: var(--s-1) var(--s-3);
  font-size: var(--text-xs);
  font-weight: 500;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg-muted);
  border-radius: 999px;
  cursor: pointer;
}
.chip:hover { background: var(--surface-alt); color: var(--fg); }
.chip.active {
  background: var(--brand-500);
  color: #fff;
  border-color: var(--brand-500);
}

.row-actions { white-space: nowrap; text-align: right; }
.row-actions .btn { padding: var(--s-1) var(--s-2); }
.svc-name a { font-weight: 500; }
.svc-name { display: flex; align-items: center; gap: var(--s-2); }
.svc-favicon { flex-shrink: 0; border-radius: 2px; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* ----- Tunnel page ----- */
dl.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--s-2) var(--s-4);
  margin: 0;
}
dl.kv dt { color: var(--fg-muted); font-size: var(--text-sm); }
dl.kv dd { margin: 0; }

/* ----- Service detail ----- */
.detail-grid {
  display: grid;
  gap: var(--s-5);
  grid-template-columns: 1fr;
}
@media (min-width: 56rem) {
  .detail-grid {
    grid-template-columns: minmax(0, 2fr) minmax(16rem, 1fr);
    grid-auto-flow: row dense;
  }
  /* Left column stacks naturally: metadata, owners, then each .jobs card.
     The sticky rail lives in column 2 and spans every row.            */
  .detail-grid > .metadata,
  .detail-grid > .owners-card,
  .detail-grid > .jobs { grid-column: 1; }
  .detail-grid > .sticky-rail {
    grid-column: 2;
    grid-row: 1 / -1;
    align-self: start;
    position: sticky;
    top: calc(var(--nav-h) + var(--s-3));
    /* Prevent the rail from growing taller than the viewport, which would
       cause it to overlap left-column content when scrolling.          */
    max-height: calc(100vh - var(--nav-h) - var(--s-6));
    overflow-y: auto;
  }
}
.action-buttons { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.action-buttons form { display: inline; }
.danger-heading {
  color: var(--danger);
  margin-top: var(--s-3);
}
.sticky-rail hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--s-4) 0;
}

/* ----- Deploy form ----- */
.deploy-form { display: flex; flex-direction: column; gap: var(--s-4); }
.deploy-form section.card h2 { margin-top: 0; }
.grid-2 {
  display: grid;
  gap: var(--s-3);
  grid-template-columns: 1fr;
}
@media (min-width: 36rem) {
  .grid-2 { grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); }
}
.form-footer {
  display: flex;
  gap: var(--s-2);
  align-items: center;
  padding-top: var(--s-2);
}

/* ----- Env editor ----- */
.env-row {
  display: grid;
  grid-template-columns: minmax(8rem, 1fr) minmax(8rem, 2fr) auto;
  gap: var(--s-2);
  margin-bottom: var(--s-2);
}
.env-row input { width: 100%; }
[data-env-remove] { font-size: var(--text-lg); line-height: 1; }

/* ----- Audit ----- */
.audit-table td code { font-size: var(--text-xs); }
.audit-row.audit-error { background: color-mix(in srgb, var(--danger-bg) 35%, transparent); }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--s-4);
}
.filter-bar__group {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  min-width: 10rem;
}
.filter-bar__group label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.filter-bar__group select {
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-size: var(--text-sm);
  min-width: 10rem;
}
.filter-bar__actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding-bottom: 1px; /* align with select bottom border */
}

/* ----- Log viewer (jobs + service logs) ----- */
.log-viewer { padding: 0; overflow: hidden; }
.log-toolbar {
  display: flex;
  gap: var(--s-2);
  align-items: center;
  flex-wrap: wrap;
  padding: var(--s-2) var(--s-3);
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
}
.log-toolbar .btn { padding: var(--s-1) var(--s-3); }
.log-toolbar .btn.active {
  background: var(--brand-500);
  color: #fff;
  border-color: var(--brand-500);
}
.log-toolbar .log-filter { flex: 1 1 12rem; max-width: 20rem; padding: var(--s-1) var(--s-2); }
.log-toolbar .log-status,
.log-toolbar .log-count { font-size: var(--text-xs); }
.log-pane {
  margin: 0;
  padding: var(--s-3);
  min-height: 22rem;
  max-height: 36rem;
  overflow: auto;
  background: var(--gray-900);
  color: #e5e7eb;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
@media (prefers-color-scheme: dark) {
  .log-pane { background: #0b0b0e; }
}

/* ----- Logout form (inline in nav) ----- */
.logout-form { margin: 0; }
.logout-form button {
  padding: var(--s-1) var(--s-3);
  font-size: var(--text-sm);
}

/* ----- Reports (cross-scope) ----- */
.reports-filters { padding: var(--s-3) var(--s-4); }
.reports-filter-form { display: flex; flex-direction: column; gap: var(--s-3); margin: 0; }
.reports-filter-form .filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-3);
}
.filter-field { display: flex; flex-direction: column; gap: var(--s-1); flex: 1 1 12rem; min-width: 10rem; }
.filter-field input,
.filter-field select { width: 100%; }
.filter-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-muted);
  font-weight: 600;
}
.reports-filter-form .filter-row > .filter-label { flex: 0 0 auto; }
.reports-filter-form .chip-failed.active { background: var(--danger);  border-color: var(--danger);  }
.reports-filter-form .chip-ok.active     { background: var(--success); border-color: var(--success); }
.reports-filter-form .chip-cancelled.active,
.reports-filter-form .chip-running.active { background: var(--fg-muted); border-color: var(--fg-muted); }

.reports-truncated-note { margin: var(--s-3) 0; font-size: var(--text-sm); }

.reports-group { padding: 0; }
.reports-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
  border-top-left-radius: var(--radius-md);
  border-top-right-radius: var(--radius-md);
}
.reports-group-title {
  margin: 0;
  font-size: var(--text-base);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: var(--s-2);
}
.reports-group-stats {
  display: flex;
  gap: var(--s-4);
  font-size: var(--text-sm);
  color: var(--fg-muted);
}
.reports-group-stats .kpi-ok    { color: var(--success); font-weight: 600; }
.reports-group-stats .kpi-error { color: var(--danger);  font-weight: 600; }

table.reports-table { border: 0; border-radius: 0; }
table.reports-table th { background: transparent; }

/* ----- Service detail: History (per-service reports) card ----- */
.reports-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-3);
  flex-wrap: wrap;
  margin-bottom: var(--s-3);
}
.reports-card-header h2 { margin: 0; }
.reports-card-substats { margin: var(--s-1) 0 0; font-size: var(--text-sm); }
.reports-card-substats .kpi-ok    { color: var(--success); font-weight: 600; }
.reports-card-substats .kpi-error { color: var(--danger);  font-weight: 600; }
.reports-card-actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }
.reports-card-empty   { margin: 0; }

/* ----- Service detail: Reachability (health-check) card ----- */
.health-check-card { margin-bottom: var(--s-4); }
.health-check-card .health-overall {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
  margin-bottom: var(--s-3);
}
.health-check-card .health-table { width: 100%; }
.health-check-card .health-table td,
.health-check-card .health-table th { vertical-align: top; }
.health-check-card .health-table .small { font-size: var(--text-sm); }
.health-check-card .health-detail {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: var(--text-sm);
  word-break: break-word;
}
.health-check-card .htmx-indicator { opacity: 0; transition: opacity .15s; }
.health-check-card .htmx-request .htmx-indicator,
.health-check-card .htmx-indicator.htmx-request { opacity: 1; }
