/*
  Base styles: brand tokens (Experiree "Patient Build"), type, buttons, forms, dialogs.
  Fonts are the brand pack files, loaded from assets/fonts (SIL Open Font Licence).
*/
@font-face { font-family: "Public Sans"; src: url("../assets/fonts/PublicSans-VF.ttf") format("truetype"); font-weight: 100 900; font-style: normal; font-display: swap; }
@font-face { font-family: "Source Serif 4"; src: url("../assets/fonts/SourceSerif4-Italic-VF.ttf") format("truetype"); font-weight: 200 900; font-style: italic; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url("../assets/fonts/IBMPlexMono-Regular.ttf") format("truetype"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url("../assets/fonts/IBMPlexMono-SemiBold.ttf") format("truetype"); font-weight: 600; font-style: normal; font-display: swap; }

:root {
  --paper: #FAF7F0;
  --paper-2: #F5F0E4;
  --linen: #E5D9BE;
  --linen-2: #EEE6D3;
  --slate: #4A5C7A;
  --slate-ink: #3A4A63;
  --slate-deep: #2C3747;
  --clay: #C28465;
  --clay-ink: #9C5D40;
  --clay-deep: #7F4930;
  --graphite: #2F2D29;
  --ink-2: #4E4A43;
  --stone: #877E72;
  --stone-ink: #6E665B;
  --rule: #E0D6C1;
  --rule-2: #CDBFA2;
  --ok: #3E7449;
  --ok-tint: #E3EDDC;
  --warn: #93600F;
  --warn-tint: #F4E7C9;
  --bad: #9E3B2B;
  --bad-tint: #F3DCD4;
  --f-sans: "Public Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --f-serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --f-mono: "IBM Plex Mono", Consolas, "Courier New", monospace;
  --r-card: 7px;
  --r-btn: 6px;
  --r-panel: 5px;
  --shadow-card: 0 1px 0 rgba(47, 45, 41, .07), 0 2px 5px rgba(47, 45, 41, .09);
  --shadow-lift: 0 2px 0 rgba(47, 45, 41, .06), 0 8px 18px rgba(47, 45, 41, .16);
  --bar-h: 58px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--f-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--graphite);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { font-weight: 750; line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.005em; }
h1 { font-size: 30px; letter-spacing: -.015em; }
h2 { font-size: 21px; }
h3 { font-size: 17px; }
h4 { font-size: 15px; }
p { margin: 0 0 .75em; }
a { color: var(--slate); text-underline-offset: 2px; }
a:hover { color: var(--slate-ink); }
small, .small { font-size: 13px; }
.muted { color: var(--stone-ink); }
.num { font-variant-numeric: tabular-nums lining-nums; }
.mono { font-family: var(--f-mono); }
.serif { font-family: var(--f-serif); font-style: italic; }
.nowrap { white-space: nowrap; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 16px 0; }
:focus-visible { outline: 2px solid var(--slate); outline-offset: 2px; }
.ico { flex: none; display: inline-block; vertical-align: -3px; }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px;
  font: 600 14px/1 var(--f-sans);
  color: var(--slate-ink); background: var(--paper);
  border: 1px solid var(--rule-2); border-radius: var(--r-btn);
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background-color .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--linen-2); border-color: var(--stone); color: var(--graphite); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--clay-ink); border-color: var(--clay-ink); color: var(--on-fill); }
.btn-primary:hover { background: var(--clay-deep); border-color: var(--clay-deep); color: var(--on-fill); }
.btn-slate { background: var(--slate); border-color: var(--slate); color: var(--on-fill); }
.btn-slate:hover { background: var(--slate-ink); border-color: var(--slate-ink); color: var(--on-fill); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--slate); }
.btn-quiet:hover { background: var(--linen-2); border-color: transparent; }
.btn-danger { color: var(--bad); }
.btn-danger:hover { background: var(--bad-tint); border-color: var(--bad); color: var(--bad); }
.btn-small { height: 30px; padding: 0 10px; font-size: 13px; gap: 5px; }
.btn-big { height: 46px; padding: 0 20px; font-size: 16px; }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0;
  background: transparent; border: 1px solid transparent; border-radius: var(--r-btn);
  color: inherit; cursor: pointer;
}
.btn-icon:hover { background: rgba(47, 45, 41, .07); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ------------------------------------------------------------------ forms */
label.field { display: block; margin: 0 0 12px; }
label.field > span { display: block; font-size: 13px; font-weight: 650; color: var(--ink-2); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  font: 15px/1.35 var(--f-sans); color: var(--graphite);
  background: var(--card); border: 1px solid var(--rule-2); border-radius: var(--r-btn);
  padding: 8px 10px; width: 100%;
}
input[type=number] { font-variant-numeric: tabular-nums; }
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--slate); outline-offset: 0; border-color: var(--slate); }
input.code-input {
  font: 600 22px/1.2 var(--f-mono); letter-spacing: .06em; text-transform: uppercase;
  padding: 10px 12px;
}
.check { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.check input { margin-top: 4px; accent-color: var(--slate); width: 16px; height: 16px; }

/* ------------------------------------------------------------------ app bar */
.bar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px;
  height: var(--bar-h); padding: 0 16px;
  background: var(--slate-deep); color: var(--on-fill);
}
.bar .btn { background: transparent; color: var(--on-fill); border-color: color-mix(in srgb, var(--on-bar) 28%, transparent); }
.bar .btn:hover { background: color-mix(in srgb, var(--on-bar) 10%, transparent); border-color: color-mix(in srgb, var(--on-bar) 50%, transparent); color: var(--on-fill); }
.bar .btn-primary { background: var(--clay-ink); border-color: var(--clay-ink); }
.bar .btn-primary:hover { background: var(--clay-deep); border-color: var(--clay-deep); }
.bar .btn-icon:hover { background: color-mix(in srgb, var(--on-bar) 12%, transparent); }
.bar-title { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.bar-title b { font-size: 16px; font-weight: 750; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-title span { font-size: 12.5px; color: color-mix(in srgb, var(--on-bar) 72%, transparent); white-space: nowrap; }
.bar-sp { flex: 1; }
.bar-home { color: var(--on-fill); display: inline-flex; }
.bar-stat { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.bar-stat .k { font-size: 11.5px; color: color-mix(in srgb, var(--on-bar) 70%, transparent); }
.bar-stat .v { font-size: 19px; font-weight: 750; font-variant-numeric: tabular-nums; }
.bar-stat.neg .v { color: var(--danger); }
.bar-div { width: 1px; align-self: stretch; margin: 12px 0; background: color-mix(in srgb, var(--on-bar) 20%, transparent); }

/* ------------------------------------------------------------------ panels, tags */
.panel { background: var(--card); border: 1px solid var(--rule); border-radius: var(--r-panel); }
.panel-pad { padding: 16px 18px; }
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: 11px;
  font-size: 12px; font-weight: 650; line-height: 1;
  background: var(--linen-2); color: var(--ink-2); white-space: nowrap;
}
.tag-ok { background: var(--ok-tint); color: var(--ok); }
.tag-warn { background: var(--warn-tint); color: var(--warn); }
.tag-bad { background: var(--bad-tint); color: var(--bad); }
.tag-slate { background: var(--accent-soft); color: var(--slate-ink); }
.code-chip { font: 600 12px/1 var(--f-mono); letter-spacing: .02em; color: var(--ink-2); }
.callout { border-left: 3px solid var(--clay); background: var(--paper-2); padding: 10px 14px; border-radius: 0 var(--r-panel) var(--r-panel) 0; }
.callout-slate { border-left-color: var(--slate); }
.callout-bad { border-left-color: var(--bad); background: var(--bad-tint); }
.note { font-size: 13px; color: var(--stone-ink); }

table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th { text-align: left; font-size: 12.5px; font-weight: 650; color: var(--stone-ink); padding: 6px 8px; border-bottom: 1px solid var(--rule-2); white-space: nowrap; }
table.tbl td { padding: 7px 8px; border-bottom: 1px solid var(--rule); vertical-align: top; }
table.tbl td.r, table.tbl th.r { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl tr.hi td { background: var(--bg-hover); }

/* ------------------------------------------------------------------ dialogs */
.dlg-back {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(44, 55, 71, .42);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  animation: fadein .14s ease-out;
}
.dlg-back.out { opacity: 0; transition: opacity .15s; }
.dlg {
  background: var(--paper); border-radius: 8px; box-shadow: 0 20px 60px rgba(30, 34, 44, .35);
  width: min(560px, 100%); max-height: calc(100vh - 48px);
  display: flex; flex-direction: column; overflow: hidden;
}
.dlg-wide { width: min(980px, 100%); }
.dlg-full { width: min(1400px, 100%); height: calc(100vh - 48px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 10px 20px; border-bottom: 1px solid var(--rule); }
.dlg-head h2 { margin: 0; font-size: 18px; }
.dlg-body { padding: 16px 20px; overflow: auto; flex: 1; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--rule); background: var(--paper-2); }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

#toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--slate-deep); color: var(--on-fill); padding: 9px 16px; border-radius: 6px; font-size: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); animation: fadein .15s; }
.toast-bad { background: var(--bad); }
.toast.out { opacity: 0; transition: opacity .4s; }

/* missing files notice (shown when the scripts cannot load) */
#boot-note { max-width: 640px; margin: 12vh auto; padding: 24px; font-family: Georgia, serif; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
