/* Topical Map Engine product UI (P10.3). Plain CSS, no framework, no build step. */
:root {
  --bg: #f6f7f9; --surface: #ffffff; --text: #1d2330; --muted: #5a6475; --border: #d8dde5;
  --accent: #1f5fbf; --accent-text: #ffffff; --focus: #f2a900;
  --ok: #1e7a46; --ok-bg: #e5f4ec; --warn: #8a5a00; --warn-bg: #fdf3dc;
  --err: #b42318; --err-bg: #fdecea; --info: #1f5fbf; --info-bg: #e8f0fc; --neutral-bg: #eef0f4;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.5; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 1rem; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip-link { position: absolute; left: -999px; }
.skip-link:focus { left: 1rem; top: 1rem; background: var(--surface); padding: .5rem; z-index: 10; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.header-inner { display: flex; align-items: center; gap: 1.5rem; min-height: 3.25rem; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.site-header nav a { text-decoration: none; font-weight: 500; }
.worker-indicator { margin: 0 0 0 auto; color: var(--muted); font-size: .9rem; }
.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; margin-right: .3rem; background: var(--muted); }
.dot-active { background: var(--ok); } .dot-stale { background: var(--warn); } .dot-stopped, .dot-never_seen { background: var(--err); }
main { padding-top: 1.25rem; padding-bottom: 2rem; }
.site-footer { color: var(--muted); font-size: .85rem; padding-bottom: 1.5rem; }

h1 { font-size: 1.6rem; margin: .25rem 0 .75rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
.breadcrumb, .meta { color: var(--muted); margin: 0 0 .5rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.5rem; }
.empty { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem 1.25rem; }
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field.wide, .actions { grid-column: 1 / -1; }
label, legend { font-weight: 600; font-size: .92rem; }
.optional { font-weight: 400; color: var(--muted); }
input[type=text], input[type=number], select, textarea {
  font: inherit; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 6px; background: #fff; width: 100%;
}
textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: .9rem; }
[aria-invalid=true] { border-color: var(--err); }
.help { color: var(--muted); font-size: .85rem; margin: 0; }
.field-error { color: var(--err); font-size: .85rem; margin: 0; font-weight: 600; }
.field-error::before { content: "Error: "; }
fieldset { border: 1px solid var(--border); border-radius: 6px; padding: .75rem 1rem; margin: 0; }
fieldset.budgets { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem 1rem; }
fieldset.budgets legend { grid-column: 1 / -1; }
.choice { display: inline-flex; align-items: center; gap: .4rem; font-weight: 500; margin-right: 1.25rem; }

/* Mode: live-only controls and help appear only when "Live" is selected; offline help only for offline. */
.run-form .live-only { display: none; }
.run-form:has(#mode-live:checked) .live-only { display: grid; }
.run-form:has(#mode-live:checked) p.live-only { display: block; }
.run-form:has(#mode-live:checked) .offline-only { display: none; }

.button { display: inline-block; font: inherit; font-weight: 600; padding: .45rem .9rem; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none; cursor: pointer; }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.button.danger { color: var(--err); border-color: var(--err); }
.actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: 1rem; }

.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table th, .table td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.table.compact th, .table.compact td { padding: .4rem .6rem; }

/* Status badges carry their text, so status never relies on colour alone. */
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .82rem; font-weight: 600;
  background: var(--neutral-bg); border: 1px solid var(--border); }
.badge-completed { background: var(--ok-bg); color: var(--ok); }
.badge-completed_with_warnings { background: var(--warn-bg); color: var(--warn); }
.badge-failed, .badge-interrupted { background: var(--err-bg); color: var(--err); }
.badge-running, .badge-queued { background: var(--info-bg); color: var(--info); }
.badge-cancelled { background: var(--neutral-bg); color: var(--muted); }
.tag { font-size: .8rem; color: var(--warn); font-weight: 600; }

.status-line { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.polling { color: var(--muted); font-size: .85rem; }
.facts { display: flex; flex-wrap: wrap; gap: .5rem 2rem; margin: 0 0 1rem; }
.facts dt { font-size: .8rem; color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }
.facts.compact { margin: .5rem 0; }

.stages { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; counter-reset: stage; }
.stage { display: flex; justify-content: space-between; gap: 1rem; padding: .4rem .7rem; border: 1px solid var(--border);
  border-radius: 6px; background: var(--surface); counter-increment: stage; }
.stage-name::before { content: counter(stage) ". "; color: var(--muted); }
.stage-status { color: var(--muted); font-size: .9rem; }
.stage-completed .stage-status, .stage-completed_partial .stage-status { color: var(--ok); }
.stage-failed .stage-status { color: var(--err); font-weight: 600; }
.stage-current { border-color: var(--accent); border-width: 2px; }
.stage-current .stage-status { color: var(--accent); font-weight: 700; }

.notice { border-radius: 6px; padding: .65rem .9rem; margin: 0 0 1rem; border: 1px solid var(--border); }
.notice p { margin: 0; }
.notice-success { background: var(--ok-bg); border-color: var(--ok); }
.notice-info { background: var(--info-bg); border-color: var(--info); }
.notice-warning { background: var(--warn-bg); border-color: var(--warn); }
.notice-error { background: var(--err-bg); border-color: var(--err); }

/* --- P10.4: run tabs, map tree and table, page detail ------------------------------------------------------- */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin: 0 0 1.25rem; }
.tab { padding: .45rem .9rem; text-decoration: none; font-weight: 600; color: var(--muted);
  border: 1px solid transparent; border-bottom: 0; border-radius: 6px 6px 0 0; margin-bottom: -1px; }
.tab.is-active { color: var(--text); background: var(--surface); border-color: var(--border); }
.muted { color: var(--muted); }
.empty-note { color: var(--muted); margin: .25rem 0; }
.slug { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; color: var(--muted); overflow-wrap: anywhere; }
.table-wrap { overflow-x: auto; margin-bottom: .75rem; }
.table caption { text-align: left; color: var(--muted); font-size: .85rem; padding: .3rem 0; caption-side: top; }
.table th a { color: inherit; }
.table th[aria-sort] a::after { content: " (sorted)"; text-transform: none; }
.plain { margin: .25rem 0 .5rem; padding-left: 1.2rem; }
.badge-intent, .badge-type { font-weight: 500; }
.flag { display: inline-block; font-size: .8rem; font-weight: 700; color: var(--warn); background: var(--warn-bg);
  border: 1px solid var(--warn); border-radius: 4px; padding: 0 .35rem; margin-right: .25rem; }
.tag-seed { color: var(--ok); }
.filters { font-size: .9rem; }

.tree { font-size: .95rem; }
.tree summary { cursor: pointer; padding: .3rem .2rem; border-radius: 4px; }
.tree summary:hover { background: var(--neutral-bg); }
.tree-list { list-style: none; margin: 0; padding-left: 1.4rem; border-left: 1px dashed var(--border); }
.tree-list > li { margin: .1rem 0; }
.tree-leaf { padding: .3rem .2rem .3rem 1.05rem; }
.tree .node-query, .tree-root > summary .node-query { font-weight: 600; }
.node-meta { color: var(--muted); font-size: .85rem; }
.node-open { font-size: .85rem; margin-left: .35rem; }
.tree summary > *, .tree-leaf > * { vertical-align: middle; }

.page-facts { display: flex; flex-wrap: wrap; gap: .4rem .6rem; align-items: center; margin: 0 0 1rem; }
.intro ul { margin: .25rem 0 .5rem; }
.review-note { border-left: 4px solid var(--warn); background: var(--warn-bg); padding: .5rem .75rem; margin: .5rem 0;
  border-radius: 0 6px 6px 0; }
.review-note.inline { margin: .35rem 0 0; padding: .25rem .5rem; font-size: .85rem; }
.dnt-group { border-left: 4px solid var(--border); padding: .25rem 0 .25rem .9rem; margin: .75rem 0 1rem; }
.dnt-exclude { border-left-color: var(--err); }
.dnt-unresolved { border-left-color: var(--warn); }
.dnt-cannibalization_hint { border-left-color: var(--info); }
.dnt-group h3 { margin-top: .25rem; }
.count { color: var(--muted); font-weight: 400; }
.review-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .6rem; }
.review-list > li { border: 1px solid var(--warn); background: var(--warn-bg); border-radius: 6px; padding: .55rem .8rem; }
.review-list p { margin: .2rem 0; }
.evidence-note { background: var(--neutral-bg); border: 1px solid var(--border); border-radius: 6px; padding: .5rem .75rem; }
.badge-evidence-available { background: var(--ok-bg); color: var(--ok); }
.badge-evidence-partially_available { background: var(--warn-bg); color: var(--warn); }
.badge-evidence-unavailable { background: var(--neutral-bg); color: var(--muted); }
.observed { margin: .25rem 0 .5rem; padding-left: 1.2rem; }
.observed > li { margin: .2rem 0; }
.url { overflow-wrap: anywhere; font-size: .85rem; }

/* --- P10.5: quality, relations summary, exports --------------------------------------------------------------- */
code { font-family: ui-monospace, Consolas, monospace; font-size: .82rem; background: var(--neutral-bg);
  border: 1px solid var(--border); border-radius: 4px; padding: 0 .3rem; overflow-wrap: anywhere; }
.quality-status { font-size: 1.05rem; }
.badge-quality-pass { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.badge-quality-warning { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.badge-quality-fail { background: var(--err-bg); color: var(--err); border-color: var(--err); }
.pass-note { background: var(--neutral-bg); border: 1px solid var(--border); border-radius: 6px; padding: .5rem .75rem; }
.check-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.check-list > li { border: 1px solid var(--border); border-radius: 6px; padding: .55rem .8rem; background: var(--surface); }
#failures .check-list > li { border-left: 4px solid var(--err); }
#warnings .check-list > li { border-left: 4px solid var(--warn); }
.check-list p { margin: .15rem 0; }
.details { font-size: .9rem; }
details > summary { cursor: pointer; font-weight: 600; padding: .35rem 0; }
.export-state { color: var(--muted); }
.export-available { color: var(--ok); }
.export-failed, .export-missing_after_completion { color: var(--err); }

/* --- P10.7: account and sign-in ------------------------------------------------------------------------------ */
.account { display: flex; align-items: center; gap: .6rem; margin: 0; }
.account-email { color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.worker-indicator + .account { margin-left: 0; }
.header-inner > .account:first-of-type { margin-left: auto; }
.login-card { max-width: 28rem; margin: 2rem auto; }

@media (max-width: 640px) {
  .table thead { display: none; }
  .table tr { display: block; border-bottom: 1px solid var(--border); padding: .4rem 0; }
  .table td { display: block; border: 0; padding: .2rem .7rem; }
  .worker-indicator { margin-left: 0; }
}
