/* billerey.re shared styles. Light tokens are the base; dark overrides them. */
:root {
  --bg: #eceff2;
  --surface: #f9fafb;
  --text: #18202b;
  --muted: #5a6573;
  --line: #cfd5dc;
  --accent: #2f4f9d;       /* tempered-steel blue */
  --accent-text: #ffffff;
  --straw: #b08a1e;        /* temper straw: major ticks of the scale */
  --danger: #a4262c;
  --radius: 10px;
  color-scheme: light;
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Dark tokens: keep both blocks in sync. */
:root[data-theme="dark"] {
  --bg: #171b21; --surface: #1f252d; --text: #e6e9ed; --muted: #9aa4b1; --line: #333c47;
  --accent: #7f9cf0; --accent-text: #10151c; --straw: #d9b44a; --danger: #f08a8f;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #171b21; --surface: #1f252d; --text: #e6e9ed; --muted: #9aa4b1; --line: #333c47;
    --accent: #7f9cf0; --accent-text: #10151c; --straw: #d9b44a; --danger: #f08a8f;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Top bar, with a graduated scale underneath: minor ticks every 8px, major every 80px. */
.topbar {
  position: relative; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .9rem clamp(1rem, 4vw, 2.5rem) 1.3rem;
}
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 9px;
  background:
    repeating-linear-gradient(90deg, var(--straw) 0 1px, transparent 1px 80px) bottom / 100% 9px no-repeat,
    repeating-linear-gradient(90deg, var(--line) 0 1px, transparent 1px 8px) bottom / 100% 5px no-repeat,
    linear-gradient(var(--line), var(--line)) bottom / 100% 1px no-repeat;
}
.brand { font-size: 1.15rem; font-weight: 800; letter-spacing: -.01em; color: var(--text); text-decoration: none; }
.controls { display: flex; align-items: center; gap: .5rem; }
.controls form { margin: 0; }

.seg button, .icon-btn, .link-btn { font: inherit; color: var(--muted); background: none; border: 0; cursor: pointer; }
.seg button:hover, .icon-btn:hover, .link-btn:hover { color: var(--text); }
.seg { display: inline-flex; padding: 2px; border: 1px solid var(--line); border-radius: 999px; }
.seg button { padding: .2rem .6rem; font-size: .8rem; font-weight: 600; border-radius: 999px; }
.seg button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.icon-btn { display: grid; place-items: center; width: 2.1rem; height: 2.1rem; border: 1px solid var(--line); border-radius: 50%; }
.icon-btn svg { display: none; width: 1.1rem; height: 1.1rem; }
:root[data-theme="auto"] .i-auto,
:root[data-theme="light"] .i-light,
:root[data-theme="dark"] .i-dark { display: block; }
.link-btn { padding: .3rem .5rem; font-size: .9rem; }

main { flex: 1; width: 100%; max-width: 60rem; margin: 0 auto; padding: clamp(1.5rem, 5vw, 3.5rem) clamp(1rem, 4vw, 2.5rem); }
h1 { margin: 0 0 .4rem; font-size: clamp(1.6rem, 3vw + 1rem, 2.4rem); line-height: 1.15; letter-spacing: -.02em; }
.muted { margin: 0 0 2rem; color: var(--muted); }

/* Forms */
.narrow { max-width: 24rem; margin: 0 auto; }
.form { display: grid; gap: 1rem; margin-top: 1.5rem; }
.form label { display: grid; gap: .35rem; font-size: .9rem; font-weight: 600; }
.form input:not([type="checkbox"]) {
  font: inherit; padding: .65rem .8rem; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.form input:focus-visible { outline-offset: 0; border-color: var(--accent); }
.btn {
  font: inherit; font-weight: 600; padding: .7rem 1rem; color: var(--accent-text); background: var(--accent);
  border: 0; border-radius: var(--radius); cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.alert { margin: 1rem 0 0; padding: .4rem .8rem; color: var(--danger); border-left: 3px solid var(--danger); }

/* App lists */
.apps { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 1rem; margin: 0; padding: 0; list-style: none; }
.app {
  display: grid; gap: .25rem; height: 100%; padding: 1.1rem 1.2rem; color: var(--text); text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.app:hover { border-color: var(--accent); }
.app-name { font-size: 1.05rem; font-weight: 700; }
.app-desc { font-size: .92rem; color: var(--muted); }

.more { margin-top: 2rem; }

/* Errors */
.code { margin: 0 0 .5rem; font-size: clamp(3rem, 10vw, 5rem); font-weight: 800; line-height: 1; letter-spacing: -.04em; color: var(--muted); }

/* Flash messages */
.flash { margin: 0 0 1.5rem; padding: .5rem .9rem; border-left: 3px solid var(--accent); background: var(--surface); }
.flash-error { border-color: var(--danger); color: var(--danger); }

/* Sections, tables, small controls */
.section { margin-top: 3rem; }
h2 { margin: 0 0 1rem; font-size: 1.25rem; letter-spacing: -.01em; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: .6rem .8rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table th { font-weight: 600; color: var(--muted); }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: .4rem; justify-content: flex-end; flex-wrap: wrap; }
.actions form { margin: 0; }
.btn-sm { font: inherit; font-size: .85rem; padding: .3rem .7rem; color: var(--text); background: none; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; }
.btn-sm:hover { border-color: var(--accent); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin: 0; }
.inline-form input[type="text"], .inline-form input:not([type]) { font: inherit; padding: .35rem .6rem; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.checks { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; font-weight: 400; }
.checks label, .form .check { display: flex; flex-direction: row; gap: .5rem; align-items: center; font-weight: 400; }
input[type="checkbox"] { width: 1rem; height: 1rem; margin: 0; accent-color: var(--accent); }
.form select { font: inherit; padding: .6rem .8rem; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.form fieldset { margin: 0; padding: 0; border: 0; display: grid; gap: .5rem; }
.form legend { padding: 0; margin-bottom: .35rem; font-size: .9rem; font-weight: 600; }
.hint { font-size: .85rem; font-weight: 400; color: var(--muted); }
.wide { max-width: 34rem; }
.crumbs { display: flex; flex-wrap: wrap; gap: .3rem; margin: 0 0 1rem; color: var(--muted); }
details summary { cursor: pointer; }
.section-gap { margin-top: 1rem; }
.narrow-left { max-width: 24rem; }
.tabs { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 1rem; }
.tabs a { padding: .3rem .8rem; color: var(--muted); text-decoration: none; border: 1px solid var(--line); border-radius: 999px; }
.tabs a[aria-current="page"] { color: var(--bg); background: var(--text); border-color: var(--text); }
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: .8rem 1.5rem; margin: 0 0 .4rem; }
.alert:empty { display: none; }
[hidden] { display: none !important; }

/* Admin shortcuts (external pages, open in a new tab) */
.links { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: .75rem; margin: 1.5rem 0 3rem; }
.link-card {
  display: grid; gap: .2rem; padding: .8rem 1rem; color: var(--text); text-decoration: none;
  border: 1px dashed var(--line); border-radius: var(--radius);
}
.link-card:hover { border-style: solid; border-color: var(--accent); }
a.link-card .app-name::after { content: " ↗"; color: var(--muted); font-weight: 400; }
.link-card.static code { font-family: ui-monospace, "DejaVu Sans Mono", Menlo, Consolas, monospace; font-size: .85rem; user-select: all; overflow-wrap: anywhere; }

/* Full-width pages (terminal) */
main.full { max-width: none; padding: 1rem clamp(.5rem, 2vw, 1.25rem); display: flex; flex-direction: column; }
.term-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; }
.term-head h1 { margin: 0; font-size: 1.4rem; }
.term-tools { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }

/* Terminal panes: 1 full, 2 split (right or down), 3 tiled around the first, 4 in quarters.
   The grid has a fixed height and minmax(0, 1fr) tracks, so terminals fit their cell instead of growing it. */
.term-grid {
  --term-bg: #0e1116;
  flex: none; display: grid; gap: .5rem; margin-top: .75rem;
  grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr);
  height: calc(100dvh - 9.75rem); min-height: 18rem;
}
.term-grid[data-count="2"][data-dir="right"],
.term-grid[data-count="3"],
.term-grid[data-count="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.term-grid[data-count="2"][data-dir="down"],
.term-grid[data-count="3"],
.term-grid[data-count="4"] { grid-template-rows: repeat(2, minmax(0, 1fr)); }
.term-grid[data-count="3"][data-dir="right"] .pane:first-child { grid-row: span 2; }
.term-grid[data-count="3"][data-dir="down"] .pane:first-child { grid-column: span 2; }
.pane {
  display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
  background: var(--term-bg); border: 1px solid var(--line); border-radius: var(--radius);
}
.pane.active { border-color: var(--accent); }
.pane-bar { display: flex; align-items: center; justify-content: space-between; padding: .15rem .3rem .15rem .7rem; font-size: .8rem; color: #9aa4b1; background: #161b22; }
.pane-close { font: inherit; font-size: 1.1rem; line-height: 1; width: 1.8rem; height: 1.8rem; color: #9aa4b1; background: none; border: 0; border-radius: 6px; cursor: pointer; }
.pane-close:hover { color: #e6e9ed; background: #242b35; }
.pane-term { flex: 1; min-height: 0; padding: .35rem; }

/* Small screens */
@media (max-width: 40rem) {
  .topbar { flex-wrap: wrap; gap: .6rem; }
  .controls { flex: 1 0 100%; flex-wrap: wrap; justify-content: flex-end; gap: .35rem; }
  .hide-sm { display: none; }
  .table th, .table td { padding: .55rem .6rem; }
  .actions { justify-content: flex-start; }
}
@media (max-width: 48rem) {
  /* Terminals stack; each gets most of the screen, the page scrolls between them. */
  .term-grid { display: flex; flex-direction: column; height: auto; }
  .term-grid .pane { flex: 0 0 auto; height: 75dvh; }
}
/* Touch screens: larger targets */
@media (pointer: coarse) {
  .btn-sm { padding: .5rem .9rem; }
  .seg button { padding: .4rem .75rem; }
  .link-btn { padding: .5rem .6rem; }
  .icon-btn { width: 2.5rem; height: 2.5rem; }
  input[type="checkbox"] { width: 1.25rem; height: 1.25rem; }
}
