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

/* Behavior islands (doc/sse.md): a custom element that adds listeners to
   server-rendered markup without introducing a layout box itself. */
.island { display: contents; }

:root {
    /* native widgets (scrollbars, form controls) follow the theme */
    color-scheme: dark;
    --bg-base: #0f131a;
    --bg-wash: linear-gradient(170deg, #0f131a 0%, #141922 55%, #12161f 100%);
    --surface-1: #191e29;
    --surface-2: #212735;
    --surface-3: #2a3141;
    --border: rgba(217, 226, 236, 0.08);
    --border-strong: rgba(217, 226, 236, 0.15);
    --border-accent: rgba(224, 93, 43, 0.35);
    --text-primary: #d9e2ec;
    --text-secondary: #9fb3c8;
    --text-muted: #627d98;
    --accent: #e05d2b;
    --accent-strong: #f36f41;
    --accent-soft: rgba(224, 93, 43, 0.12);
    /* white on the accent reads 3.6:1, so a self bubble is a muted shade:
       6.1:1, same warm family */
    --chat-bubble-self: #9c4a2c;
    --success: #2f9e6e;
    --warning: #c8912e;
    --danger: #d1493b;
    --warm: #e05d2b;
    --logo-dot: #e05d2b;
    --nav-height: 56px;
    --container-max: 1180px;
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.25);
}

[data-theme="light"] {
    color-scheme: light;
    --bg-base: #f4f6f9;
    --bg-wash: linear-gradient(170deg, #f4f6f9 0%, #ebedf2 55%, #f4f6f8 100%);
    --surface-1: #fafbfd;
    --surface-2: #f4f6f9;
    --surface-3: #e2e6ed;
    --border: rgba(0, 0, 0, 0.06);
    --border-strong: rgba(0, 0, 0, 0.13);
    --border-accent: rgba(194, 101, 67, 0.3);
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --accent: #c26543;
    --accent-strong: #aa5232;
    --accent-soft: rgba(194, 101, 67, 0.08);
    --chat-bubble-self: var(--accent);
    --warm: #c26543;
    --success: #1e7d52;
    --warning: #a27526;
    --danger: #b83a2e;
    --logo-dot: #c26543;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
}

body {
    font-family: Seravek, "Gill Sans Nova", Ubuntu, Calibri, "DejaVu Sans", "Noto Sans", "Liberation Sans", sans-serif;
    background: var(--bg-base);
    background-image: var(--bg-wash);
    color: var(--text-primary);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.15s ease, color 0.15s ease;
}

/* Scrollbars, every view: one thin themed bar for the page scroll and for
   any box that scrolls inside it (the users chart, a settings preview, a
   code block) — no page falls back to the browser's default chrome. The
   colours are vars, so [data-theme] needs no copy of this block. */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

*::-webkit-scrollbar { width: 8px; height: 8px; }

*::-webkit-scrollbar-track { background: transparent; }

*::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

::selection {
    background: var(--accent);
    color: #fff;
}

/* On a box that already is the accent, the selection wash lightens and the
   text flips to ink — theme-independent, since the accent is mid-tone either
   way. */
.chat-message-self .chat-message-body::selection,
.chat-message-self .chat-message-body ::selection,
.btn-primary::selection,
.btn-primary ::selection,
.mention-count::selection,
.mention-count ::selection,
.mention-mark::selection,
.mention-mark ::selection,
.notif-count::selection,
.notif-count ::selection {
    background: rgba(255, 255, 255, 0.55);
    color: #14181f;
}

a {
    color: inherit;
    text-decoration: none;
}

.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    height: var(--nav-height);
    padding: 0 1.5rem;
    background: var(--surface-1);
    box-shadow: inset 0 -1px 0 var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.logo span {
    color: var(--logo-dot);
}

.navbar-actions {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    min-width: 0;
}

.navbar-left {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
}

/* notification bell (doc/chat.md §Unread/read): quiet until there is a count;
   the search entry beside it (§Search) is the same round icon link */
.notif-bell,
.navbar-search {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    border-radius: 50%;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.notif-bell:hover,
.navbar-search:hover {
    background: var(--surface-2);
    color: var(--text-primary);
}

.notif-count {
    position: absolute;
    top: -0.1rem;
    right: -0.1rem;
    min-width: 1rem;
    padding: 0 0.25rem;
    border-radius: 999px;
    background: var(--accent);
    color: var(--accent-text-on-solid, #fff);
    font-size: 0.6rem;
    font-weight: 700;
    line-height: 1rem;
    text-align: center;
}

.nav-menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.nav-menu-toggle:hover {
    background: var(--surface-2);
    color: var(--text-primary);
}

.nav-menu-toggle .nav-icon {
    width: 20px;
    height: 20px;
}

.user-email {
    color: var(--text-secondary);
    font-size: 0.85rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn,
.theme-toggle {
    transition: color 0.12s ease, border-color 0.12s ease, background-color 0.12s ease;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    padding: 0.5rem 1rem;
    min-width: 120px;
    cursor: pointer;
}

.btn:active:not(:disabled) {
    transform: scale(0.97);
}

.btn-sm {
    padding: 0.35rem 0.7rem;
    font-size: 0.8rem;
    min-width: auto;
}

/* icon-only buttons (org chart node actions) */
.btn-icon {
    min-width: auto;
    padding: 0.3rem;
}

.btn-loading {
    position: relative;
}

/* Hidden unless the button is busy — as a flex item an empty span would
   also add its gap and knock the label off-center. */
.btn-spinner {
    display: none;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
}

.btn-loading .btn-text {
    visibility: visible;
}

.btn-loading .btn-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 14px;
    height: 14px;
    display: none;
    animation: spin 0.7s linear infinite;
}

.btn-loading:disabled .btn-text {
    visibility: hidden;
}

.btn-loading:disabled .btn-spinner {
    display: block;
}

.btn-primary {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

.btn-primary:hover {
    color: #fff;
    background: var(--accent-strong);
    border-color: var(--accent-strong);
    box-shadow: var(--shadow-sm);
}

.btn-outline {
    color: var(--text-secondary);
    border-color: var(--border-strong);
    background: transparent;
}

.btn-outline:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}

/* Quiet borderless buttons for dense/inline actions */

.btn-ghost {
    color: var(--text-secondary);
    background: transparent;
    border-color: transparent;
}

.btn-ghost:hover {
    color: var(--text-primary);
    background: var(--surface-3);
}

.btn-ghost-success {
    color: var(--success);
    background: transparent;
    border-color: transparent;
}

.btn-ghost-success:hover {
    color: var(--success);
    background: rgba(47, 158, 110, 0.12);
}

.btn-ghost-danger {
    color: var(--danger);
    background: transparent;
    border-color: transparent;
}

.btn-ghost-danger:hover {
    color: var(--danger);
    background: rgba(209, 73, 59, 0.12);
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Native date/time picker theming */
[data-theme="dark"] input[type="date"],
[data-theme="dark"] input[type="time"] {
    color-scheme: dark;
}

.badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    padding: 0.15rem 0.5rem;
    border: 1px solid transparent;
}

.badge-accent {
    color: var(--accent-strong);
    background: var(--accent-soft);
    border-color: rgba(42, 157, 143, 0.2);
}

.badge-success {
    color: var(--success);
    background: rgba(47, 158, 110, 0.1);
    border-color: rgba(47, 158, 110, 0.2);
}

.badge-warning {
    color: var(--warning);
    background: rgba(200, 145, 46, 0.1);
    border-color: rgba(200, 145, 46, 0.2);
}

.card {
    background: var(--surface-2);
    border-radius: var(--radius-md);
    padding: 1.25rem;
}

.panel-note {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.theme-toggle {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.theme-toggle:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.theme-toggle svg {
    width: 16px;
    height: 16px;
}

.theme-toggle .sun-icon { display: none; }
.theme-toggle .moon-icon { display: block; }
[data-theme="light"] .theme-toggle .sun-icon { display: block; }
[data-theme="light"] .theme-toggle .moon-icon { display: none; }

/* App shell layout */
.app-layout {
    display: flex;
    flex: 1;
    min-height: calc(100dvh - var(--nav-height));
}

.sidebar {
    width: 240px;
    background: var(--surface-1);
    padding: 1rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    top: var(--nav-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.55rem 0.85rem;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    transition: color 0.12s ease, background-color 0.12s ease;
}

.nav-link:hover {
    color: var(--text-secondary);
    background: var(--surface-2);
}

.nav-link.active {
    color: var(--text-primary);
    background: var(--surface-3);
}

/* Sidebar navigation tree (doc/chat.md): Chat > channel/Threads/Mentions,
   then the Direct messages section */
.nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.nav-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-count {
    min-width: 1.35rem;
    margin-left: auto;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 700;
    text-align: center;
}

.nav-count:empty { display: none; }

/* unread pills (sidebar DM rows): quiet — the mention count is
   the one that should catch the eye (doc/chat.md §Mentions) */
.unread-count {
    min-width: 1.35rem;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 700;
    text-align: center;
    flex-shrink: 0;
}

.unread-count:empty { display: none; }

.nav-link .unread-count { margin-left: auto; }

/* the Mentions nav count: accent, like the bell and the @ row marks — a
   mention is the signal that shouts (doc/chat.md §Mentions) */
.mention-count {
    min-width: 1.35rem;
    margin-left: auto;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    background: var(--accent);
    color: var(--accent-text-on-solid, #fff);
    font-size: 0.68rem;
    font-weight: 700;
    text-align: center;
    flex-shrink: 0;
}

.mention-count:empty { display: none; }

/* mention marker (doc/chat.md §Mentions): the accent @ badge on a room or
   thread row that has unread mentions for the viewer */
.mention-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.05rem;
    padding: 0 0.25rem;
    border-radius: 999px;
    background: var(--accent);
    color: var(--accent-text-on-solid, #fff);
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 1rem;
    flex-shrink: 0;
}

.nav-group {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.nav-group-items {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    margin: 0.05rem 0 0.2rem 0.55rem;
    padding-left: 0.55rem;
    border-left: 1px solid var(--border);
}

/* the group's own header — a label, not a link (doc/chat.md) */
.nav-group-label {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.5rem 0.85rem 0.15rem;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* Desktop: collapse to an icon rail (toggled from the navbar, persisted in
   localStorage; the pre-paint script avoids a flash of the open rail). */
.sidebar {
    transition: width 0.18s ease, padding 0.18s ease;
}

.sidebar-collapsed .sidebar {
    width: 60px;
    padding-left: 0.4rem;
    padding-right: 0.4rem;
}

.sidebar-collapsed .sidebar .nav-link,
.sidebar-collapsed .sidebar .nav-group-label {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

.sidebar-collapsed .nav-label,
.sidebar-collapsed .nav-count {
    display: none;
}

/* The rail is still navigation: the Chat group's children keep their icons
   (only labels/counts hide), flattened since the indent rule has no room in
   60px — otherwise /chat and /chat/threads would be unreachable. */
.sidebar-collapsed .nav-group-items {
    margin-left: 0;
    padding-left: 0;
    border-left: none;
}

.main-content {
    flex: 1;
    padding: 1.75rem 1.5rem 2.5rem;
}

@media (max-width: 820px) {
    .navbar {
        height: var(--nav-height);
        flex-wrap: nowrap;
        gap: 0.5rem;
        padding: 0 1rem;
        position: static;
    }

    .user-email {
        max-width: 9rem;
    }

    .nav-menu-toggle {
        display: inline-flex;
    }

    /* the drawer is never an icon rail, whatever the desktop preference */
    .sidebar-collapsed .sidebar {
        width: 260px;
        padding: 1rem 0.75rem;
    }

    .sidebar-collapsed .sidebar .nav-link {
        justify-content: flex-start;
        padding: 0.55rem 0.85rem;
    }

    .sidebar-collapsed .sidebar .nav-group-label {
        justify-content: flex-start;
        padding: 0.5rem 0.85rem 0.15rem;
    }

    .sidebar-collapsed .nav-label { display: inline; }
    .sidebar-collapsed .nav-count:not(:empty) { display: inline; }
    .sidebar-collapsed .nav-group-items {
        display: flex;
        margin: 0.05rem 0 0.2rem 0.55rem;
        padding-left: 0.55rem;
        border-left: 1px solid var(--border);
    }

    .app-layout {
        flex-direction: column;
    }

    .main-content {
        padding-top: 1rem;
    }

    /* the orgol bar is static at this width (it scrolls away), so the drawer
       and its backdrop own the viewport rather than starting below the bar */
    .sidebar-backdrop { top: 0; }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100dvh;
        width: 260px;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        border-bottom: none;
        border-right: 1px solid var(--border);
        padding: 1rem 0.75rem;
        flex-direction: column;
        gap: 0.2rem;
        overflow-y: auto;
    }

    .sidebar-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-open .sidebar-backdrop {
        display: block;
    }

    .sidebar-nav {
        flex-direction: column;
        overflow-x: visible;
        gap: 0.2rem;
        width: auto;
        align-items: stretch;
    }

}

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

/* Placeholder pages */
.placeholder-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 60vh;
    padding: 2rem 1rem;
    gap: 1.25rem;
}

.placeholder-title {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.placeholder-description {
    font-size: 1rem;
    color: var(--text-secondary);
    max-width: 420px;
    line-height: 1.6;
}

.placeholder-status {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.status-badge {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--accent-strong);
    background: var(--accent-soft);
    border: 1px solid rgba(42, 157, 143, 0.25);
    border-radius: var(--radius-sm);
    padding: 0.2rem 0.6rem;
}

/* Quiet dot status (no box) for dense lists */

/* --- Flat Form System --- */

.form-field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.form-field label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.form-field input,
.form-field select,
.form-field textarea {
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-1);
    color: var(--text-primary);
    font-size: 0.9rem;
    width: 100%;
    font-family: inherit;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.form-field textarea {
    resize: vertical;
    min-height: 6.5rem;
    line-height: 1.5;
}

.form-field select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
    padding-right: 2rem;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.form-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}

.form-error {
    color: var(--danger, #e5484d);
    font-size: 0.82rem;
    margin-top: 0.5rem;
    min-height: 1.2rem;
}

.form-error p {
    margin: 0;
}

/* Button color variants */

/* Magic-link hand-off (the users page): the minted URL inline under its
   node, in the same #user-edit-<id> anchor as the display-name editor.
   The URL row stacks on a phone so the long URL cannot widen the chart. */
.magic-link-inline {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin: 0.15rem 0 0.35rem 3rem;
}

.magic-link-warn {
    margin: 0;
    color: var(--warning);
    font-size: 0.78rem;
}

.magic-link-url-row {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}

.magic-link-url {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-1);
    color: var(--text-primary);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.8rem;
}

.magic-link-url:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.magic-link-copy {
    flex: 0 0 auto;
}

@media (max-width: 600px) {
    .magic-link-inline { margin-left: 0; }
    .magic-link-url-row { flex-direction: column; }
    .magic-link-copy, .magic-link-close { width: 100%; }
}

/* Org chart (the users page): an indented nested-list tree with connector
   lines, ported from v1's People page (Features/OrgChart/OrgChartPage). */
.orgchart-panel {
    display: block;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-1);
    padding: 1rem 1.25rem;
}

.orgchart-tree,
.orgchart-children {
    list-style: none;
    margin: 0;
    padding: 0;
}

.orgchart-children {
    padding-left: 2.25rem;
    position: relative;
    margin-top: 0.4rem;
}

.orgchart-children::before {
    content: "";
    position: absolute;
    left: 0.85rem;
    top: 0;
    bottom: 0.6rem;
    width: 1px;
    background: var(--border);
}

.orgchart-node {
    position: relative;
    padding: 0.2rem 0;
}

.orgchart-node:has(.orgchart-more[open]) {
    z-index: 20;
}

.orgchart-children .orgchart-node::before {
    content: "";
    position: absolute;
    left: -1.4rem;
    top: 1.35rem;
    width: 1.4rem;
    height: 1px;
    background: var(--border);
}

.orgchart-node-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.35rem 0.5rem;
    border-radius: var(--radius-sm);
}

.orgchart-node-content:hover,
.orgchart-node-content:has(.orgchart-more[open]) {
    background: var(--surface-2);
}

.orgchart-node-label {
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* a shrunk label must wrap long emails, not paint under the actions */
    overflow-wrap: anywhere;
}

.orgchart-node-name {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    font-weight: 600;
    font-size: 0.92rem;
}

.orgchart-reports {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.orgchart-node-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-left: auto;
    flex-shrink: 0;
}

/* Inline display-name editor (the pencil's @get fragment) */
.orgchart-edit-form {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0.15rem 0 0.35rem 3rem;
}

.orgchart-edit-input {
    min-width: 14rem;
    padding: 0.3rem 0.55rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text-primary);
    font-size: 0.85rem;
}

.orgchart-edit-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

/* Inline mention-email pill on a chart row */
.notify-inline-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.22rem 0.55rem;
    border-radius: 999px;
    font: inherit;
    font-size: 0.74rem;
    font-weight: 600;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.12s ease, border-color 0.12s ease, background-color 0.12s ease;
    white-space: nowrap;
}

.notify-inline-pill:hover {
    border-color: var(--text-muted);
    color: var(--text-primary);
    background: var(--surface-3);
}

.notify-inline-pill.on {
    color: var(--text-primary);
    border-color: rgba(47, 158, 110, 0.35);
    background: rgba(47, 158, 110, 0.1);
}

.notify-inline-pill.on:hover {
    border-color: var(--success);
    background: rgba(47, 158, 110, 0.16);
}

.notify-inline-pill .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}

.notify-inline-pill.on .dot {
    background: var(--success);
}

/* Anchored More dropdown on a chart node */
.orgchart-more {
    position: relative;
}

.orgchart-more > summary {
    list-style: none;
}

.orgchart-more > summary::-webkit-details-marker {
    display: none;
}

.orgchart-more[open] > summary {
    color: var(--text-primary);
    background: var(--surface-3);
}

.orgchart-menu {
    position: absolute;
    top: calc(100% + 0.25rem);
    right: 0;
    z-index: 60;
    min-width: 12.5rem;
    padding: 0.25rem;
    background: var(--surface-1);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.orgchart-menu-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.4rem 0.55rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-primary);
    font: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    text-align: left;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.1s ease, color 0.1s ease;
}

.orgchart-menu-item .nav-icon {
    width: 15px;
    height: 15px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.orgchart-menu-item:hover,
.orgchart-menu-item:focus-visible {
    background: var(--surface-2);
}

.orgchart-menu-item:hover .nav-icon,
.orgchart-menu-item:focus-visible .nav-icon {
    color: var(--text-primary);
}

.orgchart-menu-item-success {
    color: var(--success);
}

.orgchart-menu-item-success .nav-icon,
.orgchart-menu-item-success:hover .nav-icon,
.orgchart-menu-item-success:focus-visible .nav-icon {
    color: var(--success);
}

.orgchart-menu-item-danger {
    color: var(--danger);
}

.orgchart-menu-item-danger .nav-icon,
.orgchart-menu-item-danger:hover .nav-icon,
.orgchart-menu-item-danger:focus-visible .nav-icon {
    color: var(--danger);
}

.orgchart-menu-item-danger:hover,
.orgchart-menu-item-danger:focus-visible {
    background: rgba(209, 73, 59, 0.12);
}

.orgchart-menu-divider {
    height: 1px;
    background: var(--border);
    margin: 0.15rem 0.25rem;
}

.orgchart-node-disabled > .orgchart-node-content {
    opacity: 0.55;
}

.orgchart-node[draggable="true"] {
    cursor: grab;
}

.orgchart-node[draggable="true"]:active {
    cursor: grabbing;
}

.orgchart-node.orgchart-dragging > .orgchart-node-content {
    opacity: 0.45;
}

.orgchart-node.orgchart-drop-target > .orgchart-node-content {
    background: var(--accent-soft);
    outline: 2px dashed var(--accent);
    outline-offset: -2px;
}

#users-body .form-row + .panel-note {
    margin-top: 0.35rem;
}

/* Phone: the desktop row assumes width the chart's indent eats. Stack the
   node's actions below the label (they are flex-shrink:0, so on one line
   they paint over the label once it shrinks) and cut the per-level indent
   to a step, so a deep chain stays on screen without sideways scrolling. */
@media (max-width: 600px) {
    .orgchart-panel { padding: 0.75rem; }

    .orgchart-children { padding-left: 1rem; }
    .orgchart-children::before { left: 0.35rem; }
    .orgchart-children .orgchart-node::before {
        left: -0.65rem;
        width: 0.65rem;
    }

    .orgchart-node-content {
        flex-wrap: wrap;
        row-gap: 0.3rem;
    }

    .orgchart-node-actions {
        position: relative;
        flex-basis: 100%;
        /* align with the label text: 2rem avatar + the row's 0.75rem gap */
        margin-left: 0;
        padding-left: 2.75rem;
    }

    .orgchart-more {
        position: static;
    }

    .orgchart-menu {
        left: 2.75rem;
        right: auto;
    }

    .orgchart-edit-form {
        margin-left: 0;
        flex-wrap: wrap;
    }

    .orgchart-edit-input {
        min-width: 0;
        flex: 1 1 8rem;
    }

    /* invite form: fields and button stack instead of squeezing */
    #users-body .form-row {
        flex-direction: column;
        align-items: stretch;
    }
}

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem 1rem;
    gap: 0.75rem;
    color: var(--text-muted);
}

.empty-state h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.empty-state p {
    font-size: 0.875rem;
    max-width: 320px;
}

/* Chat */
.chat-workspace {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    height: calc(100dvh - var(--nav-height) - 3.5rem);
    max-width: var(--container-max);
    margin: 0 auto;
    overflow: hidden;
}

.chat-container {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.chat-thread-pane {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

/* Channel chat: parent-only threads, replies open in the thread view */
#channel-feed {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    padding: 0.75rem;
}

/* Pagination (orgol.views/show-older): "show older" is a navigation to a
   bigger window, so the control is a plain link, not an infinite scroll. */
.chat-older {
    display: flex;
    justify-content: center;
    padding: 0.15rem 0;
}
.chat-older a {
    padding: 0.25rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
}
.chat-older a:hover {
    color: var(--accent-strong);
    border-color: var(--accent-soft, var(--border));
}

.chat-thread-link {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    margin: 0.2rem 0 0 0.25rem;
}
.chat-thread-link a {
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    text-decoration: none;
}
.chat-thread-link a:hover { color: var(--accent-strong); text-decoration: underline; }
.chat-thread-self .chat-thread-link { justify-content: flex-end; }
/* the thread's last reply holds the stamp (Google Chat's shape) */
.chat-thread-time { font-size: 0.7rem; color: var(--text-muted); }
.chat-thread-time::before { content: "·\00a0"; }

/* Message actions (orgol.views/message-actions-el, doc/chat.md §Message
   actions): Reply hangs just outside the bubble's upper inner corner —
   upper right for an incoming root, upper left for the viewer's own — so
   it never covers the message, Google Chat's shape. It is nested in the
   bubble (or the run card, or an image-only message's tile), so the hover
   that reveals it is the message's own: the row spans the full line and
   an empty patch must not pop the menu. A touch long-press opens it; the
   menu stays focusable, so Tab reveals it. Hidden with pointer-events off
   rather than display. */
.chat-msg-actions {
    position: absolute;
    top: 0;
    left: 100%;
    /* transparent padding bridges the gap to the bubble: with a margin, the
       cursor crosses unhovered space and the menu vanishes before it lands */
    padding-left: 0.35rem;
    /* above the sticky composer (6) and the jump button (7): the last row's
       menu hangs down over the composer, and a popup covered by the box it
       belongs to is unusable */
    z-index: 8;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-0.2rem);
    transition: opacity 0.12s ease, transform 0.12s ease;
}
.chat-msg-actions-self { left: auto; right: 100%; padding-left: 0; padding-right: 0.35rem; }
.chat-message-body:focus-within > .chat-msg-actions,
.chat-message-media:focus-within > .chat-msg-actions,
.chat-run:focus-within > .chat-msg-actions,
.chat-msg-actions:focus-within,
.chat-msg-actions.is-open {
    opacity: 1;
    pointer-events: auto;
    transform: none;
}
@media (hover: hover) {
    .chat-message-body:hover > .chat-msg-actions,
    .chat-message-media:hover > .chat-msg-actions,
    /* image plus text: the image is the same message's, so it reveals the
       menu nested in the bubble below it */
    .chat-message-media:hover ~ .chat-message-body > .chat-msg-actions,
    .chat-run:hover > .chat-msg-actions {
        opacity: 1;
        pointer-events: auto;
        transform: none;
    }
}
/* No room beside the bubble: a phone always, and a narrow window (the
   bubble's max width leaves less than the menu's). Tuck it into the
   bubble's top corner, anchored to the outer edge so a short bubble cannot
   push the menu off-screen — touch opens it by long-press, so it never
   floats uninvited. */
@media (hover: none), (max-width: 820px) {
    .chat-msg-actions {
        top: 0.2rem;
        left: 0.2rem;
        right: auto;
        padding: 0;
    }
    .chat-msg-actions-self { right: 0.2rem; left: auto; padding: 0; }
}
/* The viewer's own bubble caps wider (88%), so the room on its left runs
   out sooner than an incoming message's right. */
@media (hover: hover) and (max-width: 1180px) {
    .chat-msg-actions-self {
        top: 0.2rem;
        right: 0.2rem;
        left: auto;
        padding: 0;
    }
}
/* The last row's menu has nowhere to hang down into: below it is the sticky
   composer (and the viewport's edge), so a downward menu would open under
   the box it belongs to. Anchor it to the row's bottom instead and it opens
   upward over the conversation. The z-index above keeps it over the composer
   when a tall bubble still reaches it. */
#channel-feed > .chat-thread:last-child .chat-msg-actions,
.thread-pane-feed > .chat-message:last-child .chat-msg-actions {
    top: auto;
    bottom: 0;
}
.chat-msg-menu {
    display: flex;
    flex-direction: column;
    /* wide enough for the reaction strip's five cells on one row
       (doc/chat.md §Reactions) */
    min-width: 10rem;
    padding: 0.2rem;
    background: var(--surface-1);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}
.chat-msg-action {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.35rem 0.55rem;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}
.chat-msg-action:hover,
.chat-msg-action:focus-visible {
    background: var(--surface-2);
    color: var(--accent-strong);
}
/* Reply is an anchor, Quote/Edit/Delete are buttons (a browser confirm and
   signal staging, not navigations): one reset so a button brings no chrome */
button.chat-msg-action {
    width: 100%;
    border: 0;
    background: none;
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}
.chat-msg-action.chat-msg-action-danger:hover,
.chat-msg-action.chat-msg-action-danger:focus-visible {
    color: var(--danger);
}
.chat-msg-action .nav-icon { width: 16px; height: 16px; flex-shrink: 0; }
/* the hold is the menu gesture, not the system callout */
@media (hover: none) {
    .chat-message { -webkit-touch-callout: none; }
}

/* Thread list view: one compact row per thread root */
.thread-list {
    display: flex;
    flex-direction: column;
    padding: 0.15rem;
}

.thread-row {
    display: block;
    padding: 0.6rem 0.65rem;
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: inherit;
    text-decoration: none;
    transition: background 0.1s ease;
}

.thread-row:last-child { border-bottom: none; }
.thread-row:hover { background: var(--surface-2); }

/* a thread with replies newer than the viewer's per-thread marker
   (doc/chat.md §Thread highlighting): a quiet accent edge, not a badge */
.thread-row-unread {
    border-left: 2px solid var(--accent);
    padding-left: 0.5rem;
    background: var(--accent-soft);
}

.thread-row-top {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
}

.thread-row-author {
    min-width: 0;
    overflow: hidden;
    color: var(--text-primary);
    font-size: 0.8rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.thread-row-time {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 0.68rem;
    flex-shrink: 0;
}

.thread-row-snippet {
    margin-top: 0.15rem;
    color: var(--text-muted);
    font-size: 0.78rem;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.thread-row-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
    color: var(--text-muted);
    font-size: 0.68rem;
}

/* an unread mention row reads louder than a read one (doc/chat.md
   §Mentions) */
.mention-row-unread .thread-row-snippet { color: var(--text-primary); }

.thread-row-working {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--accent);
}

.thread-row-working .chat-run-dot { width: 0.4rem; height: 0.4rem; }

/* a room thread names its room in the meta line (doc/chat.md) */
.thread-row-room {
    display: inline-flex;
    align-items: center;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--text-muted);
    font-size: 0.62rem;
    font-weight: 600;
}

.thread-row-proposal {
    display: inline-flex;
    align-items: center;
    padding: 0 0.3rem;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--accent-strong);
    border: 1px solid var(--border-accent);
    border-radius: 3px;
    line-height: 1.1rem;
    flex-shrink: 0;
}

/* Search view (doc/chat.md §Search): the query box over its hits */
.search-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
}

.search-form .form-field { flex: 1; min-width: 0; }

.search-count {
    padding: 0.25rem 0.65rem 0.35rem;
    color: var(--text-muted);
    font-size: 0.72rem;
}

.search-snippet mark {
    border-radius: 2px;
    background: var(--accent-soft);
    color: var(--accent-strong);
}

/* Direct messages (doc/chat.md §Direct messages): the sidebar section and,
   on the people page, the picker that starts a conversation. */
.nav-group-rooms .nav-link {
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
}

.dm-start {
    margin-top: 2rem;
    max-width: 44rem;
}

.dm-start h2 {
    margin: 0 0 0.6rem;
    font-size: 0.95rem;
    color: var(--text-muted);
}

.dm-picker {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-1);
}

.dm-pick-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0;
    cursor: pointer;
}

.dm-picker-error {
    color: var(--danger);
    font-size: 0.85rem;
}

.dm-picker-error:empty {
    display: none;
}

/* Topbar action cluster (the run's Preview, the room's @ai controls). */
.chat-topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

.chat-topbar-actions .ai-runs-badge,
.chat-topbar-actions .chat-run-preview {
    margin-left: 0;
    margin-top: 0;
}

/* Icon-only controls; the words are title/aria-label. */
.chat-topbar-actions .btn.chat-topbar-action {
    padding-left: 0.4rem;
    padding-right: 0.4rem;
}

.chat-ai-addressing {
    display: inline-flex;
    align-items: center;
}

.chat-ai-mark {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

/* Topbar action icons: one size with the .btn-sm label, and no label on a
   phone (the control's title/aria-label carries the words). */
.chat-topbar-action .nav-icon { width: 16px; height: 16px; }

/* A busy action shows the spinner over its own glyph; a hidden (not
   removed) icon keeps the button's width from jumping. */
.chat-topbar-action.btn-loading:disabled .nav-icon { visibility: hidden; }

/* A fragment landing (#msg-<id>/#thread-<id>): the browser scrolls the
   named row into view and :target pulses it — the URL carries the pulse, so
   a morph cannot strip it. scroll-margin keeps the landing clear of the
   sticky topbar. */
@keyframes chat-focus-flash {
    0% { outline-color: var(--accent); background: var(--accent-soft); }
    100% { outline-color: transparent; background: transparent; }
}

.chat-message:target,
.thread-row:target {
    outline: 2px solid transparent;
    outline-offset: 2px;
    border-radius: var(--radius-sm);
    animation: chat-focus-flash 1.6s ease-out;
}

.chat-message,
.thread-row {
    scroll-margin-top: 3.5rem;
}

.thread-pane-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.thread-pane-feed {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    padding: 0.75rem;
}

.thread-pane-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    text-align: center;
}

.chat-input.thread-pane-composer {
    margin-top: 0;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
}

.chat-input.channel-composer { margin-top: 0.75rem; }

/* Chat top bar: the only title (doc/chat.md), pinned above the message
   scroller so it never scrolls away on a phone. A column, so a thread's
   proposal can sit under the title row inside the same sticky header. */
.chat-topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.3rem;
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-1);
}

.chat-topbar-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

/* The thread's proposal: one row per repo, because every turn commits to the
   same branch, so this state and its Delete are thread-level
   (doc/agent.md §Proposals) */
.chat-topbar-proposal {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
    padding-top: 0.25rem;
    border-top: 1px solid var(--border);
}

/* one line per repo, cut with an ellipsis rather than wrapped: the strip is in
   the sticky header and must not grow (doc/agent.md §Proposals). Delete sits
   outside the cut, so a long line never hides it. */
.chat-proposal-repo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    color: var(--text-muted);
    font-size: 0.72rem;
}

.chat-proposal-line {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.chat-proposal-line > * + * { margin-left: 0.35rem; }
.chat-proposal-delete { flex: none; margin-left: auto; }
.chat-proposal-delete .btn {
    min-height: 0;
    padding: 0.05rem 0.35rem;
    font-size: 0.68rem;
}
.chat-proposal-delete .nav-icon { width: 12px; height: 12px; }
.chat-proposal-delete .btn-loading:disabled .nav-icon { visibility: hidden; }
.chat-proposal-name { color: var(--text); font-weight: 600; }
.chat-proposal-branch,
.chat-proposal-tip {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.68rem;
}
.chat-proposal-state { color: var(--text-secondary); }
.chat-proposal-note { color: var(--accent-strong); }
.chat-proposal-more { color: var(--text-muted); font-size: 0.7rem; }

.chat-topbar-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    border-radius: 50%;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.chat-topbar-back:hover {
    background: var(--surface-2);
    color: var(--text-primary);
}

.chat-topbar-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.chat-topbar .ai-runs-badge { margin-left: auto; }
.chat-topbar .chat-run-preview { margin-top: 0; }

/* Send is an icon-only button (doc/chat.md) */
.chat-send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    min-width: 2.5rem;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
}

.chat-send:hover { background: var(--accent-strong); }
.chat-send:disabled { opacity: 0.45; cursor: default; }
.chat-send .nav-icon { width: 18px; height: 18px; }

/* Screenshot composer (doc/chat.md §Attachments): an icon label over the
   visually hidden data-bind file input, and the picked file's chip, which
   renders inside the input box (.chat-input-box). */
.chat-attach {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    min-width: 2.5rem;
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    flex-shrink: 0;
}

.chat-attach:hover,
.chat-attach:focus-within { background: var(--surface-2); color: var(--text-primary); }
.chat-attach:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.chat-attach .nav-icon { width: 18px; height: 18px; }

.chat-attach-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.chat-attach-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    align-self: flex-start;
    max-width: 100%;
    padding: 0.15rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
}

.chat-attach-chip:hover,
.chat-attach-chip:focus-visible { color: var(--text-primary); border-color: var(--accent); }
/* display:inline-flex beats the hidden attribute's UA rule — keep the two
   from fighting or an empty chip shows as a placeholder */
.chat-attach-chip[hidden] { display: none; }

.chat-attach-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-attach-remove { font-size: 0.95rem; line-height: 1; flex-shrink: 0; }

.chat-attach-error { color: var(--danger); font-size: 0.75rem; }

/* The composer's staged slots (doc/chat.md §Edit, delete, and quote): the
   quote card the next message will carry, or the notice that the composer
   holds a message being edited. Menus stage them through datastar signals
   and the send's reset clears them, so `data-show` is the only visibility
   rule here — display:none comes from the signal, never from this block. */
.chat-stage {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.chat-stage-quote,
.chat-stage-edit {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.3rem 0.5rem;
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.chat-stage-edit { border-left-color: var(--text-muted); }
.chat-stage-author { font-weight: 600; color: var(--text-primary); flex-shrink: 0; }
.chat-stage-label { font-weight: 600; color: var(--text-primary); }

.chat-stage-body {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-stage-thumb {
    max-width: 3rem;
    max-height: 2rem;
    border-radius: var(--radius-sm);
}

.chat-stage-cancel {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    min-width: 1.5rem;
    margin-left: auto;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    flex-shrink: 0;
}

.chat-stage-cancel:hover,
.chat-stage-cancel:focus-visible {
    background: var(--surface-3);
    color: var(--text-primary);
}

.chat-stage-cancel .nav-icon { width: 13px; height: 13px; }

/* The rendered screenshot: its own card beside the text bubble, not inside
   it (Google Chat's shape), so no bubble padding around the image. The
   thumbnail cap is deliberately small — click opens the bytes full-size.
   A lazy load that resizes the row is re-pinned by <chat-scroller>'s
   ResizeObserver. */
.chat-attachment {
    display: block;
    width: fit-content;
    max-width: 100%;
    margin: 0 0 0.35rem;
}

/* the image card's wrapper is the action menu's anchor when the message has
   no text bubble to hang it on (an image-only message) */
.chat-message-media { position: relative; width: fit-content; max-width: 100%; }
.chat-message-self .chat-message-media { margin-left: auto; }

.chat-attachment-img {
    display: block;
    /* a definite cap, not min(20rem, 100%): the percentage made the
       fit-content anchor resolve against the whole row, so the image sat
       left in a full-width box instead of hugging the right edge. The vw
       bound keeps a narrow phone off the edge (no containing-block cycle). */
    max-width: min(20rem, calc(100vw - 3rem));
    max-height: 16rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-2);
}

/* <chat-scroller> holds this while the viewer follows the end: a window
   slide must not anchor the page away from the newest row (composer.js). */
html.chat-following { overflow-anchor: none; }

/* Jump to latest: floats above the composer, hidden while already at the end */
.chat-jump-bottom {
    position: absolute;
    right: 1rem;
    bottom: 4.5rem;
    z-index: 7;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--text-primary);
    cursor: pointer;
    box-shadow: var(--shadow-md);
}

.chat-jump-bottom:hover { background: var(--surface-3); }
.chat-jump-bottom[hidden] { display: none; }
.chat-jump-bottom .nav-icon { width: 20px; height: 20px; }

.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.chat-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 2rem;
    font-size: 0.9rem;
}

.chat-message-self {
    text-align: right;
    max-width: min(88%, 50rem);
    margin-left: auto;
}

.chat-message-header {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.15rem;
    padding-left: 0.25rem;
}

.chat-message-self .chat-message-header {
    justify-content: flex-end;
}

.chat-message-self .chat-message-author-wrapper {
    display: none;
}

.chat-message-self .chat-message-time::before {
    content: "You · ";
    color: var(--text-muted);
}

/* Message groups (doc/chat.md §Message groups): a continuation row tucks
   under the row above, so a burst from one person reads as one block. The
   header itself is dropped in the markup (orgol.views/chat-message), not
   hidden here. The channel feed wraps every root in .chat-thread, so its
   tighten rides the wrapper; the thread pane's rows are the messages
   themselves. */
.thread-pane-feed > .chat-message-grouped { margin-top: -0.45rem; }
#channel-feed > .chat-thread-grouped { margin-top: -0.45rem; }

.chat-message-author-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.chat-message-author {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chat-message-time {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* an edited message says so beside its stamp (doc/chat.md §Edit, delete,
   and quote); a grouped continuation row drops the header, and the mark
   with it — the group's own stamp carries that minute */
.chat-message-edited {
    font-size: 0.7rem;
    color: var(--text-muted);
}
.chat-message-edited::before { content: "·\00a0"; }

.chat-message-body {
    position: relative;
    display: inline-block;
    max-width: min(82%, 42rem);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text-primary);
    word-break: break-word;
    white-space: pre-wrap;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.chat-message-self .chat-message-body {
    text-align: left;
    color: var(--accent-text-on-solid, #fff);
    background: var(--chat-bubble-self);
    border: 1px solid var(--chat-bubble-self);
    border-bottom-right-radius: 0.2rem;
    max-width: 100%;
}

/* a proposal's close (doc/agent.md §Proposals): the server's line in the
   thread, centred and unfilled, so it does not read as something a person
   or the agent said */
.chat-note {
    display: flex;
    justify-content: center;
    align-items: baseline;
    gap: 0.5rem;
    margin: 0.5rem 0;
    color: var(--text-muted);
    font-size: 0.78rem;
    text-align: center;
}
.chat-note time { flex: none; white-space: nowrap; }

/* a withdrawn message keeps its place and loses its content (doc/chat.md
   §Edit, delete, and quote): muted and unfilled, so it reads as an absence
   rather than something the author still stands behind. It sits after the
   self bubble's rule and matches it at equal specificity, so source order
   is what keeps a withdrawn own message out of the accent fill. */
.chat-message-body.chat-message-deleted {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.6rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-style: italic;
}

.chat-message-deleted .nav-icon { width: 14px; height: 14px; flex-shrink: 0; }

/* Reactions (doc/chat.md §Reactions): a chip row under the bubble, inside
   #reactions-<id> — the one element a nod's answer morphs. The chips are a
   <details> summary, so a tap opens the panel of who reacted and the
   viewer's own name in it is the remove — no island, and the open panel
   survives the morph (data-preserve-attr, set in orgol.views/reaction-bar). */
.chat-who {
    position: relative;
    margin-top: 0.3rem;
    padding: 0 0.1rem;
}
.chat-who > summary {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    list-style: none;
    cursor: pointer;
}
.chat-who > summary::-webkit-details-marker { display: none; }
.chat-message-self .chat-who { text-align: right; }
.chat-reaction-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.05rem 0.4rem 0.1rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-secondary);
    line-height: 1.6;
}
.chat-who > summary:hover .chat-reaction-chip { border-color: var(--border-strong); }
.chat-reaction-chip.chat-reaction-mine {
    border-color: var(--border-accent);
    background: var(--accent-soft);
}
.chat-reaction-emoji { font-size: 0.85rem; }
.chat-reaction-count {
    font-size: 0.72rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
}
.chat-reaction-mine .chat-reaction-count { color: var(--accent-strong); }

/* The panel: one line per emoji with who used it. Your own name is the pill
   that takes it back, so removal names what goes instead of asking a person
   to remember which chip was theirs. */
.chat-who-panel {
    position: absolute;
    top: calc(100% + 0.3rem);
    left: 0;
    z-index: 9;
    width: max-content;
    max-width: 16rem;
    padding: 0.4rem;
    background: var(--surface-1);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    text-align: left;
}
.chat-message-self .chat-who-panel { left: auto; right: 0; }
.chat-who-title {
    padding: 0 0.35rem 0.3rem;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.chat-who-group {
    display: flex;
    align-items: flex-start;
    gap: 0.45rem;
    padding: 0.2rem 0.35rem;
    border-radius: var(--radius-sm);
}
.chat-who-group:hover { background: var(--surface-2); }
.chat-who-emoji { font-size: 0.9rem; line-height: 1.5; }
.chat-who-names {
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--text-secondary);
}
.chat-who-you {
    margin-left: 0.15rem;
    padding: 0 0.35rem 0 0.3rem;
    border: 0;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1.5;
    cursor: pointer;
}
.chat-who-you:hover,
.chat-who-you:focus-visible {
    background: var(--accent);
    color: #fff;
    outline: none;
}
.chat-who-you .chat-who-x { margin-left: 0.3rem; font-size: 0.9em; opacity: 0.8; }
/* the remove is a write like any other: held while its request is out, so a
   double-tap cannot add back what it was asked to take away */
.chat-who-you[disabled] { opacity: 0.5; cursor: progress; }

/* The emoji strip, in the message menu and at the panel's foot: four common
   reactions and the rest behind a more button. `data-class:compact` (a
   datastar expression on the message's signal) keeps the extras hidden, so
   the row is short until it is asked for. */
.chat-emoji-strip {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.1rem;
    padding: 0.15rem 0.1rem 0.35rem;
}
.chat-msg-menu .chat-emoji-strip {
    margin-bottom: 0.2rem;
    border-bottom: 1px solid var(--border);
}
.chat-who-panel .chat-emoji-strip {
    margin-top: 0.35rem;
    padding: 0.35rem 0 0;
    border-top: 1px solid var(--border);
}
.chat-emoji-strip button {
    flex: none;
    width: 1.75rem;
    border: 0;
    background: none;
    font-size: 1.05rem;
    line-height: 1.9;
    border-radius: var(--radius-sm);
    cursor: pointer;
    filter: grayscale(0.35);
}
.chat-emoji-strip button:hover,
.chat-emoji-strip button:focus-visible {
    background: var(--surface-2);
    filter: none;
    outline: none;
}
.chat-emoji-strip button.chat-emoji-on {
    background: var(--accent-soft);
    filter: none;
}
.chat-emoji-strip .chat-emoji-more {
    color: var(--text-muted);
    font-weight: 700;
    filter: none;
}
.chat-emoji-strip .chat-emoji-more:hover { color: var(--accent-strong); }
.chat-emoji-strip.compact .chat-emoji-extra { display: none; }
.chat-emoji-strip .chat-more-less { display: none; }
.chat-emoji-strip:not(.compact) .chat-more-less { display: inline; }
.chat-emoji-strip:not(.compact) .chat-more-more { display: none; }
/* A nod is a round trip (doc/chat.md §Reactions): aria-busy is the action's
   own datastar indicator, so the strip dims the moment it is tapped — the
   tap is acknowledged even when the answer is slow — and takes no second
   press, because the same emoji twice would add and take back before the
   server answered. The static opacity is the reduced-motion state; the
   pulse is the "still working".
   The wrapper the react action answers needs no box of its own: it is a
   block like any other row line, empty until somebody reacts. */
.chat-emoji-strip[aria-busy="true"] { cursor: progress; }
.chat-emoji-strip[aria-busy="true"] button {
    opacity: 0.45;
    pointer-events: none;
    animation: chat-reaction-wait 1s ease-in-out infinite;
}
@keyframes chat-reaction-wait {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 0.25; }
}

/* The message a reply quotes (doc/chat.md §Edit, delete, and quote): a card
   above the bubble's text — the quoted author and a clamped snippet, or the
   screenshot as a thumbnail — linking to the original row. It renders the
   original as it is now, so the quote follows an edit and shows the
   placeholder after a delete. white-space is reset: the bubble is pre-wrap. */
.chat-quote {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    margin: 0 0 0.4rem;
    padding: 0.35rem 0.55rem;
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    background: var(--surface-3);
    color: var(--text-primary);
    font-size: 0.78rem;
    text-decoration: none;
    white-space: normal;
}

a.chat-quote:hover { background: var(--surface-2); }

.chat-quote-author {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chat-quote-body {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: var(--text-secondary);
    word-break: break-word;
}

.chat-quote-thumb {
    max-width: 6rem;
    max-height: 3.5rem;
    border-radius: var(--radius-sm);
}

/* mention links in message bodies (doc/chat.md §Mentions): the @handle
   opens a DM with that person; inline so it flows in the pre-wrap body */
.chat-mention {
    display: inline;
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    font-weight: 600;
    color: var(--accent);
    cursor: pointer;
}

.chat-mention:hover { text-decoration: underline; }
.chat-message-self .chat-mention { color: #fff; text-decoration: underline; }

/* A bare URL in a human body (orgol.views/auto-links): the accent it has
   everywhere else, and underlined on the self bubble where accent vanishes */
.chat-link { color: var(--accent); text-decoration: underline; }
.chat-message-self .chat-link { color: #fff; }

/* @-mention autocomplete (composer.js): fixed above the composer */
.mention-menu {
    position: fixed;
    z-index: 30;
    max-height: 12rem;
    overflow-y: auto;
    padding: 0.25rem;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

.mention-item {
    padding: 0.35rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--text-primary);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mention-item-active { background: var(--surface-2); }

.chat-ai-badge {
    display: inline-flex;
    align-items: center;
    padding: 0 0.3rem;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #fff;
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    border-radius: 3px;
    line-height: 1.25rem;
    flex-shrink: 0;
    margin-right: 0.25rem;
}

/* the badge follows a text label inside the title (no flex gap there) */
.chat-topbar-title .chat-ai-badge { margin-left: 0.4rem; }

.chat-message-ai .chat-message-body {
    background: var(--surface-2);
    border: 1px solid var(--border);
}

/* Markdown subset in @ai bodies (orgol.views/markdown) */
.chat-message-ai .chat-message-body p { margin: 0 0 0.5rem; }
.chat-message-ai .chat-message-body p:last-child { margin-bottom: 0; }
.chat-message-ai .chat-message-body ul,
.chat-message-ai .chat-message-body ol { margin: 0.25rem 0 0.5rem; padding-left: 1.25rem; }
.chat-message-ai .chat-message-body li { margin: 0.1rem 0; }
.chat-message-ai .chat-message-body code {
    padding: 0.1rem 0.3rem; border-radius: var(--radius-sm);
    background: var(--surface-3); font-size: 0.82em;
}
.chat-message-ai .chat-message-body pre {
    margin: 0.4rem 0; padding: 0.5rem; overflow-x: auto;
    background: var(--surface-3); border-radius: var(--radius-sm);
    white-space: pre; font-size: 0.78rem;
}
.chat-message-ai .chat-message-body pre code { padding: 0; background: none; font-size: inherit; }
.chat-message-ai .chat-message-body a { color: var(--accent); text-decoration: underline; }
.chat-message-ai .chat-message-body h1,
.chat-message-ai .chat-message-body h2,
.chat-message-ai .chat-message-body h3,
.chat-message-ai .chat-message-body h4,
.chat-message-ai .chat-message-body h5,
.chat-message-ai .chat-message-body h6 {
    margin: 0.6rem 0 0.3rem; font-weight: 600; line-height: 1.3;
}
.chat-message-ai .chat-message-body h1 { font-size: 1.05rem; }
.chat-message-ai .chat-message-body h2 { font-size: 1rem; }
.chat-message-ai .chat-message-body h3,
.chat-message-ai .chat-message-body h4,
.chat-message-ai .chat-message-body h5,
.chat-message-ai .chat-message-body h6 { font-size: 0.92rem; }
.chat-message-ai .chat-message-body > :first-child,
.chat-message-ai .chat-message-body > chat-message-actions:first-child + * { margin-top: 0; }
.chat-message-ai .chat-message-body hr {
    border: 0; border-top: 1px solid var(--border); margin: 0.6rem 0;
}
.chat-message-ai .chat-message-body blockquote {
    margin: 0.4rem 0; padding-left: 0.6rem;
    border-left: 2px solid var(--border); color: var(--text-muted);
}
.chat-message-ai .chat-message-body blockquote p { margin: 0; }
.chat-message-ai .chat-message-body li input[type="checkbox"] { margin-right: 0.35rem; }
.chat-message-ai .chat-message-body del { opacity: 0.7; }

/* avatar shared with the users chart and the run cards (orgol.views/user-node) */
.chat-member-avatar { position: relative; display: inline-flex; width: 2rem; height: 2rem; align-items: center; justify-content: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong); font-size: 0.65rem; font-weight: 700; }

.chat-input {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    margin-top: 1rem;
}

.chat-input .form-field-input {
    flex: 1;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-1);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.chat-input textarea.form-field-input {
    resize: none;
    field-sizing: content;
    max-height: 10rem;
    overflow-y: auto;
    font-family: inherit;
    line-height: 1.4;
}

.chat-input .form-field-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

/* The message box: the textarea and the attachment chip share one bordered
   field (the chip inside, where the message is), and the focus ring moves
   from the textarea to the box. */
.chat-input-box {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-1);
}

.chat-input-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.chat-input-box .form-field-input,
.chat-input-box .form-field-input:focus {
    flex: none;
    width: 100%;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

@media (max-width: 600px) {
    /* a phone gets a bigger base size; every rem-based size scales with it */
    html { font-size: 17px; }
    .user-email { display: none; }
    /* full-bleed: no page gutter, no card chrome — the width is the messages' */
    .chat-workspace { gap: 0; max-width: none; }
    .chat-messages, .chat-thread-pane {
        border: none;
        border-radius: 0;
        background: transparent;
    }
    #channel-feed, .thread-pane-feed { padding: 0.5rem 0.6rem 0.6rem; }
    /* one row on a phone: the title truncates and every action is
       icon-only (title/aria-label carry the words, the commit count, and
       "not prod"), so a crowded thread never wraps onto three lines. The
       proposal row sits below it either way. */
    .chat-topbar {
        background: var(--bg-base);
    }
    .chat-topbar-actions {
        flex-wrap: nowrap;
        justify-content: flex-end;
        gap: 0.35rem;
        min-width: 0;
    }
    .chat-topbar .chat-run-preview { flex-wrap: nowrap; }
    /* a phone keeps the verdict — repo, state, who, when — and drops the
       branch and the tip: one line per repo */
    .chat-proposal-branch,
    .chat-proposal-tip { display: none; }
    /* Delete keeps its word on a desk; a phone gets the glyph */
    .chat-proposal-delete .btn-text { display: none; }
    .chat-input.channel-composer {
        margin-top: 0;
        padding: 0.5rem 0.75rem;
        border-top: 1px solid var(--border);
        background: var(--surface-1);
    }
    .chat-input.thread-pane-composer { padding: 0.5rem 0.75rem; }
    .chat-message-self, .chat-message-body { max-width: 92%; }
}

/* --- Page headings --- */
/* Forms inside navbar-actions (logout) must not grow their own box */
.navbar-actions form {
    display: contents;
}

.main-content h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.35rem;
}

.main-content > .panel-note {
    margin-bottom: 1.5rem;
}

/* --- Home --- */
/* --- Home: the needs-you strip and the visitor page (doc/home.md) --- */
.home-page {
    max-width: 46rem;
}

.needs-you-title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 1.25rem;
}

.needs-you-group {
    margin-bottom: 1.5rem;
}

.needs-you-heading {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.needs-you-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.75rem;
    margin-bottom: 0.4rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-2);
    color: var(--text-primary);
    text-decoration: none;
}

.needs-you-row:hover {
    background: var(--surface-3);
}

.needs-you-row-body {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.needs-you-row-title {
    font-weight: 600;
    font-size: 0.92rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.needs-you-row-meta {
    color: var(--text-muted);
    font-size: 0.78rem;
}

.needs-you-row-go {
    margin-left: auto;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* the signed-out landing: standalone like the auth pages, one column */
.visitor-shell {
    min-height: 100dvh;
    max-width: 42rem;
    margin: 0 auto;
    padding: 2.5rem 1.25rem 4rem;
    display: flex;
    flex-direction: column;
    gap: 3rem;
}

.visitor-hero {
    max-width: 36rem;
}

.visitor-eyebrow {
    color: var(--accent-strong);
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.visitor-title span {
    color: var(--accent-strong);
}

.visitor-title {
    margin-top: 0.6rem;
    font-size: clamp(1.8rem, 5vw, 2.6rem);
    line-height: 1.1;
    letter-spacing: -0.028em;
    text-wrap: balance;
}

.visitor-lede {
    max-width: 46ch;
    margin-top: 1rem;
    color: var(--text-secondary);
}

.visitor-points {
    list-style: none;
    margin: 1.5rem 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.visitor-points li {
    color: var(--text-secondary);
}

.visitor-points strong {
    color: var(--text-primary);
}

.visitor-cta {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 1.75rem;
}

.visitor-note {
    color: var(--text-muted);
    font-size: 0.82rem;
}

/* --- Auth pages (standalone, no app shell) --- */
.auth-shell {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.25rem;
    padding: 2rem 1rem;
}

.auth-card {
    width: 100%;
    max-width: 24rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.75rem;
}

.auth-card h1 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.auth-sub {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 0.35rem 0 1.25rem;
}

.auth-submit {
    width: 100%;
    margin-top: 1rem;
}

/* --- Login requests (doc/users.md §Login requests) ---
   The request form is a collapsed block under the sign-in form, and the
   admin's queue is a card on /users with the chart's language: a list of
   claims, each with the two decisions. */
.auth-request {
    margin-top: 1.25rem;
    border-top: 1px solid var(--border);
    padding-top: 0.9rem;
}

.auth-request summary {
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.88rem;
}

.auth-request summary:hover,
.auth-request[open] summary {
    color: var(--text-primary);
}

.auth-request[open] summary {
    margin-bottom: 0.75rem;
}

.auth-switch {
    margin: 0.9rem 0 0;
    font-size: 0.85rem;
}

.auth-switch a {
    color: var(--text-secondary);
}

.login-requests {
    margin: 1rem 0;
    padding: 0.9rem 1.25rem;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.login-requests-empty {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.65rem 1.25rem;
}

.login-requests-empty h2,
.login-requests-head h2 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.92rem;
    font-weight: 600;
}

.login-requests-head .panel-note {
    margin: 0.25rem 0 0.75rem;
}

.login-request-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0.7rem;
}

.login-request {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    border-top: 1px solid var(--border);
    padding-top: 0.7rem;
}

.login-request:first-child {
    border-top: 0;
    padding-top: 0;
}

.login-request-main {
    min-width: 0;
    overflow-wrap: anywhere;
}

.login-request-email {
    font-weight: 600;
    font-size: 0.9rem;
}

.login-request-name {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.login-request-meta {
    color: var(--text-muted);
    font-size: 0.78rem;
}

.login-request-note {
    margin: 0.35rem 0 0;
    color: var(--text-secondary);
    font-size: 0.85rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.login-request-actions {
    display: flex;
    gap: 0.4rem;
    flex-shrink: 0;
}

/* --- Chat shell (doc/chat.md) -------------------------------------------
   The chat view scrolls as a page at every width: the channel/thread header
   is the sticky top, the composer pins to the bottom, and the QA banner
   scrolls away. The viewport, not a pane, is the scroller, so the page
   carries the themed scrollbar (global, above) rather than the message
   list. Keep this block after the chat components above: same specificity,
   so source order decides, and an override written earlier (e.g. a @media
   block) never applies.
   A phone gives the top of the screen to the conversation: the orgol bar is
   static there (the app-wide mobile rule above), so the header is the
   sticky top. A desk keeps the bar pinned like every other page, so the
   header pins under it instead of over it. */
@media (min-width: 821px) {
    body:has(.chat-page) .chat-topbar { top: var(--nav-height); }
    /* A fragment landing clears both sticky rows. A thread's proposal strip
       is the header's tallest state (two repo rows and Delete), so it needs
       more room; --chat-topbar-clear is whichever applies. */
    body:has(.chat-page) { --chat-topbar-clear: 3.5rem; }
    body:has(.chat-page .chat-topbar-proposal) { --chat-topbar-clear: 7rem; }
    body:has(.chat-page) .chat-message,
    body:has(.chat-page) .thread-row {
        scroll-margin-top: calc(var(--nav-height) + var(--chat-topbar-clear));
    }
    /* the rail is navigation: it stays put under the orgol bar while a
       conversation scrolls — below 821px it is the fixed drawer instead */
    body:has(.chat-page) .sidebar {
        position: sticky;
        top: var(--nav-height);
        align-self: flex-start;
        height: calc(100dvh - var(--nav-height));
        overflow-y: auto;
    }
}

.main-content.chat-page {
    display: flex;
    height: auto;
    padding: 0.75rem 1.5rem 1rem;
    overflow: visible;
}

.chat-workspace {
    flex: 1;
    height: auto;
    min-height: 0;
    overflow: visible;
}

.chat-container,
.chat-thread-pane {
    min-height: 0;
    overflow: visible;
}

.chat-messages,
.thread-pane-messages { overflow: visible; }

.chat-input.channel-composer,
.chat-input.thread-pane-composer {
    position: sticky;
    bottom: 0;
    z-index: 6;
    background: var(--surface-1);
    border-top: 1px solid var(--border);
}

.chat-jump-bottom { position: fixed; right: 1rem; bottom: 5rem; }

@media (max-width: 600px) {
    /* full-bleed: the width belongs to the messages */
    .main-content.chat-page { padding: 0; }
}

/* --- @ai runs (orgol.ai): the run lives on the message row — a working
       row shows status/tool/live log, a finished row the answer footer --- */
.chat-run {
    position: relative;
    max-width: min(82%, 42rem);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    background: var(--surface-2);
    border: 1px solid var(--accent-soft, var(--border));
    font-size: 0.85rem;
}
.chat-run-line { display: flex; align-items: center; gap: 0.45rem; color: var(--text-muted); }
.chat-run-dot {
    width: 0.5rem; height: 0.5rem; border-radius: 50%;
    background: var(--accent);
    animation: chat-run-pulse 1.4s ease-in-out infinite;
}
@keyframes chat-run-pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
.chat-run-stream {
    margin-top: 0.5rem;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
}
.chat-run-log { margin-top: 0.4rem; }
.chat-run-log summary { cursor: pointer; color: var(--text-muted); font-size: 0.75rem; }
.chat-run-log pre {
    margin: 0.3rem 0 0; padding: 0.5rem; max-height: 12rem; overflow-y: auto;
    background: var(--surface-3); border-radius: var(--radius-sm);
    font-size: 0.72rem; white-space: pre-wrap;
}
.chat-run-evidence { margin-top: 0.4rem; }
.chat-run-evidence summary { cursor: pointer; color: var(--text-muted); font-size: 0.75rem; }
.chat-run-evidence pre {
    margin: 0.3rem 0 0; padding: 0.5rem; max-height: 12rem; overflow-y: auto;
    background: var(--surface-3); border-radius: var(--radius-sm);
    font-size: 0.72rem; white-space: pre-wrap;
}
.chat-run-meta { margin-top: 0.3rem; color: var(--text-muted); font-size: 0.72rem; word-break: break-all; }
.chat-run-cancel { margin-top: 0.4rem; }
.chat-run-preview { margin-top: 0.4rem; display: flex; align-items: center; gap: 0.5rem; }
.chat-run-preview-restart { margin: 0; }
.chat-run-preview-link { text-decoration: none; }
.chat-run-preview-note { display: inline-flex; align-items: center; gap: 0.3rem; color: var(--text-muted); font-size: 0.7rem; }
.chat-run-preview-note .nav-icon { width: 14px; height: 14px; }
.chat-run-preview-failed .chat-run-preview-note { color: var(--danger); }
/* The preview action carries the accent, matching the starting spinner. */
.chat-run-preview-action { color: var(--accent-strong); border-color: var(--accent); }
.chat-run-preview-action:hover { color: var(--accent-strong); border-color: var(--accent-strong); background: var(--accent-soft); }
.chat-run-preview-starting .badge { gap: 0.35rem; }
.chat-preview-spinner {
    width: 11px;
    height: 11px;
    flex-shrink: 0;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: chat-preview-spin 0.7s linear infinite;
}
@keyframes chat-preview-spin { to { transform: rotate(360deg); } }

/* --- QA preview banner (orgol.qa): same app, unmistakably not prod --- */
.qa-banner {
    padding: 0.35rem 1rem;
    background: var(--warning);
    color: #1b1405;
    font-size: 0.78rem;
    text-align: center;
}
.qa-banner code {
    background: rgba(0, 0, 0, 0.15);
    padding: 0.05rem 0.3rem;
    border-radius: 3px;
}
.ai-runs-badge { font-size: 0.72rem; color: var(--text-muted); }

/* --- Mockup wrapper (orgol.mockup): orgol's bar around the agent's HTML --- */
.mockup-body { margin: 0; overflow: hidden; }
.mockup-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    height: 40px;
    padding: 0 1rem;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    font-size: 0.82rem;
}
.mockup-label {
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--warning);
}
.mockup-note { color: var(--text-muted); }
.mockup-back { margin-left: auto; color: var(--accent); }
.mockup-frame {
    position: fixed;
    inset: 40px 0 0 0;
    width: 100%;
    height: calc(100dvh - 40px);
    border: 0;
    background: #fff;
}

/* --- Thread root wrapper used by the channel feed
       (orgol.views/channel-feed-el) --- */
.chat-thread { display: flex; flex-direction: column; }

.chat-input { flex-wrap: wrap; }
.chat-run-meta { max-width: min(82%, 42rem); }
.chat-message-body.chat-message-empty { color: var(--text-muted); font-style: italic; }

/* --- AI settings (org-wide, per tenant) --- */
.settings-body {
    max-width: 42rem;
}

.settings-lede {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.settings-card {
    border: 1px solid var(--border);
    margin-bottom: 1rem;
}

.settings-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.65rem;
}

.settings-title {
    min-width: 0;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

/* the effective settings line is a subtitle under the card title, not a
   right-hand column that turns narrow on a phone */
.settings-now {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    margin: 0 0 0.9rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.settings-now-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent-strong);
}

/* the agent's name is short; a full-width field reads as an email input */
.settings-agent-name {
    max-width: 24rem;
}

/* the locked brief and the exact tenant block: visible before an admin edits */
.settings-brief-list {
    margin: 0.35rem 0 0;
    padding-left: 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.settings-preview {
    margin: 0.35rem 0 0;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-2);
    color: var(--text-secondary);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.72rem;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    max-height: 16rem;
    overflow: auto;
}

.settings-warning {
    color: var(--accent-strong);
}

.settings-history-list {
    list-style: none;
    margin: 0.5rem 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.settings-history-item {
    border-top: 1px solid var(--border);
    padding-top: 0.45rem;
}

.settings-history-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    color: var(--text-secondary);
    font-size: 0.72rem;
}

.settings-history-head form {
    margin-left: auto;
}

.settings-history-rev {
    color: var(--text-primary);
    font-weight: 600;
}

.settings-meta {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-bottom: 0.9rem;
}

/* the threads that block a repo removal: link, snippet, state */
.settings-blockers {
    margin: 0.4rem 0 0;
    padding-left: 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.8rem;
}

.settings-blockers a {
    color: var(--accent-strong);
    text-decoration: underline;
}

.settings-blockers code {
    color: var(--text-muted);
    font-size: 0.72rem;
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.settings-repos {
    list-style: none;
    margin: 0 0 0.9rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.settings-repo {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.5rem 0.65rem;
    background: var(--surface-2);
}

.settings-repo-head {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-wrap: wrap;
}

.settings-repo-name {
    font-size: 0.82rem;
    color: var(--text-primary);
}

.settings-repo-path,
.settings-repo-state {
    color: var(--text-secondary);
    font-size: 0.72rem;
    word-break: break-word;
}

.settings-repo-meta {
    margin-top: 0.2rem;
    color: var(--text-muted);
    font-size: 0.72rem;
    word-break: break-word;
}

.settings-repo-fetch {
    margin-left: auto;
}

.settings-repo-manage,
.settings-repo-add,
.settings-help {
    margin-top: 0.35rem;
}

.settings-repo-manage summary,
.settings-repo-add summary,
.settings-help summary {
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.settings-help .panel-note {
    margin: 0.35rem 0 0;
}

.settings-repo-manage .settings-form,
.settings-repo-add .settings-form {
    margin-top: 0.5rem;
    gap: 0.5rem;
}

.settings-repo-manage .panel-note,
.settings-repo-add .panel-note {
    margin: 0.35rem 0;
}

.settings-repo-error {
    margin-top: 0.25rem;
    color: var(--accent-strong);
    font-size: 0.72rem;
    word-break: break-word;
}

.settings-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
    gap: 0.85rem 1rem;
}

#ai-settings-controls {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

#ai-settings-controls > .form-error,
#ai-settings-feedback .form-error,
#ai-token-feedback .form-error {
    margin: 0;
}

#ai-settings-controls > .btn {
    align-self: flex-start;
}

.settings-actions {
    display: flex;
    justify-content: flex-end;
}

.settings-token-row {
    display: flex;
    align-items: flex-end;
    gap: 0.6rem;
}

.settings-token-row .form-field {
    flex: 1 1 16rem;
    min-width: 0;
}

.settings-token-row .btn {
    flex: 0 0 auto;
}

.settings-danger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 1rem;
    padding-top: 0.9rem;
    border-top: 1px solid var(--border);
}

.settings-danger .btn {
    min-width: 0;
}

#ai-settings-feedback .form-error,
#ai-token-feedback .form-error {
    margin: 0;
}

@media (max-width: 600px) {
    .settings-card {
        padding: 1rem;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }

    /* keep a short status badge beside its title, not stacked under it */
    .settings-card-head {
        flex-wrap: nowrap;
        gap: 0.5rem;
    }

    .settings-card-head .badge {
        flex-shrink: 0;
    }

    /* the repo's Clone/Fetch sits beside its name; only a long state line
       is allowed to wrap below it */
    .settings-repo-head {
        align-items: center;
    }

    .settings-repo-fetch {
        margin-left: auto;
    }

    .settings-token-row,
    .settings-danger {
        flex-direction: column;
        align-items: stretch;
    }

    /* the base basis is a width; in a column it would be a 16rem tall field */
    .settings-token-row .form-field {
        flex: 0 0 auto;
    }

    .settings-actions .btn,
    .settings-danger .btn {
        width: 100%;
    }
}
