/* ==========================================================================
   Components. Requires tokens.css and base.css.
   Tinted components read an accent from --c (set it inline, e.g.
   style="--c: var(--green)", or with a helper class such as .c-green).
   ========================================================================== */


/* Accent defaults. :where() keeps them at zero specificity, so a .c-* helper
   class or an inline style="--c: …" always wins. */
:where(.btn.tint) { --c: var(--violet); }
:where(.pill) { --c: var(--grey); }
:where(.chip) { --c: var(--blue); }
:where(.card.tinted) { --c: var(--violet); }
:where(.notice) { --c: var(--blue); }
:where(.avatar) { --c: var(--blue); }
:where(.icon-badge) { --c: var(--blue); }
:where(.timeline .node) { --c: var(--blue); }
:where(.bubble.them) { --c: var(--violet); }
:where(.span-bar) { --c: var(--violet); }
:where(.event.placeholder) { --c: var(--grey); }
:where(.dot) { --c: var(--grey); }


/* --------------------------------------------------------------------------
   1. Buttons
   -------------------------------------------------------------------------- */
.btn {
  height: 28px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 0 10px; border-radius: var(--radius); border: 1px solid var(--line-2);
  background: var(--card); color: var(--ink); font-size: var(--fs-ui); font-weight: 500;
  cursor: pointer; box-shadow: 0 1px 1px rgba(0, 0, 0, .04); white-space: nowrap; text-decoration: none;
}
.btn:hover:not(:disabled) { background: var(--hover); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--solid); border-color: var(--solid); color: var(--onsolid); }
.btn.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--solid) 88%, #000); }
.btn.ghost { background: none; border-color: transparent; box-shadow: none; color: var(--ink-2); }
.btn.ghost:hover:not(:disabled) { background: var(--hover); color: var(--ink); }
.btn.danger { background: var(--coral); border-color: var(--coral); color: #fff; }
.btn.danger:hover:not(:disabled) { background: color-mix(in srgb, var(--coral) 88%, #000); }
/* Tinted button: a quiet accent action (e.g. "apply suggestion"). */
.btn.tint {
  background: color-mix(in srgb, var(--c) 12%, var(--card));
  border-color: color-mix(in srgb, var(--c) 40%, var(--line-2));
  color: color-mix(in srgb, var(--c) 80%, var(--ink));
}
.btn.tint:hover:not(:disabled) { background: color-mix(in srgb, var(--c) 20%, var(--card)); }
.btn.big { height: 40px; border-radius: var(--radius-tile); font-size: 13.5px; font-weight: 600; padding: 0 16px; }
.btn.sm { height: 24px; font-size: var(--fs-small); padding: 0 8px; }
.btn.icon { width: 28px; padding: 0; }
.btn.sm.icon { width: 24px; }
.btn.big.icon { width: 40px; }
.btn.block { width: 100%; }

/* Plain text button that looks like a link. */
.linkbtn { background: none; border: 0; padding: 0; color: var(--blue); cursor: pointer; font: inherit; text-decoration: underline; text-underline-offset: 2px; }


/* --------------------------------------------------------------------------
   2. Pills, badges, chips, dots
   -------------------------------------------------------------------------- */
.pill {
  height: 20px; display: inline-flex; align-items: center; gap: 4px; padding: 0 8px;
  border-radius: var(--radius-pill); font-size: var(--fs-label); font-weight: 600;
  align-self: flex-start; white-space: nowrap;
  background: color-mix(in srgb, var(--c) var(--tint), var(--card));
  color: color-mix(in srgb, var(--c) 70%, var(--ink));
}
.pill.out { background: none; border: 1px solid color-mix(in srgb, var(--c) 40%, transparent); }
.pill .dot { width: 6px; height: 6px; background: currentColor; }

/* Small solid count badge (e.g. unread items in the sidebar). */
.badge {
  display: inline-block; min-width: 16px; text-align: center;
  background: var(--orange); color: #fff; font-size: var(--fs-label); font-weight: var(--fw-label);
  border-radius: var(--radius-pill); padding: 0 6px; line-height: 16px; font-variant-numeric: tabular-nums;
}

/* Colour dot. */
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; display: inline-block; }
.dot.sm { width: 6px; height: 6px; }

/* Chip: an outlined, rounded token (tags, quick picks, filters).
   Use a <button> with aria-pressed for selectable chips. */
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 28px;
  border: 1px solid var(--line-2); border-radius: var(--radius-pill); padding: 4px 10px;
  background: var(--card); color: var(--ink); font: inherit; font-size: 12px; text-decoration: none; cursor: pointer;
}
.chip:hover { border-color: color-mix(in srgb, var(--c) 60%, var(--line-2)); }
.chip.on, .chip[aria-pressed="true"] {
  border-color: color-mix(in srgb, var(--c) 60%, var(--line-2));
  background: color-mix(in srgb, var(--c) 12%, var(--card));
  color: color-mix(in srgb, var(--c) 80%, var(--ink));
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }


/* --------------------------------------------------------------------------
   3. Cards, panels, note boxes, notices
   -------------------------------------------------------------------------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-card);
  padding: 12px; box-shadow: var(--shadow-card);
  display: flex; flex-direction: column; gap: 10px; min-width: 0;
}
.card.flat { box-shadow: none; }
.card.raised { box-shadow: var(--shadow-win); border-color: transparent; }
a.card { color: inherit; text-decoration: none; }
a.card:hover { border-color: color-mix(in srgb, var(--blue) 45%, var(--line-2)); }
/* Tinted card: suggestions, generated content, callouts. Default accent violet. */
.card.tinted {
  background: color-mix(in srgb, var(--c) 5%, var(--card));
  border-color: color-mix(in srgb, var(--c) 30%, transparent);
}
.card.tinted > .label:first-child { color: var(--c); display: flex; align-items: center; gap: 6px; }
.card-title { font-size: 13.5px; font-weight: 600; }

/* Panel: a recessed group on --pane (e.g. a tool area inside a page). */
.panel { display: flex; flex-direction: column; gap: 10px; border: 1px solid var(--line-2); border-radius: var(--radius-panel); background: var(--pane); padding: 12px; min-width: 0; }

/* Dashed note box: "coming later", hints, explanations. */
.note {
  border: 1px dashed var(--line-2); border-radius: var(--radius-card); padding: 12px 14px;
  color: var(--ink-2); font-size: var(--fs-ui); line-height: 1.5; max-width: 80ch;
}
.note b, .note strong { color: var(--ink); }
.note ul { margin: 6px 0 0; padding-left: 18px; }

/* Notice: a tinted message line. Default accent blue; use .c-green/.c-orange/.c-coral for tone. */
.notice {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 10px;
  border-radius: var(--radius-item); font-size: var(--fs-ui); line-height: 1.45;
  border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
  background: color-mix(in srgb, var(--c) 9%, var(--card));
}
.notice > span { flex: 1 1 240px; }

.error { color: var(--coral); margin: 0; font-size: var(--fs-ui); }
.ok { color: var(--green); margin: 0; font-size: var(--fs-ui); }


/* --------------------------------------------------------------------------
   4. Form controls
   -------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-meta); color: var(--ink-3); min-width: 0; }
.input {
  min-height: 30px; width: 100%; border: 1px solid var(--line-2); border-radius: var(--radius);
  background: var(--win); color: var(--ink); font-size: var(--fs-body); padding: 6px 9px;
}
.input::placeholder { color: var(--ink-4); }
.input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 18%, transparent); }
.input:disabled { opacity: .7; }
.input[aria-invalid="true"] { border-color: var(--coral); }
.textarea { resize: vertical; line-height: 1.5; font-size: 13.5px; min-height: 84px; }
select.input { padding-right: 6px; }
.counter { font-size: var(--fs-small); color: var(--ink-3); font-variant-numeric: tabular-nums; text-align: right; margin-top: -6px; }
.counter.warn { color: var(--orange); }
.counter.over { color: var(--coral); font-weight: 600; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Switch: <input type="checkbox" class="toggle"> */
.toggle {
  appearance: none; -webkit-appearance: none; margin: 0; width: 30px; height: 18px; border-radius: var(--radius-pill);
  background: var(--line-2); position: relative; flex: none; cursor: pointer;
}
.toggle::after { content: ""; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: left .15s; }
.toggle:checked { background: var(--green); }
.toggle:checked::after { left: 14px; }
.toggle:disabled { opacity: .55; cursor: default; }

/* Radio cards: <label class="radio"><input type="radio"><i></i><div><b>…</b><span>…</span></div></label> */
.radios { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.radio { display: flex; gap: 10px; align-items: flex-start; padding: 9px 10px; border: 1px solid var(--line-2); border-radius: var(--radius-item); background: var(--card); cursor: pointer; position: relative; }
.radio input { position: absolute; opacity: 0; pointer-events: none; }
.radio i { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--ink-4); flex: none; margin-top: 1px; }
.radio.on, .radio:has(input:checked) { border-color: var(--blue); background: color-mix(in srgb, var(--blue) 5%, var(--card)); }
.radio.on i, .radio:has(input:checked) i { border: 4px solid var(--blue); }
.radio:has(input:focus-visible) { outline: 2px solid var(--blue); outline-offset: 1px; }
.radio b { font-weight: 600; font-size: var(--fs-ui); display: block; }
.radio span { font-size: var(--fs-small); color: var(--ink-3); }

/* Round check mark (status, not a form control). */
.check { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--ink-4); flex: none; display: inline-block; position: relative; }
.check.on { background: var(--green); border-color: var(--green); }
.check.on::after { content: ""; position: absolute; left: 5px; top: 2px; width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }


/* --------------------------------------------------------------------------
   5. Segmented control and tabs
   -------------------------------------------------------------------------- */
.seg { display: inline-flex; background: var(--sel); border-radius: var(--radius-seg); padding: 2px; gap: 2px; }
.seg > button, .seg > a, .seg > span {
  font-size: 12px; color: var(--ink-2); padding: 3px 10px; border-radius: var(--radius-sm);
  border: 0; background: none; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.seg > :is(.on, [aria-pressed="true"], [aria-selected="true"], [aria-current="page"]) {
  background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}
.seg.wrap { flex-wrap: wrap; }
/* In column layouts, keep the control at its natural width. */
:is(.stack, .card, .panel, .view-pane, .dialog-body, .field) > .seg { align-self: flex-start; }

/* Tabs: a larger track for page-level views. Use role="tablist" / role="tab". */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; background: var(--sel); padding: 3px; border-radius: var(--radius-tile); align-self: flex-start; }
.tabs > button, .tabs > a {
  border: 0; background: none; font: inherit; font-size: var(--fs-ui); color: var(--ink-2); padding: 6px 12px;
  border-radius: var(--radius); cursor: pointer; display: inline-flex; gap: 6px; align-items: center; text-decoration: none; white-space: nowrap;
}
.tabs > :is(button, a):hover { color: var(--ink); }
.tabs > :is(.on, [aria-selected="true"], [aria-current="page"]) { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.tabs .count { font-variant-numeric: tabular-nums; color: var(--ink-3); font-weight: 600; }
/* Full-width tabs (equal columns), e.g. at the top of a side column. */
.tabs.fill { flex-wrap: nowrap; gap: 2px; align-self: stretch; }
.tabs.fill > :is(button, a) { flex: 1 1 0; min-width: 0; height: 30px; justify-content: center; padding: 0 6px; }
.tabs.fill .count { font-weight: 400; font-size: var(--fs-meta); }


/* --------------------------------------------------------------------------
   6. Avatars and icon badges
   -------------------------------------------------------------------------- */
.avatar {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-size: 10px; font-weight: 600; flex: none; overflow: hidden;
  background: radial-gradient(circle at 30% 25%, color-mix(in srgb, var(--c) 16%, var(--card)), color-mix(in srgb, var(--c) 34%, var(--card)));
  color: color-mix(in srgb, var(--c) 68%, var(--ink));
  box-shadow: 0 0 0 1.5px var(--card), 0 0 0 2px var(--line);
}
.avatar.lg { width: 34px; height: 34px; font-size: 12px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Square avatar with tint and border (for groups, roles, workspaces). */
.avatar.square {
  width: 30px; height: 30px; border-radius: var(--radius-item); font-size: 11px; font-weight: var(--fw-label); box-shadow: none;
  background: color-mix(in srgb, var(--c) var(--tint), var(--card)); color: color-mix(in srgb, var(--c) 75%, var(--ink));
  border: 1px solid color-mix(in srgb, var(--c) 30%, transparent);
}
.avatar.square.sm { width: 24px; height: 24px; font-size: 10px; border-radius: 7px; }
.avatar.square.lg { width: 44px; height: 44px; font-size: 15px; border-radius: var(--radius-panel); }
.avatars { display: flex; }
.avatars > .avatar + .avatar { margin-left: -6px; }

/* Round tinted badge holding an icon. */
.icon-badge {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: color-mix(in srgb, var(--c) var(--tint), var(--card)); color: color-mix(in srgb, var(--c) 75%, var(--ink));
}
.icon-badge .ic { width: 14px; height: 14px; }


/* --------------------------------------------------------------------------
   7. Stat tiles, progress
   -------------------------------------------------------------------------- */
.stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat { flex: 1 1 140px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-tile); padding: 10px 12px; min-width: 0; }
.stat b { display: block; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat span { color: var(--ink-3); font-size: var(--fs-small); }
.stat .delta { font-size: var(--fs-meta); font-weight: 600; color: var(--green); margin-left: 4px; }
.stat .delta.down { color: var(--coral); }
.stat .delta.flat { color: var(--ink-3); font-weight: 500; }

.progress { height: 6px; border-radius: var(--radius-pill); background: var(--sel); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--c, var(--blue)); border-radius: inherit; }


/* --------------------------------------------------------------------------
   8. Lists, tables, timeline
   -------------------------------------------------------------------------- */
.list { display: flex; flex-direction: column; min-width: 0; }
.list-row {
  display: flex; align-items: center; gap: 9px; padding: 8px 0; border-bottom: 1px solid var(--line);
  min-width: 0; color: inherit; text-decoration: none;
}
.list-row > div { min-width: 0; flex: 1; }
.list-row b { font-size: var(--fs-ui); font-weight: 600; display: block; }
.list-row small { font-size: var(--fs-meta); color: var(--ink-3); }
.list-row > .pill { margin-left: auto; align-self: center; }
a.list-row:hover b, button.list-row:hover b { color: var(--blue); }
button.list-row { font: inherit; background: none; border: 0; border-bottom: 1px solid var(--line); text-align: left; cursor: pointer; width: 100%; }
.list-row .time { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; width: 40px; flex: none; }

/* Settings row: text on the left, a control (toggle, button) on the right. */
.setting { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.setting > div { flex: 1; min-width: 0; }
.setting b { display: block; font-size: var(--fs-ui); font-weight: 600; }
.setting span { font-size: var(--fs-small); color: var(--ink-3); overflow-wrap: anywhere; }

.table-wrap { overflow-x: auto; }
.table { border-collapse: collapse; width: 100%; font-size: 12px; }
.table th { text-align: left; font-weight: 600; color: var(--ink-3); font-size: var(--fs-meta); padding: 6px 8px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
.table td { padding: 6px 8px; border-bottom: 1px solid var(--line); color: var(--ink); }
.table .r { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr:hover td { background: var(--hover); }
.table tr.dim td { color: var(--ink-4); }

/* Vertical timeline with tinted nodes. */
.timeline { display: flex; flex-direction: column; gap: 14px; position: relative; padding-left: 2px; margin: 0; list-style: none; }
.timeline::before { content: ""; position: absolute; left: 15px; top: 14px; bottom: 14px; width: 1px; background: var(--line-2); }
.timeline > li { display: flex; gap: 12px; align-items: flex-start; position: relative; }
.timeline .node {
  width: 28px; height: 28px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: color-mix(in srgb, var(--c) var(--tint), var(--card)); color: color-mix(in srgb, var(--c) 75%, var(--ink));
  box-shadow: 0 0 0 3px var(--win);
}
.timeline .node .ic { width: 14px; height: 14px; }
.timeline b { display: block; font-size: var(--fs-ui); font-weight: 600; }
.timeline small { font-size: var(--fs-meta); color: var(--ink-3); }


/* --------------------------------------------------------------------------
   9. Empty slots and drop targets
   -------------------------------------------------------------------------- */
.empty {
  border: 1px dashed var(--line-2); border-radius: var(--radius-item); color: var(--ink-4); font-size: 16px;
  display: grid; place-items: center; flex: 1; min-height: 40px; background: none; cursor: pointer;
}
.empty:hover { color: var(--blue); border-color: var(--blue); background: color-mix(in srgb, var(--blue) 5%, transparent); }
.dropzone {
  border: 1.5px dashed var(--line-2); border-radius: var(--radius-card); padding: 18px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 8px; background: var(--card); color: var(--ink-2);
}
.dropzone.over { border-color: var(--blue); background: color-mix(in srgb, var(--blue) 5%, var(--card)); }


/* --------------------------------------------------------------------------
   10. Chat bubbles
   -------------------------------------------------------------------------- */
.thread { display: flex; flex-direction: column; gap: 10px; }
.bubble { font-size: 12px; line-height: 1.45; padding: 8px 10px; border-radius: var(--radius-card); max-width: 92%; }
.bubble.me { align-self: flex-end; background: var(--solid); color: var(--onsolid); border-bottom-right-radius: 4px; }
.bubble.them {
  align-self: flex-start; border-bottom-left-radius: 4px;
  background: color-mix(in srgb, var(--c) 7%, var(--card)); border: 1px solid color-mix(in srgb, var(--c) 25%, transparent);
}


/* --------------------------------------------------------------------------
   11. Overlays: menu/popover, dialog, toast, spinner
   -------------------------------------------------------------------------- */
.menu {
  border: 1px solid var(--line-2); border-radius: var(--radius-panel); background: var(--card);
  box-shadow: var(--shadow-pop); padding: 6px; display: flex; flex-direction: column; gap: 2px; min-width: 200px;
}
.menu-item {
  display: flex; align-items: center; gap: 9px; padding: 7px; border-radius: var(--radius-seg); border: 0; background: none;
  font: inherit; color: inherit; text-align: left; cursor: pointer; min-width: 0; text-decoration: none;
}
.menu-item:hover { background: var(--hover); }
.menu-item.on, .menu-item[aria-checked="true"] { background: var(--sel); }
.menu-item > div { flex: 1; min-width: 0; }
.menu-item b { font-size: var(--fs-ui); display: block; font-weight: 600; }
.menu-item small { font-size: var(--fs-meta); color: var(--ink-3); }
.menu-foot { border-top: 1px solid var(--line); margin-top: 4px; padding: 8px 7px 4px; font-size: 12px; color: var(--ink-3); text-decoration: none; }

/* <dialog class="dialog"> with .dialog-head / .dialog-body / .dialog-foot */
.dialog {
  border: 0; padding: 0; border-radius: var(--radius-dialog); width: min(540px, calc(100vw - 24px));
  max-height: min(720px, calc(100vh - 32px)); background: var(--win); color: var(--ink); box-shadow: var(--shadow-win);
}
.dialog[open] { display: flex; flex-direction: column; }
.dialog::backdrop { background: var(--scrim); }
.dialog-head { display: flex; align-items: flex-start; gap: 10px; padding: 16px 16px 10px; border-bottom: 1px solid var(--line); }
.dialog-body { padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 0; flex: 1; }
.dialog-foot { display: flex; align-items: center; gap: 8px; padding: 10px 16px 14px; border-top: 1px solid var(--line); }
/* Static variant for showing a dialog inline (galleries, docs). */
.dialog.static { position: static; display: flex; flex-direction: column; margin: 0; width: auto; max-width: 540px; }

.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 60;
  display: flex; align-items: center; gap: 6px; max-width: calc(100vw - 32px); padding: 6px 6px 6px 14px; border-radius: var(--radius-tile);
  background: var(--solid); color: var(--onsolid); font-size: var(--fs-ui); box-shadow: var(--shadow-win);
}
.toast .btn.ghost { color: var(--onsolid); font-weight: 600; }
.toast .btn.ghost:hover { background: color-mix(in srgb, var(--onsolid) 14%, transparent); }
.toast.err { background: var(--coral); color: #fff; }
.toast.static { position: static; transform: none; align-self: flex-start; }

.spinner { width: 16px; height: 16px; flex: none; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--blue); animation: wp-spin .8s linear infinite; display: inline-block; }
@keyframes wp-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }


/* --------------------------------------------------------------------------
   12. Brand mark
   -------------------------------------------------------------------------- */
.brand { display: flex; align-items: center; gap: 8px; font-weight: var(--fw-label); font-size: 14px; color: var(--ink); text-decoration: none; }
.brand-mark { width: 20px; height: 20px; border-radius: 6px; background: var(--ink); display: grid; place-items: center; flex: none; }
.brand-mark::after { content: ""; width: 6px; height: 6px; border-radius: 2px; background: var(--page); }


/* --------------------------------------------------------------------------
   13. App shell: sidebar + content (+ optional right pane)
   <div class="app">
     <header class="mobile-bar">…</header>   (visible below 760px)
     <div class="scrim" hidden></div>
     <aside class="side">…</aside>
     <div class="content"> <div class="topbar">…</div> … </div>
   </div>
   -------------------------------------------------------------------------- */
.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }

.side {
  background: var(--side); -webkit-backdrop-filter: blur(40px) saturate(1.7); backdrop-filter: blur(40px) saturate(1.7);
  border-right: 1px solid var(--line); padding: 14px 10px; display: flex; flex-direction: column; gap: 16px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.side-head { display: flex; align-items: center; gap: 8px; padding: 2px 8px; }
.side-label { padding: 0 8px 4px; }
.side-label + .side-label, .nav-row + .side-label { padding-top: 10px; }
.side-foot { margin-top: auto; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 0 8px; color: var(--ink-3); font-size: var(--fs-meta); }

/* Account / identity block at the top of the sidebar. */
.account { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--radius-item); min-width: 0; }
.account > div { min-width: 0; }
.account b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account small { display: block; color: var(--ink-3); font-size: var(--fs-meta); }
button.account { width: 100%; border: 0; background: none; font: inherit; color: inherit; text-align: left; cursor: pointer; }
button.account:hover, button.account[aria-expanded="true"] { background: var(--hover); }

.nav { display: flex; flex-direction: column; gap: 1px; }
.nav-item {
  display: flex; align-items: center; gap: 8px; height: 28px; padding: 0 8px; border-radius: var(--radius);
  color: var(--ink); text-decoration: none; white-space: nowrap; min-width: 0;
}
.nav-item:hover { background: var(--hover); }
.nav-item .ic { color: var(--blue); }
.nav-item.on, .nav-item[aria-current="page"] { background: var(--sel); font-weight: 600; }
.nav-item.muted { color: var(--ink-4); }
.nav-item.sub { height: 26px; padding-left: 30px; font-size: var(--fs-ui); }
.nav-item .count { margin-left: auto; color: var(--ink-3); font-size: var(--fs-small); font-variant-numeric: tabular-nums; font-weight: 400; }
.nav-item .badge { margin-left: auto; }

/* Secondary sidebar row with a trailing status word (connections, sources, devices). */
.nav-row { display: flex; align-items: center; gap: 8px; min-height: 28px; padding: 0 8px; font-size: var(--fs-ui); border-radius: var(--radius); color: inherit; text-decoration: none; }
a.nav-row:hover { background: var(--hover); }
.nav-row.muted { color: var(--ink-3); }
.nav-row .status { margin-left: auto; font-size: var(--fs-label); color: var(--green); font-weight: 600; }
.nav-row .status.off { color: var(--ink-3); font-weight: 500; }
.nav-row .status.warn { color: var(--orange); }

.content { background: var(--win); min-width: 0; min-height: 100vh; }

/* Top bar of a page: serif title, sub line, actions. */
.topbar { min-height: 56px; display: flex; align-items: center; gap: 10px; padding: 10px var(--gutter); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.topbar .title { font: 400 26px/1 var(--serif); margin: 0; }
.topbar .title em { color: var(--coral); }
.topbar .sub { color: var(--ink-3); font-size: 12px; }

/* Two-column view inside .content: main column + right pane. */
.view { display: grid; grid-template-columns: minmax(0, 1fr) var(--right-w); min-width: 0; min-height: 100vh; }
.view-main { display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--line); }
.view-pane { background: var(--pane); padding: 16px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.section { padding: 14px var(--gutter) 2px; min-width: 0; }
.section + .section { padding-top: 12px; }

/* Mobile behaviour */
.mobile-bar, .scrim, .only-mobile { display: none; }

@media (max-width: 1100px) {
  .view { grid-template-columns: minmax(0, 1fr); }
  .view-main { border-right: 0; }
  .view-pane { border-top: 1px solid var(--line); }
}

@media (max-width: 760px) {
  :root { --gutter: 12px; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .mobile-bar {
    display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
    background: var(--side); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
    -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  }
  .side {
    position: fixed; inset: 0 auto 0 0; width: min(280px, 85vw); z-index: 20; transform: translateX(-105%);
    transition: transform .2s ease; background: var(--win); box-shadow: var(--shadow-win); visibility: hidden;
  }
  .side.open { transform: none; visibility: visible; }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .3); z-index: 15; }
  .scrim[hidden] { display: none; }
  .only-mobile { display: inline-flex; }
  .form-grid { grid-template-columns: 1fr; }
  .content, .view { min-height: 0; }
}
@media (max-width: 760px) and (prefers-reduced-motion: no-preference) {
  .side { transition: transform .2s ease, visibility 0s linear .2s; }
  .side.open { transition: transform .2s ease, visibility 0s; }
}


/* --------------------------------------------------------------------------
   14. Calendar: week grid and month grid
   -------------------------------------------------------------------------- */
.scroll-x { overflow-x: auto; min-width: 0; }

.week {
  display: grid; grid-template-columns: repeat(7, minmax(92px, 1fr)); min-width: 644px;
  border: 1px solid var(--line); border-radius: var(--radius-tile); background: var(--card); overflow: hidden;
}
.week > * { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); min-width: 0; }
.week > .day-head:nth-child(7), .week > .day:last-child, .week > .band { border-right: 0; }
.week > .day { border-bottom: 0; }

.day-head { padding: 8px 10px; background: var(--pane); display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 6px; }
.day-head .wd { font-size: var(--fs-label); font-weight: var(--fw-label); letter-spacing: var(--label-tracking); text-transform: uppercase; color: var(--ink-3); }
.day-head .n { font: 400 22px/1 var(--serif); color: var(--ink-2); }
.day-head.today { background: color-mix(in srgb, var(--blue) 9%, var(--pane)); }
.day-head.today .n, .day-head.today .wd { color: var(--blue); }

.day { padding: 6px; display: flex; flex-direction: column; gap: 6px; min-height: 170px; }
.day.today { background: color-mix(in srgb, var(--blue) 4%, var(--card)); }
.day > .empty.add { flex: 0 0 28px; min-height: 28px; opacity: 0; }
.day:hover > .empty.add, .day > .empty.add:focus-visible { opacity: 1; }
@media (hover: none) { .day > .empty.add { opacity: 1; } }

/* Full-width band row for multi-day spans. Place .span-bar with grid-column. */
.band { grid-column: 1 / -1; padding: 6px 8px; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 0 8px; background: var(--win); }
.span-bar {
  height: 22px; border-radius: var(--radius-pill); display: flex; align-items: center; gap: 6px; padding: 0 10px;
  font-size: var(--fs-small); font-weight: var(--fw-medium); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; text-decoration: none;
  background: color-mix(in srgb, var(--c) var(--tint), var(--card)); color: color-mix(in srgb, var(--c) 75%, var(--ink));
  border: 1px solid color-mix(in srgb, var(--c) 28%, transparent);
}

/* Calendar entry card. */
.event {
  border: 1px solid var(--line-2); border-radius: var(--radius-item); background: var(--card); padding: 7px 8px;
  display: flex; flex-direction: column; gap: 5px; box-shadow: var(--shadow-card); color: var(--ink); text-decoration: none; min-width: 0;
}
a.event:hover, button.event:hover { border-color: color-mix(in srgb, var(--blue) 45%, var(--line-2)); }
button.event { font: inherit; text-align: left; cursor: pointer; width: 100%; }
.event .time { font-size: var(--fs-meta); color: var(--ink-3); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event p { margin: 0; font-size: 12px; font-weight: var(--fw-medium); line-height: 1.3; overflow-wrap: break-word; hyphens: auto; }
.event .meta { font-size: var(--fs-meta); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.event .pill { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
/* Placeholder (planned, not yet written) and accent-edged variants. */
.event.placeholder {
  border-style: dashed; box-shadow: none;
  background: color-mix(in srgb, var(--c) 4%, transparent); border-color: color-mix(in srgb, var(--c) 55%, var(--line-2));
}
.event.placeholder p { color: var(--ink-2); font-weight: 500; }
.event.edge { border-left: 3px solid var(--c, var(--blue)); }

.week.compact .day-head { padding: 5px 10px; }
.week.compact .day-head .n { font-size: 17px; }
.week.compact .band { padding: 4px 8px; }
.week.compact .day { min-height: 76px; padding: 5px; gap: 5px; }

/* Month grid */
.month {
  display: grid; grid-template-columns: repeat(7, minmax(96px, 1fr)); min-width: 700px;
  border: 1px solid var(--line); border-radius: var(--radius-tile); background: var(--card); overflow: hidden;
}
.month > * { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); min-width: 0; }
.month > :nth-child(7n) { border-right: 0; }
.month > :nth-last-child(-n+7) { border-bottom: 0; }
.month-head { padding: 6px 10px; background: var(--pane); font-size: var(--fs-label); font-weight: var(--fw-label); letter-spacing: var(--label-tracking); text-transform: uppercase; color: var(--ink-3); }
.month-day { padding: 5px 6px 6px; min-height: 104px; display: flex; flex-direction: column; gap: 3px; }
.month-day .n { font: 400 18px/1 var(--serif); color: var(--ink-2); padding: 2px 3px; }
.month-day.out { background: var(--pane); }
.month-day.out .n { color: var(--ink-4); }
.month-day.today { background: color-mix(in srgb, var(--blue) 6%, var(--card)); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--blue) 55%, transparent); }
.month-day.today .n { color: var(--blue); }
/* Compact one-line entry for month cells. */
.mini-event {
  display: flex; align-items: center; gap: 5px; min-width: 0; height: 20px; padding: 0 6px; border-radius: var(--radius-sm);
  font-size: var(--fs-meta); text-decoration: none; color: var(--ink); border: 1px solid var(--line); background: var(--card);
}
.mini-event .dot { width: 7px; height: 7px; }
.mini-event .tt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
a.mini-event:hover { border-color: color-mix(in srgb, var(--blue) 45%, var(--line-2)); }


/* --------------------------------------------------------------------------
   15. Website layout (for content pages built from the same tokens)
   -------------------------------------------------------------------------- */
.container { width: min(1120px, 100% - 2 * var(--gutter)); margin-inline: auto; }
.container.narrow { width: min(720px, 100% - 2 * var(--gutter)); }

.site-bar {
  position: sticky; top: 0; z-index: 10; background: var(--side);
  -webkit-backdrop-filter: blur(20px) saturate(1.5); backdrop-filter: blur(20px) saturate(1.5);
  border-bottom: 1px solid var(--line);
}
.site-bar > .container { display: flex; align-items: center; gap: 10px; min-height: 52px; flex-wrap: wrap; padding-block: 8px; }
.site-nav { display: flex; gap: 2px; flex-wrap: wrap; }
.site-nav a { height: 28px; display: inline-flex; align-items: center; padding: 0 9px; border-radius: var(--radius); color: var(--ink-2); text-decoration: none; font-size: var(--fs-ui); }
.site-nav a:hover { background: var(--hover); color: var(--ink); }
.site-nav a[aria-current="page"] { background: var(--sel); color: var(--ink); font-weight: 600; }

.hero { padding: 56px 0 36px; display: flex; flex-direction: column; gap: 14px; }
.byline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--ink-3); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); gap: 12px; }
.media { border-radius: var(--radius-card); overflow: hidden; border: 1px solid var(--line); background: var(--pane); }
.site-footer { border-top: 1px solid var(--line); margin-top: 56px; padding: 22px 0 36px; color: var(--ink-3); font-size: 12px; }
.site-footer .container { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

@media (max-width: 760px) {
  .hero { padding: 32px 0 24px; }
  .site-nav { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
}


/* --------------------------------------------------------------------------
   16. Charts (styling hooks for D3 charts, see js/chart-theme.js)
   -------------------------------------------------------------------------- */
.chart { position: relative; min-width: 0; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-head { display: flex; flex-direction: column; gap: 2px; }
.chart-head h3, .chart-title { font: 400 22px/1.1 var(--serif); margin: 0; }
.chart-head p { color: var(--ink-3); font-size: var(--fs-small); margin: 0; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: var(--fs-small); color: var(--ink-2); }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; background: var(--c); display: inline-block; }
.legend i.box { width: 10px; height: 10px; border-radius: 3px; }
.chart-tip {
  position: absolute; z-index: 2; pointer-events: none; background: var(--card); color: var(--ink-2);
  border: 1px solid var(--line-2); border-radius: var(--radius-seg); box-shadow: var(--shadow-card);
  padding: 6px 9px; font-size: var(--fs-small); line-height: 1.4; width: max-content; max-width: 220px;
}
.chart-tip b { color: var(--ink); font-size: 13px; font-variant-numeric: tabular-nums; }
.chart-tip .row { gap: 6px; }
.chart-table summary { cursor: pointer; font-size: var(--fs-small); color: var(--ink-3); }
.chart-table[open] summary { margin-bottom: 6px; }
.multiples { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); gap: 14px; }
