/* ==========================================================================
   Plower infra — component and page styles (being migrated).
   Tokens: styles/tokens.css. Base: styles/base.css.
   ========================================================================== */

/* Legacy: tracked all-caps labels, removed with them in the component pass. */
:root { --tracking-label: 0.08em; }

/* ==========================================================================
   Icons (used by the controller and node SVG components)
   ========================================================================== */
.icon {
  width: 18px;
  height: 18px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.icon--sm { width: 14px; height: 14px; }

/* Detail page layout */
.detail-header {
  padding-bottom: 72px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
}

.detail-title-line {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 32px;
}

.detail-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
  padding: 20px;
}

.detail-list {
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.detail-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.detail-list div:last-child { border-bottom: none; }

.detail-list dt {
  font-size: 12px;
  color: var(--text-dim);
}

.detail-list dd {
  margin: 0;
  font-size: 13px;
  color: var(--text);
  text-align: right;
}

/* Metric cards */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  align-self: start;
}

.metric-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-card span { font-size: 12px; color: var(--text-dim); }
.metric-card strong { font-family: var(--font-mono); font-size: 22px; color: var(--text); }
.metric-card small { font-size: 12px; color: var(--text-faint); font-family: var(--font-mono); }

/* Submit drawer */

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 520px;
  max-width: 100%;
  z-index: 50;
  background: var(--bg-raised);
  border-left: 1px solid var(--line-strong);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.2s ease;
  overflow-y: auto;
}

.drawer__close {
  flex-shrink: 0;
  font-size: 18px;
  color: var(--text-dim);
  padding: 4px 8px;
}

/* Submit drawer internals */
.submit-drawer__tabs {
  padding: 0 var(--space-6);
  border-bottom: 1px solid var(--line);
}

.submit-drawer__panel {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-6);
}

/* Two classes: beats the display of any stage it hides, wherever that is
   declared. */
.submit-drawer .submit-drawer__panel--hidden { display: none; }

.submit-drawer__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--line);
}

/* Progress: numbered steps joined by hairlines. */
.submit-flow__steps {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--line);
  list-style: none;
}

.submit-flow__steps li {
  display: flex;
  flex: 1 1 0;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  color: var(--text-faint);
  font-size: var(--text-13);
  white-space: nowrap;
}

.submit-flow__steps li:last-child {
  flex: 0 0 auto;
}

.submit-flow__steps li:not(:last-child)::after {
  flex: 1;
  min-width: var(--space-3);
  height: 1px;
  margin-left: var(--space-1);
  background: var(--line-strong);
  content: "";
}

.submit-flow__step-number {
  display: grid;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: var(--text-11);
  place-items: center;
}

.submit-flow__steps [aria-current="step"] {
  color: var(--text);
  font-weight: var(--weight-medium);
}

.submit-flow__steps [aria-current="step"] .submit-flow__step-number {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-fg);
}

.submit-flow__step--complete {
  color: var(--text-dim);
}

.submit-flow__step--complete .submit-flow__step-number {
  border-color: var(--text-dim);
}

.submit-flow__stage {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-6);
}

.submit-flow__stage-heading {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.submit-flow__stage-heading h3,
.submit-flow__result h3 {
  font-size: var(--text-16);
  font-weight: var(--weight-semibold);
}

.submit-flow__stage-heading p {
  max-width: 36rem;
  color: var(--text-dim);
  font-size: var(--text-13);
  line-height: var(--leading-normal);
}

.submit-flow__result {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-10) var(--space-6);
  text-align: center;
}

.submit-flow__result-mark {
  display: grid;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--success-soft);
  color: var(--success);
  place-items: center;
}

.submit-flow__result > p {
  max-width: 26rem;
  color: var(--text-dim);
  font-size: var(--text-13);
  line-height: var(--leading-normal);
}

.submit-flow__error {
  padding: 0 var(--space-6) var(--space-4);
}

/* Form fields */

.short-textarea { height: 80px; resize: vertical; }

/* Custom select — replaces the native <select> everywhere so option
   lists share the account-menu/command-menu popover language. */

.script-editor { height: 180px; resize: vertical; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@container main (max-width: 800px) {
  .detail-grid,
.metric-grid { grid-template-columns: 1fr; }
}

/* ==========================================================================
   Cluster index
   ========================================================================== */

.infra-cluster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr));
  gap: var(--space-4);
}

.infra-cluster-card {
  transition:
    border-color var(--duration-fast) var(--ease-out),
    background-color var(--duration-fast) var(--ease-out);
}

.infra-cluster-card:hover {
  border-color: var(--line-strong);
  background: var(--bg-hover);
}

.infra-cluster-card__title {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.infra-cluster-card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  min-width: 0;
}

.infra-cluster-card__name {
  min-width: 0;
  font-size: var(--text-16);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
}

/* The link truncates itself, so its box never runs into the next card. */
.infra-cluster-card__name .ui-stretched-link {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.infra-cluster-card__endpoint {
  overflow: hidden;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: var(--text-12);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.infra-cluster-card__head > .ui-status-indicator {
  flex-shrink: 0;
}

.infra-cluster-card__facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
  margin: 0;
  padding-top: var(--space-4);
  border-top: 1px solid var(--line);
}

.infra-cluster-card__facts > div {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.infra-cluster-card__facts dt {
  color: var(--text-faint);
  font-size: var(--text-12);
}

.infra-cluster-card__facts dd {
  overflow: hidden;
  margin: 0;
  font-size: var(--text-13);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==========================================================================
   Submit drawer
   ========================================================================== */

.submit-drawer { min-height: 100%; display: flex; flex-direction: column; }
.submit-drawer .submit-drawer__actions { margin-top: auto; }

/* ==========================================================================
   Global jobs index
   ========================================================================== */

/* Cluster chooser: one stacked option per ready cluster. */
.infra-jobs__cluster-selector {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6) var(--space-6);
}

.infra-jobs__cluster-options {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.infra-jobs__cluster-option {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg-raised);
  color: var(--text-faint);
  text-align: left;
  cursor: pointer;
  transition:
    border-color var(--duration-fast) var(--ease-out),
    background-color var(--duration-fast) var(--ease-out);
}

.infra-jobs__cluster-option:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: var(--bg-hover);
  color: var(--text-dim);
}

.infra-jobs__cluster-option:disabled {
  cursor: progress;
  opacity: 0.6;
}

.infra-jobs__cluster-option-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.infra-jobs__cluster-option-name {
  color: var(--text);
  font-size: var(--text-14);
  font-weight: var(--weight-medium);
}

.infra-jobs__cluster-option-endpoint {
  overflow: hidden;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: var(--text-12);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==========================================================================
   Job detail
   ========================================================================== */

/* Service health beside the shorter timeline; one column when narrow. */
.infra-job-detail__main {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: var(--space-4);
  align-items: start;
}

.infra-job-detail__loading {
  display: grid;
  gap: var(--space-4);
}

/* ==========================================================================
   Cluster workspace
   ========================================================================== */

/* The tabs and the view under them read as one region. */
.infra-workspace {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  min-width: 0;
}

/* Three short columns fit a phone without scrolling. */
.infra-workspace__recent {
  --table-min: 20rem;
}

.infra-workspace__partition {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 100%;
}

.infra-workspace__partition > .u-mono {
  overflow: hidden;
  text-overflow: ellipsis;
}

@container main (max-width: 800px) {
  .infra-job-detail__main { grid-template-columns: 1fr; }
}

@container main (max-width: 520px) {
  .submit-drawer__actions { justify-content: stretch; }
  .submit-drawer__actions .ui-button { flex: 1; }
}

/* ==========================================================================
   Utilities added for the developer / drive / usage / ask surfaces
   ========================================================================== */
.u-dim { color: var(--text-dim); }

/* ==========================================================================
   Ask (chat.rs): a disabled composer and the questions it is built for
   ========================================================================== */

.pl-ask__composer {
  display: flex;
  gap: var(--space-3);
  min-width: 0;
}

.pl-ask__composer .ui-input {
  flex: 1 1 auto;
  min-width: 0;
}

.pl-ask__compose {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* Two columns of question + what answering it takes, divided by hairlines. */
.pl-ask__prompts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 26rem), 1fr));
  gap: 0 var(--space-8);
  margin: 0;
  padding: 0;
  list-style: none;
}

.pl-ask__prompts > li {
  padding: var(--space-4) 0;
  border-top: 1px solid var(--line);
}

.pl-ask__prompt {
  margin: 0 0 var(--space-1);
  color: var(--text);
  font-size: var(--text-14);
  font-weight: 500;
}

.pl-ask__detail {
  max-width: var(--prose-max);
  margin: 0;
  color: var(--text-dim);
  font-size: var(--text-13);
  line-height: 1.5;
}

/* ==========================================================================
   Template picker (templates page and the deploy drawer)
   ========================================================================== */

.template-picker,
.template-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.template-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.template-group__label {
  color: var(--text-dim);
  font-size: var(--text-13);
  font-weight: var(--weight-medium);
}

.template-grid__row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr));
  gap: var(--space-3);
}

.template-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  min-width: 0;
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition:
    border-color var(--duration-fast) var(--ease-out),
    background-color var(--duration-fast) var(--ease-out);
}

.template-card:hover {
  border-color: var(--line-strong);
  background: var(--bg-hover);
}

.template-card__icon {
  display: grid;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  color: var(--text-dim);
  place-items: center;
}

.template-card__text {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.template-card__name {
  font-size: var(--text-14);
  font-weight: var(--weight-semibold);
}

.template-card__description {
  display: -webkit-box;
  overflow: hidden;
  color: var(--text-dim);
  font-size: var(--text-13);
  line-height: var(--leading-normal);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.template-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.template-form__header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
}

/* Pulled left so the chevron lines up with the heading below. */
.template-form__back {
  margin: 0 0 var(--space-2) calc(var(--space-2) * -1);
}

.template-form__header h3 {
  font-size: var(--text-16);
  font-weight: var(--weight-semibold);
}

.template-form__header p {
  max-width: 36rem;
  color: var(--text-dim);
  font-size: var(--text-13);
  line-height: var(--leading-normal);
}

.template-form__fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr));
  gap: var(--space-4);
}

.template-form__footer {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-3);
  padding-top: var(--space-4);
  border-top: 1px solid var(--line);
}

.template-form__preview {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-3);
  width: 100%;
}

.template-form__preview .ui-code {
  align-self: stretch;
}

/* A long rendered script scrolls inside the block. */
.template-form__preview .ui-code__pre {
  max-height: 20rem;
  overflow-y: auto;
}

/* ─── Templates page ─────────────────────────────────────────────────── */

.templates-index__target {
  max-width: 40rem;
}

/* ==========================================================================
   Infra Developers page
   ========================================================================== */

/* ==========================================================================
   Job service health (see job_health.rs)
   ========================================================================== */

/* Three short states side by side, even in the narrower column. */
.job-health .ui-facts {
  --facts-min: 9rem;
}

.job-health__progress {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.job-health__progress-label {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  color: var(--text-dim);
  font-size: var(--text-12);
}

.job-health__progress-track {
  height: 4px;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: var(--bg-subtle);
}

/* Amber, not green: the job is not serving yet. The transition keeps a 10s
   poll from making the bar jump. */
.job-health__progress-fill {
  height: 100%;
  background: var(--warning);
  transition: width 400ms var(--ease-out);
}

/* Probe history can run long; it scrolls instead of growing the panel. */
.job-health .ui-disclosure .ui-timeline {
  max-height: 16rem;
  overflow-y: auto;
}

/* ==========================================================================
   SSH access (see ssh_access.rs) and reservations (reservations.rs)
   ========================================================================== */

/* A long ssh command truncates in its cell; the full one is in the title
   and on the copy button. */
.pl-ssh__command {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pl-ssh__key textarea {
  font-family: var(--font-mono);
  font-size: var(--text-12);
  resize: vertical;
}

/* The rejection reason is the only thing that makes a refusal actionable, so
   it wraps rather than being clipped like the rest of the row. */
.pl-reservations__reason {
  margin-top: var(--space-1);
  color: var(--text-dim);
  font-size: var(--text-12);
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
}

/* ==========================================================================
   Deployments, fleet, usage, node agent and power
   (deployments_index.rs, deployment.rs, fleet.rs, usage.rs, node_agent.rs)
   ========================================================================== */

/* A custom date range: two date inputs that stay on one line. */
.pl-usage__range {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}
.pl-usage__range .ui-input { width: 10rem; min-width: 0; }

/* ── Deployment detail ───────────────────────────────────────────────── */

/* The tabs and the view under them read as one region. */
.infra-deployment {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  min-width: 0;
}

/* How a deployment connects: cluster → replicas → load balancer → model
   name. One card per stop, joined by a hairline across the gap; one equal
   column per stop, however many the viewer can see. */
.infra-map {
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  gap: var(--space-6);
  margin: 0;
  padding: 0;
  list-style: none;
}

.infra-map__stop {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
}

.infra-map__stop + .infra-map__stop::before {
  content: "";
  position: absolute;
  top: 50%;
  right: 100%;
  width: calc(var(--space-6) + 1px);
  border-top: 1px solid var(--line-strong);
}

.infra-map__stop--link:hover {
  border-color: var(--line-strong);
  background: var(--bg-hover);
}

.infra-map__label,
.infra-map__detail {
  overflow: hidden;
  color: var(--text-dim);
  font-size: var(--text-12);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.infra-map__value {
  overflow: hidden;
  font-size: var(--text-14);
  font-weight: var(--weight-medium);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A linked value truncates inside the link, so the link's box stays within
   its stop (its hit area is the whole stop either way). */
.infra-map__value > .ui-stretched-link {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* A copyable value: the text truncates, not the box (that would clip the
   button's focus ring), and the button overhangs the line as it does in a
   facts list, so this stop's rows line up with the others'. */
.infra-map__value.ui-copy-value {
  min-height: 1lh;
  overflow: visible;
}

.infra-map__value.ui-copy-value > :first-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

.infra-map__value > .ui-copy {
  margin-block: calc(-1 * var(--space-2));
}

/* Narrow: the stops stack, joined by a vertical hairline. */
@container main (max-width: 640px) {
  .infra-map {
    grid-auto-flow: row;
    gap: var(--space-4);
  }

  .infra-map__stop + .infra-map__stop::before {
    top: auto;
    right: auto;
    bottom: 100%;
    left: var(--space-6);
    width: 0;
    height: calc(var(--space-4) + 1px);
    border-top: 0;
    border-left: 1px solid var(--line-strong);
  }
}

/* Desired replicas, edited in place in the facts panel. */
.infra-deployment__scale {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.infra-deployment__scale .ui-input {
  width: 5rem;
  height: var(--control-sm);
}

/* Six serving figures in one row on a wide page. */
/* Six figures: one row when every label fits, else two rows of three
   (never four and two). */
.infra-deployment__serving-metrics {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

@container main (max-width: 1140px) {
  .infra-deployment__serving-metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@container main (max-width: 520px) {
  .infra-deployment__serving-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.infra-deployment__config {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.infra-deployment__log {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-top: var(--space-4);
  border-top: 1px solid var(--line);
}

.infra-deployment__log-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.infra-deployment__log-title {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1) var(--space-3);
  min-width: 0;
}

.infra-deployment__log-title h3 {
  font-size: var(--text-14);
  font-weight: var(--weight-semibold);
}

.infra-deployment__log .ui-code__pre {
  max-height: 24rem;
  overflow-y: auto;
}

.infra-diff__before { color: var(--danger); }
.infra-diff__after { color: var(--success); }

.ui-chart__bar { opacity: 0.85; }
.ui-chart__bar:hover { opacity: 1; }

/* ==========================================================================
   Agent detail (node.rs)
   ========================================================================== */
/* The tabs and the view under them read as one region. */
.pl-agent,
.pl-agent__loading {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  min-width: 0;
}

/* Five short facts share one row on a wide page. */
.pl-agent__summary {
  --facts-min: 11rem;
}

/* Machine facts run long (CPU model, software versions). */
.pl-agent__machine {
  --facts-min: 18rem;
}
