/*
 * static/css/sidebar.css — the left chat panel: the header (wordmark, "Hide sidebar"), "+ New", the chat list (rows,
 * rename and delete, the working dot and the "new result" ring), the guest note, the footer (Settings, Log out), the
 * desktop show/hide (<html data-sidebar="collapsed">, applied by theme-boot.js), the phone drawer (<= 768 px, the
 * sidebar.js MOBILE_QUERY) and the profile's motif.
 *
 * Owner: plan R-110, lane sidebar (moved here from layout.css). Ray (2026-11-13): the panel "looks somewhat boring and
 * sloppy (especially the `New` button and chats)", and "a cool modern-looking floral pattern" in the spirit of an
 * airline cabin motif. Every selector is defined once, in one file (I7; T-CSS checks the critical ones).
 * - "+ New" is a full-width row with a gold disc (ink with a gold plus in light); the "+" stays in the DOM.
 * - Rows: hover tints, a press darkens, the open chat takes the tonal fill and a gold edge; rename and delete show on
 *   hover, keyboard focus and the open chat (always with touch, in the phone drawer and while computer use runs), and
 *   a title gives up its room to them only while they show, so a title is cut only where it has to be. Hidden, they
 *   take no click: an idle title runs under them (final review visual-1).
 * - The motif: the profile's --brand-sidebar-pattern (its theme.css; Baseline: /brand/sidebar-pattern.svg) is a mask
 *   drawn in --c-sidebar-motif under everything, anchored at the bottom, at the open width (it never squeezes while
 *   the sidebar slides shut), drawn once (no-repeat). Baseline's is one airy drawing as tall as a laptop's panel, not
 *   a tile (Ray 2026-11-14: the lattice was "too rigid"; "lighter ... less compact and tight", "more abstract"):
 *   sweeping hairlines, a drift of single petals thinning upward, a dotted trail, a faint bloom in the corner. Its top
 *   is empty, so a taller panel shows no edge. The token's default is an empty image, so a fork without a motif shows
 *   none. Forced colours: no motif.
 * - Computer use: the drawer starts below the banner while it covers the nav (cu.css, :root[data-cu-band]); every row
 *   shows its rename and delete while a session runs (<html data-cu-session>, set by cu/overlay.js), since its pointer
 *   never hovers: the model's picture shows what its clicks reach, by ref and by coordinates.
 */

/* ============================================================
   THE PANEL: a tonal surface with the paper grain and the motif, no edge (Q5)
   ============================================================ */
#sidebar {
    --aiw-sidebar-w: 280px;
    position: relative; isolation: isolate;
    width: var(--aiw-sidebar-w); flex-shrink: 0; overflow: hidden;
    display: flex; flex-direction: column;
    background: var(--grain), var(--c-surface-low);
    transition: width var(--dur-4) var(--ease-standard), background-color var(--dur-3) var(--ease-standard), color var(--dur-3) var(--ease-standard);
}
/* The contents keep the open width while the sidebar slides shut, so nothing in it rewraps mid-animation;
   #sidebar clips them. */
#sidebar > * { min-width: var(--aiw-sidebar-w); }
#sidebar::before {
    content: ''; position: absolute; left: 0; bottom: 0; z-index: -1;
    width: var(--aiw-sidebar-w); height: 100%; pointer-events: none;
    background: var(--c-sidebar-motif);
    -webkit-mask: var(--brand-sidebar-pattern) left bottom / var(--aiw-sidebar-w) auto no-repeat;
    mask: var(--brand-sidebar-pattern) left bottom / var(--aiw-sidebar-w) auto no-repeat;
}

/* ============================================================
   HEADER: the wordmark and the hide button, then "+ New" (.sidebar-header-actions lets its two buttons take part
   in this grid)
   ============================================================ */
.sidebar-header {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "brand collapse" "new new";
    align-items: center; column-gap: var(--space-1); row-gap: var(--space-3);
    padding: 12px 10px 14px;
}
.sidebar-brand { color: var(--c-accent-text); }
.sidebar-home-link {
    grid-area: brand; justify-self: start; max-width: 100%; height: 40px; padding: 0 10px;
    border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--c-on);
    font: 500 1.1875rem / 1.2 var(--font-display); letter-spacing: 0.005em; cursor: pointer;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    transition: background-color var(--dur-1) var(--ease-standard);
}
.sidebar-home-link:hover { background: var(--c-hover); }
.sidebar-header-actions { display: contents; }
/* The header's "Hide sidebar" button (on a phone it closes the drawer). */
.sidebar-panel-btn {
    grid-area: collapse; display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; padding: 0; border: 0; border-radius: var(--radius-sm);
    background: transparent; color: var(--c-on-3); cursor: pointer;
    transition: background-color var(--dur-1) var(--ease-standard), color var(--dur-1) var(--ease-standard);
}
.sidebar-panel-btn:hover { background: var(--c-hover); color: var(--c-on); }
.sidebar-panel-btn:active { background: var(--c-pressed); }
.sidebar-panel-icon { display: block; flex-shrink: 0; width: 20px; height: 20px; }
/* "+ New": a full-width row. The "+" (its own aria-hidden span) is the primary disc, the plus an icon drawn over it;
   the word keeps its size. */
.new-chat-btn {
    grid-area: new; position: relative; display: flex; align-items: center; gap: var(--space-3);
    width: 100%; height: 44px; padding: 0 16px 0 8px; border: 0; border-radius: var(--radius-md);
    background: color-mix(in srgb, var(--c-surface-high) 72%, transparent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c-accent) 26%, transparent);
    color: var(--c-on); font-size: 0; text-align: left; cursor: pointer;
    transition: background-color var(--dur-1) var(--ease-standard), box-shadow var(--dur-1) var(--ease-standard);
}
.new-chat-btn > span:first-child {
    flex: none; width: 28px; height: 28px; border-radius: 50%;
    background: var(--c-primary); box-shadow: inset 0 0 0 1px var(--c-primary-edge);
    transition: background-color var(--dur-1) var(--ease-standard);
}
.new-chat-btn::before {
    content: ''; position: absolute; left: 14px; top: 50%; width: 16px; height: 16px; margin-top: -8px;
    background: var(--c-on-primary-accent);
    -webkit-mask: var(--icon-plus) center / contain no-repeat; mask: var(--icon-plus) center / contain no-repeat;
}
.new-chat-btn > span:last-child { font: var(--t-label-l); font-size: 0.9375rem; }
.new-chat-btn:hover { background: var(--c-surface-high); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c-accent) 46%, transparent); }
.new-chat-btn:hover > span:first-child { background: var(--c-primary-hover); }
.new-chat-btn:active { background: var(--c-surface-highest); }
body.guest-mode .new-chat-btn, .new-chat-btn:disabled { opacity: 0.55; cursor: not-allowed; pointer-events: none; }

/* ============================================================
   THE CHAT LIST
   ============================================================ */
#chat-list { flex: 1; min-height: 0; overflow-y: auto; list-style: none; padding: var(--space-1) 10px var(--space-3); }
/* The rename/delete buttons are the link's sibling (no buttons inside an <a>); they sit over the link's right
   padding, which grows to make room for them only while they show. Hidden, they let clicks through to the link:
   a click near the end of a long idle title (or a tap without hover) opens the chat, not Rename or Delete. */
.chat-row { position: relative; margin-bottom: 2px; }
.chat-item {
    position: relative; min-height: 38px; padding: 0 12px;
    border-radius: var(--radius-sm); cursor: pointer; color: var(--c-on-2); text-decoration: none;
    display: flex; align-items: center; gap: var(--space-2);
    transition: background-color var(--dur-1) var(--ease-standard), color var(--dur-1) var(--ease-standard);
}
.chat-item:hover, .chat-row:hover > .chat-item:not(.active) { background-color: var(--c-hover); color: var(--c-on); }
.chat-item:active:not(.active) { background-color: var(--c-pressed); }
/* the open chat: the tonal fill and a short gold edge */
.chat-item.active { background-color: var(--c-accent-container); color: var(--c-on-accent-container); font-weight: 500; }
.chat-item.active::before {
    content: ''; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px;
    border-radius: var(--radius-pill); background: var(--c-accent);
}
.chat-item.title-flash { animation: title-flash 1s var(--ease-standard); }
@keyframes title-flash { from { background-color: var(--c-accent-container); } to { background-color: transparent; } }
.chat-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font: inherit; font-size: 0.875rem; }
.chat-row:hover > .chat-item, .chat-row:focus-within > .chat-item, .chat-row > .chat-item.active { padding-right: 70px; }
.chat-actions {
    position: absolute; top: 50%; right: 4px; transform: translateY(-50%); display: flex; gap: 2px;
    opacity: 0; pointer-events: none; transition: opacity var(--dur-1) var(--ease-standard);
}
.chat-row:hover > .chat-actions, .chat-row:focus-within > .chat-actions, .chat-item.active + .chat-actions { opacity: 1; pointer-events: auto; }
/* ✎ and × (kept in the DOM) drawn as line icons: a pencil and a bin */
.chat-action-btn {
    display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0;
    border: 0; border-radius: var(--radius-xs); background: transparent; color: var(--c-on-3);
    font-size: 0; line-height: 0; cursor: pointer;
    transition: background-color var(--dur-1) var(--ease-standard), color var(--dur-1) var(--ease-standard);
}
.chat-action-btn::before {
    content: ''; width: 16px; height: 16px; background: currentColor;
    -webkit-mask: var(--icon-trash) center / contain no-repeat; mask: var(--icon-trash) center / contain no-repeat;
}
.chat-action-btn:first-child::before { -webkit-mask-image: var(--icon-pencil); mask-image: var(--icon-pencil); }
.chat-action-btn:hover { color: var(--c-on); background: var(--c-hover); }
.chat-action-btn[data-action="delete"]:hover { color: var(--c-danger); }
.chat-item.active + .chat-actions .chat-action-btn { color: var(--c-on-accent-container); }
.empty-state { color: var(--c-on-3); padding: var(--space-2) var(--space-3); font: var(--t-body-m); }
.guest-empty-state {
    margin: var(--space-1) 2px; padding: 14px 16px; border-radius: var(--radius-md);
    background: color-mix(in srgb, var(--c-surface-raised) 90%, transparent); box-shadow: inset 0 0 0 1px var(--c-outline-variant);
    color: var(--c-on-2); font: var(--t-body-s); line-height: 1.55; white-space: normal;
}

/* D3 / R-79: working indicator (pulsing gold dot; steady under reduced motion) and the hollow "new result" ring for
   a chat that finished in the background (FA §12.1, Q1). The nav's show button pulses the same way (layout.css). */
.run-dot { display: none; flex: 0 0 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--c-accent); box-sizing: border-box; }
.chat-item.running .run-dot { display: block; animation: run-dot-pulse 1.4s ease-in-out infinite; }
.chat-item.unseen:not(.running) .run-dot { display: block; background: transparent; border: 1.5px solid var(--c-accent); }
@keyframes run-dot-pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.35; transform: scale(0.8); } }

/* ============================================================
   FOOTER: Settings and Log out ("Return to home" for a guest), under a gold hairline that fades at both ends
   ============================================================ */
.sidebar-footer { position: relative; display: grid; gap: 2px; padding: var(--space-3) 10px 12px; }
.sidebar-footer::before {
    content: ''; position: absolute; top: 0; left: 22px; right: 22px; height: 1px;
    background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--c-accent) 34%, transparent) 30%, color-mix(in srgb, var(--c-accent) 34%, transparent) 70%, transparent);
}
.logout-btn {
    width: 100%; min-height: 40px; display: flex; align-items: center; gap: var(--space-3); padding: 0 12px;
    border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--c-on-2);
    font: var(--t-body-m); text-align: left; cursor: pointer;
    transition: background-color var(--dur-1) var(--ease-standard), color var(--dur-1) var(--ease-standard);
}
.logout-btn::before {
    content: ''; flex: none; width: 18px; height: 18px; background: currentColor;
    -webkit-mask: var(--icon-logout) center / contain no-repeat; mask: var(--icon-logout) center / contain no-repeat;
}
#settings-btn::before { -webkit-mask-image: var(--icon-settings); mask-image: var(--icon-settings); }
body.guest-mode #logout-btn::before { -webkit-mask-image: var(--icon-home); mask-image: var(--icon-home); }
.logout-btn:hover { background: var(--c-hover); color: var(--c-on); }
.logout-btn:active { background: var(--c-pressed); }

/* ============================================================
   SHOW / HIDE
   ============================================================ */
/* Desktop show/hide (Ray, 2026-10-29): theme-boot.js and sidebar.js set <html data-sidebar="collapsed">;
   the chat takes the freed width, and the nav's show button appears only while the sidebar is hidden
   (sidebar.js also makes the hidden sidebar inert). Phones ignore this state: their sidebar is the drawer
   (`min-width: 768.02px` complements the phone query, sidebar.js MOBILE_QUERY, without range syntax). */
@media (min-width: 768.02px) {
    :root[data-sidebar="collapsed"] #sidebar { width: 0; }
    :root:not([data-sidebar="collapsed"]) #sidebar-toggle { display: none; }
}
/* The phone drawer: a modal overlay (sidebar.js). The shadow belongs to the open state only: closed, its blur would
   darken the screen's left edge. */
@media (max-width: 768px) {
    #sidebar { position: fixed; z-index: 50; height: 100vh; height: 100dvh; box-shadow: none; transform: translateX(-100%); display: flex; --aiw-sidebar-w: min(300px, calc(100vw - 56px)); transition: transform var(--dur-4) var(--ease-standard), box-shadow var(--dur-4) var(--ease-standard); }
    body.sidebar-open #sidebar { transform: translateX(0); box-shadow: var(--elev-3); }
    body.sidebar-open::after { content: ''; position: fixed; inset: 0; background: var(--c-scrim); z-index: 40; backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }
}
/* Without a hover (touch) and in the drawer, every row keeps its rename and delete on screen; so does computer use
   while a session runs (cu/overlay.js marks <html>): its pointer never hovers, and the model's picture then shows
   exactly what its clicks reach (final review visual-1). */
@media (max-width: 768px), (hover: none) {
    .chat-actions { opacity: 1; pointer-events: auto; }
    .chat-row > .chat-item { padding-right: 70px; }
}
:root[data-cu-session] .chat-actions { opacity: 1; pointer-events: auto; }
:root[data-cu-session] .chat-row > .chat-item { padding-right: 70px; }

/* Forced colours: no motif; the line icons are masks (they would take the Canvas colour), the disc keeps an edge,
   and the open chat's edge takes the highlight. */
@media (forced-colors: active) {
    #sidebar::before { display: none; }
    .new-chat-btn::before, .logout-btn::before, .chat-action-btn::before { forced-color-adjust: none; background: ButtonText; }
    .new-chat-btn > span:first-child { border: 1px solid ButtonText; }
    .chat-item.active::before { forced-color-adjust: none; background: Highlight; }
}

@media (prefers-reduced-motion: reduce) {
    #sidebar { transition: none; }
    .chat-item.running .run-dot { animation: none; }
    .chat-item.title-flash { animation: none; }
}
