/* ===== Input Area ===== */
.input-container {
    padding: 16px 20px;
    background-color: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

/* Composer field wrapper (P2-05a) — a two-row box: textarea on top, the
   control row beneath. Owns the rounded border and clips the textarea's
   scrollbar to the corners (same approach as the settings textboxes). */
.composer-field {
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* Match the message column width and center it for an in-line look. */
    max-width: var(--chat-max-width);
    margin-inline: auto;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: border-color 0.2s;
}

.composer-field:focus-within {
    border-color: var(--accent);
}

.composer-field textarea {
    width: 100%;
    padding: 12px 16px 6px;
    background-color: transparent;
    border: none;
    border-radius: 0;
    color: var(--text-primary);
    font-family: var(--font-chat);
    font-size: var(--text-base);
    resize: none;
    /* Auto-grows with content (JS) up to ~1/3 of the viewport, then scrolls. */
    max-height: 30dvh;
    overflow-y: auto;
}

.composer-field textarea:focus {
    outline: none;
}

/* Control row: attach + tools toggle left, model chip + send/stop right. */
.composer-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px 8px;
}

/* File-tools toggle pill. Ships disabled until the tool backend (Track A
   P2-02) lands; .on is the enabled/accent state used from P2-05b onward. */
.tools-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-weight: 500;
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.2s, background-color 0.2s, border-color 0.2s;
}

.tools-toggle:hover:not(:disabled) {
    color: var(--text-secondary);
    border-color: var(--text-muted);
}

.tools-toggle.on {
    background: var(--accent-subtle);
    color: var(--accent);
    border-color: transparent;
}

.tools-toggle:disabled {
    opacity: 0.55;
    cursor: default;
}

.tools-toggle svg {
    flex-shrink: 0;
}

/* Composer model chip: same accent pill as the top-bar model button, sized
   down for the control row; long model names truncate instead of wrapping.
   margin-left: auto pushes the chip + send/stop to the right edge. */
.composer-controls .model-button {
    padding: 5px 12px;
    /* Transparent border matches the tools pill's box height exactly. */
    border: 1px solid transparent;
    min-width: 0;
    margin-left: auto;
}

.composer-controls .model-badge {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.send-button {
    width: 34px;
    height: 34px;
    background-color: var(--accent);
    border: none;
    border-radius: 50%;
    color: var(--on-accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, transform 0.2s, opacity 0.2s;
    flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
    background-color: var(--accent-hover);
    transform: scale(1.05);
}

.send-button:disabled {
    background-color: var(--border-color);
    cursor: not-allowed;
}

.send-button svg,
.stop-button svg {
    display: block;
}

/* Composer footer row (UIP-04): Enter hint left, clickable Usage counter right */
.composer-footer {
    max-width: var(--chat-max-width);
    margin: 6px auto 0;
    padding: 0 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: var(--text-xs);
    color: var(--text-muted);
}

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

.composer-usage-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    margin-right: -6px;
    padding: 2px 6px;
    border: none;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: inherit;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    flex: 0 0 auto;
    transition: color 0.15s, background-color 0.15s;
}

.composer-usage-btn:hover {
    color: var(--accent);
    background-color: var(--bg-tertiary);
}

.composer-usage-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    /* `visibility` is animatable, so `transition: all` makes hidden -> visible
       take effect only once the transition passes 0 — a frame later. Until then
       the modal is computed-hidden and nothing inside it can take focus, so a
       .focus() on open silently does nothing. Flip visibility instantly on
       open, and delay it on close so the opacity fade-out still plays. */
    transition: opacity 0.3s, visibility 0s linear 0.3s;
}

.modal-overlay.visible {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s, visibility 0s;
}

/* Secondary modals can be opened from within the settings modal, so they must
   stack above it (the settings modal is moved to the end of <body>, which would
   otherwise put it on top at equal z-index). */
#modelModal,
#expressionModal {
    z-index: 250;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 400px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg); /* lift floating modals (hybrid depth) */
    transform: scale(0.9);
    transition: transform 0.3s;
}

.modal-overlay.visible .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: var(--text-lg);
    font-weight: 600;
    letter-spacing: -0.01em;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    /* Not `all` — same reason as .modal-btn: it would delay the visibility
       flip inherited from .modal-overlay and make this unfocusable on open. */
    transition: background-color 0.2s, color 0.2s;
}

.modal-close:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
}

.modal-body label {
    display: block;
    font-size: var(--text-sm);
    margin-bottom: 6px;
    color: var(--text-primary);
}

/* Appearance comes from the base field rule; a modal only sets its own layout.
   Checkboxes and the other non-text types are excluded so they keep their
   intrinsic size instead of stretching to the modal's full width. */
.modal-body input:where(:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"])),
.modal-body select,
.modal-body textarea {
    width: 100%;
    margin-bottom: 16px;
}

/* Right-aligned by default: a footer's choices read as a group. Use .split for
   the exception — a destructive action that should be held away from the
   primary one (see the expression modal's Delete vs Save). */
.modal-footer {
    display: flex;
    justify-content: flex-end;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    gap: 12px;
}

.modal-footer.split {
    justify-content: space-between;
}

.modal-btn {
    padding: 10px 20px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    /* Not `all`: that would include the visibility flip inherited from
       .modal-overlay and leave the button unfocusable for a frame on open. */
    transition: background-color 0.2s, border-color 0.2s, color 0.2s, filter 0.2s, box-shadow 0.15s, transform 0.1s;
}

.modal-btn:active:not(:disabled) {
    transform: translateY(0.5px);
    box-shadow: none;
}

.modal-btn.primary {
    background-color: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
    box-shadow: var(--shadow-btn);
}

.modal-btn.primary:hover {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
}

.modal-btn.secondary {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    box-shadow: var(--shadow-btn-secondary);
}

.modal-btn.secondary:hover {
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

/* A destructive action sitting alongside a primary one: quiet at rest, so it
   doesn't compete, and unmistakably destructive on hover. This is what
   .secondary:hover used to do for every secondary button, including plain
   Cancel/Close ones where "destructive" was the wrong signal. */
.modal-btn.danger-quiet:hover {
    border-color: var(--error);
    color: var(--error);
}

/* ===== Confirm Dialog ===== */
/* Stacks above every other modal — it can be opened from inside one (e.g. the
   delete button in the expression modal, which is itself at z-index 250). */
#confirmModal {
    z-index: 300;
}

/* The dialog deliberately focuses Cancel so a stray Enter is safe. Opening it
   by mouse means :focus-visible won't match, hiding the ring — and an invisible
   focus position makes that safety invisible too. Show it on plain :focus. */
#confirmModal .modal-btn:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.modal-confirm .modal-body p {
    margin: 0;
    font-size: var(--text-sm);
    line-height: 1.6;
    color: var(--text-secondary);
}

.modal-btn.danger {
    background-color: var(--error);
    border-color: var(--error);
    color: var(--on-error);
    box-shadow: var(--shadow-btn);
}

.modal-btn.danger:hover {
    filter: brightness(1.08);
}

/* ===== Model Management Modal ===== */
.modal-large {
    max-width: 600px;
}

/* Settings checkbox row (e.g. developer-mode toggle) */
.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    margin-top: 12px;
}

/* Request inspector: scrollable, monospaced JSON dump */
.request-inspector-pre {
    max-height: 60vh;
    overflow: auto;
    margin: 8px 0 0;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: var(--font-mono, monospace);
    font-size: var(--text-xs);
    line-height: 1.5;
    /* Wrap like chat code blocks do — long strings (system prompts, file
       contents) would otherwise force a very wide horizontal scroll. */
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    color: var(--text-primary);
}

/* Request inspector modal: wider than other modals — it shows a full request
   body, so use the desktop real estate now that the JSON wraps. */
.modal-content.modal-xl {
    max-width: 1100px;
    width: 95%;
}

/* Settings modal: roomy, with a fixed header and a scrolling body. */
.modal-content.modal-settings {
    max-width: 680px;
    width: 92vw;
    max-height: 88vh;
    overflow: hidden; /* the body scrolls instead of the whole content */
    display: flex;
    flex-direction: column;
}

.modal-content.modal-settings .modal-header {
    flex-shrink: 0;
}

.settings-modal-body {
    padding: 20px;
    overflow-y: auto;
}

/* The settings sections were styled for the sidebar; the first one shouldn't
   add a top border/gap at the top of the modal body. */
.settings-modal-body .settings-section:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

/* ===== Main-area form panels (WR-07b Settings, persona editor) ===== */
/* Same max-width + padding as .section-view / .container-page so every main-area
   view shares one spacing system. */
.main-view-panel {
    flex: 1;
    overflow-y: auto;
    padding: 28px 24px 60px;
}

.main-view-panel[hidden] {
    display: none;
}

.settings-view-crumb {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: var(--section-max-width);
    margin: 0 auto 8px;
}

.settings-view-title {
    max-width: var(--section-max-width);
    margin: 0 auto 16px;
    font-size: var(--text-xl);
    font-weight: 600;
    color: var(--text-primary);
}

.main-view-panel .settings-modal-body {
    max-width: var(--section-max-width);
    margin: 0 auto;
    padding: 0;
    overflow: visible;
}

/* ===== Settings tabs (AP-02) ===== */
/* Settings outgrew one scroll when Advanced arrived. The strip is built from the
   sections themselves (js/views/settings.js) — each declares data-settings-tab. */
.settings-tabs {
    display: flex;
    gap: 4px;
    max-width: var(--section-max-width);
    margin: 0 auto 4px;
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;          /* narrow windows scroll the strip, not the page */
    scrollbar-width: none;
}

.settings-tabs::-webkit-scrollbar {
    display: none;
}

.settings-tab {
    flex: 0 0 auto;
    padding: 8px 14px;
    border: none;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.settings-tab:hover {
    color: var(--text-primary);
}

.settings-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* The tab strip already separates the sections from the title, and a tab often
   shows a single section — the leading rule reads as a stray line there. */
.main-view-panel .settings-modal-body .settings-section {
    padding-left: 0;
    padding-right: 0;
}

/* ===== Persona Editor tabs, separate WYSIWYG card & Phone Strip A (UIP-05) ===== */
#personaEditView .settings-tabs {
    margin-bottom: 18px;
}

.persona-hero-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 220px;
    gap: 20px;
    align-items: stretch;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.persona-hero-row[hidden] {
    display: none;
}

.main-view-panel .settings-modal-body .persona-hero-row > .settings-section {
    padding: 0;
    border-bottom: none;
    margin: 0;
}

.main-view-panel .settings-modal-body #personaModelSection {
    padding-top: 0;
}

.persona-live-aside {
    display: flex;
    flex-direction: column;
}

.persona-live-card {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 12px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
}

.persona-live-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.persona-live-card .persona-tile-portrait {
    width: 100%;
}

/* Show full tagline in the live editor card while typing it. */
.persona-live-card .persona-tile-tagline {
    display: block;
    overflow: visible;
    -webkit-line-clamp: unset;
    line-clamp: unset;
}

.persona-live-card-btn {
    margin-top: auto;
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: var(--text-xs);
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    transition: border-color 0.15s, color 0.15s;
}

.persona-live-card-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

/* Phone Strip A: hidden on desktop, shown above the 3-tab strip on narrow screens */
.persona-strip {
    display: none;
}

.persona-strip[hidden] {
    display: none;
}

@media (max-width: 767px) {
    .persona-strip {
        display: flex;
        align-items: stretch;
        gap: 14px;
        max-width: var(--section-max-width);
        margin: 0 auto 14px;
        padding: 12px;
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-lg);
    }

    .persona-strip-port-col {
        display: flex;
        flex-direction: column;
        gap: 6px;
        width: 94px;
        flex-shrink: 0;
    }

    .persona-strip-port {
        position: relative;
        width: 94px;
        height: 94px;
        border-radius: var(--radius-md);
        overflow: hidden;
        display: flex;
        align-items: center;
        justify-content: center;
        background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--accent-subtle) 100%);
        border: 1px solid var(--border-color);
        font-size: 46px;
    }

    .persona-strip-port img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
    }

    .persona-strip-edit-btn {
        width: 100%;
        padding: 4px 6px;
        border: 1px solid var(--border-color);
        border-radius: var(--radius-sm);
        background: var(--bg-tertiary);
        color: var(--text-secondary);
        font-family: inherit;
        font-size: 11px;
        font-weight: 500;
        cursor: pointer;
        text-align: center;
        transition: border-color 0.15s, color 0.15s;
    }

    .persona-strip-edit-btn:hover {
        border-color: var(--accent);
        color: var(--text-primary);
    }

    .persona-strip-info-col {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 5px;
    }

    .persona-strip-eyebrow {
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-size: 10px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-muted);
    }

    .persona-strip-title-row {
        display: flex;
        align-items: center;
        gap: 7px;
        flex-wrap: wrap;
    }

    .persona-strip-name {
        font-size: var(--text-base);
        font-weight: 600;
        color: var(--text-primary);
        line-height: 1.25;
        overflow-wrap: anywhere;
    }

    .persona-strip-model-foot {
        margin-top: 2px;
        display: inline-flex;
        align-items: center;
        gap: 6px;
        font-size: 11px;
        color: var(--text-muted);
    }

    .persona-strip-model-dot {
        width: 6px;
        height: 6px;
        border-radius: var(--radius-full);
        background: var(--text-muted);
        flex-shrink: 0;
    }

    .persona-strip-model-foot.is-fixed .persona-strip-model-dot {
        background: var(--accent);
    }

    .persona-hero-row {
        display: block;
    }

    .persona-live-aside {
        display: none;
    }

    #personaEditView .settings-tabs {
        gap: 2px;
    }

    #personaEditView .settings-tab {
        flex: 1 1 auto;
        padding: 8px 3px;
        font-size: 11.5px;
        text-align: center;
        white-space: nowrap;
    }
}

/* Inline Fixed-model picker inside Defaults & Capabilities → Model */
.persona-fixed-picker {
    margin-top: 12px;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.persona-fixed-picker[hidden] {
    display: none;
}

.persona-fixed-picker .help-text {
    margin: 0;
}

.persona-fixed-picker-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

.persona-fixed-picker-title {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-primary);
}

.persona-fixed-models-link {
    border: none;
    background: none;
    padding: 0;
    font-family: inherit;
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--accent-light, var(--accent));
    cursor: pointer;
}

.persona-fixed-models-link:hover {
    text-decoration: underline;
}

.persona-fixed-model-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s;
}

.persona-fixed-model-btn:hover {
    border-color: var(--accent);
}

.persona-fixed-model-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
}

.persona-fixed-provider-badge {
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 7px;
    border-radius: var(--radius-full);
    background: var(--accent-subtle);
    color: var(--accent-light, var(--accent));
    flex-shrink: 0;
}

.persona-fixed-model-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.persona-fixed-chevron {
    flex-shrink: 0;
    color: var(--text-secondary);
}

/* ===== Prompt preset list (AP-02) ===== */
.preset-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.preset-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
}

/* The active preset is the one every chat gets by default — worth more than a
   badge alone, since the list is scanned for "which one am I on". */
.preset-row.active {
    border-color: var(--accent);
    background: var(--accent-subtle);
}

.preset-row-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.preset-name {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preset-note {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preset-badge {
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--on-accent);
    background: var(--accent);
    padding: 2px 8px;
    border-radius: var(--radius-full);
}

.preset-action {
    flex-shrink: 0;
    padding: 4px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: var(--text-xs);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}

.preset-action:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.preset-action.danger-quiet:hover {
    border-color: var(--error);
    color: var(--error);
}

/* Actions are secondary to reading the list: on a narrow panel they wrap under
   the name rather than squeezing it to nothing. */
@media (max-width: 600px) {
    .preset-row {
        flex-wrap: wrap;
    }

    .preset-row-main {
        flex-basis: 100%;
    }
}

/* ===== Composer prompt-preset pill (AP-04) ===== */
/* Borrows .tools-toggle's shape. Muted while the preset is inherited, accent
   once THIS chat pins one — the same "is this mine or inherited" distinction
   the file-tools toggle draws. */
.preset-pill[hidden] {
    display: none;
}

.preset-pill .preset-pill-name {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preset-pill.pinned {
    background: var(--accent-subtle);
    color: var(--accent);
    border-color: transparent;
}

/* The inherit row's "from the persona" hint, under its label. */
.preset-menu-note {
    display: block;
    font-size: var(--text-xs);
    color: var(--text-muted);
}

/* ===== Prompt preset block editor (AP-03) ===== */
.preset-editor[hidden] {
    display: none;
}

.preset-editor-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
}

.preset-editor-head-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* "+ New preset" is full-width by inheritance from .add-expression-btn; Import
   is the quieter sibling beside it. */
.preset-list-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.preset-list-actions .add-expression-btn {
    flex: 1;
    margin-bottom: 0;
}

.preset-editor-title {
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

/* Reads as ambient status, not as a control — it changes on its own. */
.preset-save-status {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.preset-blocks {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.preset-block {
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
}

/* A disabled block stays legible — you are still editing it — but shouldn't
   read as part of the prompt at a glance. */
.preset-block.is-off {
    opacity: 0.6;
}

.preset-block.dragging {
    opacity: 0.4;
    border-color: var(--accent);
}

.preset-block-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.preset-block-grip {
    cursor: grab;
    color: var(--text-muted);
    letter-spacing: -2px;
    user-select: none;
}

.preset-block[draggable="true"] {
    /* The whole card is the drag handle; the grip is the affordance for it. */
    cursor: grab;
}

.preset-block-title {
    flex: 1;
    min-width: 0;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
}

.preset-block-state {
    flex-shrink: 0;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

/* Stands in for the toggle on a locked block (the session-state block): it can
   be moved but not edited or switched off, so there is nothing to toggle. */
.preset-block-locked {
    flex-shrink: 0;
    margin-left: auto;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent);
    background: var(--accent-subtle);
    padding: 2px 8px;
    border-radius: var(--radius-full);
}

.preset-block-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    margin-bottom: 0;
    font-size: var(--text-xs);
    color: var(--text-secondary);
    cursor: pointer;
}

/* .settings-section label sets display:block + a bottom margin; the inline
   toggle inside a card wants neither. */
.settings-section .preset-block-toggle {
    display: inline-flex;
    margin-bottom: 0;
}

.preset-block-desc {
    font-size: var(--text-xs);
    line-height: 1.5;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

/* The "only sent when…" clause: a preset controls wording, never whether a
   block applies, and this is where that shows up in the UI. */
.preset-block-cond {
    display: block;
    color: var(--text-muted);
}

/* Overrides `.settings-section textarea`, which is sized for short fields.
   The box, border and sizing come from the shared `.textarea-resizable`
   wrapper — no `resize` here, or the native grip would return alongside the
   drag-bar. Uses the same `--font-main` and `--text-sm` as every other prose
   textarea in the app so the font doesn't jump mid-block (UIP-01). */
.settings-section .preset-block-text {
    min-height: 120px;
    font-family: var(--font-main);
    font-size: var(--text-sm);
    line-height: 1.5;
    /* Long prompt lines wrap rather than scrolling sideways (UI principle). */
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* The warning line beneath owns the gap, so the wrapper adds none. */
.preset-block .textarea-resizable {
    margin-bottom: 0;
}

.preset-block-text::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

.preset-block-warn {
    margin-top: 6px;
    font-size: var(--text-xs);
    line-height: 1.5;
    color: var(--warning);
}

.preset-block-warn[hidden] {
    display: none;
}

.preset-group-label {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin: 4px 0 8px;
}

.preset-macros {
    margin-top: 16px;
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.preset-macros summary {
    cursor: pointer;
    color: var(--text-secondary);
    padding: 6px 0;
}

.preset-macros ul {
    list-style: none;
    padding: 0;
    margin: 4px 0 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 4px 16px;
}

.preset-macros code {
    font-family: var(--font-mono);
    color: var(--accent);
}

/* ===== Prompt inspector (AP-05) ===== */
.prompt-inspector {
    margin-top: 12px;
}

.prompt-inspector:empty {
    display: none;
}

.inspector-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    padding: 8px 0 12px;
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.inspector-block {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    margin-bottom: 6px;
}

.inspector-block summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: var(--text-sm);
}

.inspector-block-name {
    flex: 1;
    min-width: 0;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Where the text came from. Only an override is accented — the whole point is
   to make "this is yours" separable from "this is Tessera's" at a glance. */
.inspector-source {
    flex-shrink: 0;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    padding: 1px 8px;
}

.inspector-source.source-preset {
    color: var(--accent);
    border-color: var(--accent);
}

.inspector-chars {
    flex-shrink: 0;
    font-size: var(--text-xs);
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
}

.inspector-text {
    margin: 0;
    padding: 10px 12px;
    border-top: 1px solid var(--border-color);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    line-height: 1.5;
    color: var(--text-secondary);
    /* Prompt lines are long; wrap them rather than scrolling the panel sideways. */
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.inspector-excluded {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: var(--text-xs);
    line-height: 1.7;
    color: var(--text-secondary);
}

.inspector-excluded strong {
    color: var(--text-primary);
    font-weight: 600;
}

.preset-editor-preview {
    margin-top: 20px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.model-section {
    margin-bottom: 20px;
}

.model-section h4 {
    font-size: var(--text-sm);
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.modal-divider {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 20px 0;
}

/* The add-model modal's provider picker (Slice 7): the catalog chips, but
   single-select and laid out for a modal rather than the centred tab column. */
.provider-chips.single {
    max-width: none;
    margin: 0;
}

.empty-state {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    text-align: center;
    padding: 20px;
    background-color: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

/* Fetch Models Section */
.fetch-models-section {
    margin-bottom: 16px;
}

/* One primary slot, two states: #fetchModelsBtn or #modalKeyBtn, never both
   (renderFetchSection toggles `hidden`), so this styles whichever is showing. */
.fetch-models-btn {
    width: 100%;
    padding: 10px 16px;
    background-color: var(--accent);
    border: none;
    border-radius: var(--radius-md);
    color: var(--on-accent);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, opacity 0.2s;
}

.fetch-models-btn:hover:not(:disabled) {
    background-color: var(--accent-hover);
}

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

/* Available Models Grid */
.available-models-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
    margin-top: 12px;
    max-height: 200px;
    overflow-y: auto;
    padding: 4px;
}

.available-model-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: border-color 0.2s, opacity 0.2s;
}

.available-model-card:hover:not(.already-added) {
    border-color: var(--accent);
}

.available-model-card.already-added {
    opacity: 0.6;
}

.available-model-name {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-primary);
}

.available-model-id {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    font-family: var(--font-mono);
    word-break: break-all;
}

.add-available-model-btn {
    margin-top: 6px;
    padding: 6px 10px;
    background-color: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: var(--on-accent);
    font-size: var(--text-xs);
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}

.add-available-model-btn:hover:not(:disabled) {
    background-color: var(--accent-hover);
}

.add-available-model-btn:disabled {
    background-color: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: default;
}

/* Manual Add Divider */
.manual-add-divider {
    display: flex;
    align-items: center;
    margin: 20px 0;
    color: var(--text-secondary);
    font-size: var(--text-xs);
}

.manual-add-divider::before,
.manual-add-divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border-color);
}

.manual-add-divider span {
    padding: 0 12px;
}

/* Manual Add Form */
.manual-add-form {
    display: flex;
    flex-direction: column;
}

.add-model-btn {
    padding: 10px 16px;
    background-color: var(--accent);
    border: none;
    border-radius: var(--radius-md);
    color: var(--on-accent);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, opacity 0.2s;
}

.add-model-btn:hover {
    background-color: var(--accent-hover);
}

/* ===== Overlay for sidebar ===== */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 99;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0s linear 0.3s;
}

.sidebar-overlay.visible {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s, visibility 0s;
}

/* ===== Responsive ===== */
@media (min-width: 768px) {
    .sidebar {
        position: relative;
        left: 0;
        z-index: auto;
        flex-shrink: 0;
        box-shadow: none; /* inline column on desktop uses the border, not a shadow */
    }

    /* Sidebar always visible on desktop - no hiding rule */

    .close-sidebar {
        display: none;
    }

    .sidebar-overlay {
        display: none;
    }

    /* Hide hamburger button on desktop - sidebar is always visible */
    .menu-button {
        display: none;
    }
}

@media (max-width: 767px) {
    .inline-menu-button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 38px;
        height: 38px;
        padding: 0;
        margin-left: -8px;
    }

    .main-view-panel {
        padding: 20px 16px 48px;
    }

    .input-container {
        padding: 10px 12px 8px;
    }

    .composer-footer {
        margin-top: 4px;
        padding: 0 2px;
    }

    .composer-hint {
        display: none;
    }
}

@media (max-width: 768px) {
    .message {
        padding-left: 16px;
        padding-right: 16px;
    }

    /* A touch more room for the composer on small screens (~1/3 of viewport) */
    .composer-field textarea {
        max-height: 33dvh;
    }

    /* Auto-shrink avatar on mobile */
    .floating-avatar .avatar-image {
        width: var(--avatar-small) !important;
        height: var(--avatar-small) !important;
        font-size: 2rem !important;
    }

    .avatar-label {
        display: none;
    }
}

@media (max-width: 480px) {
    .composer-controls .model-badge {
        max-width: 110px;
    }

    .tools-toggle span {
        display: none; /* icon-only pill on small phones */
    }
}

/* ===== Scrollbar Styling (Chromium) =====
   Defined track + inset rounded thumb + triangle arrow buttons top/bottom,
   styled after the Claude desktop scrollbar. Theme-aware via --scrollbar-thumb.
   Note: do NOT also set the standard scrollbar-width/scrollbar-color, or
   Chromium ignores these ::-webkit rules (incl. the arrow buttons). */
::-webkit-scrollbar {
    width: 14px;
    height: 14px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 8px;
    border: 3px solid var(--bg-tertiary); /* inset padding so the thumb floats */
    min-height: 36px;
}

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

::-webkit-scrollbar-corner {
    background: var(--bg-tertiary);
}

/* Arrow buttons: hide everything by default, then show up/down triangles on
   vertical scrollbars (horizontal scrollbars stay arrow-less). */
::-webkit-scrollbar-button {
    display: none;
}

::-webkit-scrollbar-button:single-button:vertical:decrement,
::-webkit-scrollbar-button:single-button:vertical:increment {
    display: block;
    width: 14px;
    height: 14px;
    background-color: var(--bg-tertiary);
    background-repeat: no-repeat;
    background-position: center;
    background-size: 8px 8px;
}

::-webkit-scrollbar-button:single-button:vertical:decrement {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'%3E%3Cpath fill='%238a8fa3' d='M4 2 L7 6 L1 6 Z'/%3E%3C/svg%3E");
}

::-webkit-scrollbar-button:single-button:vertical:increment {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'%3E%3Cpath fill='%238a8fa3' d='M1 2 L7 2 L4 6 Z'/%3E%3C/svg%3E");
}

/* ===== Advanced Settings / Model Parameters ===== */
.param-group {
    margin-bottom: 1rem;
}

.param-group label {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.param-value {
    color: var(--accent);
    font-weight: 500;
    font-size: var(--text-sm);
}

/* Sliders and number inputs draw from the base field rules; only the layout
   these rows need is stated here. */
.param-group input[type="range"] {
    width: 100%;
    margin-top: 0.5rem;
}

.param-group input[type="number"] {
    width: 100%;
}

/* Toggle labels */
.toggle-label {
    display: flex !important;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

/* Tag input for stop sequences */
.tag-input-container {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.5rem;
    min-height: 40px;
}

.tags-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.tags-wrapper:empty {
    display: none;
}

.tag {
    display: inline-flex;
    align-items: center;
    background: var(--accent);
    color: var(--on-accent);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: var(--text-sm);
    cursor: pointer;
    transition: opacity 0.2s;
}

.tag:hover {
    opacity: 0.8;
}

.tag::after {
    content: '×';
    margin-left: 0.5rem;
    font-weight: bold;
}

.tag-input-container input {
    border: none;
    background: transparent;
    color: var(--text-primary);
    width: 100%;
    padding: 0.25rem 0;
    font-size: var(--text-sm);
}

.tag-input-container input:focus {
    outline: none;
}

.tag-input-container input::placeholder {
    color: var(--text-secondary);
}

/* Provider-specific sections */
.provider-params {
    border-top: 1px solid var(--border-color);
    margin-top: 1rem;
    padding-top: 1rem;
}

.provider-params h4 {
    margin: 0 0 1rem 0;
    color: var(--accent);
    font-size: var(--text-sm);
    font-weight: 600;
}

/* Safety settings collapsible */
.safety-settings {
    margin-top: 1rem;
}

.safety-settings summary {
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0.5rem 0;
    user-select: none;
}

.safety-settings summary:hover {
    color: var(--text-primary);
}

.safety-settings[open] summary {
    margin-bottom: 1rem;
}

.safety-settings .param-group {
    margin-bottom: 0.75rem;
}

.safety-settings select {
    width: 100%;
    padding: 0.4rem;
    font-size: var(--text-sm);
}

/* Disabled parameter groups */
.param-group.disabled input[type="range"],
.param-group.disabled input[type="number"] {
    opacity: 0.4;
    pointer-events: none;
}

.param-group.disabled .param-value {
    opacity: 0.4;
}

.param-group.disabled .help-text {
    opacity: 0.4;
}

/* Enable checkbox in param labels — size and color come from the base rule. */
.param-group label input[type="checkbox"] {
    margin-right: 6px;
    vertical-align: middle;
}

/* ===== Usage breakdown (U-04) =====
   Shows WHERE a chat tokens went. Rows are per (provider, model) and are
   never summed across models: Tessera reports tokens and never money, so a
   figure is only useful if the user can apply their own per-MTok rate, and a
   mixed total is a number nobody can price. */
.usage-modal { max-width: 640px; }

/* The panel is a list that can run long; keep it scrolling inside itself so
   the page never scrolls horizontally or grows past the viewport. */
.usage-modal .modal-body {
    max-height: 65vh;
    overflow-y: auto;
}

.usage-note {
    margin: 0 0 1rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.5;
}

.usage-total,
.usage-turns { margin-bottom: 1.25rem; }

.usage-total h3,
.usage-turns h3 {
    margin: 0 0 0.6rem;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.usage-model {
    padding: 0.5rem 0.7rem;
    margin-bottom: 0.4rem;
    background: var(--bg-tertiary);
    border-radius: 6px;
}

.usage-model-name {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    /* Model ids are long and must wrap rather than scroll the panel sideways. */
    overflow-wrap: anywhere;
}

.usage-model-figures {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1rem;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.usage-cache,
.usage-thinking { color: var(--text-secondary); }

.usage-turn-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.usage-turn {
    padding: 0.5rem 0;
    border-top: 1px solid var(--border-color);
}

.usage-turn-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.35rem;
    font-size: 0.82rem;
}

.usage-turn-n { color: var(--text-primary); font-weight: 500; }
.usage-turn-meta { color: var(--text-secondary); }

.usage-flag {
    color: var(--warning, #d98032);
    font-weight: 500;
}

.usage-floor {
    margin: 0.5rem 0 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* ===== Persona section fields (PS-02) =====
   The five named persona sections in the editor. They use the app-wide field
   appearance; only the rhythm between them belongs here, so a stack of six
   labelled boxes reads as a form rather than a wall. */

.persona-sections-intro {
    margin-bottom: 14px;
}

/* Each section (PT-05): label, help, trait tags, then one panel holding the
   Prompt text and the section's own textarea. The break between sections
   comes from the section block, not the fields inside it. */
.persona-section {
    margin-bottom: 22px;
}

.persona-section > .help-text {
    margin: 2px 0 8px;
}

#personaSectionFields .trait-panel .textarea-resizable {
    margin-bottom: 0;
}

/* ===== Persona traits (PT-05) =====
   Tags for what is picked, the Prompt text panel (trait sentences as
   assembled, click to edit) and the picker sheet. Design:
   docs/design/PERSONA_TRAITS_DESIGN.md D9. */

.trait-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.trait-tag {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    border: 1px solid var(--accent);
    background: var(--accent-subtle);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
}

.trait-tag.is-customised { border-color: var(--warning); }
.trait-tag.is-unknown { border-color: var(--border-color); background: none; color: var(--text-muted); }
.trait-tag.is-linked { box-shadow: 0 0 0 2px var(--accent-light); }

.trait-tag-label,
.trait-tag-remove {
    background: none;
    border: none;
    color: inherit;
    font: inherit;
    cursor: pointer;
}

.trait-tag-label { padding: 3px 4px 3px 11px; overflow-wrap: anywhere; text-align: left; }
.trait-tag-label:disabled { cursor: default; }
.trait-tag-remove { padding: 3px 9px 3px 4px; opacity: 0.7; font-size: 0.9rem; line-height: 1; }
.trait-tag-remove:hover { opacity: 1; }

.trait-add {
    border: 1px dashed var(--text-muted);
    background: none;
    color: var(--text-secondary);
    border-radius: var(--radius-full);
    padding: 3px 11px;
    font: inherit;
    font-size: var(--text-xs);
    cursor: pointer;
}

.trait-add:hover:not(:disabled) { border-color: var(--accent); color: var(--text-primary); }

.trait-panel {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px 12px 12px;
}

.trait-panel-cap {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.trait-text { margin-bottom: 8px; }

.trait-paragraph {
    margin: 0 0 6px;
    font-size: var(--text-sm);
    line-height: 1.6;
    overflow-wrap: anywhere;
}

.trait-sentence {
    border-radius: 3px;
    cursor: text;
    transition: background-color 0.1s;
}

.trait-sentence:hover,
.trait-sentence:focus-visible,
.trait-sentence.is-linked { background: var(--accent-subtle); outline: none; }

.trait-sentence.is-customised {
    text-decoration: underline dotted var(--warning);
    text-underline-offset: 3px;
}

.trait-text-empty {
    margin: 0;
    font-size: var(--text-sm);
    color: var(--text-muted);
}

.trait-edit { margin: 4px 0 8px; }
.trait-edit-field { width: 100%; resize: vertical; }

.trait-edit-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 12px;
    margin-top: 4px;
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.trait-edit-state { flex: 1; min-width: 10em; }
.trait-edit-state .is-customised,
.trait-tag.is-customised .trait-tag-label span { color: var(--warning); }

.trait-link-btn {
    background: none;
    border: none;
    padding: 2px 0;
    color: var(--accent-light);
    font: inherit;
    cursor: pointer;
}

.trait-link-btn:hover { text-decoration: underline; }

/* The picker: a centred sheet, a bottom sheet on a phone. Not a .modal-overlay
   (it is created on open and removed on close, so there is no visibility
   transition to get wrong), but it stacks the same way. */
.trait-sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 260;
}

.trait-sheet {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.trait-sheet-head {
    padding: 14px 16px 12px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.trait-sheet-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.trait-sheet-title-row h3 { margin: 0; font-size: var(--text-base); }

.trait-sheet-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
}

.trait-sheet-search { width: 100%; }

/* `contain` stops a scroll that reaches the end from moving the page behind. */
.trait-sheet-list { overflow-y: auto; overscroll-behavior: contain; padding: 12px 16px; flex: 1; }

.trait-group { margin-bottom: 12px; }

.trait-group-name {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.trait-group-kind { text-transform: none; letter-spacing: 0; color: var(--text-muted); }

.trait-option {
    display: flex;
    gap: 10px;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    padding: 6px 8px;
    color: var(--text-primary);
    font: inherit;
    cursor: pointer;
}

.trait-option:hover { background: var(--bg-tertiary); }

.trait-option-check {
    flex: none;
    width: 18px;
    height: 18px;
    margin-top: 2px;
    border: 1px solid var(--text-muted);
    border-radius: 4px;
    display: grid;
    place-items: center;
    font-size: 0.7rem;
}

.trait-option.is-radio .trait-option-check { border-radius: 50%; }
.trait-option.is-on .trait-option-check { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.trait-option-body { min-width: 0; }
.trait-option-label { display: block; font-size: var(--text-sm); font-weight: 600; }
.trait-option-text { display: block; font-size: var(--text-xs); color: var(--text-secondary); overflow-wrap: anywhere; }

.trait-sheet-foot {
    padding: 10px 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
}

@media (max-width: 600px) {
    .trait-sheet-backdrop { align-items: flex-end; padding: 0; }
    .trait-sheet { max-width: none; max-height: 85vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
}
