/* KinetiX: shared tokens and components for the chat, the consent page, and the admin page.
   Direction in DESIGN.md ("ledger"): warm paper, ink, one ledger-green accent. */

/* ---------- tokens ---------- */
:root {
  --paper: #f8fafc; --ink: #0f172a; --muted: #475569; --rule: #e2e8f0; --field: #fff;
  --accent: #0369a1; --accent-ink: #fff; --warn: #8a5a00; --warn-bg: #fbf1dc;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --radius: 6px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --paper: #0b1220; --ink: #e2e8f0; --muted: #94a3b8; --rule: #1e293b; --field: #111a2e;
    --accent: #38bdf8; --accent-ink: #082f49; --warn: #f0c36b; --warn-bg: #2e2615;
    color-scheme: dark;
  }
}
:root[data-theme=dark] {
  --paper: #0b1220; --ink: #e2e8f0; --muted: #94a3b8; --rule: #1e293b; --field: #111a2e;
  --accent: #38bdf8; --accent-ink: #082f49; --warn: #f0c36b; --warn-bg: #2e2615;
  color-scheme: dark;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); font: 15px/1.55 var(--sans); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code, .mono { font-family: var(--mono); font-size: .9em; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- icons ---------- */
.ic { width: 18px; height: 18px; flex: none; fill: currentColor; }
.mark { width: 22px; height: 20px; flex: none; fill: currentColor; color: var(--accent); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 16px; margin: 0; }

/* ---------- buttons ---------- */
button, .btn {
  text-decoration: none;
  font: inherit; cursor: pointer; border-radius: var(--radius); min-height: 44px; padding: 0 14px;
  border: 1px solid var(--rule); background: transparent; color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
button:hover, .btn:hover { border-color: var(--muted); }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { background: var(--warn); color: var(--paper); border-color: var(--warn); font-weight: 600; }
button:disabled { opacity: .55; cursor: not-allowed; }
button.quiet, .btn.quiet { border-color: transparent; }
button.quiet:hover, .btn.quiet:hover { border-color: var(--rule); }

/* ---------- fields ---------- */
.field { display: block; margin: 0 0 14px; font-size: 14px; }
.field > span:first-child { display: block; margin-bottom: 4px; }
input[type=text], input[type=email], input[type=url], input[type=password], input:not([type]), textarea, select {
  display: block; width: 100%; padding: 10px 12px; font: inherit; color: var(--ink);
  background: var(--field); border: 1px solid var(--rule); border-radius: var(--radius); min-height: 44px;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
.check { display: flex; gap: 10px; align-items: center; min-height: 44px; margin: 0; font-size: 14px; }
.check input { width: 18px; height: 18px; margin: 0; flex: none; accent-color: var(--accent); }
.hint { font-size: 13px; color: var(--muted); margin: 4px 0 0; }

/* ---------- messages ---------- */
.notice { color: var(--warn); background: var(--warn-bg); border: 1px solid var(--warn); border-radius: var(--radius); padding: 10px 12px; margin: 12px 0; }
.notice.ok { color: var(--ink); background: var(--field); border-color: var(--accent); }
.chip { font-size: 12px; border: 1px solid var(--rule); border-radius: 4px; padding: 1px 6px; color: var(--muted); }

/* ---------- tables ---------- */
.tablewrap { overflow-x: auto; margin: 0 0 10px; border: 1px solid var(--rule); }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 14px; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { font-weight: 600; background: var(--field); }
tr:last-child td { border-bottom: 0; }

/* ---------- app bar ----------
   Its contents line up with the page column: each page sets --col to its column's max width. */
.appbar { display: flex; align-items: center; gap: 8px; padding: 10px max(20px, calc((100% - var(--col, 100%)) / 2 + 20px)); border-bottom: 1px solid var(--rule); }
.appbar .brand { margin-right: 4px; }
.appbar .who { color: var(--muted); font-size: 13px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appbar .btn, .appbar button { font-size: 14px; padding: 0 12px; }
.appbar .menu-btn { gap: 6px; }
.appbar .menu-btn .ic:last-child { width: 14px; height: 14px; color: var(--muted); }
@media (max-width: 560px) {
  .appbar { padding: 8px 12px; }
  .appbar .who { visibility: hidden; } /* the account menu shows who and where */
}

/* ---------- popover (native Popover API) ---------- */
[popover].pop {
  position: fixed; inset: auto; margin: 0; padding: 6px; background: var(--field); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 8px; max-width: calc(100vw - 16px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .14); /* the one floating layer */
}
.pop .mi { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; padding: 0 10px; justify-content: flex-start; }
.pop .mi:hover, .pop .mi:focus-visible { background: var(--paper); }
.pop hr { border: 0; border-top: 1px solid var(--rule); margin: 6px 0; }
.pop .meta { padding: 8px 10px; font-size: 13px; color: var(--muted); line-height: 1.45; }
.pop .meta strong { display: block; color: var(--ink); font-size: 14px; }
.pop .group-label { padding: 6px 10px 4px; font-size: 12px; color: var(--muted); }
.account-menu { width: 280px; }

/* ---------- segmented radio (theme) ---------- */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 0 4px 4px; }
.seg button { padding: 0 6px; font-size: 13px; flex-direction: column; gap: 2px; }
.seg button[aria-checked=true] { border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* ---------- styled select (enhances <select data-styled>) ---------- */
.select-trigger { justify-content: space-between; width: 100%; padding: 0 12px; text-align: left; background: var(--field); }
.select-trigger .ic { color: var(--muted); }
[role=listbox].pop { padding: 4px; overflow-y: auto; max-height: min(320px, 60vh); }
[role=listbox]:focus-visible { outline: none; }
[role=option] { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 10px; border-radius: var(--radius); cursor: pointer; }
[role=option] .ic { visibility: hidden; color: var(--accent); }
[role=option][aria-selected=true] { font-weight: 600; }
[role=option][aria-selected=true] .ic { visibility: visible; }
[role=option].active { background: var(--paper); outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- card for a proposed change or build step ---------- */
.proposal { margin-top: 14px; border: 1px solid var(--warn); background: var(--warn-bg); border-radius: var(--radius); padding: 14px; }
.proposal h2 { font-size: 15px; margin: 0 0 4px; color: var(--warn); display: flex; align-items: center; gap: 8px; }
.proposal .what { font-family: var(--mono); font-size: .9em; overflow-wrap: anywhere; }
.proposal .tablewrap { margin-top: 10px; background: var(--field); }
.proposal th { background: transparent; color: var(--muted); font-weight: 500; white-space: nowrap; }
.proposal .check-result { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; margin-top: 10px; }
.proposal .check-result.ok { color: var(--accent); }
.proposal .actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.proposal .note { font-size: 13px; color: var(--muted); margin-top: 8px; }

/* ---------- inline links ---------- */
.lead a, .intro a:not(.btn) { color: var(--accent); text-underline-offset: 3px; }
.notice a { color: inherit; font-weight: 600; text-underline-offset: 3px; }
