/* =====================================================================
   COMPONENTS
   The shared primitives the Razor components in Components/Ui render.
   They are global, not scoped, because they compose: a ledger row holds
   statuses, a heading holds buttons. Shell layout (top bar, rail, dock)
   lives in the layout components' scoped .razor.css files.
   ===================================================================== */

/* ---- Status: always a mark and a word, never colour alone ---------- */

.status { display: inline-flex; align-items: center; gap: 6px; color: var(--text-body); font-size: var(--text-md); line-height: 1.35; }
.status--success { color: var(--success); }
.status--warning { color: var(--warning); }
.status--danger { color: var(--danger); }
.status--neutral { color: var(--text-body); }

.status-mark { display: inline-block; width: 8px; height: 8px; flex: 0 0 8px; border: 1px solid currentColor; border-radius: 50%; color: var(--neutral-status); background: var(--surface); }
.status-mark--success { color: var(--success); background: var(--success); }
.status-mark--warning { color: var(--warning); background: var(--warning); }
.status-mark--danger { color: var(--danger); background: var(--danger); }
.status-mark--neutral { color: var(--neutral-status); background: var(--surface); }
.status-mark--large { width: 10px; height: 10px; flex-basis: 10px; }
.status-mark--small { width: 7px; height: 7px; flex-basis: 7px; }
.status--compact { gap: 5px; font-size: var(--text-sm); }

/* ---- Buttons --------------------------------------------------------- */

.button {
  position: relative;
  display: inline-flex;
  min-height: var(--hit);
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-3);
  border: 1px solid var(--border-input);
  border-radius: var(--radius);
  color: var(--text-body);
  background: var(--surface);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color var(--time-hover) var(--ease-settle), border-color var(--time-hover) var(--ease-settle), color var(--time-hover) var(--ease-settle), transform var(--time-hover) var(--ease-settle);
}
.button:hover { color: var(--text-body); background: var(--surface-hover); border-color: var(--border-strong); }
.button:active { background: var(--surface-press); }
.button:disabled, .button[aria-disabled="true"] { color: var(--text-disabled); background: var(--surface); border-color: var(--border); cursor: not-allowed; transform: none; }

/* One primary action per view: the only filled use of the command accent. */
.button--primary { padding: 0 var(--space-4); border-color: var(--accent); color: var(--on-accent); background: var(--accent); font-weight: 600; }
.button--primary:hover { border-color: var(--accent-hover); color: var(--on-accent); background: var(--accent-hover); transform: translateY(-1px); }
.button--primary:active { border-color: var(--accent-press); color: var(--on-accent); background: var(--accent-press); transform: translateY(0); }

/* An irreversible action, confirmed in a dialog: danger ink, never the accent. */
.button--danger { border-color: var(--danger); color: var(--danger); font-weight: 600; }
.button--danger:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-fill); }

.button--text { padding: 0 var(--space-2); border-color: transparent; color: var(--accent); background: none; font-weight: 600; }
.button--text:hover { border-color: transparent; color: var(--accent-hover); background: none; text-decoration: underline; text-underline-offset: 3px; }
.button--text:active { color: var(--accent-press); background: none; }

.button[aria-busy="true"] .button__label { visibility: hidden; }
.button__spinner { position: absolute; width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: turn 750ms linear infinite; }
@keyframes turn { to { transform: rotate(360deg); } }

/* ---- Headings -------------------------------------------------------- */

.page-heading { display: flex; min-width: 0; align-items: flex-end; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-4); }
.page-heading__copy { min-width: 0; }
.page-heading__subtitle { margin: var(--space-2) 0 0; color: var(--text-muted); line-height: 1.5; }
.page-heading__actions { display: flex; flex-shrink: 0; align-items: center; gap: var(--space-3); }
.page-heading__external-group { white-space: nowrap; }
.page-heading__external { text-transform: none; letter-spacing: 0; white-space: nowrap; }
.page-heading__title { margin: 0; color: var(--text); font-size: var(--text-2xl); font-weight: 600; line-height: 1.15; }
.eyebrow { display: block; margin: 0 0 var(--space-2); }

.section { min-width: 0; padding-top: var(--space-3); border-top: 1px solid var(--border-strong); }
.section + .section { margin-top: var(--space-6); }
.section-heading { display: flex; min-width: 0; align-items: flex-end; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.section-heading .eyebrow { margin-bottom: var(--space-1); }
.section-heading__tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }

/* ---- Summary line ---------------------------------------------------- */

.summary-line { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-6); margin: 0 0 var(--space-4); padding: var(--space-2) 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); font-size: var(--text-md); }
.summary-line > * { white-space: nowrap; }
.summary-line a { text-underline-offset: 3px; }
.summary-line__zero { color: var(--text-muted); }

/* ---- Alert banner: the one lit lamp ---------------------------------- */

.alert { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--space-4); margin-bottom: var(--space-6); padding: var(--space-3) var(--space-4); }
.alert--danger { background: var(--danger-fill); }
.alert--warning { background: var(--warning-fill); }
.alert--success { background: var(--success-fill); }
.alert--neutral { background: var(--neutral-fill); }
.alert__status { display: flex; min-height: var(--hit); align-items: center; }
.alert__copy { min-width: 0; }
.alert__title { font-size: var(--text-lg); line-height: 1.3; }
.alert__title .mono { font-size: var(--text-md); }
.alert__body { margin: var(--space-1) 0 0; color: var(--text-body); }

/* ---- Screen states: loading, error, empty ----------------------------- */

.screen-state { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--space-4); margin: 0 0 var(--space-3); padding: var(--space-3) 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.screen-state--loading { grid-template-columns: auto minmax(0, 1fr); }
.screen-state--empty { grid-template-columns: minmax(0, 1fr) auto; }
.screen-state__title { font-size: var(--text-lg); }
.screen-state__body { margin: var(--space-1) 0 0; color: var(--text-muted); }
.screen-state__spinner { width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: turn 750ms linear infinite; }
.is-stale { opacity: .55; transition: opacity var(--time-panel) var(--ease-settle); }

.empty-note { margin: var(--space-3) 0; color: var(--text-muted); font-size: var(--text-md); }

/* ---- Form controls ---------------------------------------------------- */

.field { display: grid; gap: var(--space-1); color: var(--text-body); font-size: var(--text-md); }
.field__label { color: var(--text-body); font-weight: 600; }
.field__hint { margin: 0; color: var(--text-muted); font-size: var(--text-md); }
.field__error { margin: 0; color: var(--danger); font-size: var(--text-md); }
.input {
  width: 100%;
  min-width: 0;
  min-height: var(--hit);
  padding: 0 var(--space-2);
  border: 1px solid var(--border-input);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface-sunken);
}
textarea.input { min-height: 96px; padding: var(--space-2); resize: vertical; line-height: 1.45; }
.input:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input::placeholder { color: var(--text-muted); opacity: 1; }

.search { display: flex; flex: 1 1 18rem; min-width: 0; max-width: 32rem; min-height: var(--hit); align-items: center; gap: var(--space-2); padding: 0 var(--space-2); border: 1px solid var(--border-input); border-radius: var(--radius); background: var(--surface-sunken); }
.repo-filter { display: block; flex: 0 1 15rem; min-width: 0; }
.search:focus-within { border-color: var(--focus); }
.search input { width: 100%; min-width: 0; min-height: calc(var(--hit) - 2px); padding: 0; border: 0; outline: 0; color: var(--text); background: none; }
.search input::placeholder { color: var(--text-muted); opacity: 1; }
.search input::-webkit-search-cancel-button { display: none; }
.search__glyph { position: relative; width: 14px; height: 14px; flex: 0 0 14px; border: 1px solid var(--text-muted); border-radius: 50%; }
.search__glyph::after { position: absolute; right: -4px; bottom: -2px; width: 5px; border-top: 1px solid var(--text-muted); transform: rotate(45deg); content: ""; }
.search__clear { min-height: calc(var(--hit) - 2px); padding: 0 var(--space-1); border: 0; color: var(--accent); background: none; cursor: pointer; }

.segmented { display: flex; min-width: 0; }
.segmented__option { min-height: var(--hit); padding: 0 var(--space-2); border: 1px solid var(--border-input); color: var(--text-body); background: var(--surface); cursor: pointer; white-space: nowrap; transition: background-color var(--time-hover) var(--ease-settle); }
.segmented__option + .segmented__option { border-left: 0; }
.segmented__option:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.segmented__option:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.segmented__option:hover { background: var(--surface-hover); }
.segmented__option:active { background: var(--surface-press); }
.segmented__option[aria-pressed="true"] { border-color: var(--border-strong); background: var(--surface-press); font-weight: 600; }

/* ---- Ledger: the dense, rule-divided table ---------------------------- */

.ledger-scroll { width: 100%; min-width: 0; }
.ledger { width: 100%; min-width: 0; border-collapse: collapse; table-layout: fixed; }
.ledger th { padding: 0 var(--space-2) var(--space-2); border-bottom: 1px solid var(--border-strong); color: var(--text-faint); font-family: var(--font-data); font-size: var(--text-sm); font-weight: 400; letter-spacing: .08em; line-height: 1.35; text-align: left; text-transform: uppercase; }
.ledger td { min-width: 0; padding: var(--space-2); vertical-align: middle; }
.ledger__row { border-bottom: 1px solid var(--border); transition: background-color var(--time-hover) var(--ease-settle); }
.ledger__row:hover { background: var(--surface-hover); }
.ledger__row.is-selected { background: var(--surface-select); }
.ledger__row.is-selected td:first-child { box-shadow: inset 2px 0 0 var(--accent); }

/* The repository evidence row's cells. */
.repo-identity, .evidence { display: grid; min-width: 0; gap: 3px; }
.repo-identity__name { color: var(--text); font-size: var(--text-lg); font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; }
a.repo-identity__name { text-decoration: none; }
a.repo-identity__name:hover { color: var(--accent-hover); text-decoration: underline; }
.repo-identity__branch { color: var(--text-muted); font-size: var(--text-xs); line-height: 1.3; }
a.evidence { min-height: var(--hit); align-content: center; color: var(--text-body); text-decoration: none; }
a.evidence:hover { color: var(--accent-hover); text-decoration: underline; }
.evidence__line { display: flex; min-width: 0; flex-wrap: wrap; align-items: center; gap: 5px; }
.evidence .mono { font-size: var(--text-sm); color: var(--text); }
.evidence__detail { color: var(--text-muted); font-size: var(--text-sm); line-height: 1.3; overflow-wrap: anywhere; }
.evidence__empty { color: var(--text-muted); font-size: var(--text-sm); }

/* On a phone the ledger becomes stacked records, labelled from data-label. */
@media (max-width: 640px) {
  .ledger, .ledger tbody { display: block; width: 100%; }
  .ledger thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
  .ledger__row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 var(--space-3); padding: var(--space-2) var(--space-2) var(--space-1); }
  .ledger__row.is-selected { box-shadow: inset 2px 0 0 var(--accent); }
  .ledger__row.is-selected td:first-child { box-shadow: none; }
  .ledger__row td { display: flex; min-width: 0; flex-direction: column; gap: 3px; padding: 6px 0; }
  .ledger__row td:first-child { grid-column: 1 / -1; padding-left: var(--space-1); }
  .ledger__row td[data-label]:not(:first-child)::before { content: attr(data-label); color: var(--text-faint); font-family: var(--font-data); font-size: var(--text-xs); letter-spacing: .08em; text-transform: uppercase; }
}

/* ---- Record lists: compact rule-divided records ---------------------- */

.record-list { margin: 0; padding: 0; list-style: none; }
.record { display: grid; min-width: 0; gap: var(--space-1); padding: var(--space-3) 0; border-bottom: 1px solid var(--border); }
.record--danger { background: var(--danger-fill); }
.record__heading { display: flex; min-width: 0; align-items: flex-start; justify-content: space-between; gap: var(--space-2); }
.record__title { display: flex; min-width: 0; align-items: baseline; gap: var(--space-2); color: var(--text); font-weight: 600; line-height: 1.35; text-decoration: none; }
a.record__title:hover { color: var(--accent-hover); text-decoration: underline; }
.record__title .mono { flex: 0 0 auto; font-size: var(--text-sm); }
.record__context { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-1) var(--space-2); margin: 0; color: var(--text-muted); font-size: var(--text-sm); }
.record__context .mono { font-size: var(--text-xs); }
.record__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }

/* ---- Confirm dialog --------------------------------------------------- */

.dialog-backdrop { position: fixed; z-index: 50; inset: 0; display: grid; place-items: center; padding: var(--space-4); background: color-mix(in srgb, var(--text) 40%, transparent); }
.dialog { display: grid; width: min(480px, 100%); max-height: calc(100dvh - 2 * var(--space-4)); gap: var(--space-4); overflow-y: auto; padding: var(--space-6); border-top: 2px solid var(--border-strong); color: var(--text-body); background: var(--surface); }
.dialog--danger { border-top-color: var(--danger); }
.dialog__title { font-size: var(--text-xl); }
.dialog__body { display: grid; gap: var(--space-3); }
.dialog__body p { margin: 0; }
.dialog__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); }

@media (max-width: 640px) {
  .page-heading { display: block; }
  .page-heading__actions { margin-top: var(--space-3); flex-wrap: wrap; }
  /* A page's actions sit in a bar above the dock instead of filling the first screen. */
  .page-heading:not(.page-heading--sample) .page-heading__actions:has(.button) {
    position: fixed; z-index: 4; right: 0; bottom: calc(60px + env(safe-area-inset-bottom, 0px)); left: 0;
    justify-content: flex-end; gap: var(--space-2); margin: 0; padding: var(--space-2) var(--space-3);
    border-top: 1px solid var(--border); background: var(--surface);
  }
  .page-heading:not(.page-heading--sample) .page-heading__actions:not(:has(.button)) { display: none; }
  #main-content:has(.page-heading:not(.page-heading--sample) .page-heading__actions .button) > * { padding-bottom: 168px; }
  .alert { grid-template-columns: auto minmax(0, 1fr); gap: var(--space-2) var(--space-3); padding: var(--space-3); }
  .alert__action { grid-column: 2; justify-self: start; }
  .screen-state, .screen-state--empty { grid-template-columns: minmax(0, 1fr); }
  .search { flex-basis: 100%; max-width: none; }
  .repo-filter { flex: 1 1 100%; }
  .repo-filter select { width: 100%; }
  .segmented { width: 100%; }
  .segmented__option { flex: 1; }
  .record__heading { flex-direction: column; gap: var(--space-1); }
  .dialog { padding: var(--space-4); }
}

/* ---- Diff ------------------------------------------------------------- */

.diff { max-height: 520px; overflow: auto; border: 1px solid var(--border); background: var(--surface-sunken); }
.diff:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; }
.diff__code { margin: 0; padding: var(--space-1) 0; font-family: var(--font-data); font-size: var(--text-md); line-height: 1.5; }
.diff__line { display: block; min-width: max-content; padding: 0 var(--space-3); white-space: pre; color: var(--text-body); }
.diff__line--added { background: var(--success-fill); }
.diff__line--removed { background: var(--danger-fill); }
.diff__line--hunk { color: var(--text-muted); background: var(--surface-press); }
.diff__line--note { color: var(--text-muted); font-style: italic; }

/* ---- Log ------------------------------------------------------------ */

.log { max-height: 480px; overflow: auto; border: 1px solid var(--border); background: var(--surface-sunken); }
.log:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; }
.log__note { margin: 0; padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); color: var(--text-muted); font-size: var(--text-sm); }
.log__code { margin: 0; padding: var(--space-1) 0; font-family: var(--font-data); font-size: var(--text-md); line-height: 1.5; }
.log__line { display: block; min-width: max-content; padding: 0 var(--space-3); white-space: pre; color: var(--text-body); }
.log__line--group { color: var(--text); font-weight: 600; }
.log__line--command { color: var(--text-muted); }
.log__line--warning { background: var(--warning-fill); }
.log__line--error { background: var(--danger-fill); color: var(--text); }
.log__mark { color: var(--text-muted); font-weight: 400; }
.log__line--error .log__mark { color: var(--danger); font-weight: 600; }
.log__line--warning .log__mark { color: var(--warning); font-weight: 600; }

/* ---- Labels --------------------------------------------------------- */

.label-list { display: flex; flex-wrap: wrap; gap: var(--space-1); margin: 0; padding: 0; list-style: none; }
.label-list__item { padding: 0 var(--space-2); border: 1px solid var(--border-strong); border-radius: var(--radius); color: var(--text-muted); font-family: var(--font-data); font-size: var(--text-xs); line-height: 20px; }

/* A quiet square icon control on the navy top band. The label is visually hidden, never absent. */
.header-button {
  position: relative;
  display: inline-flex;
  width: var(--hit);
  height: var(--hit);
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  color: var(--on-header);
  background: transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background-color var(--time-hover) var(--ease-settle);
}
.header-button:hover, .header-button:active, .header-button[aria-expanded="true"] { color: var(--on-header); background: var(--header-hover); }
.header-button:focus-visible { outline-color: var(--on-header); }
.header-button svg { width: 20px; height: 20px; }

/* Markdown written on GitHub (pull requests, issues, release notes), rendered through Markdown.ToHtml. */
.markdown { min-width: 0; color: var(--text-body); line-height: 1.6; overflow-wrap: anywhere; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p, .markdown ul, .markdown ol, .markdown pre, .markdown blockquote, .markdown table { margin: 0 0 var(--space-3); }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { margin: var(--space-4) 0 var(--space-2); color: var(--text); line-height: 1.3; }
.markdown h1 { font-size: var(--text-xl); }
.markdown h2 { font-size: var(--text-lg); }
.markdown h3, .markdown h4 { font-size: var(--text-base); }
.markdown ul, .markdown ol { padding-left: var(--space-6); }
.markdown li + li { margin-top: var(--space-1); }
.markdown code { padding: 1px 4px; border-radius: var(--radius); background: var(--surface-sunken); font-family: var(--font-data); font-size: .9em; }
.markdown pre { overflow-x: auto; padding: var(--space-3); border: 1px solid var(--border); background: var(--surface-sunken); }
.markdown pre code { padding: 0; background: none; }
.markdown blockquote { padding-left: var(--space-3); border-left: 3px solid var(--border-strong); color: var(--text-muted); }
.markdown table { display: block; overflow-x: auto; border-collapse: collapse; }
.markdown th, .markdown td { padding: var(--space-1) var(--space-2); border: 1px solid var(--border); text-align: left; }

/* A record's title is a full-size touch target where the pointer is a finger; with a mouse it hugs its text, so the context line stays with it. */
@media (pointer: coarse) {
  .record__title { min-height: var(--hit); }
}
