/* Work home — Engine section (OPS-224 lane E).
   Same visual language as the landing: near-black ground, cyan/purple/pink
   accents, glass surfaces, restrained motion. Reading panes are more opaque
   than the landing card so sustained reading stays comfortable. */

:root {
  --bg: #050505;
  --ink: #e7e9ee;
  --ink-dim: #a3a8b3;
  --ink-faint: #71767f;
  --cyan: #22d3ee;
  --purple: #a78bfa;
  --pink: #f472b6;
  --amber: #fbbf24;
  --green: #34d399;
  --red: #f87171;
  --glass: rgba(16, 17, 20, 0.86);
  --glass-soft: rgba(255, 255, 255, 0.03);
  --edge: rgba(255, 255, 255, 0.08);
  --edge-strong: rgba(255, 255, 255, 0.16);
  --radius: 14px;
  --touch: 44px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

#topography {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  opacity: 0.5;
  pointer-events: none;
}

#app { position: relative; z-index: 1; }

.noscript { color: var(--ink-dim); padding: 2rem; }

/* ---------------------------------------------------------------- shell -- */

.work-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh;
  padding: 0 clamp(10px, 1.6vw, 22px) clamp(10px, 1.6vh, 18px);
  gap: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 10px 16px;
  margin-top: 10px;
  background: var(--glass);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.brand {
  font-size: 1.05rem;
  font-weight: 300;
  letter-spacing: 0.02em;
  background: linear-gradient(90deg, var(--cyan), var(--purple), var(--pink));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-decoration: none;
  white-space: nowrap;
}

.topnav { display: flex; align-items: center; gap: 4px; }
.topnav a {
  color: var(--ink-dim);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 9px 12px;
  border-radius: 8px;
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
}
.topnav a.active { color: var(--ink); background: var(--glass-soft); border: 1px solid var(--edge); }
.topnav a:hover { color: var(--ink); }

.topbar .spacer { flex: 1; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--ink-dim);
  border: 1px solid var(--edge);
  border-radius: 999px;
  padding: 5px 11px;
  white-space: nowrap;
  background: var(--glass-soft);
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-faint); flex: none; }
.chip.ok { color: var(--green); border-color: rgba(52, 211, 153, 0.35); }
.chip.ok .dot { background: var(--green); }
.chip.warn { color: var(--amber); border-color: rgba(251, 191, 36, 0.4); }
.chip.warn .dot { background: var(--amber); }

.account { font-size: 0.8rem; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }

button, .btn {
  font: inherit;
  color: var(--ink);
  background: var(--glass-soft);
  border: 1px solid var(--edge-strong);
  border-radius: 10px;
  padding: 9px 16px;
  min-height: var(--touch);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
button:hover:not(:disabled), .btn:hover { background: rgba(255, 255, 255, 0.07); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary {
  background: linear-gradient(90deg, rgba(34, 211, 238, 0.18), rgba(167, 139, 250, 0.18));
  border-color: rgba(34, 211, 238, 0.45);
}
button.primary:hover:not(:disabled) { background: linear-gradient(90deg, rgba(34, 211, 238, 0.3), rgba(167, 139, 250, 0.3)); }
button.quiet { border-color: transparent; color: var(--ink-dim); }
button.linkish { border: none; background: none; color: var(--cyan); padding: 6px 8px; min-height: 0; }

/* ------------------------------------------------------------ 3 columns -- */

.panes {
  display: grid;
  gap: 12px;
  min-height: 0;
  grid-template-columns: minmax(0, 32fr) minmax(0, 43fr) minmax(0, 25fr);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.pane {
  background: var(--glass);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.pane-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--edge);
}
.pane-head h2 {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.pane-head .count { font-size: 0.75rem; color: var(--ink-faint); margin-left: auto; }

.pane-body { overflow-y: auto; min-height: 0; flex: 1; padding: 10px 12px 14px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.15) transparent; }

/* ----------------------------------------------------------------- board -- */

.job-card {
  border: 1px solid var(--edge);
  border-radius: 11px;
  padding: 11px 13px;
  margin-bottom: 9px;
  background: rgba(255, 255, 255, 0.025);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
  min-width: 0;
}
.job-card:hover { border-color: var(--edge-strong); }
.job-card.selected { border-color: rgba(34, 211, 238, 0.65); background: rgba(34, 211, 238, 0.06); }
.job-card[data-lifecycle="finished"], .job-card[data-lifecycle="cancelled"] { opacity: 0.75; }

.job-title { font-weight: 600; font-size: 0.95rem; overflow-wrap: anywhere; }
.job-q { color: var(--ink-dim); font-size: 0.82rem; margin: 3px 0 7px; overflow-wrap: anywhere; }

.job-meta { display: flex; flex-wrap: wrap; gap: 5px 8px; align-items: center; font-size: 0.74rem; color: var(--ink-faint); }
.job-meta .sep { opacity: 0.5; }

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  border: 1px solid var(--edge);
  color: var(--ink-dim);
}
.tag.lifecycle-active { color: var(--cyan); border-color: rgba(34, 211, 238, 0.4); }
.tag.lifecycle-queued { color: var(--purple); border-color: rgba(167, 139, 250, 0.4); }
.tag.lifecycle-paused { color: var(--amber); border-color: rgba(251, 191, 36, 0.4); }
.tag.lifecycle-finished { color: var(--green); border-color: rgba(52, 211, 153, 0.35); }
.tag.lifecycle-cancelled { color: var(--ink-faint); }
.tag.lifecycle-unknown { color: var(--ink-dim); border-style: dashed; }
.tag.phase { color: var(--ink-dim); }

.badge-attention {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.badge-attention.stuck { color: var(--red); border: 1px solid rgba(248, 113, 113, 0.5); background: rgba(248, 113, 113, 0.08); }
.badge-attention.worker_reports_stall { color: var(--amber); border: 1px solid rgba(251, 191, 36, 0.5); background: rgba(251, 191, 36, 0.07); }
.badge-attention.unknown { color: var(--ink-dim); border: 1px dashed var(--edge-strong); }

details.finished-group { margin-top: 10px; border-top: 1px solid var(--edge); padding-top: 8px; }
details.finished-group > summary {
  cursor: pointer;
  color: var(--ink-faint);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 8px 4px;
  min-height: var(--touch);
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
}
details.finished-group > summary::-webkit-details-marker { display: none; }
details.finished-group > summary::before { content: '▸'; transition: transform 0.15s ease; }
details.finished-group[open] > summary::before { transform: rotate(90deg); }

.board-empty { color: var(--ink-dim); font-size: 0.88rem; padding: 18px 6px; }
.board-note { color: var(--ink-faint); font-size: 0.75rem; padding: 4px 6px 10px; }

/* pulse once when a live event lands on the job */
@keyframes card-pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.55); }
  100% { box-shadow: 0 0 0 12px rgba(34, 211, 238, 0); }
}
.job-card.pulse-once { animation: card-pulse 900ms ease-out 1; }

/* ---------------------------------------------------------------- stream -- */

.stream-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--edge); }
.stream-tools select {
  font: inherit;
  font-size: 0.78rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--edge);
  border-radius: 8px;
  padding: 7px 8px;
  min-height: 40px;
  max-width: 130px;
}
.stream-tools label { font-size: 0.75rem; color: var(--ink-faint); display: inline-flex; align-items: center; gap: 6px; min-height: 40px; }

.new-events {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 14px;
  z-index: 5;
  font-size: 0.8rem;
  border-color: rgba(34, 211, 238, 0.55);
  color: var(--cyan);
  background: #0a0c0f;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  display: none;
}
.new-events.visible { display: inline-flex; }
.pane-stream { position: relative; }

.stream-row {
  border: 1px solid var(--edge);
  border-radius: 10px;
  padding: 9px 12px;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.02);
  overflow-wrap: anywhere;
}
.stream-row .row-head { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; font-size: 0.72rem; color: var(--ink-faint); margin-bottom: 4px; }
.stream-row .row-kind { color: var(--purple); font-weight: 600; }
.stream-row .row-lane { color: var(--ink-faint); }
.stream-row .row-seq { font-variant-numeric: tabular-nums; opacity: 0.8; }
.stream-row .row-time { margin-left: auto; }
.stream-row .row-text { font-size: 0.9rem; }
.stream-row .row-metrics { margin-top: 5px; font-size: 0.78rem; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.stream-row .row-metrics .metric { display: inline-block; margin-right: 10px; }
.stream-row .row-metrics .metric .label { color: var(--ink-faint); }

details.raw { margin-top: 6px; font-size: 0.78rem; }
details.raw > summary {
  cursor: pointer;
  color: var(--ink-faint);
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  list-style: none;
}
details.raw > summary::-webkit-details-marker { display: none; }
details.raw > summary::before { content: '▸'; }
details.raw[open] > summary::before { transform: rotate(90deg); }
details.raw .raw-line {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.74rem;
  color: var(--ink-dim);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--edge);
  border-radius: 7px;
  padding: 7px 9px;
  margin: 4px 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
details.raw .redaction-marks { color: var(--ink-faint); font-size: 0.7rem; }
details.raw .redaction-marks .mark {
  display: inline-block;
  border: 1px dashed var(--edge-strong);
  border-radius: 5px;
  padding: 0 5px;
  margin: 2px 3px 0 0;
}

@keyframes row-arrive {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: none; }
}
.stream-row.row-in { animation: row-arrive 480ms ease-out 1; }

.stream-empty { color: var(--ink-dim); font-size: 0.85rem; padding: 16px 6px; }

/* -------------------------------------------------------------- steering -- */

.steer-target { padding: 10px 14px; border-bottom: 1px solid var(--edge); font-size: 0.8rem; color: var(--ink-dim); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 46px; }
.steer-target .target-name { color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }

.steer-compose { padding: 12px 14px; border-bottom: 1px solid var(--edge); }
.steer-compose textarea {
  width: 100%;
  min-height: 96px;
  resize: vertical;
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid var(--edge-strong);
  border-radius: 10px;
  padding: 10px 12px;
}
.steer-compose textarea:focus { outline: 1px solid rgba(34, 211, 238, 0.6); }
.compose-foot { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.compose-foot .char-count { font-size: 0.74rem; color: var(--ink-faint); margin-left: auto; font-variant-numeric: tabular-nums; }
.steer-status { font-size: 0.78rem; color: var(--ink-dim); min-height: 1.2em; margin-top: 8px; }
.steer-status.saved { color: var(--green); }
.steer-status.error { color: var(--red); }
.agent-hint { font-size: 0.74rem; color: var(--amber); margin-top: 4px; }
/* read-only steering pane (STEERING_ENABLED=0): the pane says why instead of
   offering a composer */
.steer-closed {
  font-size: 0.84rem; color: var(--ink-dim); padding: 14px; margin: 0;
  border-bottom: 1px solid var(--edge);
}

.steer-history { display: flex; flex-direction: column; gap: 8px; }
.steer-item { border: 1px solid var(--edge); border-radius: 10px; padding: 9px 12px; background: rgba(255, 255, 255, 0.02); }
.steer-item .item-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 0.72rem; color: var(--ink-faint); margin-bottom: 4px; }
.steer-item .item-text { font-size: 0.85rem; overflow-wrap: anywhere; }
.steer-item .item-reply { border-left: 2px solid rgba(34, 211, 238, 0.5); padding: 4px 0 4px 10px; margin-top: 7px; }
.steer-item .item-reply .reply-text { font-size: 0.84rem; overflow-wrap: anywhere; }
.steer-item .item-reply .reply-at { font-size: 0.7rem; color: var(--ink-faint); margin-top: 3px; }
.steer-item.pending-local { border-style: dashed; }

.state-badge { font-size: 0.7rem; font-weight: 600; letter-spacing: 0.05em; border-radius: 6px; padding: 2px 7px; border: 1px solid var(--edge-strong); color: var(--ink-dim); }
.state-badge.saved { color: var(--ink-dim); }
.state-badge.observed { color: var(--cyan); border-color: rgba(34, 211, 238, 0.4); }
.state-badge.planned { color: var(--purple); border-color: rgba(167, 139, 250, 0.45); }
.state-badge.declined { color: var(--red); border-color: rgba(248, 113, 113, 0.45); }
.state-badge.expired { color: var(--ink-faint); }
.state-badge.applying { color: var(--amber); border-color: rgba(251, 191, 36, 0.45); }
.state-badge.applied { color: var(--green); border-color: rgba(52, 211, 153, 0.45); }
.state-badge.failed { color: var(--red); border-color: rgba(248, 113, 113, 0.45); }
.state-badge.outcome_unknown { color: var(--amber); border-style: dashed; }

/* -------------------------------------------------------- access states -- */

.center-view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
}
.center-view .glass-card {
  background: var(--glass);
  border: 1px solid var(--edge);
  border-radius: 16px;
  padding: 34px 38px;
  max-width: 460px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.center-view h1 { font-weight: 300; font-size: 1.6rem; margin: 0 0 6px; }
.center-view .sub { color: var(--ink-dim); font-size: 0.9rem; margin-bottom: 18px; }
.center-view .home-link { color: var(--ink-faint); font-size: 0.8rem; }
.center-view .denied-title { color: var(--amber); }

.loading-shell { color: var(--ink-dim); letter-spacing: 0.1em; font-size: 0.85rem; }

/* --------------------------------------------------- iPad / narrow shapes -- */

@media (max-width: 1279px) and (min-width: 1024px) {
  .panes {
    grid-template-columns: minmax(0, 40fr) minmax(0, 60fr);
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }
  .pane-board { grid-row: 1 / 3; }
  .pane-steering { grid-column: 2; }
}

@media (max-width: 1023px) {
  .work-shell { height: auto; min-height: 100dvh; }
  .panes { display: flex; flex-direction: column; }
  .pane { overflow: hidden; }
  .pane-body { overflow: visible; }
  .pane-board .pane-body { max-height: none; }
  .pane-stream .pane-body { max-height: 60vh; }

  .pane-shortcuts {
    position: sticky;
    top: 6px;
    z-index: 6;
    display: flex;
    gap: 8px;
    justify-content: center;
    padding: 8px;
    margin: 0 -6px;
  }
  .pane-shortcuts a {
    color: var(--ink-dim);
    text-decoration: none;
    font-size: 0.8rem;
    border: 1px solid var(--edge);
    border-radius: 999px;
    padding: 8px 14px;
    background: var(--glass);
    backdrop-filter: blur(8px);
    min-height: var(--touch);
    display: inline-flex;
    align-items: center;
  }

  .steer-fab {
    position: sticky;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    z-index: 6;
    margin: 14px auto 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--touch);
    padding: 10px 30px;
    border-radius: 999px;
    border: 1px solid rgba(34, 211, 238, 0.45);
    background: #0a0c0f;
    color: var(--cyan);
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-decoration: none;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
  }
}

.pane-shortcuts, .steer-fab { display: none; }
@media (max-width: 1023px) {
  .pane-shortcuts, .steer-fab { display: flex; }
}

/* ------------------------------------------------------ reduced motion -- */

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .stream-row.row-in { animation: none; }
  .job-card.pulse-once { animation: none; }
  #topography { opacity: 0.3; }
}
/* the hidden attribute must always win over display rules (the read-only
   steering pane relies on it) */
[hidden] { display: none !important; }
