/* Copyright 2026, Niklas Hauser
 * SPDX-License-Identifier: MPL-2.0
 *
 * The look of all modm-data pages: colours in light and dark, fonts, the site bar and the
 * building blocks the pages share. Page styles load after this file and only add to it.
 * Views (render functions that the MCP server may also show) use only these variables, so they
 * follow the light or dark theme of whatever shows them.
 */
@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600&display=swap");

:root {
  --ground: #F3F5F4;
  --surface: #FFFFFF;
  --band: #F8FAF9;
  --ink: #16201C;
  --muted: #5B6863;
  --faint: #85918C;
  --rule: #DDE3E0;
  --rule-strong: #C3CCC8;
  --accent: #1C6B56;
  --accent-ink: #FFFFFF;
  --accent-soft: #E2EFEA;
  --hover: #EEF4F1;
  --mark: #FBE3A0;
  --mark-ink: #16201C;
  --mark-line: #C99A1B;
  --error: #B42318;
  --warn: #B8741A;
  --ok: #1E8A4C;
  --hatch: #CDD6D2;
  --used: #C2570C;
  --nc-ink: #A9B3AF;
  /* hue based categories: hsl(var(--h) var(--cat-s) var(--cat-bg-l)) and so on */
  --cat-s: 55%;
  --cat-bg-l: 89%;
  --cat-line-l: 38%;
  --cat-ink-l: 25%;
  --font-sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 10px;
  --radius-s: 7px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #0E1311;
    --surface: #141A18;
    --band: #111715;
    --ink: #E2E8E5;
    --muted: #9AA8A2;
    --faint: #6E7B76;
    --rule: #232D29;
    --rule-strong: #34403B;
    --accent: #5FC0A0;
    --accent-ink: #0B1512;
    --accent-soft: #16302A;
    --hover: #19231F;
    --mark: #6A5616;
    --mark-ink: #FFF4D1;
    --mark-line: #D9B13F;
    --error: #F4A39B;
    --warn: #E8B060;
    --ok: #5FD18E;
    --hatch: #2A3531;
    --used: #F08A45;
    --nc-ink: #4A5853;
    --cat-s: 45%;
    --cat-bg-l: 20%;
    --cat-line-l: 62%;
    --cat-ink-l: 78%;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ground: #0E1311;
  --surface: #141A18;
  --band: #111715;
  --ink: #E2E8E5;
  --muted: #9AA8A2;
  --faint: #6E7B76;
  --rule: #232D29;
  --rule-strong: #34403B;
  --accent: #5FC0A0;
  --accent-ink: #0B1512;
  --accent-soft: #16302A;
  --hover: #19231F;
  --mark: #6A5616;
  --mark-ink: #FFF4D1;
  --mark-line: #D9B13F;
  --error: #F4A39B;
  --warn: #E8B060;
  --ok: #5FD18E;
  --hatch: #2A3531;
  --used: #F08A45;
  --nc-ink: #4A5853;
  --cat-s: 45%;
  --cat-bg-l: 20%;
  --cat-line-l: 62%;
  --cat-ink-l: 78%;
  color-scheme: dark;
}

/* ------------------------------------------------------------------ base */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font: 14px/1.45 var(--font-sans);
}
a { color: inherit; }
input, select, button, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
code, kbd, samp, pre { font-family: var(--font-mono); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Full window pages: site bar, page bar, then the panels fill the rest */
body.app {
  display: flex; flex-direction: column; gap: 10px;
  padding-inline: clamp(16px, 3vw, 32px); padding-block: 0 14px;
  height: 100dvh;
}

/* ------------------------------------------------------------- site bar */
.site {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px;
  padding-block: 9px; border-bottom: 1px solid var(--rule);
  font-size: 13px;
}
body.app > .site { margin-inline: calc(-1 * clamp(16px, 3vw, 32px)); padding-inline: clamp(16px, 3vw, 32px); }
.site .brand { font: 600 14px var(--font-mono); text-decoration: none; color: var(--ink); }
.site .brand span { color: var(--accent); }
.site .pages { display: flex; flex-wrap: wrap; gap: 2px 4px; }
.site .pages a {
  text-decoration: none; color: var(--muted); padding: 3px 8px; border-radius: 6px;
}
.site .pages a:hover { background: var(--hover); color: var(--ink); }
.site .pages a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.site .end { margin-left: auto; color: var(--faint); font-size: 12px; text-decoration: none; }
.site .end:hover { color: var(--ink); }

/* -------------------------------------------------------------- page bar */
.top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 24px; }
.top h1 { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: -0.01em; }
.top .sub { margin: 0; color: var(--muted); font-size: 13px; }
.totals { display: flex; gap: 18px; font-variant-numeric: tabular-nums; }
.total { display: grid; gap: 1px; text-align: right; }
.total b { font: 600 17px/1.1 var(--font-mono); }
.total span { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }

/* ---------------------------------------------------------------- panels */
.shell { flex: 1; min-height: 0; display: grid; gap: 12px; grid-template-columns: minmax(200px, 260px) minmax(0, 1fr); }
.panel {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  min-height: 0; min-width: 0; display: flex; flex-direction: column; overflow: hidden;
}
.side-head { padding: 10px; border-bottom: 1px solid var(--rule); display: grid; gap: 8px; }
.side-head label, .label {
  color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
}
.side-list { overflow: auto; padding: 6px; flex: 1; min-height: 0; }
.main-head { padding: 12px 16px; border-bottom: 1px solid var(--rule); background: var(--band); }
.main-head h2 { margin: 0; font: 600 17px var(--font-mono); }
.main-head p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.empty { padding: 14px; color: var(--faint); font-size: 13px; }

/* A row in a side list: count, name, extra */
.row-button {
  display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: baseline;
  width: 100%; text-align: left; padding: 5px 8px; border: 0; border-radius: 6px;
  background: none; color: inherit; font: 13px var(--font-sans); cursor: pointer;
}
.row-button:hover { background: var(--hover); }
.row-button[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.row-button .count { font: 600 12px var(--font-mono); font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }
.row-button .name { font: 12px var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-button .extra { color: var(--faint); font: 11px var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- inputs */
input[type="search"], input[type="text"], input[type="number"], select {
  width: 100%; padding: 7px 9px; border: 1px solid var(--rule-strong); border-radius: var(--radius-s);
  background: var(--band); color: var(--ink); font: 13px var(--font-mono);
}
input.bad { border-color: var(--error); }

/* A regular expression field: <div class="search"><span class="delim">/</span><input type="search">
 * <span class="delim">/i</span></div>, invalid with the class "invalid" or an input.bad */
.search {
  min-width: 0; display: flex; align-items: center;
  background: var(--band); border: 1px solid var(--rule-strong); border-radius: var(--radius-s);
  font: 13px var(--font-mono); padding-inline: 8px;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.search.invalid, .search:has(input.bad) { border-color: var(--error); box-shadow: 0 0 0 1px var(--error); }
.search .delim { color: var(--faint); user-select: none; }
.search input {
  flex: 1; width: auto; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink);
  font: inherit; padding: 6px 4px;
}
.search input::placeholder { color: var(--faint); }

.btn {
  font: 500 13px/1 var(--font-sans); color: var(--ink);
  background: var(--surface); border: 1px solid var(--rule-strong); border-radius: 6px;
  padding: 7px 12px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 4px 8px; font-size: 12px; }

/* A group of exclusive options: <div class="modes"><button aria-pressed>name<span>hint</span></button> */
.modes { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; }
.modes button {
  padding: 5px 4px; border: 1px solid var(--rule-strong); border-radius: var(--radius-s); cursor: pointer;
  background: var(--band); color: var(--muted); font: 600 11px var(--font-sans); display: grid; gap: 1px;
}
.modes button span { font: 400 10px var(--font-mono); color: var(--faint); }
.modes button:hover { background: var(--hover); }
.modes button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.modes button[aria-pressed="true"] span { color: inherit; }

/* ------------------------------------------------------------ small parts */
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  font: 11px var(--font-mono); padding: 2px 6px; border-radius: 5px;
  background: var(--surface); border: 1px solid var(--rule); color: var(--muted);
}
button.chip, a.chip { cursor: pointer; text-decoration: none; }
button.chip:hover, a.chip:hover { background: var(--hover); }
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.chip.on { background: var(--mark); color: var(--mark-ink); border-color: transparent; }
/* A small upper case label, e.g. the vendor or the access of a register */
.tag {
  font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--accent); background: var(--accent-soft); border-radius: 4px; padding: 1px 6px;
}

.cards { display: flex; flex-wrap: wrap; gap: 10px; }
.card { border: 1px solid var(--rule); border-radius: 9px; padding: 9px 12px; min-width: 120px; }
.card b { display: block; font: 600 17px var(--font-mono); font-variant-numeric: tabular-nums; }
.card span { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }

details.box { border: 1px solid var(--rule); border-radius: 9px; background: var(--band); }
details.box > summary {
  cursor: pointer; padding: 8px 12px; font-weight: 600; font-size: 13px;
  display: flex; gap: 8px; align-items: baseline;
}
details.box > summary::marker { color: var(--faint); }
details.box > summary em { font-style: normal; color: var(--faint); font-weight: 400; font-size: 12px; }
details.box > div { padding: 0 12px 12px; max-height: 230px; overflow: auto; }

/* Facts as a two column list: <dl class="facts"><dt>kind</dt><dd>gpio</dd></dl> */
.facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 12px; }
.facts dt { color: var(--faint); }
.facts dd { margin: 0; font-family: var(--font-mono); overflow-wrap: anywhere; }

pre.code {
  background: var(--band); border: 1px solid var(--rule); border-radius: var(--radius-s); padding: 8px;
  overflow-x: auto; font: 11px/1.45 var(--font-mono); margin: 0; white-space: pre; tab-size: 4;
}

@media (max-width: 1100px) {
  body.app { height: auto; }
  .shell { grid-template-columns: 1fr; }
  .side-list { max-height: 30vh; }
}
