/* Mission Control theme — tokens ported from the Next.js reference app. */
:root {
    --ink: #0e172b;
    --accent: #f9870b;
    --accent-dark: #c56807;
    --page-bg: #f6f7f9;
    --card-bg: #ffffff;
    --border: #e6e9ef;
    --border-hover: #cfd6e2;
    --muted-bg: #f9fafb;
    --text-secondary: #64748b;
    --text-body: #334155;
    --text-heading: #0e172b;

    --status-not-started: #64748b; --status-not-started-bg: #eef1f5;
    --status-scheduled: #4f56d3; --status-scheduled-bg: #ecedfb;
    --status-running: #f9870b; --status-running-bg: #fff2e2;
    --status-needs-approval: #d1425a; --status-needs-approval-bg: #fdecef;
    --status-needs-attention: #7c3aed; --status-needs-attention-bg: #f2ecfd;
    --status-completed: #2f855a; --status-completed-bg: #e7f4ec;

    --agent-gs: #4f56d3;
    --agent-ms: #0f766e;

    --danger: #b3243f;
    --banner-bg: #7a5416;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Public Sans", system-ui, -apple-system, sans-serif;
    background: var(--page-bg);
    color: var(--text-body);
    -webkit-font-smoothing: antialiased;
}

code, .mono { font-family: "JetBrains Mono", ui-monospace, monospace; }

a { color: inherit; text-decoration: none; }

.app-shell { display: flex; height: 100vh; width: 100vw; overflow: hidden; flex-direction: column; }
.app-body { display: flex; flex: 1; min-height: 0; }

/* Icon rail */
.icon-rail {
    width: 72px;
    background: var(--ink);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 0;
    flex-shrink: 0;
}
.icon-rail .logo-dot-grid {
    width: 20px; height: 20px;
    display: grid; grid-template-columns: 1fr 1fr; gap: 3px;
    margin-bottom: 24px;
}
.icon-rail .logo-dot-grid span { background: var(--accent); border-radius: 2px; }
.icon-rail .rail-link {
    width: 44px; height: 44px; border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    color: #90a2b9; margin-bottom: 6px; font-size: 18px; position: relative;
    transition: background-color .12s, color .12s, transform .1s;
}
.icon-rail .rail-link:hover { background: #1f2c48; color: #dfe6f0; }
.icon-rail .rail-link:active { transform: scale(.92); }
.icon-rail .rail-link.active { background: var(--accent); color: #fff; box-shadow: 0 6px 16px -4px rgba(249,135,11,.55); }
.icon-rail .rail-badge {
    position: absolute; top: 2px; right: 2px;
    background: var(--danger); color: #fff; font-size: 10px; font-weight: 700;
    border-radius: 999px; min-width: 16px; height: 16px; display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
.icon-rail .rail-spacer { flex: 1; }
.icon-rail .rail-avatar {
    width: 36px; height: 36px; border-radius: 50%; background: var(--accent);
    color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; margin-top: 8px;
}

/* Secondary panel */
.secondary-panel {
    width: 240px; background: #fff; border-right: 1px solid var(--border);
    flex-shrink: 0; overflow-y: auto; padding: 20px 16px;
}
.secondary-panel h1 { font-size: 15px; font-weight: 800; margin: 0 0 2px; color: var(--text-heading); }
.secondary-panel .sub { font-size: 11.5px; color: var(--text-secondary); margin-bottom: 20px; }
.secondary-panel .section-label { font-size: 10.5px; font-weight: 700; letter-spacing: .04em; color: var(--text-secondary); text-transform: uppercase; margin: 18px 0 8px; }
.secondary-panel .type-row { display: flex; justify-content: space-between; font-size: 12.5px; padding: 4px 0; color: var(--text-body); }
.agent-card { border: 1px solid var(--border); border-radius: 12px; padding: 10px; margin-bottom: 8px; display: flex; gap: 8px; align-items: flex-start; }
.agent-avatar { width: 28px; height: 28px; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 11px; flex-shrink: 0; }
.agent-card .name { font-size: 12.5px; font-weight: 700; }
.agent-card .desc { font-size: 11px; color: var(--text-secondary); }
.pulse-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); display: inline-block; animation: live-pulse 1.4s ease-in-out infinite; }
@keyframes live-pulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .3; transform: scale(.72); } }

main.content { flex: 1; overflow-y: auto; padding: 28px 32px; min-width: 0; }

.mc-scroll::-webkit-scrollbar { width: 9px; }
.mc-scroll::-webkit-scrollbar-thumb { background: #cbd2dd; border-radius: 6px; background-clip: padding-box; }
.mc-scroll::-webkit-scrollbar-thumb:hover { background: #b3bdca; }
main.content, .inspector-panel, .secondary-panel { scrollbar-width: thin; scrollbar-color: #cbd2dd transparent; }
main.content::-webkit-scrollbar, .inspector-panel::-webkit-scrollbar { width: 9px; }
main.content::-webkit-scrollbar-thumb, .inspector-panel::-webkit-scrollbar-thumb { background: #cbd2dd; border-radius: 6px; background-clip: padding-box; }
main.content::-webkit-scrollbar-thumb:hover, .inspector-panel::-webkit-scrollbar-thumb:hover { background: #b3bdca; }

/* Keyboard-focus rings — visible on tab navigation, invisible on mouse click */
.btn:focus-visible, .rail-link:focus-visible, .tabs a:focus-visible, .agent-card:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 2px;
}

.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; gap: 16px; flex-wrap: nowrap; }
.page-header > div:first-child { min-width: 0; flex-shrink: 1; }
.page-header h1 { font-size: 22px; font-weight: 800; margin: 0 0 4px; color: var(--text-heading); white-space: nowrap; }
.page-header .sub { font-size: 12.5px; color: var(--text-secondary); white-space: nowrap; }
/* Tabs + search + primary CTA travel together as one unit on the right, and the whole
   header is forced to stay a single row (matching the reference) — the title/subtitle
   block shrinks first rather than the row wrapping onto two lines. */
.page-header-controls { display: flex; align-items: center; gap: 10px; flex-wrap: nowrap; flex-shrink: 0; }

.btn {
    display: inline-flex; align-items: center; gap: 6px; border-radius: 10px; border: 1px solid var(--border);
    background: #fff; padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--text-body);
    transition: border-color .12s, background-color .12s, box-shadow .12s, transform .06s;
}
.btn:hover { border-color: var(--border-hover); box-shadow: 0 1px 3px rgba(14,23,43,.06); }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-dark); border-color: var(--accent-dark); box-shadow: 0 3px 10px -3px rgba(197,104,7,.5); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: #f0b8c2; background: #fdecef; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }

.tabs { display: inline-flex; background: var(--muted-bg); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.tabs a { padding: 6px 14px; font-size: 12.5px; font-weight: 600; border-radius: 8px; color: var(--text-secondary); transition: background-color .12s, color .12s; }
.tabs a:not(.active):hover { color: var(--text-heading); }
.tabs a.active { background: #fff; color: var(--text-heading); box-shadow: 0 1px 2px rgba(14,23,43,.08); }

.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 14px; padding: 16px; box-shadow: 0 1px 2px rgba(14,23,43,.03); transition: box-shadow .15s, border-color .15s; }
.card:hover { box-shadow: 0 4px 14px -4px rgba(14,23,43,.14); border-color: var(--border-hover); }

.board-columns { display: grid; grid-template-columns: repeat(6, minmax(220px, 1fr)); gap: 14px; align-items: start; overflow-x: auto; }
.board-column-header { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; margin-bottom: 10px; color: var(--text-heading); }
.board-column-header .dot { width: 8px; height: 8px; border-radius: 50%; }
.board-column-header .count { margin-left: auto; background: var(--muted-bg); border-radius: 999px; font-size: 11px; padding: 1px 7px; color: var(--text-secondary); }
.board-column-body { display: flex; flex-direction: column; gap: 10px; min-height: 40px; }

.chip { display: inline-flex; align-items: center; font-size: 10.5px; font-weight: 700; border-radius: 999px; padding: 2px 8px; }

/* Small colored agent-initials square — used inside .mission-card's .agent-chip, but
   also standalone in the List view's table row and the Inspector's Sync-type box, so
   it's a global rule rather than one scoped to a single ancestor. */
.sq { width: 18px; height: 18px; border-radius: 6px; color: #fff; font-size: 8.5px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
/* Small muted relative-timestamp — used in mission cards, run-history rows, and the
   webhooks page's recent-activity rows, so likewise global rather than scoped. */
.time-ago { font-size: 10.5px; color: var(--text-secondary); }
/* Section eyebrow label — used in the Inspector panel and on plain .card sections
   elsewhere (e.g. the Webhooks page), so global rather than scoped to .inspector-panel. */
.label { font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-secondary); margin: 18px 0 8px; }

.mission-card { cursor: pointer; transition: box-shadow .15s, border-color .15s, transform .1s; }
.mission-card:hover { transform: translateY(-1px); }
.mission-card.selected { box-shadow: 0 0 0 2px var(--accent); }
.mission-card.selected:hover { transform: none; }
.mission-card .top-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.mission-card .name { font-weight: 700; font-size: 13.5px; color: var(--text-heading); margin-bottom: 6px; }
.mission-card .activity { font-size: 11.5px; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.mission-card .bottom-row { display: flex; justify-content: space-between; align-items: center; }
.mission-card .agent-chip { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-secondary); }

table.list-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.list-table th { text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-secondary); padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.list-table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list-table tr { transition: background-color .1s; }
table.list-table tr:hover { background: var(--muted-bg); cursor: pointer; }
table.list-table tr.selected { background: var(--muted-bg); box-shadow: inset 3px 0 0 var(--accent); }

.inspector-panel { width: 398px; flex-shrink: 0; background: #fff; border-left: 1px solid var(--border); overflow-y: auto; padding: 20px; }
.inspector-panel .empty { color: var(--text-secondary); font-size: 13px; padding: 40px 0; text-align: center; }
.timeline-item { display: flex; gap: 10px; margin-bottom: 12px; }
.timeline-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 4px; flex-shrink: 0; }
.run-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 12px; }

.inspector-box { background: var(--muted-bg); border-radius: 10px; padding: 12px 14px; }
.inspector-box .name { font-size: 12.5px; font-weight: 700; }
.inspector-box .desc { font-size: 11px; color: var(--text-secondary); }
.action-primary { display: flex; gap: 8px; margin-top: 4px; }
.action-primary .btn { flex: 1; justify-content: center; padding: 11px 14px; font-size: 13.5px; }
.action-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 10px; }
.action-grid .btn { flex-direction: column; gap: 4px; padding: 10px 4px; font-size: 10.5px; border-radius: 10px; }
.action-grid .btn svg { margin: 0 !important; }

/* Kanban column wrapper — a plain grid item; min-width:0 lets its .board-column-body
   cards shrink instead of overflowing the grid track. */
.board-column { display: flex; flex-direction: column; min-width: 0; }

.scheduler-banner { background: var(--banner-bg); color: #fff; padding: 8px 20px; font-size: 12.5px; display: flex; justify-content: space-between; flex-shrink: 0; }
.scheduler-banner a { text-decoration: underline; }

form .field { margin-bottom: 14px; }
form label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; color: var(--text-heading); }
form input[type=text], form input[type=number], form input[type=email], form input[type=password],
form input[type=time], form input[type=datetime-local], form select, form textarea {
    width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; font-family: inherit; background: #fff;
    transition: border-color .12s, box-shadow .12s;
}
form input:focus, form select:focus, form textarea:focus, .ssel-input:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(249,135,11,.15);
}
form textarea { font-family: "JetBrains Mono", monospace; font-size: 12px; }
form .field > textarea:not(#rawSql) { min-height: 100px; resize: vertical; line-height: 1.5; }
.hint, form .hint { font-size: 11px; color: var(--text-secondary); margin-top: 4px; }
form .row-repeatable { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 8px; }
form .row-repeatable > div { flex: 1; }

/* Direct-SQL column mapper row: 3 fields + action icons, with an optional JSON chip panel below */
form .raw-col-row { margin-bottom: 10px; }
form .raw-col-fields { display: flex; gap: 8px; align-items: center; }
form .raw-col-fields > div { flex: 1; min-width: 0; }
form .raw-col-fields input[readonly] { background: var(--muted-bg); color: var(--text-secondary); cursor: default; }
form .raw-col-fields .row-actions { display: flex; gap: 4px; align-items: center; flex: 0 0 auto; }
form .raw-col-fields .row-actions .btn.icon-btn { padding: 8px 10px; }
form .btn-json-toggle { color: var(--accent); border-color: #fadfba; font-weight: 700; flex: 0 0 auto; }
form .btn-json-toggle:hover { background: #fff2e2; }
.json-chip-panel { margin-top: 8px; padding: 10px 12px; background: var(--muted-bg); border-radius: 8px; }
.json-chip-panel .hint { margin: 0 0 8px; }
.json-chip-list { display: flex; flex-wrap: wrap; gap: 8px; }
.json-chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: #fff; border-radius: 999px; padding: 4px 10px 4px 4px; font-size: 12px; }
.json-chip .add-btn { background: none; border: none; color: var(--accent); font-weight: 700; font-size: 11.5px; cursor: pointer; padding: 3px 8px; border-radius: 999px; }
.json-chip .add-btn:hover { background: #fff2e2; }
.json-chip .key { font-weight: 600; color: var(--ink); }
.json-chip .sample { color: var(--text-secondary); font-family: "JetBrains Mono", monospace; font-size: 11px; }
form .toggle-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
form .field-row-2 { display: flex; gap: 14px; }
form .field-row-2 > .field { flex: 1; margin-bottom: 14px; }
form .field-label-row { display: flex; justify-content: space-between; align-items: baseline; }
form .field-label-row label { margin-bottom: 5px; }
.link-btn { background: none; border: none; padding: 0; color: var(--accent); font-size: 12px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.link-btn:hover { color: var(--accent-dark); text-decoration: underline; }
.info-box { border: 1px solid var(--border); border-radius: 8px; background: var(--muted-bg); padding: 9px 11px; font-size: 13px; color: var(--text-body); }

/* Toggle switch (visual wrapper around a real checkbox input) */
.switch { position: relative; display: inline-flex; width: 38px; height: 22px; flex-shrink: 0; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .slider { position: absolute; inset: 0; background: #cbd2dd; border-radius: 999px; transition: background .15s; pointer-events: none; }
.switch:hover .slider { background: #b3bdca; }
.switch input:checked ~ .slider:hover { background: var(--accent-dark); }
.switch .slider::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(16px); }
.switch input:focus-visible + .slider { box-shadow: 0 0 0 3px rgba(249,135,11,.25); }

/* Repeatable-row column headers (Builder field/filter/raw-column mappers) */
.row-repeatable-header { display: flex; gap: 8px; margin-bottom: 6px; }
.row-repeatable-header > div { flex: 1; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-secondary); }
.row-repeatable-header > div.write-to-sheet-header { flex: 0 0 110px; text-align: center; }
.row-repeatable-header > div.record-key-header { flex: 0 0 90px; text-align: center; }
/* Matches the width of a data row's .row-actions (↑/↓/✕ icon buttons) so the
   header's flexible columns don't stretch wider than the actual rows below
   them — without this, a header label visibly floats over the arrows
   instead of whatever it's meant to label. */
.row-repeatable-header > div.row-actions-header-spacer { flex: 0 0 122px; }

/* Per-column "Write to sheet" toggle and "Record key" radio in the Direct-SQL column mapper */
form .raw-col-fields .write-to-sheet-cell { flex: 0 0 110px; display: flex; align-items: center; justify-content: center; }
form .raw-col-fields .record-key-cell { flex: 0 0 90px; display: flex; align-items: center; justify-content: center; }
form .raw-col-fields .record-key-cell input[type="radio"] { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }

/* Searchable select combobox */
.ssel-wrap { position: relative; }
.ssel-input { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; font-family: inherit; background: #fff; }
.ssel-list { position: absolute; z-index: 20; top: 100%; left: 0; margin-top: 2px; width: max-content; min-width: 100%; max-width: 320px; max-height: 280px; overflow-y: auto; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 20px -4px rgba(14,23,43,.18); }
.ssel-group { padding: 7px 10px 3px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-secondary); }
.ssel-item { padding: 6px 10px; font-size: 12.5px; cursor: pointer; line-height: 1.35; transition: background-color .08s; }
.ssel-item:hover { background: var(--muted-bg); }
.ssel-item-selected { background: #fff2e2; }
.ssel-item-main { font-weight: 600; color: var(--ink); }
.ssel-item-sub { font-size: 10.5px; color: var(--text-secondary); margin-top: 1px; white-space: nowrap; }
.ssel-empty { padding: 10px; font-size: 12.5px; color: var(--text-secondary); text-align: center; }

/* SQL syntax highlighting — used only for the read-only "Compiled query" block (dark bg) */
.sql-code { background: #0e172b; color: #dfe6f0; padding: 14px; border-radius: 8px; overflow: auto; font-size: 12px; line-height: 1.6; }
.sql-kw { color: #60a5fa; font-weight: 600; }
.sql-str { color: #34d399; }
.sql-num { color: #fbbf24; }
.sql-comment { color: #7c8aa5; font-style: italic; }

/* Editable Direct SQL box — a plain textarea, deliberately not a highlighted overlay.
   An earlier transparent-text-over-highlighted-<pre> version kept breaking (misaligned
   wrapping, spellcheck squiggles, text-selection color leaking through) across browsers,
   so this trades syntax coloring for content that is simply, reliably visible. */
.code-textarea {
    width: 100%; font-family: "JetBrains Mono", monospace; font-size: 12.5px; line-height: 1.6;
    color: var(--ink); background: #fff; resize: vertical; white-space: pre; overflow: auto;
}

.login-wrap {
    display: flex; align-items: center; justify-content: center; height: 100vh;
    background: radial-gradient(circle at 30% 20%, #1a2842 0%, var(--ink) 60%);
}
.login-card { background: #fff; border-radius: 16px; padding: 36px; width: 360px; box-shadow: 0 20px 60px -15px rgba(0,0,0,.4); }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card .sub { font-size: 12.5px; color: var(--text-secondary); margin-bottom: 20px; }
.error-banner { background: #fdecef; color: var(--danger); border-radius: 8px; padding: 8px 12px; font-size: 12.5px; margin-bottom: 14px; }
.success-banner { background: #e7f4ec; color: #2f855a; border-radius: 8px; padding: 8px 12px; font-size: 12.5px; margin-bottom: 14px; }
