/*
OpenFief's built-in UI, built on the design system (docs/dev/design-system.md). The page loads design/fonts/fonts.css
and design/tokens.css first, both served by the UI under /static/design/, so this file uses only their variables and
writes no color of its own. Served from the UI itself: the CSP allows no inline styles.
*/

/* The charts' series, in the order the design system draws them (D-30): vert, or, kasztan, a grey, the vert tint.
   app.js reads these at runtime, so the charts follow light and dark like the rest of the page. */
:root {
  --series-1: var(--accent);
  --series-2: var(--highlight);
  --series-3: var(--label);
  --series-4: var(--border-strong);
  --series-5: var(--accent-soft);
  --chart-ink: var(--muted);
  --chart-grid: var(--border);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--font-sans);
}
a { color: var(--link); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
code { font-family: var(--font-mono); font-size: 0.88em; background: var(--sunken); padding: 0.1em 0.35em; border-radius: var(--radius-input); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); font-size: 0.92rem; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Top bar: the Gate and the wordmark, the navigation, the session's scope and sign-out */
.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-5);
  padding: var(--space-2) var(--space-4);
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand {
  display: inline-flex; align-items: center; gap: var(--space-2); min-height: 44px;
  font-family: var(--font-display); font-weight: 800; font-size: 1.3rem; letter-spacing: -0.02em;
  color: var(--text); text-decoration: none;
}
.mark { flex: none; color: currentColor; }
.mark-fief { fill: var(--highlight); }
.top nav { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.top nav a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--space-3);
  border-radius: var(--radius); color: var(--text); text-decoration: none; font-weight: 500;
}
.top nav a:hover { background: var(--sunken); }
.top nav a[aria-current="page"] { background: var(--accent-soft); color: var(--link); box-shadow: inset 0 -3px 0 var(--highlight); }
.session { margin-left: auto; display: flex; align-items: center; gap: var(--space-3); }

main { max-width: 72rem; margin: 0 auto; padding: var(--space-5) var(--space-4) var(--space-7); }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.2; letter-spacing: -0.02em; }
h1 { font-size: 2rem; font-weight: 800; margin: 0 0 var(--space-4); }
h2 { font-size: 1.3rem; font-weight: 700; margin: 0 0 var(--space-3); }
h3 { font-size: 1.05rem; font-weight: 700; margin: var(--space-5) 0 var(--space-2); }
p { margin: 0 0 var(--space-3); max-width: 75ch; }
.lede { color: var(--muted); }
.eyebrow {
  margin: 0 0 var(--space-1); color: var(--label);
  font-family: var(--font-mono); font-size: 0.75rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.1em;
}

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--space-5); margin-bottom: var(--space-4); min-width: 0;
}
.card > :last-child { margin-bottom: 0; }
.narrow { max-width: 30rem; }
.total .figure {
  margin: 0 0 var(--space-2); font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: clamp(1.8rem, 5vw, 2.6rem); font-weight: 500; letter-spacing: -0.01em; white-space: nowrap;
}
.secret { display: inline-block; padding: var(--space-2) var(--space-3); word-break: break-all; user-select: all; }

/* Messages above a page or a form */
.alert { padding: var(--space-3) var(--space-4); border-radius: var(--radius-input); margin: 0 0 var(--space-4); max-width: none; }
.alert-error { background: var(--danger-soft); color: var(--danger-text); border-left: 3px solid var(--danger); }
.alert-warn { background: var(--warn-soft); color: var(--warn-text); border-left: 3px solid var(--highlight); }
.alert a { color: inherit; }
.notice { border-left: 3px solid var(--highlight); }
.warn-text { color: var(--warn-text); }

/* Status pills: always a word, and an icon or a dot when it matters */
.pills { display: inline-flex; flex-wrap: wrap; gap: var(--space-1); }
.pill {
  display: inline-flex; align-items: center; gap: 0.35em; padding: 0.1em 0.65em;
  border-radius: var(--radius-pill); font-size: 0.8rem; font-weight: 600; line-height: 1.6; white-space: nowrap;
}
.pill svg { width: 0.9em; height: 0.9em; flex: none; }
.pill-ok { background: var(--ok-soft); color: var(--ok-text); }
.pill-warn { background: var(--warn-soft); color: var(--warn-text); }
.pill-danger { background: var(--danger-soft); color: var(--danger-text); }
.pill-neutral { background: var(--neutral-soft); color: var(--neutral-text); }
.pill .mono { font-weight: 500; }
.dot { width: 0.5em; height: 0.5em; border-radius: var(--radius-pill); background: var(--highlight); flex: none; }

/* Tables: a sunken header row, no zebra stripes, figures in monospace on the right; wide ones scroll in their box */
.table { position: relative; overflow-x: auto; margin: 0 0 var(--space-3); }
table { width: 100%; border-collapse: collapse; font-size: 0.94rem; }
th, td { text-align: left; vertical-align: top; padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); }
thead th { background: var(--sunken); color: var(--muted); font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
tfoot th, tfoot td { border-bottom: 0; font-weight: 600; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
td.empty { color: var(--muted); }
.postings { margin: 0; padding-left: var(--space-4); }
.postings .mono { white-space: nowrap; }
.removed { margin-left: var(--space-1); }

/* Buttons: primary (one per view), secondary, quiet, destructive. Touch targets are 44 px. */
button, .button {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 var(--space-4);
  font: 600 0.95rem/1 var(--font-sans); border-radius: var(--radius); cursor: pointer; text-decoration: none;
  border: 1.5px solid var(--accent); background: transparent; color: var(--link);
}
button:hover, .button:hover { background: var(--accent-soft); }
button.primary { background: var(--accent); color: var(--on-accent); }
button.primary:hover { background: var(--accent); filter: brightness(1.12); }
button.danger { background: var(--danger); border-color: var(--danger); color: var(--on-danger); }
button.danger:hover { background: var(--danger); filter: brightness(1.08); }
button.quiet {
  min-height: 44px; padding: 0; border: 0; background: none; color: var(--link);
  font-weight: 500; text-decoration: underline; text-underline-offset: 3px;
}
button.quiet:hover { background: none; text-decoration-thickness: 2px; }
button[disabled] { opacity: 0.6; cursor: progress; }
form.inline { display: inline; margin: 0; }

/* Inputs: a label above every field, help text under it, a unit inside amount fields */
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: var(--space-4); align-items: start; margin: var(--space-4) 0; }
.field { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.field label, .label { font-weight: 600; font-size: 0.9rem; color: var(--text); }
.help { color: var(--muted); font-size: 0.85rem; margin: 0; }
input, select {
  font: inherit; min-height: 44px; width: 100%; padding: var(--space-2) var(--space-3);
  border: 1.5px solid var(--border-strong); border-radius: var(--radius-input);
  background: var(--surface); color: var(--text);
}
input[type="file"] { padding: var(--space-2); }
input[type="checkbox"] { width: 1.25rem; min-height: 1.25rem; accent-color: var(--accent); }
.unit { display: flex; align-items: stretch; }
.unit input { border-right: 0; border-radius: var(--radius-input) 0 0 var(--radius-input); min-width: 0; font-family: var(--font-mono); }
.unit span {
  display: inline-flex; align-items: center; padding: 0 var(--space-3);
  border: 1.5px solid var(--border-strong); border-left: 0; border-radius: 0 var(--radius-input) var(--radius-input) 0;
  background: var(--sunken); color: var(--muted); font-family: var(--font-mono); font-size: 0.9rem;
}
.unit:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-input); }
.unit input:focus-visible { outline: 0; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin-top: var(--space-4); }
label.check { display: flex; align-items: center; gap: var(--space-2); min-height: 44px; font-weight: 600; }
.targets td { vertical-align: middle; }
.targets input, .targets select { min-width: 6rem; }

/* The first-run wizard's steps (D-73) and the change forms folded into tables */
.steps { display: flex; flex-wrap: wrap; gap: var(--space-2); list-style: none; padding: 0; margin: 0 0 var(--space-5); counter-reset: step; }
.steps li { counter-increment: step; }
.steps a {
  display: inline-flex; align-items: center; gap: var(--space-2); min-height: 44px; padding: 0 var(--space-4);
  border: 1.5px solid var(--border-strong); border-radius: var(--radius-pill);
  color: var(--text); text-decoration: none; font-weight: 500; font-size: 0.92rem;
}
.steps a::before { content: counter(step); font-family: var(--font-mono); color: var(--muted); }
.steps a:hover { background: var(--sunken); }
.steps a[aria-current="step"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.steps a[aria-current="step"]::before { color: var(--on-accent); }
details.change > summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--link); font-weight: 500; }
details.change[open] { padding: var(--space-3); background: var(--sunken); border-radius: var(--radius); margin-bottom: var(--space-2); }

/* Charts (D-30) */
.chart { position: relative; height: 18rem; margin-bottom: var(--space-4); }
.switch { display: flex; flex-wrap: wrap; gap: var(--space-1); margin-bottom: var(--space-4); }
.switch a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--space-4);
  border: 1.5px solid var(--border-strong); border-radius: var(--radius-pill);
  color: var(--text); text-decoration: none; font-weight: 500; font-size: 0.92rem;
}
.switch a:hover { background: var(--sunken); }
.switch a[aria-current="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* Kasztan: at most once per screen, on a light ground the poses are drawn for */
.state { display: flex; align-items: center; gap: var(--space-5); flex-wrap: wrap; }
.state > div { flex: 1 1 16rem; min-width: 0; }
.kasztan { flex: none; width: 8rem; margin: 0; padding: var(--space-3); background: var(--argent); border-radius: var(--radius); }
.kasztan img { display: block; width: 100%; height: auto; }
.state-title { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; margin: 0 0 var(--space-1); }
.signin { display: grid; grid-template-columns: minmax(0, 1fr) 11rem; gap: var(--space-5); align-items: center; }
.signin .kasztan { width: 100%; }

@media (max-width: 640px) {
  h1 { font-size: 1.6rem; }
  .card { padding: var(--space-4); }
  .session { margin-left: 0; }
  .signin { grid-template-columns: minmax(0, 1fr); }
  .signin .kasztan { width: 8rem; grid-row: 1; }
  .kasztan { width: 6rem; }
}

@media (prefers-reduced-motion: no-preference) {
  a, button, .button, .switch a, .top nav a { transition: background-color 150ms ease, filter 150ms ease; }
}
