/* ============================================================================
   ATLAS REDESIGN — Automations screen styles  ·  Phase 2
   Branch: atlas-redesign-2026-06-29

   Prefix: .rd-automations. Tokens only (--r-*) so Calm (almanac) + Operator
   themes both work automatically. No hardcoded hex.
   ========================================================================== */

.rd-automations {
  font-family: var(--r-font-body);
  color: var(--r-body);
  padding: var(--r-gutter);
  max-width: var(--r-page-max);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---- 1 · header block ---------------------------------------------------- */
.rd-au-head {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.rd-au-eyebrow {
  font-family: var(--r-font-mono);
  font-size: var(--r-fs-eyebrow);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--r-clay);
}
.rd-au-h1 {
  font-family: var(--r-font-display);
  font-size: 26px;
  font-weight: 600;
  line-height: 1.1;
  color: var(--r-ink);
  margin: 0;
}
.rd-au-sub {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--r-muted);
  max-width: 620px;
}

/* ---- 2 · KPI strip (one panel, 4 cells split by hairlines) --------------- */
.rd-au-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--r-surface);
  border: 1px solid var(--r-border);
  border-radius: var(--r-radius-card);
  box-shadow: var(--r-shadow-card);
  overflow: hidden;
}
.rd-au-kpi {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 18px;
  border-left: 1px solid var(--r-hairline);
}
.rd-au-kpi:first-child { border-left: none; }
.rd-au-kpi-label {
  font-family: var(--r-font-mono);
  font-size: var(--r-fs-eyebrow);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--r-faint);
}
.rd-au-kpi-value {
  font-family: var(--r-font-display);
  font-size: 26px;
  font-weight: 600;
  line-height: 1;
  color: var(--r-ink);
}
.rd-au-kpi-sub {
  font-size: 12px;
  line-height: 1.3;
  color: var(--r-muted);
}
.rd-au-kpi-sub.is-good { color: var(--r-good); }
.rd-au-kpi-sub.is-empty { color: var(--r-faint); }

/* ---- 3 · main grid (library | recent runs) ------------------------------- */
.rd-au-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 20px;
  align-items: start;
  min-height: 0;
}

/* shared card shell */
.rd-au-card {
  background: var(--r-surface);
  border: 1px solid var(--r-border);
  border-radius: var(--r-radius-card);
  box-shadow: var(--r-shadow-card);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.rd-au-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.rd-au-card-title {
  margin: 0;
  font-family: var(--r-font-display);
  font-size: var(--r-fs-h2);
  font-weight: 600;
  color: var(--r-ink);
}
.rd-au-card-note {
  font-size: 12px;
  color: var(--r-muted);
}

/* ---- workflow library ---------------------------------------------------- */
.rd-au-library-body {
  min-height: 0;
  overflow: auto;
  max-height: calc(100vh - 360px);
  margin: 0 -6px;
  padding: 0 6px;
}
.rd-au-wf-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

/* one workflow card */
.rd-au-wf {
  background: var(--r-canvas-raised);
  border: 1px solid var(--r-hairline);
  border-radius: var(--r-radius-card);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color var(--r-dur) var(--r-ease),
              box-shadow var(--r-dur) var(--r-ease),
              transform var(--r-dur) var(--r-ease);
}
.rd-au-wf:hover {
  border-color: var(--r-border);
  box-shadow: var(--r-shadow-hover);
  transform: translateY(-1px);
}
/* active/inactive semantic clarity — the hover tint follows the real state */
.rd-au-wf[data-active="1"]:hover { border-color: color-mix(in srgb, var(--r-good) 32%, var(--r-hairline)); }
.rd-au-wf[data-active="0"] { opacity: .72; }
.rd-au-wf[data-active="0"]:hover { opacity: .92; }
.rd-au-wf[data-active="0"] .rd-au-wf-icon { background: var(--r-well); color: var(--r-faint); }
.rd-au-wf-top {
  display: flex;
  align-items: flex-start;
  gap: 11px;
}
.rd-au-wf-icon {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: var(--r-radius-control);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--r-mint-surface);
  color: var(--r-mint-ink);
}
.rd-au-wf-icon i { font-size: 17px; }
.rd-au-wf-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.rd-au-wf-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--r-ink);
}
.rd-au-wf-trig {
  font-size: 12px;
  line-height: 1.3;
  color: var(--r-faint);
}
.rd-au-wf-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 11px;
  border-top: 1px solid var(--r-hairline);
}
.rd-au-wf-ran {
  font-family: var(--r-font-mono);
  font-size: 12px;
  color: var(--r-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* "Run now" pill */
.rd-au-run {
  appearance: none;
  flex: 0 0 auto;
  border: none;
  background: var(--r-mint-surface);
  color: var(--r-mint-ink);
  font-family: var(--r-font-body);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  padding: 6px 12px;
  border-radius: var(--r-radius-pill);
  cursor: pointer;
  transition: filter var(--r-dur) var(--r-ease),
              box-shadow var(--r-dur) var(--r-ease);
}
.rd-au-run:hover { filter: brightness(1.05); box-shadow: var(--r-shadow-card); }
.rd-au-run:focus-visible { outline: var(--r-focus); outline-offset: 2px; }

/* ---- recent runs --------------------------------------------------------- */
.rd-au-runs-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: auto;
  max-height: calc(100vh - 360px);
  margin: 0 -4px;
  padding: 0 4px;
}
/* execution tail — a real grid so started/status/duration line up down the list */
.rd-au-run-head,
.rd-au-run-row {
  display: grid;
  grid-template-columns: 18px 1fr 62px 50px;
  align-items: center;
  gap: 11px;
}
.rd-au-run-head {
  padding: 0 4px 8px;
  font-family: var(--r-font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--r-faint);
  border-bottom: 1px solid var(--r-hairline);
}
.rd-au-run-head span:nth-child(3),
.rd-au-run-head span:nth-child(4) { text-align: right; }
.rd-au-run-row {
  padding: 11px 4px;
  border-top: 1px solid var(--r-hairline);
}
.rd-au-run-row:first-child { border-top: none; }
.rd-au-run-icon {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.rd-au-run-icon i { font-size: 16px; }
.rd-au-run-icon[data-tone="good"]  i { color: var(--r-good); }
.rd-au-run-icon[data-tone="alert"] i { color: var(--r-alert); }
.rd-au-run-text {
  min-width: 0;
  font-size: 13px;
  color: var(--r-body);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rd-au-run-when,
.rd-au-run-dur {
  font-family: var(--r-font-mono);
  font-size: 12px;
  color: var(--r-faint);
  white-space: nowrap;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---- empty states (honest, dashed) --------------------------------------- */
.rd-au-empty {
  font-family: var(--r-font-mono);
  font-size: var(--r-fs-meta);
  letter-spacing: .02em;
  color: var(--r-faint);
  text-align: center;
  padding: 30px 14px;
  border: 1px dashed var(--r-border);
  border-radius: var(--r-radius-control);
}
.rd-au-empty-lib { margin: 2px; }

/* ---- responsive ---------------------------------------------------------- */
@media (max-width: 980px) {
  .rd-au-grid { grid-template-columns: 1fr; }
  .rd-au-wf-grid { grid-template-columns: 1fr; }
  .rd-au-library-body,
  .rd-au-runs-body { max-height: 52vh; }
}
@media (max-width: 720px) {
  .rd-au-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rd-au-kpi:nth-child(3) { border-left: none; }
  .rd-au-kpi:nth-child(n+3) { border-top: 1px solid var(--r-hairline); }
}

/* W-F5S3: live monitor — search box, status pill, overflow note */
.rd-au-search {
  height: 30px; padding: 0 10px; margin-left: auto; width: 200px;
  border: 1px solid var(--r-border); border-radius: var(--r-radius-control);
  background: var(--r-canvas-raised); color: var(--r-ink);
  font-family: var(--r-font-body); font-size: 12.5px;
  transition: border-color var(--r-dur) var(--r-ease), box-shadow var(--r-dur) var(--r-ease);
}
.rd-au-search::placeholder { color: var(--r-muted); }
.rd-au-search:hover { border-color: var(--r-hairline-2); }
.rd-au-search:focus-visible { outline: var(--r-focus); outline-offset: 1px; border-color: var(--r-hairline-2); }
.rd-au-state {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--r-font-mono); font-size: 11px; letter-spacing: 0.04em;
}
.rd-au-state[data-tone="good"] { color: var(--r-good); }
.rd-au-state[data-tone="off"]  { color: var(--r-muted); }
.rd-au-state-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.rd-au-more { padding: 10px 2px 0; font-size: 12px; color: var(--r-muted); }

/* ---- motion (respect reduced-motion) -------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .rd-au-wf,
  .rd-au-search { transition: none; }
  .rd-au-wf:hover { transform: none; }
}

/* ---- focus visibility (keyboard) ------------------------------------------ */
.rd-automations :focus-visible { outline: var(--r-focus); outline-offset: 2px; }

/* ---- mobile 390px: card head + search wrap instead of overflow ------------- */
@media (max-width: 480px) {
  .rd-au-card-head { flex-wrap: wrap; }
  .rd-au-search { width: 100%; margin-left: 0; order: 3; }
  .rd-au-card-note { order: 2; }
  .rd-au-run-head { display: none; }
  .rd-au-run-row { grid-template-columns: 16px 1fr 46px; }
  .rd-au-run-dur { display: none; }
}
