/*
 * tsutsumbi — an instrument, not a page.
 *
 * The interface is read several times a day and mostly scanned, so density is
 * the point: 34px rows, a 13.5px base, and the full width of the screen. The
 * navy is the chrome, the orange is the mark and the focus ring, and four muted
 * hues carry the ticket statuses. Nothing else is saturated, which is why the
 * eye lands on the one thing that is.
 *
 * Sections, in order: fonts, tokens, reset, shell, rail, topbar, grids,
 * badges, actors, filters, forms, timeline, prose, tokens screen, login.
 */

/* ------------------------------------------------------------------- fonts */

@font-face {
    font-family: 'Nunito';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('/fonts/nunito-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
        U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
        U+FEFF, U+FFFD;
}

@font-face {
    font-family: 'Nunito';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('/fonts/nunito-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304,
        U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0,
        U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* Identifiers — ticket keys, project paths, agent slugs, scopes, tokens — are
   strings a human compares character by character. A monospace face makes that
   comparison possible; the proportional one does not. Self-hosted like Nunito,
   because the policy forbids a remote font and the licence (OFL) allows it. */
@font-face {
    font-family: 'JetBrains Mono';
    font-style: normal;
    font-weight: 400 600;
    font-display: swap;
    src: url('/fonts/jetbrains-mono-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
        U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
        U+FEFF, U+FFFD;
}

@font-face {
    font-family: 'JetBrains Mono';
    font-style: normal;
    font-weight: 400 600;
    font-display: swap;
    src: url('/fonts/jetbrains-mono-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304,
        U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0,
        U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ------------------------------------------------------------------ tokens */

/*
 * Every colour is declared once, as a light/dark pair. `color-scheme` decides
 * which half applies, so the theme switch is one property on the root rather
 * than a second copy of the palette — and native controls, scrollbars and form
 * widgets follow the theme for free. Without an explicit choice the root keeps
 * `light dark` and the system preference wins.
 */
:root {
    color-scheme: light dark;

    --canvas: light-dark(#f5f6f8, #0d131f);
    --surface: light-dark(#ffffff, #141c2b);
    --sunken: light-dark(#fafbfc, #111827);
    --raised: light-dark(#ffffff, #1a2436);
    --line: light-dark(#e2e6ec, #25314a);
    --line-strong: light-dark(#cdd4de, #33415e);

    --ink: light-dark(#16202f, #e7ecf5);
    --ink-soft: light-dark(#4a5666, #a6b2c6);
    --ink-faint: light-dark(#7a8494, #77869e);

    --rail: light-dark(#1b2a4a, #0a1120);
    --rail-raised: light-dark(#24365c, #1b2a4a);
    --rail-ink: #e7ecf5;
    --rail-faint: light-dark(#93a1bd, #8394b3);

    /* The primary button is navy in both themes, but it cannot simply reuse the
       rail: on a dark ground the rail is darker than the page, and a button
       filled with it reads as a hole rather than as something raised. This pair
       stays a step above the surface either way. */
    --button-fill: light-dark(#1b2a4a, #2e4477);
    --button-fill-hover: light-dark(#24365c, #3a548f);

    /* The one saturated colour. It brightens in the dark theme only to keep the
       same contrast against a darker ground, not to be used more often. */
    --accent: light-dark(#de8a2a, #e79b46);
    --on-accent: #1b2a4a;

    --status-todo: light-dark(#6b7684, #8b95a5);
    --status-in_progress: light-dark(#1f6f8b, #4fa8c7);
    --status-blocked: light-dark(#a33a3a, #d97070);
    --status-done: light-dark(#4a7a52, #78ad82);

    /* Tints are declared rather than mixed: a badge sits on --surface, and a
       color-mix against a transparent ground shifts as the theme flips. */
    --tint-todo: light-dark(#f0f1f3, #1c2434);
    --tint-in_progress: light-dark(#e6f1f5, #152a35);
    --tint-blocked: light-dark(#f8eaea, #301c1e);
    --tint-done: light-dark(#eaf2ea, #16291c);

    /* Type. The base is 13.5px: small enough to fit thirty rows on a screen,
       large enough to read a paragraph of description without leaning in. */
    --text-micro: 0.65625rem;   /* 10.5px — uppercase column heads, eyebrows */
    --text-tiny: 0.6875rem;     /* 11px  — scopes, dense metadata */
    --text-small: 0.75rem;      /* 12px  — captions, help text */
    --text-meta: 0.78125rem;    /* 12.5px — dates, secondary cells */
    --text-ui: 0.8125rem;       /* 13px  — controls and buttons */
    --text-body: 0.84375rem;    /* 13.5px — the base */
    --text-lead: 0.875rem;      /* 14px  — description prose */
    --text-title: 1.25rem;      /* 20px  — the one heading per screen */

    /* Space. Seven steps, and nothing between them. */
    --space-1: 0.25rem;
    --space-2: 0.375rem;
    --space-3: 0.5rem;
    --space-4: 0.625rem;
    --space-5: 0.875rem;
    --space-6: 1.25rem;
    --space-7: 1.5rem;

    /* Fixed measures. The row height is the density decision made numeric. */
    --row-h: 2.125rem;      /* 34px */
    --head-h: 1.875rem;     /* 30px */
    --control-h: 1.875rem;  /* 30px */
    --topbar-h: 2.625rem;   /* 42px */
    --touch-h: 2.75rem;     /* 44px — the minimum target below 700px */
    --rail-w: 13rem;        /* 208px */
    --rail-w-narrow: 3.25rem;
    --gutter-w: 3px;        /* the alert stripe down the left of a row */

    --radius: 0.2rem;
    --shadow: 0 1px 2px light-dark(rgb(16 25 46 / 6%), rgb(0 0 0 / 30%));

    --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

:root[data-theme='light'] { color-scheme: light; }
:root[data-theme='dark'] { color-scheme: dark; }

/* ------------------------------------------------------------------- reset */

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--canvas);
    color: var(--ink);
    font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: var(--text-body);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
    margin: 0;
    line-height: 1.25;
    font-weight: 700;
}

h1 {
    font-size: var(--text-title);
    letter-spacing: -0.01em;
}

/* Every section heading below the page title is an eyebrow, not a headline:
   it labels a region for someone scanning, and steps out of the way. */
h2, h3 {
    font-size: var(--text-ui);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

a {
    color: var(--ink-soft);
    text-decoration-color: var(--line-strong);
    text-underline-offset: 0.15em;
}

a:hover {
    color: var(--ink);
    text-decoration-color: currentcolor;
}

input, select, textarea, button {
    font: inherit;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 1px;
}

::selection {
    background: color-mix(in srgb, var(--accent) 22%, transparent);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.mono {
    font-family: var(--mono);
    font-size: var(--text-small);
}

.numeric {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------- shell */

/*
 * Full width, always. The old 68rem column wasted 40% of a 1920px screen while
 * the ticket list truncated its own columns; the rail and the content now take
 * the whole viewport and the reading measure is capped per block instead — on
 * prose and on the timeline, where a long line actually hurts.
 */
.app {
    display: flex;
    min-height: 100dvh;
}

.rail-region {
    flex: none;
}

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.page {
    padding: var(--space-6) var(--space-7) 2.5rem;
}

/* -------------------------------------------------------------------- rail */

/*
 * A permanent rail for two destinations is hard to justify on its own — but it
 * carries the pinned projects and the session, and it is the only place a
 * persistent element can live without eating vertical space on every screen.
 * Collapsed it is 52px of icons; the choice is a cookie, so it survives a
 * reload and works with scripting off.
 */
.rail {
    width: var(--rail-w);
    height: 100dvh;
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    padding: var(--space-5) 0;
    background: var(--rail);
    color: var(--rail-ink);
    overflow: hidden;
}

.rail-brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0 var(--space-5) var(--space-5);
    color: var(--rail-ink);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    text-decoration: none;
    white-space: nowrap;
}

.rail-brand img {
    flex: none;
}

.rail-nav {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 0 var(--space-3);
}

.rail-nav a {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    height: 2rem;
    padding: 0 var(--space-3);
    border-radius: var(--radius);
    color: var(--rail-ink);
    font-size: var(--text-body);
    text-decoration: none;
    white-space: nowrap;
}

.rail-nav a:hover {
    background: var(--rail-raised);
    color: var(--rail-ink);
}

/* The current page is marked by weight and by a filled ground, not by the
   accent: the orange is spent on the mark and the focus ring alone. */
.rail-nav a[aria-current='page'] {
    background: var(--rail-raised);
    font-weight: 700;
}

.rail-nav svg {
    flex: none;
    opacity: 0.9;
}

.rail-section {
    margin-top: var(--space-7);
    padding: 0 var(--space-5);
    min-height: 0;
    overflow-y: auto;
}

.rail-section-title {
    margin: 0 0 var(--space-2);
    font-size: var(--text-micro);
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--rail-faint);
}

.rail-pins {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.rail-pin {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    height: 1.625rem;
    padding: 0 var(--space-2);
    margin: 0 calc(var(--space-2) * -1);
    border-radius: var(--radius);
    color: var(--rail-faint);
    font-size: var(--text-meta);
    text-decoration: none;
}

.rail-pin:hover {
    background: var(--rail-raised);
    color: var(--rail-ink);
}

.rail-pin-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rail-pin-count {
    font-variant-numeric: tabular-nums;
}

/* A pinned project with a blocked ticket shows it here, so the alert reaches
   the eye from any screen and not only from the dashboard. */
.rail-pin-dot {
    width: 5px;
    height: 5px;
    flex: none;
    border-radius: 50%;
    background: var(--status-todo);
}

.rail-pin-dot.is-blocked {
    background: var(--status-blocked);
}

.rail-foot {
    margin-top: auto;
    padding: var(--space-4) var(--space-5) 0;
    border-top: 1px solid var(--rail-raised);
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.rail-user {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--text-small);
    color: var(--rail-faint);
}

.rail-icon-button {
    display: flex;
    flex: none;
    padding: 2px;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    color: var(--rail-faint);
    cursor: pointer;
}

.rail-icon-button:hover {
    background: var(--rail-raised);
    color: var(--rail-ink);
}

/* Collapsed: the icons stay, every label goes. Hiding rather than shrinking,
   because a truncated word is worse than no word. */
.rail-narrow .rail {
    width: var(--rail-w-narrow);
}

.rail-narrow .rail-label,
.rail-narrow .rail-section,
.rail-narrow .rail-user {
    display: none;
}

.rail-narrow .rail-brand,
.rail-narrow .rail-nav a,
.rail-narrow .rail-foot {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

/* ----------------------------------------------------------------- topbar */

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: var(--space-4);
    height: var(--topbar-h);
    flex: none;
    padding: 0 var(--space-4) 0 var(--space-3);
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.topbar form {
    display: flex;
    flex: none;
}

.icon-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    flex: none;
    padding: 0;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    color: var(--ink-soft);
    cursor: pointer;
}

.icon-button:hover {
    background: var(--sunken);
    color: var(--ink);
}

.icon-button-outlined {
    border: 1px solid var(--line);
}

.icon-button-outlined:hover {
    border-color: var(--line-strong);
}

/*
 * When no preference is stored, the effective state is the stylesheet's call
 * and the server cannot know it. Both toggle buttons are then rendered and
 * these rules reveal the one that matches what is actually on screen, so the
 * button always posts the opposite of what the reader sees — with no script.
 */
.when-rail-closed,
.when-dark {
    display: none;
}

@media (max-width: 74.9375rem) {
    .when-rail-open { display: none; }
    .when-rail-closed { display: flex; }
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) .when-light { display: none; }
    :root:not([data-theme]) .when-dark { display: flex; }
}

/* The trail is the only navigation state on screen once the rail is collapsed,
   so it stays legible: the last crumb is the current place, in full ink. */
.crumbs {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    overflow: hidden;
    font-size: var(--text-ui);
}

.crumbs a,
.crumbs span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-decoration: none;
}

.crumbs a {
    color: var(--ink-soft);
    flex: none;
    max-width: 21rem;
}

.crumbs a:hover {
    color: var(--ink);
    text-decoration: underline;
}

.crumbs-current {
    color: var(--ink);
    font-weight: 700;
    min-width: 0;
}

.crumbs-sep {
    color: var(--line-strong);
    flex: none;
}

/* ------------------------------------------------------------------ flashes */

/* A flash is a strip across the top of the content, not a card inside it: it
   belongs to the moment, not to the page, and it must not push the list down
   by a whole card's height. */
.flash {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
    padding: var(--space-3) var(--space-7);
    border-bottom: 1px solid var(--line);
    background: var(--sunken);
    color: var(--ink-soft);
    font-size: var(--text-ui);
}

.flash::before {
    content: '';
    width: 6px;
    height: 6px;
    flex: none;
    border-radius: 50%;
    background: currentcolor;
}

.flash-success {
    background: var(--tint-done);
    border-bottom-color: color-mix(in srgb, var(--status-done) 30%, var(--line));
    color: var(--status-done);
}

.flash-error {
    background: var(--tint-blocked);
    border-bottom-color: color-mix(in srgb, var(--status-blocked) 30%, var(--line));
    color: var(--status-blocked);
}

/* --------------------------------------------------------------- page head */

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-7);
    margin-bottom: var(--space-6);
}

.page-head-main {
    min-width: 0;
}

.page-head p {
    margin: 2px 0 0;
    color: var(--ink-faint);
    font-size: var(--text-meta);
}

.page-head-actions {
    display: flex;
    gap: var(--space-3);
    flex: none;
}

.page-title-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.page-path {
    margin: 2px 0 0;
    max-width: 40rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--mono);
    font-size: var(--text-tiny);
    color: var(--ink-faint);
}

/* ------------------------------------------------------------------- grids */

/*
 * The lists are CSS grids rather than tables. A table cannot reflow into a card
 * without duplicating the markup, and the server has no idea how wide the
 * screen is — one grid with named areas gives thirty dense rows on a monitor
 * and a readable card on a phone, from a single pass of HTML.
 */
.grid {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
}

.grid-head,
.grid-row {
    display: grid;
    grid-template-columns: var(--cols);
    align-items: center;
    column-gap: var(--space-4);
}

.grid-head {
    height: var(--head-h);
    padding: 0 var(--space-4) 0 calc(var(--space-4) + var(--gutter-w));
    background: var(--sunken);
    border-bottom: 1px solid var(--line);
    font-size: var(--text-micro);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

/* A heading that wraps would overflow a row locked to 30px. The columns are
   sized for their heading, so this only fails loudly if one is ever too
   narrow — which is the point. */
.grid-head > * {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.grid-row {
    height: var(--row-h);
    padding: 0 var(--space-4) 0 var(--space-4);
    border-bottom: 1px solid var(--line);
    border-left: var(--gutter-w) solid transparent;
    text-decoration: none;
    color: inherit;
}

.grid-row:last-child {
    border-bottom: 0;
}

.grid-row:hover {
    background: var(--sunken);
    color: inherit;
}

/* The gutter is the answer to "which project is in trouble?". It is a stripe,
   not a colour on the text: it survives at a glance across thirty rows, and it
   reads as a mark in the margin rather than as an error state on the row. */
.grid-row.is-blocked {
    border-left-color: var(--status-blocked);
}

/* Archived and closed rows stay in the list. They are dimmed, never removed —
   nothing is lost, so nothing disappears. */
.grid-row.is-muted {
    opacity: 0.5;
}

.grid-row > * {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.grid-empty {
    padding: 2.5rem var(--space-6);
    text-align: center;
}

.grid-empty p {
    margin: 0;
    font-size: var(--text-lead);
    font-weight: 700;
}

/* The empty state says what will fill it. Nobody has to do anything here — the
   agents create the rows — and that is exactly what is not obvious. */
.grid-empty p + p {
    margin: var(--space-1) auto 0;
    max-width: 29rem;
    font-size: var(--text-ui);
    font-weight: 400;
    color: var(--ink-faint);
}

.grid-note {
    margin: var(--space-3) 0 0;
    font-size: var(--text-tiny);
    color: var(--ink-faint);
}

.grid-projects { --cols: 5.25rem minmax(8.75rem, 1fr) minmax(11.25rem, 1.4fr) 4.375rem 5rem 10.625rem; }
.grid-tickets  { --cols: 5.375rem minmax(12.5rem, 1fr) 4.625rem 5.5rem 9.375rem 8.75rem; }
/* The scope column is the one that must never be cut — a scope truncated to
   "comments…" says nothing — so it gets a floor and the widest share of what
   is left. The selector and the agent slug have known, short shapes. */
.grid-tokens   { --cols: 5.5rem minmax(6rem, 1fr) 7rem minmax(7.5rem, 1.3fr) 9.5rem 5.75rem; }

/* The only list whose rows breathe: a token carries its scopes, and a scope
   list is the one cell here that has to be read in full rather than scanned. */
.grid-tokens .grid-row {
    height: auto;
    min-height: var(--row-h);
    padding-top: var(--space-1);
    padding-bottom: var(--space-1);
}

/* One scope per line. Joined into a sentence they wrap mid-word at whatever
   width is left, and "comments:write" cut after "comments:" is unreadable. */
.grid-tokens .c-scopes span {
    display: block;
    line-height: 1.35;
}

.c-key {
    font-family: var(--mono);
    font-size: var(--text-small);
    font-weight: 700;
    letter-spacing: -0.01em;
}

.c-path,
.c-selector,
.c-agent {
    font-family: var(--mono);
    font-size: var(--text-tiny);
    color: var(--ink-faint);
}

.c-scopes {
    font-family: var(--mono);
    font-size: var(--text-tiny);
    color: var(--ink-faint);
}

.c-type {
    font-size: var(--text-tiny);
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.c-when,
.c-used {
    text-align: right;
    font-size: var(--text-meta);
    color: var(--ink-soft);
    font-variant-numeric: tabular-nums;
}

.c-active,
.c-blocked {
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--ink-soft);
}

/* A zero is not news. Only a count that is actually there earns full ink, and
   only a blocked count earns the alert colour. */
.c-active.is-zero,
.c-blocked.is-zero {
    color: var(--ink-faint);
}

.c-blocked:not(.is-zero) {
    color: var(--status-blocked);
    font-weight: 700;
}

.c-title.is-closed {
    text-decoration: line-through;
    text-decoration-color: var(--line-strong);
}

.c-actor {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.c-action {
    text-align: right;
}

/* ------------------------------------------------------------------ badges */

.badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: var(--radius);
    font-size: var(--text-tiny);
    font-weight: 700;
    white-space: nowrap;
    color: var(--badge-color, var(--ink-soft));
    background: var(--badge-tint, var(--sunken));
}

.badge-todo { --badge-color: var(--status-todo); --badge-tint: var(--tint-todo); }
.badge-in_progress { --badge-color: var(--status-in_progress); --badge-tint: var(--tint-in_progress); }
.badge-blocked { --badge-color: var(--status-blocked); --badge-tint: var(--tint-blocked); }
.badge-done { --badge-color: var(--status-done); --badge-tint: var(--tint-done); }

.badge-plain {
    background: transparent;
    border: 1px solid var(--line-strong);
    color: var(--ink-soft);
    font-family: var(--mono);
    font-weight: 500;
    letter-spacing: 0.02em;
}

.badge-archived {
    --badge-color: var(--ink-faint);
    --badge-tint: transparent;
    border: 1px solid var(--line-strong);
    font-weight: 600;
}

.badge-alert {
    --badge-color: var(--status-blocked);
    --badge-tint: transparent;
    border: 1px solid var(--status-blocked);
    font-size: var(--text-micro);
}

/* ------------------------------------------------------------------ actors */

/*
 * Who did this — an agent or a human, and which agent. The distinction has to
 * hold in black and white, so it is carried by fill: an agent is a solid chip
 * in its own colour, a human is the same chip outlined and empty. The colour
 * then tells the agents apart, and the monogram tells them apart again for
 * anyone who sees neither.
 */
.actor {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
    font-size: var(--text-meta);
    color: var(--ink-soft);
    white-space: nowrap;
}

.actor-chip {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    flex: none;
    border: 1px solid var(--actor-color, var(--ink-faint));
    border-radius: var(--radius);
    font-size: 0.5625rem;
    font-weight: 700;
    line-height: 1;
}

.actor-agent .actor-chip {
    background: var(--actor-color, var(--ink-faint));
    color: #fff;
}

.actor-human .actor-chip {
    background: transparent;
    color: var(--actor-color, var(--ink-faint));
}

.actor-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ----------------------------------------------------------------- results */

/*
 * Results left, filters right — the pattern taken from KDS. Below 1200px the
 * filter card cannot hold a column of its own, so it moves above the results
 * as a <details> the reader opens on demand; that is the single breakpoint
 * rule, applied to every list screen.
 */
.results {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-6);
    align-items: start;
}

.results-main {
    min-width: 0;
}

/* A <details> at every width. Below 1200px it is the only way the filter card
   can sit above a screenful of rows without costing a screenful of its own;
   above it, it is open and the summary reads as the card's heading. */
.filters {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    padding: var(--space-5);
}

.filters > summary {
    margin-bottom: var(--space-4);
    font-size: var(--text-small);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-faint);
    cursor: pointer;
}

.filters:not([open]) > summary {
    margin-bottom: 0;
}

.filters-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.filters-summary {
    margin: var(--space-4) 0 0;
    padding-top: var(--space-4);
    border-top: 1px solid var(--line);
    font-size: var(--text-tiny);
    color: var(--ink-faint);
}

/* The resolution filter only means something once closed tickets are in the
   list. Dimmed and disabled rather than hidden: the reader learns the rule. */
.filters .field-dependent {
    opacity: 0.55;
}

.filters .field-dependent:has(select:not(:disabled)) {
    opacity: 1;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-6);
    margin-top: var(--space-4);
    font-size: var(--text-meta);
    color: var(--ink-soft);
}

.pagination-links {
    display: flex;
    gap: var(--space-2);
}

/* ------------------------------------------------------------------- forms */

.field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.field + .field {
    margin-top: var(--space-4);
}

.filters-body .field + .field {
    margin-top: 0;
}

.field > label,
fieldset > legend {
    font-size: var(--text-small);
    font-weight: 700;
    color: var(--ink-soft);
    padding: 0;
}

input[type='text'],
input[type='email'],
input[type='password'],
input[type='date'],
input[type='search'],
select,
textarea {
    width: 100%;
    height: var(--control-h);
    padding: 0 var(--space-3);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font-size: var(--text-ui);
}

textarea {
    height: auto;
    min-height: 4.875rem;
    padding: var(--space-3);
    line-height: 1.55;
    resize: vertical;
}

select {
    padding-right: var(--space-6);
}

input:disabled,
select:disabled,
textarea:disabled {
    background: var(--sunken);
    color: var(--ink-faint);
}

::placeholder {
    color: var(--ink-faint);
}

input[type='checkbox'],
input[type='radio'] {
    accent-color: var(--button-fill);
    margin: 0;
    flex: none;
}

.help,
.form-help {
    margin: 0;
    font-size: var(--text-tiny);
    color: var(--ink-faint);
}

ul.form-error-messages,
.form-error-message {
    margin: 0;
    padding: 0;
    list-style: none;
    color: var(--status-blocked);
    font-size: var(--text-small);
    font-weight: 700;
}

.field-invalid input,
.field-invalid select,
.field-invalid textarea {
    border-color: var(--status-blocked);
}

fieldset {
    margin: 0;
    padding: 0;
    border: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.choice-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    margin-top: 2px;
}

.choice-row,
.toggle {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-meta);
    color: var(--ink-soft);
    cursor: pointer;
}

.choice-row label {
    margin: 0;
    font-weight: 400;
    color: var(--ink);
    cursor: pointer;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    height: var(--control-h);
    padding: 0 var(--space-5);
    border: 1px solid var(--button-fill);
    border-radius: var(--radius);
    background: var(--button-fill);
    color: #fff;
    font-size: var(--text-ui);
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}

.button:hover {
    background: var(--button-fill-hover);
    border-color: var(--button-fill-hover);
    color: #fff;
}

.button-quiet {
    background: var(--surface);
    border-color: var(--line-strong);
    color: var(--ink);
}

.button-quiet:hover {
    background: var(--sunken);
    border-color: var(--ink-faint);
    color: var(--ink);
}

.button-danger {
    background: transparent;
    border-color: var(--line-strong);
    color: var(--status-blocked);
    font-weight: 600;
}

.button-danger:hover {
    background: var(--tint-blocked);
    border-color: var(--status-blocked);
    color: var(--status-blocked);
}

.button-block {
    width: 100%;
}

/* Reset is a link that happens to sit among buttons; making it look like one
   would give it the same weight as applying the filter. */
.link-button {
    padding: 0;
    border: 0;
    background: none;
    color: var(--ink-soft);
    font-size: var(--text-small);
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.link-button:hover {
    color: var(--ink);
}

.actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin-top: var(--space-4);
}

.actions .help {
    font-size: var(--text-tiny);
}

/* ---------------------------------------------------------------- ticket */

.ticket-head {
    display: flex;
    align-items: flex-start;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-bottom: var(--space-7);
}

.ticket-key {
    flex: none;
    padding-top: 3px;
    font-family: var(--mono);
    font-size: var(--text-ui);
    font-weight: 700;
    color: var(--ink-faint);
    white-space: nowrap;
}

.ticket-head h1 {
    max-width: 56rem;
    text-wrap: pretty;
}

.ticket-head .badge {
    margin-top: 3px;
    flex: none;
    padding: 2px 8px;
    font-size: var(--text-small);
}

.ticket-detail {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-7);
    align-items: start;
}

.ticket-main {
    min-width: 0;
}

.ticket-aside {
    display: flex;
    flex-direction: column;
    gap: var(--space-7);
}

.ticket-description {
    max-width: 47.5rem;
    margin-bottom: 1.625rem;
    color: var(--ink-soft);
    font-size: var(--text-lead);
    line-height: 1.65;
}

.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}

.section-head span {
    font-size: var(--text-small);
    color: var(--ink-faint);
}

.ticket-comment-form {
    margin-top: 1.625rem;
    max-width: 51rem;
}

/* Editing a ticket by hand is the exception — the agents do it — so the form
   is folded away behind its own heading instead of taking a screenful. */
.panel > summary {
    font-size: var(--text-small);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-faint);
    cursor: pointer;
}

.panel[open] > summary {
    margin-bottom: var(--space-4);
}

/* A folded form above a full-width list, rather than beside it. */
.form-panel {
    margin-bottom: var(--space-6);
    padding: var(--space-5);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

/* Two columns as soon as there is room, so a four-field form does not stand
   taller than the list it belongs to. */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
    gap: 0 var(--space-6);
    align-items: start;
}

.form-grid > .field:first-child {
    margin-top: 0;
}

.meta-list {
    margin: 0;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: var(--space-2) var(--space-5);
    align-items: baseline;
    padding: var(--space-4) var(--space-5);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: var(--text-ui);
}

.meta-list dt {
    color: var(--ink-faint);
    font-size: var(--text-small);
}

.meta-list dd {
    margin: 0;
    text-align: right;
    color: var(--ink);
}

/* ---------------------------------------------------------------- timeline */

/*
 * Two natures of entry share one chronology, and they are not given equal
 * weight. A comment is a body of text and gets a surface to sit on; a status
 * change is one line and gets no container at all — a box around six words
 * would make the log look busier than the discussion. The rail dot separates
 * them again: filled for a comment, hollow for a change.
 */
.timeline {
    margin: 0;
    padding: 0 0 0 1.125rem;
    border-left: 1px solid var(--line);
    list-style: none;
    max-width: 51rem;
}

.timeline > li {
    position: relative;
    padding-bottom: var(--space-5);
}

.timeline > li:last-child {
    padding-bottom: 0;
}

.timeline > li::before {
    content: '';
    position: absolute;
    left: -1.4375rem;
    width: 7px;
    height: 7px;
    border: 1px solid var(--line-strong);
    border-radius: 50%;
    background: var(--canvas);
}

.timeline-change::before {
    top: 0.5rem;
}

.timeline-comment::before {
    top: 0.375rem;
    width: 9px;
    height: 9px;
    left: -1.5rem;
    border-color: var(--ink-faint);
    background: var(--ink-faint);
}

.timeline-change {
    display: flex;
    align-items: baseline;
    gap: var(--space-3);
    flex-wrap: wrap;
    font-size: var(--text-ui);
    color: var(--ink-soft);
}

.timeline-changes {
    margin: 0;
    padding: 0;
    list-style: none;
}

.timeline-changes li + li {
    margin-top: 2px;
}

.timeline-changes .from {
    text-decoration: line-through;
    color: var(--ink-faint);
}

.timeline-changes .to {
    font-weight: 700;
    color: var(--ink);
}

.timeline-head {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0 0 var(--space-1);
    font-size: var(--text-ui);
}

.timeline-head .actor-name {
    font-weight: 700;
    color: var(--ink);
}

.timeline-head time,
.timeline-change time {
    color: var(--ink-faint);
    font-size: var(--text-small);
}

.timeline-body {
    padding: var(--space-4) var(--space-5);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink-soft);
    font-size: var(--text-body);
    line-height: 1.6;
}

.attachments {
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: var(--text-ui);
}

.attachments li + li {
    margin-top: var(--space-3);
    padding-top: var(--space-3);
    border-top: 1px solid var(--line);
}

.attachments .help {
    display: block;
}

.empty-note {
    margin: 0;
    font-size: var(--text-meta);
    color: var(--ink-faint);
}

/* -------------------------------------------------------------------- prose */

.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p { margin: 0 0 var(--space-4); }
.prose ul, .prose ol { margin: 0 0 var(--space-4); padding-left: 1.125rem; }
.prose li + li { margin-top: 2px; }
.prose strong { color: var(--ink); }

.prose code {
    padding: 0 4px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--sunken);
    font-family: var(--mono);
    font-size: 0.9em;
}

.prose pre {
    overflow-x: auto;
    padding: var(--space-4);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--sunken);
}

.prose pre code {
    border: 0;
    background: none;
    padding: 0;
}

.prose blockquote {
    margin: 0 0 var(--space-4);
    padding-left: var(--space-4);
    border-left: 2px solid var(--line-strong);
    color: var(--ink-soft);
}

/* -------------------------------------------------------------- api tokens */

/*
 * The plain token is shown once and never again. It gets the accent — the only
 * screen besides the mark and the focus ring where the orange is spent — a
 * heading that says what to do, and no competing action next to it.
 */
.token-reveal {
    margin: 0 0 var(--space-6);
    padding: var(--space-5) var(--space-6);
    border: 1px solid var(--accent);
    border-left-width: var(--gutter-w);
    border-radius: var(--radius);
    background: var(--surface);
}

.token-reveal-warning {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin: 0 0 var(--space-2);
    font-size: var(--text-body);
    font-weight: 700;
}

.token-reveal-warning::before {
    content: '';
    width: 7px;
    height: 7px;
    flex: none;
    border-radius: 50%;
    background: var(--accent);
}

.token-reveal-value {
    display: block;
    overflow-wrap: anywhere;
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--sunken);
    font-family: var(--mono);
    font-size: var(--text-ui);
    user-select: all;
}

.token-reveal .help {
    margin-top: var(--space-3);
}

/* ------------------------------------------------------------------- login */

.login {
    display: flex;
    min-height: 100dvh;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
}

.login-inner {
    width: 100%;
    max-width: 21.25rem;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin: 0 0 var(--space-7);
    font-size: 1.1875rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.login-card {
    padding: var(--space-6);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.login-alert {
    margin: 0 0 var(--space-5);
    padding: var(--space-2) var(--space-4);
    border: 1px solid var(--status-blocked);
    border-left-width: var(--gutter-w);
    border-radius: var(--radius);
    background: var(--tint-blocked);
    color: var(--status-blocked);
    font-size: var(--text-ui);
}

.login-card .toggle {
    margin-top: var(--space-4);
}

.login-note {
    margin: var(--space-5) 0 0;
    font-size: var(--text-small);
    color: var(--ink-faint);
}

/* ---------------------------------------------------------- below 1200px */

/*
 * One rule, applied everywhere: the right-hand column stops being a column.
 * Filters and the ticket sidebar move above the content, the filter card
 * becomes a <details> so it costs one line when closed, and the rail collapses
 * to icons unless the reader has pinned it open.
 */
@media (min-width: 75rem) {
    .results {
        grid-template-columns: minmax(0, 2fr) minmax(17.5rem, 1fr);
    }

    .ticket-detail {
        grid-template-columns: minmax(0, 1fr) 18.75rem;
    }

    .results .filters,
    .ticket-aside {
        position: sticky;
        top: calc(var(--topbar-h) + var(--space-4));
    }

    /* The markup puts the filters first so a single column reaches them before
       a screenful of rows; here they go back to the right-hand third. */
    .results-main { order: 1; }
    .results-side { order: 2; }
}

@media (max-width: 74.9375rem) {
    .rail:not(.rail-pinned) {
        width: var(--rail-w-narrow);
    }

    .rail:not(.rail-pinned) .rail-label,
    .rail:not(.rail-pinned) .rail-section,
    .rail:not(.rail-pinned) .rail-user {
        display: none;
    }

    .rail:not(.rail-pinned) .rail-brand,
    .rail:not(.rail-pinned) .rail-nav a,
    .rail:not(.rail-pinned) .rail-foot {
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
    }
}

/* ----------------------------------------------------------- below 700px */

/*
 * Consultation on a phone is rare but must not break. The rail becomes a tab
 * bar at the bottom, and every grid row folds into a card through named areas
 * — same markup, no duplicate template, no viewport guess on the server.
 */
@media (max-width: 43.6875rem) {
    .app {
        flex-direction: column;
    }

    .rail-region {
        order: 2;
        position: sticky;
        bottom: 0;
        z-index: 12;
    }

    .rail {
        width: 100%;
        height: auto;
        position: static;
        flex-direction: row;
        padding: 0;
        border-top: 1px solid var(--line);
        background: var(--surface);
    }

    .rail-brand,
    .rail-section,
    .rail-user,
    .rail-label {
        display: none;
    }

    .rail-nav {
        flex: 1;
        flex-direction: row;
        padding: 0;
    }

    .rail-nav a {
        flex: 1;
        flex-direction: column;
        justify-content: center;
        gap: 3px;
        height: 3.75rem;
        border-radius: 0;
        color: var(--ink-faint);
        font-size: var(--text-tiny);
    }

    .rail-nav a .rail-label {
        display: block;
    }

    .rail-nav a[aria-current='page'] {
        background: var(--sunken);
        color: var(--ink);
    }

    .rail-nav svg {
        width: 20px;
        height: 20px;
    }

    .rail-foot {
        margin: 0;
        padding: 0;
        border-top: 0;
        border-left: 1px solid var(--line);
        width: 4rem;
        justify-content: center;
    }

    .rail-icon-button {
        width: 100%;
        height: 3.75rem;
        justify-content: center;
        color: var(--ink-faint);
    }

    .main {
        order: 1;
    }

    .page {
        padding: var(--space-5) var(--space-5) var(--space-7);
    }

    .page-head {
        flex-direction: column;
        align-items: stretch;
        gap: var(--space-4);
    }

    /* Cards, not rows. The grid keeps its markup and changes its shape. */
    .grid {
        border-left: 0;
        border-right: 0;
        border-radius: 0;
        margin: 0 calc(var(--space-5) * -1);
    }

    .grid-head {
        display: none;
    }

    .grid-row {
        height: auto;
        min-height: 3.625rem;
        padding: var(--space-4) var(--space-5);
        column-gap: var(--space-3);
        row-gap: 3px;
        align-items: baseline;
    }

    .grid-row > * {
        white-space: normal;
    }

    .grid-projects .grid-row {
        grid-template-columns: auto 1fr auto;
        grid-template-areas:
            'key  name   when'
            'path active blocked';
    }

    .grid-tickets .grid-row {
        grid-template-columns: auto 1fr auto;
        grid-template-areas:
            'key   status status'
            'title title  title'
            'type  actor  when';
    }

    .grid-tokens .grid-row {
        grid-template-columns: 1fr auto;
        grid-template-areas:
            'label    action'
            'agent    selector'
            'scopes   scopes'
            'used     used';
    }

    .c-key { grid-area: key; }
    .c-name { grid-area: name; font-size: var(--text-lead); }
    .c-path { grid-area: path; }
    .c-active { grid-area: active; }
    .c-blocked { grid-area: blocked; }
    .c-when { grid-area: when; }
    .c-title { grid-area: title; font-size: var(--text-lead); line-height: 1.4; text-wrap: pretty; }
    .c-type { grid-area: type; }
    .c-status { grid-area: status; }
    .c-actor { grid-area: actor; }
    .c-label { grid-area: label; font-size: var(--text-lead); font-weight: 700; }
    .c-selector { grid-area: selector; text-align: right; }
    .c-agent { grid-area: agent; }
    .c-scopes { grid-area: scopes; overflow-wrap: anywhere; }
    .c-used { grid-area: used; text-align: left; }
    .c-action { grid-area: action; }

    .c-when,
    .c-active,
    .c-blocked {
        font-size: var(--text-tiny);
    }

    /* Anything a finger has to hit grows to 44px; nothing else moves. */
    .button,
    .rail-nav a,
    input[type='text'],
    input[type='email'],
    input[type='password'],
    input[type='date'],
    input[type='search'],
    select {
        height: var(--touch-h);
        font-size: var(--text-lead);
    }

    .toggle,
    .choice-row {
        min-height: var(--touch-h);
    }

    .meta-list dd {
        text-align: left;
    }

    .ticket-detail,
    .results {
        gap: var(--space-6);
    }
}
