/* Minimal, clean, dependency-free styling (U3): server-rendered pages only. */

:root {
  --ink: #1c2430;
  --muted: #5b6572;
  --line: #dde3ea;
  --accent: #1f6f52;
  --warn-bg: #fdf3d7;
  --warn-ink: #7a5a00;
  --error-bg: #fbe9e7;
  --error-ink: #8c2f24;
  --bg: #f7f9fa;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0.7rem 1.5rem;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-left: auto;  /* nav sits next to the brand; identity + controls go right */
}

/* Nav. Until 2026-07-29 this had no rules at all and rendered as the browser's
   default underlined purple links -- visited-state colouring on your own app's
   primary navigation, which reads as an unstyled page rather than a product. */

.nav { display: flex; gap: 0.35rem; }
.nav a {
  padding: 0.35rem 0.7rem;
  border-radius: 5px;
  color: var(--muted);
  font-size: 0.94rem;
  font-weight: 500;
  text-decoration: none;
}
.nav a:hover { background: var(--bg); color: var(--ink); }
.nav a.current { background: var(--bg); color: var(--ink); font-weight: 600; }

/* Quiet secondary controls: present, legible, never competing with the page's
   own primary action (a green "Generate now" button). */

button.ghost {
  padding: 0.32rem 0.7rem;
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
  font-size: 0.88rem;
}
button.ghost:hover { filter: none; border-color: var(--muted); color: var(--ink); }

.logout { display: flex; align-items: center; gap: 0.6rem; margin: 0; }
.logout .who { color: var(--muted); font-size: 0.9rem; }

/* Operator view: one discreet toggle, no banner.
   The client view is now every session's default, so the state worth signalling is
   the ELEVATED one -- and it earns a lit dot and a tinted top border, not a full
   warning strip across a page EG reads all day. */

.operator-view { margin: 0; }
.operator-view .dot {
  display: inline-block;
  width: 0.45rem;
  height: 0.45rem;
  margin-right: 0.45rem;
  border-radius: 50%;
  background: var(--line);
  vertical-align: middle;
}
.operator-view button.on {
  background: #eef4f1;
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.operator-view button.on .dot { background: var(--accent); }
.topbar-operator { box-shadow: inset 0 3px 0 var(--accent); }

@media (max-width: 42rem) {
  .topbar { flex-wrap: wrap; gap: 0.75rem 1rem; }
  .topbar-right { gap: 0.6rem; }
  .logout .who { display: none; }  /* the email is the first thing to give up */
}

main { max-width: 72rem; margin: 2rem auto; padding: 0 1.5rem; }

h1 { font-size: 1.35rem; }

button {
  font: inherit;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }

/* Login */

.login-card {
  max-width: 24rem;
  margin: 4rem auto 0;
  padding: 2rem;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.login-card form { display: grid; gap: 1rem; margin-top: 1rem; }
.login-card label { display: grid; gap: 0.3rem; font-size: 0.9rem; color: var(--muted); }
.login-card input {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
}

.error {
  padding: 0.6rem 0.8rem;
  border-radius: 4px;
  background: var(--error-bg);
  color: var(--error-ink);
}

.hint { color: var(--muted); font-size: 0.85rem; }
.empty { color: var(--muted); }

/* Run list */

table.runs {
  width: 100%;
  border-collapse: collapse;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table.runs th, table.runs td {
  text-align: left;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

table.runs th { font-size: 0.8rem; text-transform: uppercase; color: var(--muted); }

tr.stale td { background: #fffdf5; }

.stale-banner {
  display: inline-block;
  margin-top: 0.3rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--warn-bg);
  color: var(--warn-ink);
}

/* The as-of note and the in-flight line: sub-lines, not columns. Both are the
   exception rather than the rule -- a run reads the database as its first step, so
   its data is its own data and there is normally nothing to add. */

.data-lag {
  margin-top: 0.3rem;
  font-size: 0.78rem;
  color: var(--warn-ink);
}
.run-progress {
  margin-top: 0.3rem;
  font-size: 0.78rem;
  color: var(--muted);
  font-style: italic;
}

.status {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: var(--line);
}
.status-succeeded { background: #e2f2e9; color: var(--accent); }
.status-failed, .status-crashed, .status-unreadable { background: var(--error-bg); color: var(--error-ink); }
.status-running, .status-queued { background: #e8eef7; color: #274b76; }

.artifacts a { display: inline-block; margin: 0 0.6rem 0.25rem 0; color: var(--accent); }
.artifacts .artifact-final { font-weight: 600; }

/* Operator downloads collapse: everything but final.xlsx behind a native <details>. */
.tech-artifacts { margin-top: 0.25rem; font-size: 0.85rem; }
.tech-artifacts summary { cursor: pointer; color: var(--muted); }
.tech-artifacts a { display: block; margin: 0.25rem 0 0 1rem; }

/* Deliverable labels + the per-run written panel (Phase B UX) */

.review-note { display: block; font-size: 0.78rem; color: var(--muted); }
.run-details-link { font-size: 0.85rem; }
.backlink { margin: 0 0 0.5rem; font-size: 0.85rem; }
.backlink a { color: var(--muted); }

.run-details {
  padding: 1rem 1.25rem;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.run-details h2 { margin: 1.25rem 0 0.4rem; font-size: 1rem; }
.detail-facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 1.1rem;
  margin: 0;
}
.detail-facts dt { color: var(--muted); font-size: 0.85rem; }
.detail-facts dd { margin: 0; font-size: 0.95rem; }
.detail-downloads { margin: 1rem 0 0; }
.warnings { margin: 0.25rem 0 0; padding-left: 1.2rem; font-size: 0.9rem; }
.flag-chip {
  display: inline-block;
  margin: 0 0.3rem 0.2rem 0;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
  background: var(--warn-bg);
  color: var(--warn-ink);
}
.flag-items { margin: 0.25rem 0 0; padding-left: 1.2rem; font-size: 0.9rem; }

/* Accounts page status chips */
.status-active { background: #e2f2e9; color: var(--accent); }
.status-invited { background: #e8eef7; color: #274b76; }
.status-disabled { background: var(--error-bg); color: var(--error-ink); }

/* Trigger (U4) */

.trigger {
  margin: 1rem 0 2rem;
  padding: 1rem 1.25rem;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.trigger h2 { margin: 0 0 0.5rem; font-size: 1rem; }
.trigger-form { display: flex; align-items: center; gap: 0.75rem; }
.trigger-form input[type="number"] {
  font: inherit;
  width: 6rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
}
.trigger .hint { margin: 0.6rem 0 0; font-size: 0.85rem; color: var(--muted); }

.notice {
  padding: 0.6rem 0.8rem;
  border-radius: 4px;
  background: #e2f2e9;
  color: var(--accent);
}

.failure-summary { margin-top: 0.35rem; font-size: 0.85rem; color: var(--error-ink); }
.failure-detail { margin-top: 0.35rem; font-size: 0.8rem; }
.failure-detail pre { white-space: pre-wrap; word-break: break-word; margin: 0.3rem 0 0; }

/* Schedules (U6): create form + calendar preview + schedule cards */

.schedule-layout {
  display: grid;
  grid-template-columns: minmax(18rem, 1fr) minmax(20rem, 1.4fr);
  gap: 1.25rem;
  align-items: start;
  margin: 1rem 0 2rem;
}
@media (max-width: 56rem) {
  .schedule-layout { grid-template-columns: 1fr; }
}

.schedule-create, .calendar {
  padding: 1rem 1.25rem;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.schedule-create h2, .calendar h2 { margin: 0 0 0.5rem; font-size: 1rem; }

.schedule-form { display: grid; gap: 1rem; }
.schedule-form .field { display: grid; gap: 0.35rem; }
.schedule-form label { font-size: 0.9rem; color: var(--muted); }
.schedule-form input {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  max-width: 14rem;
}

button.secondary {
  background: #ffffff;
  color: var(--accent);
}
button.danger {
  background: #ffffff;
  color: var(--error-ink);
  border-color: var(--error-ink);
}

/* Off-hours recommendation band (R7): shaded segments = recommended ET times */

.offhours-band { max-width: 14rem; margin-top: 0.2rem; }
.offhours-band .band-track {
  position: relative;
  height: 0.6rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  overflow: hidden;
}
.offhours-band .band-off {
  position: absolute;
  top: 0;
  bottom: 0;
  background: #cdeeda; /* recommended: off-hours green */
}
/* Band segments (00:00-08:00 and 18:00-24:00 ET) live here, not as inline style
   attributes: the CSP is "default-src 'self'" with no 'unsafe-inline'. */
.offhours-band .band-off-early { left: 0%; width: 33.34%; }
.offhours-band .band-off-late { left: 75%; width: 25%; }
.offhours-band .band-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--muted);
  margin-top: 0.15rem;
}
.offhours-hint { margin: 0.2rem 0 0; }

/* Variant weeks rows */

.variant-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
.variant-row input { width: 6rem; }
.variant-row .variant-remove {
  background: #ffffff;
  color: var(--muted);
  border-color: var(--line);
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
}
#variant-add { justify-self: start; }

/* Calendar preview: vertical timeline of the next firings */

.firings { list-style: none; margin: 0.5rem 0 0; padding: 0; }

.firing {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 1rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
}
.firing-main { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
.firing-weekday { font-weight: 700; font-size: 1.05rem; min-width: 2.6rem; }
.firing-date { font-variant-numeric: tabular-nums; }
.firing-time { color: var(--muted); }

.week-strip { display: flex; gap: 0.15rem; align-self: center; }
.strip-day {
  width: 1.15rem;
  height: 1.15rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #ffffff;
}
.strip-day.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.badge {
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
}
.badge-offhours { background: #e2f2e9; color: var(--accent); }
.badge-bizhours { background: var(--warn-bg); color: var(--warn-ink); }

/* An anchor whose instant has passed but which has not fired yet. Without this
   the card is indistinguishable from one scheduled for the future, which is how
   a duplicate schedule got read as the already-fired one (2026-07-28). */
.badge-overdue {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  background: var(--warn-bg);
  color: var(--warn-ink);
}

.interval {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.15rem 0 0.15rem 1.1rem;
}
.interval::before {
  content: "";
  display: block;
  width: 1px;
  height: 1.3rem;
  background: var(--line);
}
.interval-label { font-size: 0.75rem; color: var(--muted); }

.coverage { grid-column: 1 / -1; display: grid; gap: 0.3rem; }
.coverage-bar {
  position: relative;
  height: 1.15rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #ffffff;
  overflow: hidden;
}
.coverage-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  background: #dbe9f6;
}
.coverage-label {
  position: relative;
  font-size: 0.72rem;
  color: var(--ink);
  padding-left: 0.45rem;
  line-height: 1.15rem;
  white-space: nowrap;
}
.drift-note { margin-top: 0.6rem; }
.calendar-error { margin-top: 0.6rem; }

/* Active-schedule cards */

.schedule-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}
.schedule-card {
  padding: 1rem 1.25rem;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.card-time { font-weight: 700; font-size: 1.05rem; }
.card-cadence { color: var(--muted); font-size: 0.85rem; }
.card-facts { display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 0.9rem; margin: 0 0 0.8rem; }
.card-facts dt { color: var(--muted); font-size: 0.8rem; }
.card-facts dd { margin: 0; font-size: 0.9rem; }
.card-next { font-weight: 600; }
.window-chip {
  display: inline-block;
  margin: 0 0.3rem 0.2rem 0;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
  background: #dbe9f6;
  color: #274b76;
}

/* Deleted-schedule history */

table.schedules {
  width: 100%;
  border-collapse: collapse;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
table.schedules th, table.schedules td {
  text-align: left;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.schedules th { font-size: 0.8rem; text-transform: uppercase; color: var(--muted); }
tr.deleted td { color: var(--muted); }

/* Run origin. Once schedules fire unattended, "who started this?" is the first
   question about a row nobody expected -- and the answer already lives on the row
   as schedule_id, it just was not shown. */
.origin {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.origin-scheduled { background: #e8eef8; color: #2c4a7c; }
.origin-manual { background: #f0efe9; color: #5f5a4a; }
