/* ==========================================================================
   MuSCAT-db shared stylesheet
   Single source of truth for the design system. Linked from base.html, so
   every page inherits it. Page templates should only define genuinely
   page-specific rules; shared components live here to stay consistent.
   ========================================================================== */

:root, [data-theme="light"] {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface2: #eef0f6;
  --border: #d8dce6;
  --text: #1a1d27;
  --text-dim: #5b6178;
  --accent: #3457d5;
  --accent2: #0f9d8b;
  --red: #c0392b;
  --green: #16a085;
  --blue: #2980b9;
  --input-bg: #ffffff;
  /* Filled call-to-action ("To Jobs"). Deliberately theme-independent: the
     white-on-blue pairing is the same in light and dark. */
  --btn-solid: #0056b3;
}
[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242838;
  --border: #2e3348;
  --text: #e1e4ed;
  --text-dim: #8b90a5;
  --accent: #6c8cff;
  --accent2: #45d6b5;
  --red: #f87171;
  --green: #6ee7b7;
  --blue: #6c8cff;
  --input-bg: #1a1d27;
  --btn-solid: #0056b3;
}

/* ---------- Base elements ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
/* Bare links advertise whether their destination downloads or opens separately.
   Buttons are excluded: their label/icon is part of the control design. */
a:not(.btn)[download]::before { content: "⬇ "; }
a:not(.btn)[target="_blank"]::after { content: " ↗"; }
/* Figure previews already communicate their destination visually. */
figure a[download]::before,
figure a[target="_blank"]::after { content: none; }
h1 { font-size: 1.5rem; font-weight: 600; margin-bottom: 1.5rem; }
h2 { font-size: 1.15rem; font-weight: 500; margin-bottom: 1rem; color: var(--text-dim); }
.mono { font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 0.8rem; }
.container { max-width: 1200px; margin: 0 auto; padding: 2rem; }

/* Breadcrumb links inside an <h1> (obslog: Instruments / muscat3 / 250101 / …).
   The parent segments read as dim, regular-weight links so the final,
   non-link segment stays bold and full-strength — a clear "you are here". */
h1 a.crumb {
  color: var(--text-dim);
  font-weight: 400;
  transition: color 0.15s;
}
h1 a.crumb:hover { color: var(--accent); text-decoration: none; }

/* ---------- Messages ---------- */
.lco-msg {
  font-size: 0.82rem;
  margin-top: 0.5rem;
  min-height: 1em;
  color: var(--text-dim);
}
.lco-msg.err { color: var(--red); }
.lco-msg.ok { color: var(--green); }
.lco-msg a {
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.lco-msg a:hover { color: var(--accent); }

/* ---------- Navigation ---------- */
nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 2rem;
  display: flex; align-items: center; gap: 1.5rem;
}
nav a {
  color: var(--text-dim); text-decoration: none; font-size: 0.9rem;
  transition: color 0.15s;
}
nav a:hover { color: var(--accent); }
nav a[aria-current="page"] {
  color: var(--text);
  text-decoration-line: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.35rem;
}
nav .brand { color: var(--accent2); font-weight: 700; font-size: 1.1rem; }
nav .brand[aria-current="page"] {
  color: var(--accent2);
  text-decoration-color: var(--accent2);
}
nav .spacer { flex: 1; }

/* ---------- Cards ---------- */
.card-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
}
.card a { color: var(--text); text-decoration: none; }
.card .name  { font-size: 1.1rem; font-weight: 600; }
.card .meta  { font-size: 0.85rem; color: var(--text-dim); margin-top: 0.35rem; }

/* ---------- Tables ---------- */
table:not(#toi-table):not(#nx-table) {
  width: 100%; border-collapse: collapse; margin: 1rem 0;
  font-size: 0.85rem;
}
/* Catalog tables should use their intrinsic column widths. Their .csv-wrap
   containers provide horizontal scrolling instead of squeezing/truncating
   headers and values into the viewport width. */
#toi-table, #nx-table {
  width: max-content;
  table-layout: auto;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.85rem;
}
#toi-table th, #toi-table td,
#nx-table th, #nx-table td {
  max-width: none;
  overflow: visible;
  text-overflow: clip;
}
table.resizable-init { table-layout: fixed; }
.csv-wrap { overflow-x: auto; margin-top: 0.5rem; }
th {
  background: var(--surface2);
  color: var(--text-dim);
  font-weight: 500;
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: max-content;
}
td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: max-content;
}
th .col-resizer {
  position: absolute;
  top: 0; right: -3px;
  width: 8px; height: 100%;
  cursor: col-resize;
  user-select: none;
  z-index: 5;
}
th .col-resizer::after {
  content: ''; display: block;
  position: absolute; top: 25%; right: 3px;
  width: 2px; height: 50%;
  background: var(--border);
  transition: background 0.15s;
}
th .col-resizer:hover::after,
th .col-resizer.resizing::after {
  background: var(--accent);
}
th.resizing, td.col-resizing {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
tr:hover td { background: var(--surface); }
/* Single-row "nothing here" cell spanning a table (No frames / No dates / …).
   Dim, italic and centered so an empty table reads as intentional rather than
   a broken row. */
td.empty-cell {
  color: var(--text-dim);
  font-style: italic;
  text-align: center;
  padding: 1.5rem 0.75rem;
  white-space: normal;
}
tr:hover td.empty-cell { background: transparent; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--accent); }
th.sortable::after {
  content: '';
  display: inline-block;
  margin-left: 0.35rem;
  font-size: 0.7em;
  color: var(--text-dim);
  opacity: 0.4;
}
th.sortable[data-sort-dir="asc"]::after  { content: '▲'; opacity: 1; color: var(--accent); }
th.sortable[data-sort-dir="desc"]::after { content: '▼'; opacity: 1; color: var(--accent); }

/* ---------- Filter row ---------- */
tr.filter-row th { padding: 0.3rem 0.4rem; background: var(--surface); }
tr.filter-row th input {
  width: 100%; box-sizing: border-box;
  background: var(--input-bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 0.25rem 0.45rem;
  font-size: 0.78rem; font-family: inherit;
}
tr.filter-row th input:focus { outline: none; border-color: var(--accent); }
tr.filter-row th input.invalid { border-color: var(--red); }
tr.filter-row th input::placeholder { color: var(--text-dim); font-style: italic; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
}
.badge-green  { background: #065f46; color: #6ee7b7; }
.badge-blue   { background: #1e3a5f; color: #ffffff; }
.badge-amber  { background: #5c3d0e; color: #fcd34d; }
.badge-filter-g   { background: #dde6f5; color: #1e3a6b; }
.badge-filter-r   { background: #d9ebe0; color: #1f4a3a; }
.badge-filter-i   { background: #f1e6cd; color: #5a4520; }
.badge-filter-z   { background: #f1d9d9; color: #6e2a2a; }
.badge-filter-g.narrow { background: #aebfdd; color: #0d2247; }
.badge-filter-r.narrow { background: #afcfba; color: #0d2c20; }
.badge-filter-i.narrow { background: #d6bf86; color: #3b2a0a; }
.badge-filter-z.narrow { background: #d6a8a8; color: #4a1818; }
.badge-filter-other { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
/* Narrow-band filter chips stack one per line so a target with many narrow
   bands (g_narrow, i_narrow, z_narrow, Na_D, ...) doesn't force the Filters
   column wide; broad-band chips above stay inline. width:fit-content keeps the
   colour fill only as wide as the label text instead of the whole column. */
.filter-narrow-line { display: block; width: fit-content; margin-top: 2px; }
[data-theme="dark"] .badge-filter-g        { background: #2a3f6b; color: #c9d4ee; }
[data-theme="dark"] .badge-filter-r        { background: #2b4a3a; color: #c4e0cf; }
[data-theme="dark"] .badge-filter-i        { background: #5a4520; color: #ecd9a8; }
[data-theme="dark"] .badge-filter-z        { background: #5a2e2e; color: #ecc8c8; }
[data-theme="dark"] .badge-filter-g.narrow { background: #16223c; color: #8fa3cc; }
[data-theme="dark"] .badge-filter-r.narrow { background: #142e22; color: #88b69d; }
[data-theme="dark"] .badge-filter-i.narrow { background: #382912; color: #c2a76d; }
[data-theme="dark"] .badge-filter-z.narrow { background: #381c1c; color: #c08e8e; }

/* Status badges for job states */
.badge-error   { background: var(--red); color: #ffffff; }
.badge-cancelled { background: var(--text-dim); color: #ffffff; }
.badge-pending { background: var(--blue); color: #ffffff; }

/* ---------- Instrument filter badges ---------- */
.instrument-badges {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.instrument-badges-label {
  font-size: 0.85rem;
  color: var(--text-dim);
  font-weight: 500;
}
.instrument-badge {
  cursor: pointer;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  transition: border-color 0.15s, color 0.15s, transform 0.15s;
}
.instrument-badge:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}
.instrument-badge.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ---------- Move-target button ---------- */
.btn-move {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.15rem 0.35rem;
  font-size: 0.7rem;
  cursor: pointer;
  color: var(--text-dim);
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s;
}
.btn-move:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- Editable note cells ---------- */
.note-cell { cursor: text; min-width: 140px; position: relative; }
.note-cell .note-text { color: var(--text); word-break: break-word; }
.note-cell .note-placeholder { color: var(--text-dim); font-style: italic; font-size: 0.8rem; }
.note-cell:hover .note-placeholder { color: var(--accent); }
.note-cell.editing { padding: 0.25rem; overflow: visible; white-space: normal; }
.note-cell.editing .note-actions { flex-wrap: wrap; }
.note-cell textarea {
  width: 100%; min-height: 2.2rem; resize: vertical;
  background: var(--input-bg); color: var(--text);
  border: 1px solid var(--accent); border-radius: 4px;
  padding: 0.35rem 0.5rem; font: inherit;
}
.note-cell .note-actions { margin-top: 0.25rem; display: flex; gap: 0.35rem; }
.note-cell .note-actions button {
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 0.2rem 0.55rem; font-size: 0.75rem; cursor: pointer;
}
.note-cell .note-actions button.save { border-color: var(--accent2); color: var(--accent2); }
.note-cell .note-actions button.del  { border-color: var(--red);     color: var(--red); margin-left: auto; }
.note-cell .note-actions button:hover { filter: brightness(1.2); }

/* ---------- Theme toggle ---------- */
.theme-toggle {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem;
  width: 2.1rem; height: 2.1rem;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, transform 0.2s;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); transform: rotate(15deg); }
.theme-toggle svg { width: 1.05rem; height: 1.05rem; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: inline; }
[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ---------- Loading + status bars ---------- */
#loading-bar {
  position: fixed; top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent2), var(--accent));
  background-size: 200% 100%;
  animation: loading-slide 1.1s linear infinite;
  z-index: 9999;
  transition: opacity 0.25s ease;
}
#loading-bar.done { opacity: 0; pointer-events: none; }
@keyframes loading-slide {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
#status-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.4rem 1rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  display: flex; align-items: center; gap: 0.75rem;
  transform: translateY(100%);
  transition: transform 0.25s ease;
  z-index: 9998;
}
#status-bar.visible { transform: translateY(0); }
#status-bar .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent2);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.4; transform: scale(0.7); }
}

/* ---------- Search bar ---------- */
.search-bar {
  display: flex; gap: 0.5rem; align-items: center;
  margin-bottom: 1rem; flex-wrap: wrap;
}
.search-bar input[type="text"] {
  flex: 1; min-width: 220px;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}
.search-bar input[type="text"]:focus {
  outline: none; border-color: var(--accent);
}
.search-bar label {
  color: var(--text-dim); font-size: 0.85rem;
  display: flex; align-items: center; gap: 0.35rem;
  cursor: pointer;
}
.search-bar .hint { color: var(--text-dim); font-size: 0.8rem; }
.search-bar .invalid { color: var(--red); font-size: 0.8rem; }
.search-bar .csv-btn {
  display: inline-flex; align-items: center; gap: 0.25rem;
  padding: 0.25rem 0.55rem; border-radius: 4px;
  background: var(--accent); color: #fff;
  font-size: 0.75rem; font-weight: 600; text-decoration: none;
  white-space: nowrap;
}
.search-bar .csv-btn:hover { opacity: 0.85; }

/* ==========================================================================
   Shared components — previously duplicated (and divergent) across the
   jobs, photometry, and transit-fit pages. Unified here so buttons, forms,
   and panels look identical everywhere.
   ========================================================================== */

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 0.5rem 1rem; font-size: 0.85rem;
  font-family: inherit; text-decoration: none; cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { border-color: var(--accent2); color: var(--accent2); }
/* Filled variant used by every page-footer navigation link ("Back to Top",
   "To Jobs", "To Photometry", …). Declared after .btn:hover so the fill and
   white label survive hover, as the old inline styles did. */
.btn.solid {
  background: var(--btn-solid); border-color: var(--btn-solid); color: #fff;
  border-radius: 4px; line-height: 1.2; padding: 0.5em 2em;
}
/* Compact variant for dense table-row actions. */
.btn.sm { padding: 0.15rem 0.5rem; font-size: 0.75rem; border-radius: 4px; }
/* Destructive variant. */
.btn.danger { border-color: var(--red); color: var(--red); background: transparent; }
.btn.danger:hover { border-color: var(--red); background: var(--red); color: #fff; }

/* ---------- Section headings ---------- */
.phot-section { margin: 2rem 0 1rem; }
.phot-section h2 { color: var(--text); margin-bottom: 0.75rem; }

/* Inst/date/target picker card used by the transit-fit and ttv-fit pages. */
.selector-group {
  display: flex; gap: 1rem; align-items: center; margin-bottom: 2rem; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); padding: 1rem; border-radius: 8px;
}
.selector-group label { font-size: 0.85rem; color: var(--text-dim); display: flex; flex-direction: column; gap: 0.35rem; }
.selector-group select {
  background: var(--input-bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.45rem 0.75rem; min-width: 160px; font-size: 0.9rem;
}
.selector-group select:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Page lede & empty states ---------- */
/* One-line description under a page <h1>. Shared by the photometry, transit-fit
   and ephemeris pages so page intros read consistently. */
.page-lede {
  color: var(--text-dim);
  font-size: 0.95rem;
  line-height: 1.5;
  max-width: 70ch;
  margin-bottom: 1.5rem;
}
/* Centered placeholder for a page with nothing to show yet — no selection made,
   or no data found. Replaces the per-page ad-hoc empty panels so every "nothing
   here yet" surface looks the same. Add .error for a red rule + red icon when
   the placeholder reports missing data rather than prompting a choice. */
.empty-state {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 2.5rem 2rem;
  text-align: center;
  margin-top: 1.5rem;
}
.empty-state.error { border-color: var(--red); }
.empty-state .empty-icon { font-size: 2.5rem; line-height: 1; margin-bottom: 0.85rem; }
.empty-state.error .empty-icon { color: var(--red); }
.empty-state h2 { color: var(--text); margin-bottom: 0.5rem; }
.empty-state p { color: var(--text-dim); max-width: 520px; margin: 0 auto; line-height: 1.6; font-size: 0.9rem; }
.empty-state .btn { margin-top: 1.25rem; }

/* Foldable section: a <details> whose <summary> carries the section <h2>. */
.phot-fold > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 0.5rem;
}
.phot-fold > summary::-webkit-details-marker { display: none; }
.phot-fold > summary::before {
  content: '\25B8'; color: var(--text-dim); font-size: 0.9rem;
  transition: transform 0.15s ease; flex-shrink: 0;
}
.phot-fold[open] > summary::before { transform: rotate(90deg); }
.phot-fold > summary h2 { margin: 0; }
/* Interactive controls in the summary (csv download links) must not toggle. */
.phot-fold > summary a { cursor: pointer; }

/* Foldable card section: a <details> whose <summary> carries an <h3>. */
.section-fold > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 0.5rem;
}
.section-fold > summary::-webkit-details-marker { display: none; }
.section-fold > summary::before {
  content: '\25B8'; color: var(--text-dim); font-size: 0.9rem;
  transition: transform 0.15s ease; flex-shrink: 0;
}
.section-fold[open] > summary::before { transform: rotate(90deg); }
.section-fold > summary h3 { margin: 0; }
.section-fold[open] > summary { margin-bottom: 0.85rem; }

/* ---------- Options form ---------- */
.opt-grid {
  display: grid; gap: 0.75rem 1.25rem;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  padding: 0.5rem 0 0.75rem;
}
.opt { display: flex; flex-direction: column; gap: 0.25rem; }
.opt > label { font-size: 0.78rem; color: var(--text-dim); }
.opt input[type="text"], .opt input[type="number"], .opt select {
  background: var(--input-bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 0.35rem 0.5rem; font-size: 0.85rem; font-family: inherit;
}
.opt input:focus, .opt select:focus { outline: none; border-color: var(--accent); }
.opt.check { flex-direction: row; align-items: center; gap: 0.45rem; }
.opt.check label { color: var(--text); font-size: 0.85rem; }
.opt .hint { font-size: 0.7rem; color: var(--text-dim); }

.opt-check-row {
  display: flex; flex-wrap: wrap; gap: 1rem 1.5rem;
  padding: 0.25rem 0 0.5rem;
}
.opt-check-item {
  display: inline-flex; align-items: center; gap: 0.3rem;
  cursor: pointer; font-size: 0.85rem; color: var(--text);
  white-space: nowrap;
}
.opt-check-item input, .opt-check-item select { cursor: pointer; }

/* Heading that spans a full .opt-grid row. */
.opt-section-title {
  grid-column: 1 / -1; font-size: 0.85rem; font-weight: 600; color: var(--accent2);
  margin-top: 1rem; border-bottom: 1px solid var(--border); padding-bottom: 0.25rem;
}

/* Collapsible option group inside an .opt-grid, collapsed by default. */
.opt-collapse { grid-column: 1 / -1; margin-top: 1rem; }
.opt-collapse > summary {
  font-size: 0.85rem; font-weight: 600; color: var(--accent2);
  border-bottom: 1px solid var(--border); padding-bottom: 0.25rem;
  cursor: pointer; user-select: none; list-style: none;
  display: flex; align-items: center; gap: 0.4rem;
}
.opt-collapse > summary::-webkit-details-marker { display: none; }
.opt-collapse > summary::before {
  content: '\25B8'; color: var(--text-dim); font-size: 0.8rem;
  transition: transform 0.15s ease;
}
.opt-collapse[open] > summary::before { transform: rotate(90deg); }
.opt-collapse > *:not(summary) { margin-top: 0.7rem; }

/* ---------- Advanced disclosure ---------- */
details.adv {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 0.5rem 1rem; margin: 0.75rem 0;
}
details.adv > summary {
  cursor: pointer; font-size: 0.9rem; color: var(--text-dim);
  padding: 0.35rem 0; user-select: none;
}
details.adv[open] > summary { color: var(--text); margin-bottom: 0.5rem; }

/* Keep every Ephemeris disclosure indicator the same readable size. */
.ephemeris-fold > summary {
  list-style: none; display: flex; align-items: center; gap: 0.5rem;
}
.ephemeris-fold > summary::-webkit-details-marker { display: none; }
.ephemeris-fold > summary::before {
  content: '\25B8'; color: var(--text-dim); font-size: 1rem; line-height: 1;
  transition: transform 0.15s ease; flex-shrink: 0;
}
.ephemeris-fold[open] > summary::before { transform: rotate(90deg); }
/* Top-level folds sit beside an h2 and need a larger optical glyph. */
.ephemeris-fold.phot-fold > summary::before { font-size: 1.35rem; }

/* ---------- Run panel ---------- */
.run-panel { border-top: 1px solid var(--border); padding-top: 1.25rem; margin-top: 2rem; }
.run-actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 0.5rem; }
#run-log {
  display: none; margin-top: 1rem; text-align: left;
  background: #0b0d13; color: #cdd3e0; border: 1px solid var(--border);
  border-radius: 8px; padding: 0.75rem; max-height: 22rem; overflow: auto;
  font-family: 'JetBrains Mono', monospace; font-size: 0.75rem;
  white-space: pre-wrap; word-break: break-word;
}
.run-cmd { display: flex; gap: 0.5rem; align-items: stretch; margin-top: 1rem; width: 100%; }
.run-cmd code {
  flex: 1; text-align: left; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 0.5rem 0.75rem; font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem; overflow-x: auto; white-space: pre;
}

/* ---------- Page-footer navigation ---------- */
/* The row of .btn.solid links closing every page. Wraps on narrow viewports
   rather than overflowing. */
.page-nav {
  display: flex; justify-content: center; align-items: center;
  gap: 1rem; flex-wrap: wrap; margin: 2em 0;
}

/* ---------- Run/site selector chips ---------- */
/* Used as <a> (server-rendered navigation) and as <button> (client-side
   switching), so the font must be inherited rather than the UA button default. */
.site-chips { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; margin: 0 0 0.75rem; }
.site-chips .site-label { font-size: 0.8rem; color: var(--text-dim); }
.site-chip {
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 0.3rem 0.9rem; font-size: 0.85rem; cursor: pointer;
  text-decoration: none; font-family: inherit;
}
.site-chip.active { border-color: var(--accent); color: var(--accent); }

/* ---------- Result figure grid ---------- */
/* Shared by the transit-fit, ttv-fit and ephemeris result sections. The
   <figcaption class="cap"> is placed first so the label sits above the plot. */
.fig-grid {
  display: grid; gap: 1.5rem; grid-template-columns: repeat(auto-fill, minmax(480px, 1fr));
  margin-top: 1rem;
}
@media (max-width: 600px) { .fig-grid { grid-template-columns: 1fr; } }
.fig {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.75rem; display: flex; flex-direction: column; gap: 0.5rem;
}
.fig img { width: 100%; height: auto; border-radius: 6px; display: block; background: var(--input-bg); }
.fig .cap { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; font-size: 0.8rem; color: var(--text-dim); }

/* ---------- Misc shared ---------- */
.dl-row { margin-top: 0.75rem; display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.85rem; }
.help-tooltip {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 13px; height: 13px; font-size: 0.65rem; font-weight: bold;
  border-radius: 50%; background: var(--border); color: var(--text-dim);
  cursor: help; margin-left: 4px; vertical-align: middle; border: 1px solid var(--border);
  text-transform: none; letter-spacing: normal;
}
.help-tooltip:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
/* Instant, styled tooltip bubble. Reads text from the element's title
   attribute via attr(); white-space: pre-line honors &#10; line breaks. */
.help-tooltip::after {
  content: attr(title);
  text-transform: none; letter-spacing: normal;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 280px;
  white-space: pre-line;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.45;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease;
  z-index: 1000;
  pointer-events: none;
}
.help-tooltip:hover::after,
.help-tooltip:focus::after {
  opacity: 1;
  visibility: visible;
}

/* ---------- Workflow Diagram & Help ---------- */
.workflow-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  font-size: 0.85rem;
  font-weight: bold;
  border-radius: 50%;
  background: var(--surface2);
  color: var(--text-dim);
  cursor: pointer;
  margin-left: 10px;
  vertical-align: middle;
  border: 1px solid var(--border);
  text-decoration: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.workflow-help:hover {
  background: var(--accent2);
  color: var(--bg);
  border-color: var(--accent2);
  transform: scale(1.15) rotate(10deg);
  box-shadow: 0 0 10px rgba(69, 214, 181, 0.4);
  text-decoration: none;
}

.workflow-container {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  max-width: 1000px;
  margin: 0 auto;
}

.workflow-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.workflow-diagram-wrap {
  background: var(--surface2);
  border-radius: 8px;
  padding: 1.5rem;
  border: 1px solid var(--border);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: auto;
}

.workflow-grid {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.workflow-stage {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 1.5rem;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  position: relative;
}

.workflow-stage:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
  border-color: var(--accent);
}

.workflow-stage.stage-phot {
  border-left-color: var(--accent2);
}

.workflow-stage.stage-phot:hover {
  border-color: var(--accent2);
}

.workflow-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.workflow-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface2);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.8rem;
  border: 1px solid var(--border);
}

.workflow-stage.stage-phot .workflow-badge {
  color: var(--accent2);
}

.workflow-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.workflow-desc {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.5;
}

.workflow-cmd {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  background: var(--surface2);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--text);
  margin-top: 0.5rem;
  display: inline-block;
}

/* Drag and drop columns styling */
th[draggable="true"] {
  cursor: grab;
  user-select: none;
}
th[draggable="true"]:active {
  cursor: grabbing;
}
th.dragging {
  opacity: 0.5;
  background: var(--surface2) !important;
}
th.drag-over-left {
  border-left: 3px solid var(--accent) !important;
}
th.drag-over-right {
  border-right: 3px solid var(--accent) !important;
}

/* ---------- Jobs page ---------- */
.jobs-summary {
  display: flex; gap: 0.5rem; align-items: center;
  margin: 1rem 0; flex-wrap: wrap;
}
.job-count {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}
.job-count:hover { border-color: var(--accent); }
.job-count.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.job-count.has-running { border-color: var(--amber, #f59e0b); }
.job-count.has-pending { border-color: var(--blue); }
.job-count.has-done { border-color: var(--green, #10b981); }
.job-count.has-error { border-color: var(--red); }
.job-count.has-cancelled { border-color: var(--text-dim); }
.job-count.active.has-running { background: var(--amber, #f59e0b); border-color: var(--amber, #f59e0b); }
.job-count.active.has-pending { background: var(--blue); border-color: var(--blue); }
.job-count.active.has-done { background: var(--green, #10b981); border-color: var(--green, #10b981); }
.job-count.active.has-error { background: var(--red); border-color: var(--red); }
.job-count.active.has-cancelled { background: var(--text-dim); border-color: var(--text-dim); }
.job-count-num { font-weight: 700; font-size: 1rem; }
.job-count-label { font-size: 0.8rem; opacity: 0.8; }
.job-count-bar-spacer { flex: 1; }

.job-actions { white-space: nowrap; }

.jobs-table[data-job-type="lco_archive_download"] {
  min-width: 980px;
}
.jobs-table[data-job-type="lco_archive_download"] .lco-actions-head,
.jobs-table[data-job-type="lco_archive_download"] .lco-actions-cell {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--surface);
  box-shadow: 1px 0 0 var(--border);
  min-width: 168px;
  max-width: 184px;
}
.jobs-table[data-job-type="lco_archive_download"] .lco-actions-head {
  background: var(--surface2);
  z-index: 4;
}
.jobs-table[data-job-type="lco_archive_download"] .lco-actions-cell {
  white-space: normal;
}
.jobs-table[data-job-type="lco_archive_download"] .lco-actions-cell .btn {
  margin: 0.1rem 0.15rem 0.1rem 0;
}

.log-row td { padding: 0; background: var(--surface); }
.log-row pre.log-content {
  margin: 0; padding: 1rem;
  max-height: 400px; overflow: auto;
  font-size: 0.78rem; line-height: 1.4;
  background: var(--input-bg);
  border-radius: 0;
  white-space: pre-wrap;
  word-break: break-all;
}

.badge.pulse {
  animation: pulse 1.5s infinite;
}

#message-modal,
#hide-confirm-overlay,
#move-confirm-overlay,
#delete-confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 10000;
  align-items: center;
  justify-content: center;
}
#message-modal.visible,
#hide-confirm-overlay.visible,
#move-confirm-overlay.visible,
#delete-confirm-overlay.visible {
  display: flex;
}
#message-modal[data-mode="message"] #message-modal-cancel {
  display: none !important;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
#message-modal[data-kind="success"] .modal-box {
  border-color: var(--green);
}
#message-modal[data-kind="error"] .modal-box {
  border-color: var(--red);
}
#message-modal[data-kind="notice"] .modal-box {
  border-color: var(--blue);
}
.modal-title {
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
}
#message-modal[data-kind="success"] .modal-title { color: var(--green); }
#message-modal[data-kind="error"] .modal-title { color: var(--red); }
#message-modal[data-kind="notice"] .modal-title { color: var(--blue); }
.modal-text {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 1.5rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ---------- Native <dialog> ---------- */
/* The UA default for <dialog> is unthemed (canvas/canvastext colors, plain
   border), so without this it's the only surface on the site that ignores
   light/dark mode. Match the .modal-box treatment used by the custom overlay
   modals above so every "popup" surface looks like one system. */
dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  margin: auto;
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}
dialog h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text);
}

/* ---------- LCO Schedule page ---------- */
.muscat-only { display: none; }
.sinistro-only { display: none; }

/* ---------- Chat Window ---------- */
#chat-window {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 320px;
    max-width: calc(100vw - 40px);
    border: 1px solid var(--border);
    border-radius: 12px;
    background-color: var(--surface);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

#chat-window.hidden { display: none; }

#chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background-color: var(--surface2);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
}

.chat-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: var(--text);
}

.chat-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--red);
    flex: none;
    transition: background-color 0.2s ease;
}

.chat-status-dot.online { background-color: var(--green); }

.chat-online {
    font-size: 0.72rem;
    font-weight: 400;
    color: var(--text-dim);
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-unread {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background-color: var(--accent);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
}

.chat-unread.hidden { display: none; }

#chat-messages {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    overflow-y: auto;
    height: 260px;
}

.chat-empty {
    margin: auto;
    text-align: center;
    color: var(--text-dim);
    font-size: 0.8rem;
    line-height: 1.5;
}

.chat-empty code {
    background-color: var(--surface2);
    border-radius: 4px;
    padding: 1px 4px;
}

#chat-input {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
}

#message-input {
    flex-grow: 1;
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 9px;
    background-color: var(--input-bg);
    color: var(--text);
    font-size: 0.85rem;
}

#message-input:focus {
    outline: none;
    border-color: var(--accent);
}

#send-button {
    flex: none;
    padding: 7px 14px;
    border: 1px solid var(--accent);
    background-color: var(--accent);
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
}

#send-button:hover { filter: brightness(1.08); }

#minimize-chat {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    padding: 0 4px;
}

#minimize-chat:hover { color: var(--text); }

#chat-window.minimized #chat-messages,
#chat-window.minimized #chat-input {
    display: none;
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    align-self: flex-start;
}

.message.me { align-self: flex-end; }

.message-meta {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 2px;
    font-size: 0.68rem;
}

.message.me .message-meta { flex-direction: row-reverse; }

.message-meta .user {
    font-weight: 600;
    color: var(--accent);
}

.message-meta .time { color: var(--text-dim); }

.message-body {
    padding: 6px 10px;
    border-radius: 10px;
    background-color: var(--surface2);
    color: var(--text);
    font-size: 0.85rem;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.message.me .message-body {
    background-color: var(--accent);
    color: #fff;
}

.message-body .chat-link {
    color: var(--blue);
    text-decoration: underline;
}

.message.me .message-body .chat-link {
    color: #fff;
    text-decoration: underline;
}

@media (max-width: 480px) {
    #chat-window {
        right: 10px;
        left: 10px;
        bottom: 10px;
        width: auto;
    }
}

/* ---------- Chat: rich features ---------- */
.message-row {
    display: flex;
    align-items: flex-start;
    gap: 6px;
}

.message.me .message-row { flex-direction: row-reverse; }

.message-actions {
    display: none;
    gap: 2px;
    flex: none;
    position: relative;
}

.message:hover .message-actions { display: flex; }

.message-actions .act {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.8rem;
    line-height: 1;
    padding: 2px 3px;
    border-radius: 4px;
}

.message-actions .act:hover { color: var(--text); background: var(--surface2); }

/* Edit/delete only make sense on your own messages. */
.message:not(.me) .message-actions .edit,
.message:not(.me) .message-actions .delete { display: none; }

.message-meta .edited { color: var(--text-dim); font-style: italic; }

.message-meta .tag {
    background: var(--surface2);
    color: var(--text-dim);
    border-radius: 4px;
    padding: 0 4px;
    text-transform: uppercase;
    font-size: 0.6rem;
    letter-spacing: 0.04em;
}

.message.ephemeral .message-body {
    border: 1px dashed var(--border);
    background: transparent;
    font-style: italic;
    opacity: 0.85;
}

.message.mention-me .message-body {
    box-shadow: inset 3px 0 0 var(--accent2);
}

/* Codebase assistant (@bot) replies: accent the surface so they read as a
   distinct participant rather than a teammate. */
.message.agent .message-body {
    border-left: 2px solid var(--accent);
    background: var(--surface2);
}

.message-meta .tag.agent-tag {
    background: var(--accent);
    color: #fff;
}

.message.system {
    align-self: center;
    max-width: 95%;
    text-align: center;
}

.message.system .message-body {
    background: transparent;
    color: var(--text-dim);
    font-size: 0.75rem;
    font-style: italic;
    padding: 2px 8px;
}

.message.system .time { margin-left: 6px; opacity: 0.7; }

.chat-mention { color: var(--accent); font-weight: 600; }
.chat-mention.mention-self { background: var(--accent2); color: #06231d; border-radius: 4px; padding: 0 3px; }
.message.me .chat-mention { color: #fff; text-decoration: underline; }

.reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 3px;
}

.message.me .reactions { justify-content: flex-end; }

.reaction-chip {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0 6px;
    font-size: 0.72rem;
    line-height: 1.5;
    cursor: pointer;
    color: var(--text);
}

.reaction-chip.mine { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, transparent); }

.emoji-picker {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 1100;
    display: flex;
    gap: 2px;
    padding: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}

.emoji-picker button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 2px 4px;
    border-radius: 4px;
}

.emoji-picker button:hover { background: var(--surface2); }

.edit-input {
    width: 100%;
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 5px 8px;
    background: var(--input-bg);
    color: var(--text);
    font-size: 0.85rem;
    resize: vertical;
}

.chat-typing {
    min-height: 1rem;
    padding: 0 12px;
    font-size: 0.72rem;
    font-style: italic;
    color: var(--text-dim);
}

#chat-window.minimized .chat-typing { display: none; }

.chat-input-wrap {
    position: relative;
    flex-grow: 1;
    min-width: 0;
    display: flex;
}

.chat-input-wrap #message-input { width: 100%; }

.chat-autocomplete {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    margin-bottom: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    z-index: 1100;
}

.chat-autocomplete.hidden { display: none; }

.ac-item {
    padding: 6px 10px;
    font-size: 0.82rem;
    cursor: pointer;
    color: var(--text);
}

.ac-item.active, .ac-item:hover { background: var(--accent); color: #fff; }

#chat-online { cursor: help; }

