/* ==========================================================================
   vamshiclaw — OpenClaw WebUI
   A field journal for AI work. Warm paper, deliberate type, considered detail.
   ========================================================================== */

/* Fonts ------------------------------------------------------------------- */
@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,500;0,9..144,600;0,9..144,700;1,9..144,400;1,9..144,500&family=Inter+Tight:wght@400;450;500;550;600;700&family=JetBrains+Mono:ital,wght@0,400;0,500;0,600;1,400&display=swap');

/* Design tokens ----------------------------------------------------------- */
:root {
    --font-display: 'Fraunces', 'Iowan Old Style', 'Apple Garamond', 'Baskerville', Georgia, serif;
    --font-sans: 'Inter Tight', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
        'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

    --tracking-display: -0.035em;
    --tracking-tight: -0.02em;
    --tracking-snug: -0.01em;
    --tracking-eyebrow: 0.18em;

    --radius-xs: 4px;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-pill: 999px;

    --duration-fast: 140ms;
    --duration-med: 220ms;
    --duration-slow: 360ms;
    --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
    --ease-out: cubic-bezier(0.16, 0.84, 0.32, 1);

    --measure: 68ch;
    --sidebar-w: 296px;
}

[data-theme='light'] {
    --bg: #f3ede0;
    --bg-grain: rgba(60, 38, 18, 0.025);
    --bg-tint: #ece5d2;
    --surface: #fbf7ec;
    --surface-2: #f5efde;
    --surface-3: #ebe4cf;
    --sidebar-bg: #ebe3cf;
    --sidebar-tint: #e2d9c0;
    --border: rgba(28, 22, 14, 0.10);
    --border-strong: rgba(28, 22, 14, 0.18);
    --border-faint: rgba(28, 22, 14, 0.05);
    --rule: rgba(28, 22, 14, 0.14);
    --text: #1a140d;
    --text-muted: #5e544a;
    --text-faint: #8c8273;
    --text-vfaint: #b3a999;
    --accent: #2c5738;
    --accent-hover: #1f4328;
    --accent-soft: rgba(44, 87, 56, 0.09);
    --accent-soft-strong: rgba(44, 87, 56, 0.16);
    --accent-fg: #f5efde;
    --warm: #8b3a1f;
    --warm-soft: rgba(139, 58, 31, 0.10);
    --user-bubble: #1a140d;
    --user-bubble-fg: #f3ede0;
    --code-bg: #ece4cd;
    --code-border: rgba(28, 22, 14, 0.10);
    --selection: rgba(44, 87, 56, 0.18);
    --good: #2c5738;
    --warn: #8b5a1f;
    --danger: #8b2f2f;

    --shadow-sm: 0 1px 0 rgba(28, 22, 14, 0.04), 0 1px 2px rgba(28, 22, 14, 0.04);
    --shadow-md: 0 1px 0 rgba(28, 22, 14, 0.04), 0 8px 20px -10px rgba(28, 22, 14, 0.18);
    --shadow-lg: 0 1px 0 rgba(28, 22, 14, 0.04), 0 24px 48px -20px rgba(28, 22, 14, 0.22);
    --shadow-focus: 0 0 0 1px var(--accent), 0 0 0 4px var(--accent-soft);
    --shadow-inset: inset 0 0 0 1px rgba(28, 22, 14, 0.06);
}

[data-theme='dark'] {
    --bg: #14110d;
    --bg-grain: rgba(255, 245, 220, 0.015);
    --bg-tint: #1a1612;
    --surface: #1c1813;
    --surface-2: #221d17;
    --surface-3: #2a241c;
    --sidebar-bg: #181410;
    --sidebar-tint: #14110d;
    --border: rgba(245, 235, 210, 0.08);
    --border-strong: rgba(245, 235, 210, 0.14);
    --border-faint: rgba(245, 235, 210, 0.04);
    --rule: rgba(245, 235, 210, 0.12);
    --text: #f0e9d6;
    --text-muted: #a99e88;
    --text-faint: #7a7060;
    --text-vfaint: #4a4438;
    --accent: #7fb38c;
    --accent-hover: #95c4a0;
    --accent-soft: rgba(127, 179, 140, 0.12);
    --accent-soft-strong: rgba(127, 179, 140, 0.20);
    --accent-fg: #14110d;
    --warm: #d77a4f;
    --warm-soft: rgba(215, 122, 79, 0.12);
    --user-bubble: #f0e9d6;
    --user-bubble-fg: #14110d;
    --code-bg: #221d17;
    --code-border: rgba(245, 235, 210, 0.08);
    --selection: rgba(127, 179, 140, 0.20);
    --good: #7fb38c;
    --warn: #d4a259;
    --danger: #d4725a;

    --shadow-sm: 0 1px 0 rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 1px 0 rgba(0, 0, 0, 0.3), 0 12px 24px -12px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 1px 0 rgba(0, 0, 0, 0.3), 0 32px 64px -24px rgba(0, 0, 0, 0.6);
    --shadow-focus: 0 0 0 1px var(--accent), 0 0 0 4px var(--accent-soft);
    --shadow-inset: inset 0 0 0 1px rgba(245, 235, 210, 0.06);
}

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

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.55;
    color: var(--text);
    background-color: var(--bg);
    background-image:
        radial-gradient(var(--bg-grain) 1px, transparent 1px),
        radial-gradient(var(--bg-grain) 1px, transparent 1px);
    background-size: 3px 3px, 7px 7px;
    background-position: 0 0, 1px 2px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    overflow: hidden;
    font-feature-settings: 'ss01', 'cv11', 'kern';
    transition: background-color var(--duration-med) var(--ease),
        color var(--duration-med) var(--ease);
}

[data-theme='dark'] body {
    background-image: none;
}

::selection {
    background: var(--selection);
    color: var(--text);
}

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

button {
    background: none;
    border: 0;
    cursor: pointer;
    padding: 0;
    color: inherit;
}

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

kbd {
    font-family: var(--font-mono);
    font-size: 10.5px;
    font-weight: 500;
    padding: 1px 5px;
    color: var(--text-muted);
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 4px;
    line-height: 1.4;
    letter-spacing: 0.02em;
}

h1, h2, h3, h4, p, ul, ol, pre, figure, blockquote {
    margin: 0;
}

/* App layout -------------------------------------------------------------- */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    height: 100vh;
    height: 100dvh;
    background: var(--bg);
}

.sidebar {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--rule);
    position: relative;
}

.sidebar::after {
    content: '';
    position: absolute;
    top: 0;
    right: -1px;
    bottom: 0;
    width: 1px;
    background: linear-gradient(180deg, transparent, var(--border-strong) 12%, var(--border-strong) 88%, transparent);
    pointer-events: none;
}

.main {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-width: 0;
    min-height: 0;
    background: var(--bg);
    position: relative;
}

/* Sidebar: top ----------------------------------------------------------- */
.sidebar-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 18px 14px 12px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    flex: 1;
    min-width: 0;
    padding: 4px 4px 4px 2px;
    border-radius: var(--radius-sm);
    transition: opacity var(--duration-fast) var(--ease);
}

.brand:hover {
    opacity: 0.85;
}

/* Custom monogram mark — claw-feel, not generic triangles */
.brand-mark {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    background: var(--text);
    color: var(--bg);
    border-radius: 7px;
    flex: 0 0 auto;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-inset);
}

.brand-mark::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 0%, transparent 50%, var(--accent-soft-strong) 100%);
    pointer-events: none;
}

.brand-mark svg {
    width: 18px;
    height: 18px;
    position: relative;
    z-index: 1;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.05;
    min-width: 0;
}

.brand-name {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 500;
    letter-spacing: var(--tracking-display);
    color: var(--text);
    font-feature-settings: 'ss01', 'kern';
}

.brand-meta {
    font-size: 10px;
    color: var(--text-faint);
    font-weight: 500;
    margin-top: 3px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.icon-btn {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    transition: background var(--duration-fast) var(--ease),
        color var(--duration-fast) var(--ease),
        border-color var(--duration-fast) var(--ease);
}

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

.icon-btn:focus-visible {
    outline: 0;
    box-shadow: var(--shadow-focus);
}

.icon-btn svg {
    width: 15px;
    height: 15px;
    stroke-width: 1.4;
}

/* New conversation button — editorial, not pillowy */
.new-chat-btn {
    position: relative;
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 0 14px 14px;
    padding: 10px 12px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-sm);
    letter-spacing: var(--tracking-snug);
    transition: background var(--duration-fast) var(--ease),
        border-color var(--duration-fast) var(--ease),
        transform var(--duration-fast) var(--ease),
        box-shadow var(--duration-fast) var(--ease);
}

.new-chat-btn:hover {
    background: var(--surface-2);
    border-color: var(--border-strong);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.new-chat-btn:active {
    transform: translateY(0);
}

.new-chat-btn:focus-visible {
    outline: 0;
    box-shadow: var(--shadow-focus);
}

.new-chat-btn svg {
    width: 13px;
    height: 13px;
    color: var(--accent);
    flex: 0 0 auto;
    stroke-width: 1.6;
}

.new-chat-btn kbd {
    margin-left: auto;
    font-size: 9.5px;
    padding: 1px 4px 2px;
    border-bottom-width: 1px;
}

@keyframes pulse-accent {
    0%, 100% { box-shadow: var(--shadow-sm); }
    50% { box-shadow: var(--shadow-sm), 0 0 0 3px var(--accent-soft); }
}

.new-chat-btn.is-pulsing {
    animation: pulse-accent 2.4s var(--ease) 1;
}

/* Search field ------------------------------------------------------------ */
.sidebar-search {
    position: relative;
    display: flex;
    align-items: center;
    margin: 0 14px 14px;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid var(--border);
    border-bottom-width: 1px;
    border-radius: 0;
    border-top: 0;
    border-left: 0;
    border-right: 0;
    padding: 8px 2px;
    transition: border-color var(--duration-fast) var(--ease);
}

.sidebar-search:hover {
    border-color: var(--border-strong);
}

.sidebar-search:focus-within {
    border-color: var(--accent);
}

.sidebar-search-icon {
    width: 13px;
    height: 13px;
    margin-right: 8px;
    flex: 0 0 auto;
    color: var(--text-faint);
    stroke-width: 1.4;
    transition: color var(--duration-fast) var(--ease);
}

.sidebar-search:focus-within .sidebar-search-icon {
    color: var(--accent);
}

.sidebar-search-input {
    flex: 1;
    min-width: 0;
    height: 18px;
    padding: 0;
    background: transparent;
    border: 0;
    outline: 0;
    color: var(--text);
    font-size: 12.5px;
    font-family: var(--font-sans);
    letter-spacing: var(--tracking-snug);
}

.sidebar-search-input::placeholder {
    color: var(--text-vfaint);
    font-style: italic;
    font-family: var(--font-display);
    font-size: 13px;
    letter-spacing: 0;
}

.sidebar-search-input::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;
}

.sidebar-search-kbd {
    margin-left: 6px;
    font-size: 9.5px;
    padding: 0 4px 1px;
    color: var(--text-vfaint);
    background: transparent;
    border: 1px solid var(--border);
    border-bottom-width: 1px;
    border-radius: 3px;
}

.sidebar-search:focus-within .sidebar-search-kbd {
    opacity: 0;
}

/* Sections --------------------------------------------------------------- */
.sidebar-section {
    padding: 4px 14px 8px;
    min-height: 0;
}

.sidebar-section + .sidebar-section {
    margin-top: 4px;
    border-top: 1px solid var(--border-faint);
    padding-top: 12px;
}

.sidebar-quicklinks {
    margin-top: auto;
    padding-top: 12px;
    padding-bottom: 6px;
    border-top: 1px solid var(--border-faint);
}

.section-label {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 4px 2px 8px;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-faint);
    letter-spacing: var(--tracking-eyebrow);
    text-transform: uppercase;
    text-align: left;
    background: transparent;
    transition: color var(--duration-fast) var(--ease);
}

.section-label:hover {
    color: var(--text-muted);
}

.section-label:focus-visible {
    outline: 0;
    box-shadow: var(--shadow-focus);
    border-radius: 2px;
}

.section-label-left {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    font-family: var(--font-mono);
    font-weight: 500;
}

.section-label .num {
    color: var(--text-vfaint);
    font-size: 9.5px;
    font-weight: 500;
}

.section-chevron {
    width: 10px;
    height: 10px;
    color: var(--text-vfaint);
    flex: 0 0 auto;
    stroke-width: 1.6;
    transition: transform var(--duration-med) var(--ease),
        color var(--duration-fast) var(--ease);
}

.section-label[aria-expanded='false'] .section-chevron {
    transform: rotate(-90deg);
}

.section-label:hover .section-chevron {
    color: var(--text-muted);
}

.section-count {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 500;
    color: var(--text-vfaint);
    transition: color var(--duration-fast) var(--ease);
}

.section-label:hover .section-count {
    color: var(--text-muted);
}

/* Collapsible section body */
[data-section] .history {
    overflow: hidden;
    max-height: 2000px;
    opacity: 1;
    transform: translateY(0);
    transition: max-height var(--duration-med) var(--ease),
        opacity var(--duration-fast) var(--ease),
        transform var(--duration-med) var(--ease),
        margin var(--duration-med) var(--ease);
}

[data-section][data-collapsed='true'] .history {
    max-height: 0;
    opacity: 0;
    transform: translateY(-4px);
    margin-top: 0;
    pointer-events: none;
}

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

.history-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 7px 6px 7px 2px;
    border-radius: 0;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 450;
    text-align: left;
    isolation: isolate;
    transition: color var(--duration-fast) var(--ease),
        padding-left var(--duration-fast) var(--ease);
    line-height: 1.3;
}

.history-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 4px;
    bottom: 4px;
    width: 1px;
    background: transparent;
    transition: background var(--duration-fast) var(--ease);
}

.history-item:hover {
    color: var(--text);
    padding-left: 8px;
}

.history-item:hover::before {
    background: var(--text-vfaint);
}

.history-item:focus-visible {
    outline: 0;
    box-shadow: var(--shadow-focus);
}

.history-item.is-active {
    color: var(--text);
    font-weight: 550;
    padding-left: 8px;
}

.history-item.is-active::before {
    background: var(--accent);
}

.history-item.is-unread .history-title {
    color: var(--text);
    font-weight: 550;
}

.history-item.is-unread .history-title::before {
    content: '·';
    display: inline-block;
    margin-right: 5px;
    color: var(--warm);
    font-weight: 700;
    transform: translateY(-1px);
}

.history-icon {
    display: grid;
    place-items: center;
    width: 16px;
    height: 16px;
    color: var(--text-vfaint);
    flex: 0 0 auto;
    transition: color var(--duration-fast) var(--ease);
}

.history-icon svg {
    width: 13px;
    height: 13px;
    stroke-width: 1.4;
}

.history-item.is-active .history-icon {
    color: var(--accent);
}

.history-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
    font-feature-settings: 'kern';
}

.history-time {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 500;
    color: var(--text-vfaint);
    flex: 0 0 auto;
    letter-spacing: 0.02em;
    transition: color var(--duration-fast) var(--ease);
}

.history-item:hover .history-time,
.history-item.is-active .history-time {
    color: var(--text-faint);
}

/* Hover actions */
.history-actions {
    display: none !important;
    align-items: center;
    gap: 1px;
    margin-left: auto;
    padding-left: 4px;
    opacity: 0;
    transform: translateX(2px);
    transition: opacity var(--duration-fast) var(--ease),
        transform var(--duration-fast) var(--ease);
}

.history-item:hover .history-actions,
.history-item:focus-within .history-actions,
.history-item.is-active .history-actions {
    opacity: 1;
    transform: translateX(0);
}

.history-action {
    display: none !important;
    place-items: center;
    width: 20px;
    height: 20px;
    color: var(--text-faint);
    background: transparent;
    border-radius: 3px;
    transition: background var(--duration-fast) var(--ease),
        color var(--duration-fast) var(--ease);
}

.history-action:hover {
    background: var(--surface-3);
    color: var(--text);
}

.history-action[data-action='delete']:hover {
    color: var(--danger);
    background: color-mix(in oklab, var(--danger) 12%, transparent);
}

.history-action svg {
    width: 11px;
    height: 11px;
    stroke-width: 1.4;
}

.history-kbd {
    margin-left: auto;
    font-size: 10px;
    padding: 0 4px 1px;
    color: var(--text-vfaint);
    background: transparent;
    border: 1px solid var(--border);
    border-bottom-width: 1px;
}

/* Ghost items (settings/help) */
.history-item--ghost {
    color: var(--text-faint);
    font-weight: 500;
    font-size: 12.5px;
    padding: 6px 2px;
    font-family: var(--font-sans);
    letter-spacing: var(--tracking-snug);
}

.history-item--ghost:hover {
    color: var(--text);
}

.history-item--ghost .history-icon {
    width: 14px;
    height: 14px;
}

.history-item--ghost .history-icon svg {
    width: 12px;
    height: 12px;
}

.history-item.is-dimmed {
    display: none;
}

/* Sidebar foot (user profile) ------------------------------------------- */
.sidebar-foot {
    margin-top: 0;
    padding: 12px 14px 14px;
    border-top: 1px solid var(--rule);
    background: linear-gradient(180deg, transparent, color-mix(in oklab, var(--sidebar-tint) 60%, transparent));
}

.user-row {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 4px 6px 2px;
    cursor: pointer;
    transition: padding-left var(--duration-fast) var(--ease);
}

.user-row::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 1px;
    background: transparent;
    transition: background var(--duration-fast) var(--ease);
}

.user-row:hover {
    padding-left: 8px;
}

.user-row:hover::before {
    background: var(--accent);
}

.user-row:focus-visible {
    outline: 0;
    box-shadow: var(--shadow-focus);
    border-radius: 4px;
}

.avatar {
    position: relative;
    width: 30px;
    height: 30px;
    border-radius: 5px;
    display: grid;
    place-items: center;
    background: var(--text);
    color: var(--bg);
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 500;
    flex: 0 0 auto;
    user-select: none;
    letter-spacing: -0.02em;
    box-shadow: var(--shadow-inset);
    transition: transform var(--duration-fast) var(--ease);
}

.avatar .avatar-date {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 13px;
    height: 13px;
    background: var(--bg);
    color: var(--text-faint);
    font-family: var(--font-mono);
    font-size: 8px;
    font-weight: 600;
    border-radius: 3px;
    display: grid;
    place-items: center;
    border: 1px solid var(--border);
    letter-spacing: 0;
}

.user-row:hover .avatar {
    transform: scale(1.04);
}

.avatar.is-warm {
    background: var(--warm);
    color: var(--bg);
}

.avatar.is-cool {
    background: var(--text-muted);
    color: var(--bg);
}

.avatar.is-accent {
    background: var(--accent);
    color: var(--accent-fg);
}

.user-meta {
    flex: 1;
    min-width: 0;
    line-height: 1.2;
}

.user-name {
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    letter-spacing: var(--tracking-snug);
    font-feature-settings: 'ss01', 'kern';
}

.user-role {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 10.5px;
    color: var(--text-faint);
    margin-top: 2px;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-family: var(--font-mono);
}

.user-row-chevron {
    width: 12px;
    height: 12px;
    color: var(--text-faint);
    flex: 0 0 auto;
    stroke-width: 1.6;
    transition: color var(--duration-fast) var(--ease);
    margin-right: 2px;
}

.user-row:hover .user-row-chevron {
    color: var(--text);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--good);
    box-shadow: 0 0 0 2px var(--sidebar-bg);
    flex: 0 0 auto;
    transition: background var(--duration-fast) var(--ease);
}

.status-dot[data-status='warn'] { background: var(--warn); }
.status-dot[data-status='danger'] { background: var(--danger); }

/* Topbar ------------------------------------------------------------------ */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 32px;
    border-bottom: 1px solid var(--rule);
    background: color-mix(in oklab, var(--bg) 88%, transparent);
    backdrop-filter: saturate(180%) blur(10px);
    -webkit-backdrop-filter: saturate(180%) blur(10px);
}

.topbar-left, .topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Model pill — editorial hairline, not a chip */
.model-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 5px 4px 5px 0;
    font-size: 12px;
    color: var(--text);
    background: transparent;
    border: 0;
    border-left: 1px solid var(--rule);
    padding-left: 12px;
    margin-left: 4px;
}

.model-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
    position: relative;
    flex: 0 0 auto;
}

.model-dot::before {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 1px solid var(--accent-soft-strong);
    animation: model-pulse 2.4s var(--ease) infinite;
}

@keyframes model-pulse {
    0%, 100% { transform: scale(0.9); opacity: 0.6; }
    50% { transform: scale(1.15); opacity: 0; }
}

.model-name {
    font-weight: 550;
    letter-spacing: var(--tracking-snug);
    font-feature-settings: 'tnum';
}

.model-divider {
    color: var(--text-vfaint);
    font-family: var(--font-mono);
    font-size: 11px;
}

.model-label {
    color: var(--text-muted);
    font-weight: 450;
    font-style: italic;
    font-family: var(--font-display);
    font-size: 12.5px;
    letter-spacing: 0;
}

.icon-sun, .icon-moon {
    display: none;
}
[data-theme='light'] .icon-moon { display: block; }
[data-theme='dark'] .icon-sun { display: block; }

/* Conversation ------------------------------------------------------------ */
.conversation {
    min-height: 0;
    overflow-y: auto;
    padding: 0 clamp(24px, 5vw, 56px);
    scroll-behavior: smooth;
}

.conversation-inner {
    max-width: 760px;
    margin: 0 auto;
    padding: 0 0 24px;
}

.conversation::-webkit-scrollbar { width: 10px; }
.conversation::-webkit-scrollbar-thumb { background: transparent; }
.conversation:hover::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: var(--radius-pill);
    border: 2px solid var(--bg);
}

/* Day separator */
.day-sep {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 36px 0 18px;
    color: var(--text-faint);
    font-family: var(--font-mono);
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.day-sep::before,
.day-sep::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-faint);
}

.day-sep .day-num {
    color: var(--accent);
    font-weight: 600;
}

/* Messages */
.message {
    display: grid;
    grid-template-columns: 36px 1fr;
    gap: 18px;
    width: 100%;
    padding: 22px 0 20px;
    position: relative;
}

.message + .message {
    border-top: 1px solid var(--border-faint);
}

.message.user {
    grid-template-columns: 1fr 36px;
}

.message.user .msg-body {
    grid-column: 1;
    grid-row: 1;
}

.message.user .msg-avatar {
    grid-column: 2;
    grid-row: 1;
}

.msg-avatar {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    flex: 0 0 auto;
    box-shadow: var(--shadow-inset);
    overflow: hidden;
    position: relative;
}

.message.bot .msg-avatar {
    background: var(--text);
    color: var(--bg);
    border-color: var(--text);
}

.message.user .msg-avatar {
    background: var(--text);
    color: var(--bg);
    border-color: var(--text);
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 500;
    letter-spacing: -0.02em;
}

.msg-avatar svg {
    width: 15px;
    height: 15px;
    stroke-width: 1.5;
}

.msg-body {
    min-width: 0;
    max-width: 100%;
}

.msg-meta {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 11.5px;
    color: var(--text-faint);
    font-family: var(--font-mono);
    letter-spacing: 0.02em;
}

.msg-author {
    font-weight: 600;
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 12.5px;
    letter-spacing: var(--tracking-snug);
    text-transform: none;
}

.msg-role {
    color: var(--text-vfaint);
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 500;
}

.msg-time {
    color: var(--text-faint);
    margin-left: auto;
    font-size: 10.5px;
    font-weight: 500;
}

.msg-actions {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-left: 2px;
    opacity: 0;
    transform: translateY(-1px);
    transition: opacity var(--duration-fast) var(--ease),
        transform var(--duration-fast) var(--ease);
}

.message:hover .msg-actions,
.message:focus-within .msg-actions {
    opacity: 1;
    transform: translateY(0);
}

.msg-actions[hidden] {
    display: none;
}

.msg-action {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    color: var(--text-faint);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 5px;
    transition: background var(--duration-fast) var(--ease),
        border-color var(--duration-fast) var(--ease),
        color var(--duration-fast) var(--ease);
}

.msg-action svg {
    width: 13px;
    height: 13px;
}

.msg-action:hover {
    color: var(--text);
    background: var(--surface-hover);
    border-color: var(--border);
}

.msg-action.is-danger:hover {
    color: #ff8f9b;
    border-color: color-mix(in oklab, #ff8f9b 32%, transparent);
    background: color-mix(in oklab, #ff8f9b 10%, transparent);
}

.msg-bubble {
    display: block;
    color: var(--text);
    font-size: 15px;
    line-height: 1.7;
    max-width: 100%;
    font-family: var(--font-sans);
    font-feature-settings: 'kern', 'liga', 'calt';
    letter-spacing: 0;
}

.message.user .msg-bubble {
    background: var(--user-bubble);
    color: var(--user-bubble-fg);
    padding: 12px 16px 14px;
    border-radius: 4px 12px 12px 4px;
    white-space: pre-wrap;
    max-width: 88%;
    margin-left: auto;
    font-size: 14.5px;
    line-height: 1.65;
    box-shadow: 0 1px 0 color-mix(in oklab, var(--text) 0%, transparent);
}

.message.user .msg-bubble p {
    color: inherit;
}

.message.bot .msg-bubble {
    padding: 0;
    white-space: normal;
}

.message-attachments {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 240px));
    gap: 10px;
    margin-top: 12px;
}

.message-attachment {
    margin: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--surface-2);
}

.message-attachment img {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    background: var(--surface-3);
}

.message-attachment figcaption {
    padding: 6px 8px;
    color: var(--text-faint);
    font-family: var(--font-mono);
    font-size: 10.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Prose styles for assistant messages */
.msg-bubble > * + * { margin-top: 14px; }

.msg-bubble p {
    color: var(--text);
    font-size: 15px;
    line-height: 1.7;
    white-space: pre-wrap;
}

.msg-bubble p:first-of-type {
    font-size: 15.5px;
}

.msg-bubble strong {
    color: var(--text);
    font-weight: 600;
    letter-spacing: var(--tracking-snug);
}

.msg-bubble em {
    font-style: italic;
    font-family: var(--font-display);
    color: var(--text);
    font-feature-settings: 'ss01';
}

.msg-bubble a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-color: color-mix(in oklab, var(--accent) 35%, transparent);
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    transition: text-decoration-color var(--duration-fast) var(--ease);
}

.msg-bubble a:hover {
    text-decoration-color: var(--accent);
}

.msg-bubble code {
    padding: 1px 5px 2px;
    color: var(--text);
    background: var(--code-bg);
    border: 1px solid var(--code-border);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.86em;
}

.msg-bubble pre {
    background: var(--code-bg);
    border: 1px solid var(--code-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    font-size: 13px;
    box-shadow: var(--shadow-sm);
}

.code-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 14px;
    border-bottom: 1px solid var(--code-border);
    color: var(--text-faint);
    font-family: var(--font-mono);
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: color-mix(in oklab, var(--code-bg) 80%, var(--surface-3));
}

.code-head .lang {
    color: var(--text-muted);
}

.code-head .copy {
    color: var(--text-faint);
    cursor: pointer;
    border-radius: 3px;
    padding: 1px 6px 2px;
    transition: color var(--duration-fast) var(--ease),
        background var(--duration-fast) var(--ease);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-weight: 500;
}

.code-head .copy:hover {
    color: var(--text);
    background: var(--surface-3);
}

.msg-bubble pre code {
    display: block;
    overflow-x: auto;
    padding: 14px 16px;
    background: transparent;
    border: 0;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 12.5px;
    line-height: 1.7;
    border-radius: 0;
    white-space: pre;
    font-feature-settings: 'liga' 0, 'calt' 0;
}

.msg-bubble ul, .msg-bubble ol {
    padding-left: 22px;
    display: grid;
    gap: 6px;
}

.msg-bubble li {
    line-height: 1.7;
}

.msg-bubble li::marker {
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 0.85em;
}

.msg-bubble h3, .msg-bubble h4 {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 500;
    color: var(--text);
    margin: 4px 0 0;
    letter-spacing: var(--tracking-display);
    line-height: 1.3;
    font-feature-settings: 'ss01';
}

.msg-bubble h4 {
    font-size: 15px;
    font-style: italic;
}

.msg-bubble blockquote {
    border-left: 2px solid var(--accent);
    padding: 2px 0 2px 16px;
    color: var(--text-muted);
    font-style: italic;
    font-family: var(--font-display);
    font-feature-settings: 'ss01';
}

/* Thinking / trace */
.trace {
    display: grid;
    gap: 2px;
    padding: 14px 18px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    max-width: 480px;
}

.trace-row {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-faint);
    font-size: 12.5px;
    line-height: 1.5;
    font-family: var(--font-mono);
    transition: color var(--duration-fast) var(--ease);
    padding: 2px 0;
}

.trace-row.is-active { color: var(--text); }
.trace-row.is-done { color: var(--text-muted); }

.trace-mark {
    width: 12px;
    height: 12px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    color: var(--text-faint);
    stroke-width: 1.6;
}

.trace-row.is-active .trace-mark { color: var(--accent); }
.trace-row.is-done .trace-mark { color: var(--good); }
.trace-mark svg { width: 10px; height: 10px; }

.trace-row.is-active .trace-mark .icon-spinner {
    animation: spin 1.2s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Welcome state — editorial journal entry */
.welcome {
    max-width: 720px;
    margin: 0 auto;
    padding: 60px 0 24px;
}

.welcome-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--text-faint);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-weight: 500;
}

.welcome-eyebrow .eyebrow-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.welcome-eyebrow .eyebrow-sep {
    color: var(--text-vfaint);
    margin: 0 2px;
}

.welcome-title {
    margin: 14px 0 12px;
    font-family: var(--font-display);
    font-size: clamp(34px, 5vw, 48px);
    font-weight: 400;
    letter-spacing: var(--tracking-display);
    line-height: 1.05;
    color: var(--text);
    font-feature-settings: 'ss01', 'kern';
    text-wrap: balance;
}

.welcome-title .accent {
    color: var(--accent);
    font-style: italic;
    font-weight: 500;
}

.welcome-sub {
    color: var(--text-muted);
    font-size: 15.5px;
    line-height: 1.65;
    max-width: 56ch;
    margin-top: 4px;
    font-family: var(--font-sans);
    letter-spacing: 0;
}

.welcome-sub em {
    font-family: var(--font-display);
    font-style: italic;
    color: var(--text);
    font-feature-settings: 'ss01';
}

.welcome-rule {
    margin: 28px 0 18px;
    height: 1px;
    background: var(--border);
    position: relative;
}

.welcome-rule::after {
    content: '§';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translate(-2px, -50%);
    background: var(--bg);
    padding: 0 8px 0 0;
    color: var(--text-vfaint);
    font-family: var(--font-display);
    font-size: 14px;
    font-style: italic;
}

.suggestions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.suggestion {
    display: grid;
    grid-template-columns: 24px 1fr;
    gap: 12px;
    padding: 14px 16px;
    text-align: left;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    transition: background var(--duration-fast) var(--ease),
        border-color var(--duration-fast) var(--ease),
        transform var(--duration-fast) var(--ease);
    position: relative;
}

.suggestion:hover {
    background: var(--surface-2);
    border-color: var(--border-strong);
    transform: translateY(-1px);
}

.suggestion-num {
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--text-vfaint);
    letter-spacing: 0.06em;
    line-height: 1.3;
    font-weight: 500;
    border-right: 1px solid var(--border-faint);
    padding-right: 10px;
    text-align: right;
    align-self: start;
    padding-top: 2px;
}

.suggestion:hover .suggestion-num {
    color: var(--accent);
}

.suggestion-body {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.suggestion-title {
    font-size: 13.5px;
    font-weight: 550;
    color: var(--text);
    letter-spacing: var(--tracking-snug);
    line-height: 1.3;
}

.suggestion-desc {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}

.welcome-foot {
    margin-top: 26px;
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--text-faint);
    letter-spacing: 0.04em;
}

.welcome-foot .foot-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.welcome-foot .foot-key {
    color: var(--text-vfaint);
}

.welcome-foot .foot-sep {
    color: var(--text-vfaint);
    opacity: 0.5;
}

/* Composer ---------------------------------------------------------------- */
.composer-wrap {
    padding: 12px clamp(24px, 5vw, 56px) 20px;
    background: linear-gradient(180deg, transparent, var(--bg) 40%);
}

.composer {
    max-width: 760px;
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 4px 12px 12px 12px;
    box-shadow: var(--shadow-md);
    transition: border-color var(--duration-fast) var(--ease),
        box-shadow var(--duration-fast) var(--ease);
    position: relative;
}

.composer::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 0;
    width: 32px;
    height: 1px;
    background: var(--accent);
    border-radius: 1px;
}

.composer:focus-within {
    border-color: var(--text);
    box-shadow: var(--shadow-md), 0 0 0 3px var(--accent-soft);
}

.composer:focus-within::before {
    width: 56px;
    background: var(--accent);
}

.composer-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 6px 0 14px;
}

.composer-toolbar-left, .composer-toolbar-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 8px;
    color: var(--text-faint);
    background: transparent;
    border-radius: var(--radius-xs);
    font-size: 11.5px;
    font-weight: 500;
    letter-spacing: 0.02em;
    transition: background var(--duration-fast) var(--ease),
        color var(--duration-fast) var(--ease);
    font-family: var(--font-mono);
    text-transform: lowercase;
}

.chip:hover {
    background: var(--surface-3);
    color: var(--text);
}

.chip svg {
    width: 12px;
    height: 12px;
    stroke-width: 1.5;
}

.meta-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px 3px 6px;
    color: var(--text-faint);
    font-size: 10.5px;
    font-weight: 500;
    border-radius: 3px;
    background: transparent;
    font-family: var(--font-mono);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    transition: color var(--duration-fast) var(--ease);
}

.meta-pill .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--good);
    box-shadow: 0 0 0 2px color-mix(in oklab, var(--good) 22%, transparent);
}

.meta-pill[data-state='warn'] { color: var(--warn); }
.meta-pill[data-state='warn'] .dot { background: var(--warn); box-shadow: 0 0 0 2px color-mix(in oklab, var(--warn) 22%, transparent); }
.meta-pill[data-state='danger'] { color: var(--danger); }
.meta-pill[data-state='danger'] .dot { background: var(--danger); box-shadow: 0 0 0 2px color-mix(in oklab, var(--danger) 22%, transparent); }

.composer-input {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 8px 10px 16px;
}

.attachment-tray {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
    padding: 0 12px 10px 16px;
}

.attachment-preview {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 24px;
    align-items: center;
    gap: 9px;
    min-width: 0;
    padding: 6px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.attachment-preview img {
    width: 42px;
    height: 42px;
    object-fit: cover;
    border-radius: var(--radius-xs);
    background: var(--surface-3);
}

.attachment-meta {
    min-width: 0;
    display: grid;
    gap: 1px;
}

.attachment-name,
.attachment-size {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-name {
    color: var(--text);
    font-size: 12px;
    font-weight: 550;
}

.attachment-size {
    color: var(--text-faint);
    font-family: var(--font-mono);
    font-size: 10.5px;
}

.attachment-remove {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    color: var(--text-faint);
    border-radius: var(--radius-xs);
}

.attachment-remove:hover {
    color: var(--danger);
    background: color-mix(in oklab, var(--danger) 12%, transparent);
}

.attachment-remove svg {
    width: 12px;
    height: 12px;
}

#user-input {
    flex: 1;
    min-width: 0;
    min-height: 26px;
    max-height: 200px;
    padding: 4px 0;
    background: transparent;
    border: 0;
    outline: 0;
    resize: none;
    color: var(--text);
    font-size: 15px;
    line-height: 1.55;
    font-family: var(--font-sans);
    letter-spacing: 0;
}

#user-input::placeholder {
    color: var(--text-vfaint);
    font-style: italic;
    font-family: var(--font-display);
    font-size: 16px;
    letter-spacing: 0;
}

.send-btn {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    color: var(--accent-fg);
    background: var(--text);
    border-radius: 4px 8px 8px 4px;
    flex: 0 0 auto;
    transition: background var(--duration-fast) var(--ease),
        transform var(--duration-fast) var(--ease),
        opacity var(--duration-fast) var(--ease);
    position: relative;
}

.send-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent);
    border-radius: 4px 0 0 4px;
}

.send-btn:hover:not(:disabled) {
    background: var(--accent);
}

.send-btn:hover:not(:disabled)::before {
    background: var(--accent-hover);
}

.send-btn:active:not(:disabled) {
    transform: translateY(1px);
}

.send-btn:disabled {
    background: var(--surface-3);
    color: var(--text-faint);
    cursor: not-allowed;
}

.send-btn:disabled::before {
    background: var(--text-vfaint);
    opacity: 0.4;
}

.send-btn svg {
    width: 14px;
    height: 14px;
    stroke-width: 1.6;
    margin-left: 2px;
}

.composer-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 4px 16px 10px;
    color: var(--text-faint);
    font-size: 10.5px;
    font-family: var(--font-mono);
    letter-spacing: 0.04em;
    text-transform: lowercase;
}

.composer-foot kbd {
    font-size: 9.5px;
    padding: 0 4px 1px;
    border-bottom-width: 1px;
    text-transform: none;
    letter-spacing: 0.02em;
}

.composer-foot .foot-sep {
    color: var(--text-vfaint);
    margin: 0 2px;
}

/* Toast ------------------------------------------------------------------- */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translate(-50%, 12px);
    z-index: 60;
    padding: 10px 18px;
    background: var(--text);
    color: var(--bg);
    border-radius: var(--radius-pill);
    font-size: 12.5px;
    font-weight: 500;
    font-family: var(--font-sans);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    letter-spacing: var(--tracking-snug);
    transition: opacity var(--duration-med) var(--ease),
        transform var(--duration-med) var(--ease);
}

.toast::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    margin-right: 8px;
    vertical-align: 2px;
}

.toast.is-show {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* Dialog ------------------------------------------------------------------ */
.scrim {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: color-mix(in oklab, var(--bg) 60%, transparent);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

dialog {
    position: fixed;
    inset: 0;
    margin: auto;
    width: min(580px, calc(100vw - 32px));
    max-height: calc(100vh - 64px);
    padding: 0;
    background: transparent;
    border: 0;
    color: var(--text);
}

dialog[open] {
    animation: dialog-in var(--duration-med) var(--ease-out);
}

dialog::backdrop {
    background: color-mix(in oklab, var(--bg) 50%, transparent);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

@keyframes dialog-in {
    from { opacity: 0; transform: translateY(8px) scale(0.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.dialog-card {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    max-height: calc(100vh - 64px);
    display: flex;
    flex-direction: column;
    position: relative;
}

.dialog-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--accent), var(--warm) 60%, var(--accent));
}

.dialog-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 22px 24px 16px;
    border-bottom: 1px solid var(--border-faint);
}

.dialog-eyebrow {
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.dialog-header h2 {
    margin: 4px 0 0;
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 500;
    letter-spacing: var(--tracking-display);
    font-feature-settings: 'ss01';
}

.dialog-header-sub {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 4px;
    line-height: 1.5;
}

.account-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 8px 16px;
    max-height: 280px;
}

.account-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    transition: background var(--duration-fast) var(--ease);
    border: 1px solid transparent;
}

.account-row:hover {
    background: var(--surface-2);
    border-color: var(--border-faint);
}

.account-row + .account-row { margin-top: 2px; }

.account-info {
    flex: 1;
    min-width: 0;
    line-height: 1.3;
}

.account-name {
    font-family: var(--font-display);
    font-size: 14.5px;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    letter-spacing: var(--tracking-snug);
}

.account-handle {
    font-size: 11.5px;
    color: var(--text-faint);
    margin-top: 2px;
    font-family: var(--font-mono);
    letter-spacing: 0.02em;
}

.role-pill {
    padding: 3px 8px 4px;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 3px;
    font-size: 10.5px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-family: var(--font-mono);
}

.role-pill.is-admin {
    color: var(--accent);
    background: var(--accent-soft);
    border-color: var(--accent-soft-strong);
}

.dialog-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 24px;
    color: var(--text-faint);
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-family: var(--font-mono);
}

.dialog-divider::before,
.dialog-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-faint);
}

.account-form {
    display: grid;
    grid-template-columns: 1fr 1fr 130px auto;
    gap: 10px;
    padding: 12px 24px 22px;
    align-items: end;
}

.field {
    display: grid;
    gap: 5px;
    min-width: 0;
}

.field-label {
    color: var(--text-faint);
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-family: var(--font-mono);
}

.field input,
.field select {
    height: 36px;
    padding: 0 10px;
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13.5px;
    font-family: var(--font-sans);
    transition: border-color var(--duration-fast) var(--ease),
        box-shadow var(--duration-fast) var(--ease);
}

.field input::placeholder {
    color: var(--text-vfaint);
    font-style: italic;
    font-family: var(--font-display);
    font-size: 14px;
}

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

.primary-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 36px;
    padding: 0 16px;
    color: var(--bg);
    background: var(--text);
    border-radius: var(--radius-sm);
    font-size: 12.5px;
    font-weight: 550;
    letter-spacing: var(--tracking-snug);
    transition: background var(--duration-fast) var(--ease),
        transform var(--duration-fast) var(--ease);
    white-space: nowrap;
}

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

.primary-btn:active {
    transform: scale(0.98);
}

.primary-btn svg {
    width: 12px;
    height: 12px;
    stroke-width: 1.6;
}

/* Sidebar scrollbar ----------------------------------------------------- */
.sidebar {
    overflow-y: auto;
}

.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: transparent; }
.sidebar:hover::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: var(--radius-pill);
    border: 2px solid var(--sidebar-bg);
}

/* Responsive -------------------------------------------------------------- */
.mobile-menu {
    display: none;
}

@media (max-width: 880px) {
    .app {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 50;
        width: 296px;
        transform: translateX(-100%);
        transition: transform var(--duration-med) var(--ease);
        box-shadow: var(--shadow-lg);
    }

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

    .mobile-menu {
        display: grid;
    }

    .topbar {
        padding: 12px 18px;
    }

    .model-pill {
        padding-left: 10px;
        margin-left: 0;
    }

    .model-divider,
    .model-label {
        display: none;
    }

    .conversation {
        padding: 0 16px;
    }

    .composer-wrap {
        padding: 10px 14px 14px;
    }

    .composer-foot {
        padding: 4px 14px 10px;
    }

    .composer-foot-right {
        display: none;
    }

    .account-form {
        grid-template-columns: 1fr 1fr;
    }

    .field--narrow,
    .primary-btn {
        grid-column: span 2;
    }

    .welcome {
        padding: 30px 0 12px;
    }
}

@media (max-width: 480px) {
    .message {
        grid-template-columns: 28px 1fr;
        gap: 12px;
    }

    .message.user {
        grid-template-columns: 1fr 28px;
    }

    .message.user .msg-bubble {
        max-width: 92%;
    }

    .topbar-right .icon-btn:nth-child(2) {
        display: none;
    }

    .account-form {
        grid-template-columns: 1fr;
    }

    .field--narrow,
    .primary-btn {
        grid-column: auto;
    }

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

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
