/* ==========================================================================
   Maelstrom Chat — v2 stylesheet
   ========================================================================== */
* { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Inter", system-ui, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
}
body { height: 100dvh; overflow: hidden; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- Tokens --------------------------------------------------------------- */
:root {
    --bg: #f5f4fa;
    --surface: #ffffff;
    --surface-2: #eeecf6;
    --surface-3: #e4e1ef;
    --text: #1b1a22;
    --text-dim: #6c6979;
    --text-faint: #9a97a8;
    --border: #e2dfec;
    --accent: #6d4cff;
    --accent-hover: #5b39f2;
    --accent-soft: rgba(109, 76, 255, .10);
    --accent-grad: linear-gradient(135deg, #6d4cff 0%, #9b6bff 100%);
    --user-bg: var(--accent-grad);
    --user-text: #ffffff;
    --claude-bg: #ffffff;
    --danger: #dc3c62;
    --danger-soft: rgba(220, 60, 98, .10);
    --success: #17a673;
    --success-soft: rgba(23, 166, 115, .12);
    --warn: #c98a05;
    --code-bg: #f3f1fa;
    --diff-add: rgba(23, 166, 115, .14);
    --diff-del: rgba(220, 60, 98, .12);
    --shadow-sm: 0 1px 2px rgba(27, 26, 34, .06);
    --shadow-md: 0 6px 20px rgba(27, 26, 34, .09);
    --shadow-lg: 0 16px 48px rgba(27, 26, 34, .18);
    --radius: 16px;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f0e14; --surface: #17161e; --surface-2: #201e2a; --surface-3: #2a2836;
        --text: #ebe8f4; --text-dim: #9a96ab; --text-faint: #6d6a7c; --border: #2b2937;
        --accent: #9d7bff; --accent-hover: #b094ff; --accent-soft: rgba(157, 123, 255, .16);
        --accent-grad: linear-gradient(135deg, #6f4dff 0%, #a06bff 100%);
        --claude-bg: #1b1a23; --danger: #ff6b8a; --danger-soft: rgba(255, 107, 138, .14);
        --success: #34d399; --success-soft: rgba(52, 211, 153, .14); --warn: #f0b429;
        --code-bg: #14131a; --diff-add: rgba(52, 211, 153, .16); --diff-del: rgba(255, 107, 138, .16);
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35); --shadow-md: 0 6px 20px rgba(0, 0, 0, .4);
        --shadow-lg: 0 16px 48px rgba(0, 0, 0, .6);
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --bg: #0f0e14; --surface: #17161e; --surface-2: #201e2a; --surface-3: #2a2836;
    --text: #ebe8f4; --text-dim: #9a96ab; --text-faint: #6d6a7c; --border: #2b2937;
    --accent: #9d7bff; --accent-hover: #b094ff; --accent-soft: rgba(157, 123, 255, .16);
    --accent-grad: linear-gradient(135deg, #6f4dff 0%, #a06bff 100%);
    --claude-bg: #1b1a23; --danger: #ff6b8a; --danger-soft: rgba(255, 107, 138, .14);
    --success: #34d399; --success-soft: rgba(52, 211, 153, .14); --warn: #f0b429;
    --code-bg: #14131a; --diff-add: rgba(52, 211, 153, .16); --diff-del: rgba(255, 107, 138, .16);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35); --shadow-md: 0 6px 20px rgba(0, 0, 0, .4);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, .6);
    color-scheme: dark;
}

/* --- Buttons ---------------------------------------------------------------- */
.btn-primary, .btn-ghost, .btn-danger {
    display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
    padding: .55rem 1rem; border-radius: 10px; font-weight: 600; font-size: .9rem;
    border: 1px solid transparent; transition: background .12s, border-color .12s, transform .08s, opacity .12s;
    white-space: nowrap;
}
.btn-primary { background: var(--accent-grad); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { transform: translateY(1px); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-ghost.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.btn-ghost.danger:hover { background: var(--danger-soft); }
.btn-ghost.ok { color: var(--success); border-color: color-mix(in srgb, var(--success) 45%, transparent); }
.btn-ghost.ok:hover { background: var(--success-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger[hidden], .btn-primary[hidden], .btn-ghost[hidden] { display: none; }
.btn-danger:hover { filter: brightness(1.08); }
.small { padding: .38rem .7rem; font-size: .8rem; border-radius: 8px; }
.wide { width: 100%; }
button:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
    background: transparent; border: 0; color: var(--text); font-size: 1.15rem; padding: .35rem .5rem;
    border-radius: 8px; min-width: 38px; min-height: 38px; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.subtle { color: var(--text-dim); }

/* --- Login ------------------------------------------------------------------ */
body.login-page { display: grid; place-items: center; padding: 1rem; overflow: auto; }
.login-card {
    width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 20px; padding: 2rem 1.8rem; box-shadow: var(--shadow-lg);
}
.login-card .brand { font-size: 1.4rem; margin-bottom: .2rem; }
.login-sub { color: var(--text-dim); margin: 0 0 1.2rem; font-size: .92rem; }
.login-err { color: var(--danger); font-size: .88rem; margin: .2rem 0 .6rem; }
.login-card .btn-primary { width: 100%; margin-top: .5rem; padding: .7rem; }

.field { display: block; margin: .6rem 0; }
.field span { display: block; font-size: .78rem; color: var(--text-dim); margin-bottom: .3rem; font-weight: 500; }
.field input, .field textarea, .field select {
    width: 100%; padding: .65rem .8rem; border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface-2); font-size: 1rem; transition: border-color .12s, box-shadow .12s;
}
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }

.brand { display: flex; align-items: center; gap: .45rem; font-weight: 800; letter-spacing: -.01em; font-size: 1.15rem; }
.brand-mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 9px; background: var(--accent-grad); color: #fff; font-size: 1rem; }

/* --- Layout ----------------------------------------------------------------- */
#app { display: grid; grid-template-columns: 1fr; height: 100dvh; }
@media (min-width: 768px) { #app { grid-template-columns: 290px 1fr; } }

#sidebar {
    background: var(--surface); border-right: 1px solid var(--border);
    padding: .9rem .9rem 0; display: flex; flex-direction: column; gap: 1.1rem; overflow-y: auto;
    position: fixed; top: 0; left: 0; bottom: 0; width: 86%; max-width: 330px;
    transform: translateX(-100%); transition: transform 200ms ease; z-index: 100;
    padding-bottom: max(.9rem, env(safe-area-inset-bottom));
}
#sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
@media (min-width: 768px) {
    #sidebar { position: static; width: auto; max-width: none; transform: none; }
    .mobile-only { display: none !important; }
}
.sidebar-header { display: flex; justify-content: space-between; align-items: center; }
.section { display: flex; flex-direction: column; gap: .45rem; }
.section.grow { flex: 1; min-height: 120px; }
.section-head { display: flex; align-items: center; justify-content: space-between; }
.section-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); font-weight: 600; }
.project-row { display: flex; gap: .4rem; align-items: stretch; }
.project-row select { flex: 1; min-width: 0; }
select {
    width: 100%; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 9px;
    background: var(--surface-2); font-size: .92rem;
}
.sidebar-footer {
    margin-top: auto; padding-top: .8rem; border-top: 1px solid var(--border);
    display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--text-dim);
}
.current-user { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout-link { color: var(--text-dim); text-decoration: none; }
.logout-link:hover { color: var(--danger); }

/* threads */
.threads { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.threads-empty { color: var(--text-dim); font-size: .85rem; padding: .4rem .5rem; }
.thread {
    display: flex; align-items: center; gap: .55rem; padding: .5rem .55rem; border-radius: 10px; cursor: pointer;
    color: var(--text); transition: background .1s;
}
.thread:hover { background: var(--surface-2); }
.thread.active { background: var(--accent-soft); }
.thread.active .thread-title { color: var(--accent); font-weight: 650; }
.thread-status { width: 8px; height: 8px; border-radius: 50%; background: var(--surface-3); flex-shrink: 0; }
.thread.running .thread-status { background: var(--success); box-shadow: 0 0 0 0 var(--success); animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 60%, transparent); } 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.thread-body { flex: 1; min-width: 0; }
.thread-title { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-meta { font-size: .72rem; color: var(--text-faint); margin-top: 1px; }
.thread-delete { background: none; border: 0; color: var(--text-faint); padding: .15rem .3rem; border-radius: 6px; opacity: 0; font-size: .85rem; }
.thread:hover .thread-delete, .thread:focus-within .thread-delete { opacity: 1; }
.thread-delete:hover { color: var(--danger); background: var(--danger-soft); }
@media (hover: none) { .thread-delete { opacity: .6; } }

/* issues */
.issue-none { font-size: .82rem; color: var(--text-faint); margin: 0; }
.issue-cat { margin-bottom: .2rem; }
.issue-cat > summary { list-style: none; cursor: pointer; user-select: none; display: flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--text-dim); padding: .25rem .2rem; }
.issue-cat > summary::-webkit-details-marker { display: none; }
.issue-cat > summary::before { content: ''; border: solid var(--text-faint); border-width: 0 2px 2px 0; padding: 2px; transform: rotate(-45deg); transition: transform .15s; flex-shrink: 0; }
.issue-cat[open] > summary::before { transform: rotate(45deg); }
.issue-cat-label { flex: 1; }
.issue-count { font-size: .7rem; background: var(--surface-2); color: var(--text-dim); border-radius: 10px; padding: 0 .45rem; min-width: 1.2rem; text-align: center; }
.issue-list { list-style: none; margin: .1rem 0 .3rem; padding: 0; }
.issue-row { display: flex; align-items: center; gap: .5rem; padding: .38rem .5rem .38rem .9rem; border-radius: 8px; cursor: pointer; font-size: .85rem; }
.issue-row:hover, .issue-row.expanded { background: var(--surface-2); }
.issue-ind { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.issue-ind.bug { background: var(--danger); }
.issue-ind.feature { background: var(--accent); }
.issue-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.issue-row.in-progress .issue-title { font-style: italic; opacity: .85; }
.issue-wip { color: var(--text-faint); }
.issue-empty { list-style: none; padding: .2rem .5rem .2rem .9rem; font-size: .8rem; color: var(--text-faint); }
.issue-detail { list-style: none; margin: 0 0 .4rem .9rem; padding: .6rem .7rem; background: var(--surface-2); border-left: 2px solid var(--accent); border-radius: 0 8px 8px 0; font-size: .8rem; color: var(--text-dim); }
.issue-detail .id-title { color: var(--text); font-weight: 600; font-size: .86rem; margin-bottom: .3rem; line-height: 1.3; }
.issue-detail .id-meta { text-transform: uppercase; letter-spacing: .04em; font-size: .66rem; margin-bottom: .35rem; }
.issue-detail .id-line { margin: .1rem 0; }
.issue-detail .id-desc { margin: .45rem 0 .1rem; padding-top: .4rem; border-top: 1px solid var(--border); color: var(--text); white-space: pre-wrap; word-break: break-word; line-height: 1.45; max-height: 11rem; overflow-y: auto; }
.issue-detail .id-url { color: var(--accent); text-decoration: none; }
.issue-actions { margin-top: .55rem; display: flex; flex-wrap: wrap; gap: .4rem; }
.issue-actions .btn-ghost { flex: 1 1 0; }

/* --- Drawer backdrop ------------------------------------------------------ */
#drawer-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 99; }
#drawer-backdrop.open { display: block; }
@media (min-width: 768px) { #drawer-backdrop.open { display: none; } }

/* --- Main ------------------------------------------------------------------ */
#main { display: flex; flex-direction: column; height: 100dvh; min-width: 0; position: relative; }
.topbar {
    flex-shrink: 0; padding: .55rem .8rem; border-bottom: 1px solid var(--border); background: var(--surface);
    display: flex; align-items: center; gap: .6rem; min-height: 54px;
}
.topbar-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: .4rem; overflow: hidden; }
.topbar-project { color: var(--text-faint); font-size: .82rem; white-space: nowrap; }
.topbar-thread {
    background: none; border: 0; padding: .2rem .35rem; margin-left: -.35rem; border-radius: 6px; font-weight: 650; font-size: .98rem;
    color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; text-align: left;
}
.topbar-thread:not(:disabled):hover { background: var(--surface-2); }
.topbar-thread:disabled { color: var(--text-dim); font-weight: 400; cursor: default; }
.topbar-controls { display: flex; align-items: center; gap: .4rem; flex-shrink: 0; }
.mini-select { width: auto; padding: .32rem .5rem; font-size: .78rem; border-radius: 8px; max-width: 150px; }
@media (max-width: 560px) { #effort-select { display: none !important; } .mini-select { max-width: 110px; } }
.status-pill {
    font-size: .74rem; color: var(--text-dim); background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 999px; padding: .22rem .6rem; white-space: nowrap; flex-shrink: 0;
}
.status-pill.running { color: var(--success); border-color: color-mix(in srgb, var(--success) 40%, transparent); background: var(--success-soft); }
@media (max-width: 480px) { .status-pill { display: none; } }

/* messages */
.messages { flex: 1; overflow-y: auto; padding: 1rem .9rem 1.2rem; display: flex; flex-direction: column; gap: .9rem; scroll-behavior: smooth; }
@media (min-width: 1100px) { .messages { padding-left: max(.9rem, calc((100% - 960px) / 2)); padding-right: max(.9rem, calc((100% - 960px) / 2)); } }
.loading { color: var(--text-dim); text-align: center; margin: 3rem 0; }
.empty-state { color: var(--text-dim); text-align: center; margin: auto; max-width: 420px; padding: 2rem 1rem; }
.empty-state h2 { font-size: 1.15rem; margin: .6rem 0 .3rem; color: var(--text); }
.empty-state p { margin: 0; font-size: .92rem; }
.empty-mark { font-size: 2rem; width: 56px; height: 56px; border-radius: 16px; background: var(--accent-grad); color: #fff; display: inline-grid; place-items: center; }

.row { display: flex; flex-direction: column; }
.row.user { align-items: flex-end; }
.row.claude { align-items: flex-start; }
.msg-user-label { color: var(--text-faint); font-size: .68rem; margin: 0 .3rem .15rem 0; }
.msg {
    max-width: min(82%, 760px); padding: .7rem 1rem; border-radius: var(--radius); font-size: .95rem; line-height: 1.55;
    word-wrap: break-word; overflow-wrap: anywhere; position: relative;
}
@media (max-width: 600px) { .msg { max-width: 92%; } }
.msg.user { background: var(--user-bg); color: var(--user-text); border-bottom-right-radius: 5px; box-shadow: var(--shadow-md); }
.msg.user .msg-content { white-space: pre-wrap; }
.row.pending { opacity: .6; }
.msg.claude { background: var(--claude-bg); border: 1px solid var(--border); border-bottom-left-radius: 5px; box-shadow: var(--shadow-sm); }
.msg .ts { display: block; font-size: .66rem; opacity: .55; margin-top: .35rem; text-align: right; }

.claude-turn { display: flex; flex-direction: column; gap: .45rem; max-width: min(88%, 800px); align-self: flex-start; }
@media (max-width: 600px) { .claude-turn { max-width: 96%; } }
.claude-turn .msg.claude { max-width: 100%; }
.turn-foot { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; font-size: .68rem; color: var(--text-faint); padding: 0 .3rem; }
.turn-foot .ts { margin: 0; font-size: .66rem; opacity: .8; }
.turn-error { font-family: var(--mono); font-size: .76rem; color: var(--danger); background: var(--danger-soft); border-radius: 10px; padding: .5rem .7rem; white-space: pre-wrap; }
.badge { font-size: .64rem; padding: .05rem .4rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.badge.error { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.sys-note { align-self: center; font-size: .74rem; color: var(--text-faint); background: var(--surface-2); border-radius: 999px; padding: .2rem .75rem; text-align: center; }
.sys-note.warn { color: var(--warn); }

/* markdown inside bubbles */
.msg-content > :first-child { margin-top: 0; }
.msg-content > :last-child { margin-bottom: 0; }
.msg-content p { margin: .5em 0; }
.msg-content h1, .msg-content h2, .msg-content h3, .msg-content h4 { margin: .9em 0 .35em; line-height: 1.3; font-weight: 700; }
.msg-content h1 { font-size: 1.25em; } .msg-content h2 { font-size: 1.14em; } .msg-content h3 { font-size: 1.04em; } .msg-content h4 { font-size: 1em; }
.msg-content ul, .msg-content ol { margin: .45em 0; padding-left: 1.4em; }
.msg-content li { margin: .18em 0; }
.msg-content li > ul, .msg-content li > ol { margin: .15em 0; }
.msg-content li::marker { color: var(--text-dim); }
.msg-content .task input { vertical-align: -2px; margin-right: .3em; }
.msg-content a { color: var(--accent); text-decoration: none; font-weight: 500; }
.msg-content a:hover { text-decoration: underline; }
.msg.user .msg-content a { color: #fff; text-decoration: underline; }
.msg-content strong { font-weight: 650; }
.msg-content del { opacity: .65; }
.msg-content blockquote { margin: .6em 0; padding: .1em .9em; border-left: 3px solid var(--accent); color: var(--text-dim); }
.msg-content hr { border: 0; border-top: 1px solid var(--border); margin: .9em 0; }
.msg-content code { background: var(--code-bg); border: 1px solid var(--border); padding: .08em .38em; border-radius: 5px; font-size: .86em; font-family: var(--mono); }
.msg-content pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px; margin: .6em 0; overflow: hidden; }
.msg-content pre code { display: block; background: none; border: 0; padding: .65rem .85rem; font-size: .82em; line-height: 1.5; overflow-x: auto; white-space: pre; }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: .25rem .6rem .25rem .85rem; border-bottom: 1px solid var(--border); font-size: .68rem; color: var(--text-faint); font-family: var(--mono); }
.code-copy { background: none; border: 1px solid var(--border); color: var(--text-dim); border-radius: 6px; padding: .1rem .45rem; font-size: .68rem; }
.code-copy:hover { background: var(--surface-2); color: var(--text); }
.msg.user .msg-content code, .msg.user .msg-content pre { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.25); color: #fff; }
.tbl-wrap { overflow-x: auto; margin: .6em 0; }
.msg-content table { border-collapse: collapse; font-size: .9em; min-width: 50%; }
.msg-content th, .msg-content td { border: 1px solid var(--border); padding: .35em .6em; text-align: left; vertical-align: top; }
.msg-content th { background: var(--surface-2); font-weight: 650; }

/* live + thinking */
.live-zone { display: flex; flex-direction: column; align-items: flex-start; gap: .4rem; max-width: min(88%, 800px); }
.msg.claude.streaming { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.stream-cursor { color: var(--accent); margin-left: 1px; animation: cursor-blink 1s infinite; }
@keyframes cursor-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
.thinking { display: flex; align-items: center; gap: .6rem; padding: .5rem .8rem; color: var(--text-dim); font-size: .82rem; }
.dots { display: inline-flex; gap: .25rem; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: blink 1.4s infinite both; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* tool steps */
.tool-cluster { width: 100%; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); overflow: hidden; }
.tool-cluster > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: .5rem; padding: .42rem .7rem; font-size: .78rem; color: var(--text-dim); user-select: none; }
.tool-cluster > summary::-webkit-details-marker { display: none; }
.tool-cluster > summary:hover { background: var(--surface-2); }
.cluster-caret { display: inline-block; transition: transform .15s; color: var(--text-faint); }
.tool-cluster[open] > .cluster-caret, .tool-cluster[open] > summary .cluster-caret { transform: rotate(90deg); }
.cluster-title { font-weight: 600; color: var(--text); }
.cluster-detail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-list { display: flex; flex-direction: column; border-top: 1px solid var(--border); }
.tool-list.nested { border: 1px solid var(--border); border-radius: 8px; margin: .3rem 0; }
.tool-step { border-bottom: 1px solid var(--border); }
.tool-step:last-child { border-bottom: 0; }
.tool-step > summary {
    list-style: none; cursor: pointer; display: flex; align-items: center; gap: .5rem; padding: .36rem .7rem;
    font-size: .8rem; color: var(--text-dim); min-width: 0; user-select: none;
}
.tool-step > summary::-webkit-details-marker { display: none; }
.tool-step > summary:hover { background: var(--surface-2); }
.tool-icon { flex-shrink: 0; width: 1.2em; text-align: center; font-size: .85rem; }
.tool-label { color: var(--text); font-weight: 600; flex-shrink: 0; }
.tool-detail { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-detail.mono { font-family: var(--mono); font-size: .76rem; }
.tool-result-gist { flex-shrink: 0; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-faint); font-size: .74rem; }
.tool-step.busy > summary .tool-result-gist::after { content: '…'; color: var(--accent); animation: cursor-blink 1s infinite; }
.tool-step.error > summary .tool-label { color: var(--danger); }
.tool-step.error > summary .tool-result-gist { color: var(--danger); }
.tool-body { padding: .4rem .7rem .6rem; background: var(--code-bg); border-top: 1px dashed var(--border); }
.tool-body-title { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); margin: .35rem 0 .2rem; }
.tool-pre { margin: 0; font-family: var(--mono); font-size: .76rem; line-height: 1.45; white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .5rem .6rem; }
.tool-pre.err { color: var(--danger); }
.tool-pre.diff span { display: block; }
.tool-pre.diff .add { background: var(--diff-add); }
.tool-pre.diff .del { background: var(--diff-del); }
.tool-pre.diff .meta { color: var(--text-faint); }

/* jump to bottom */
.jump-bottom {
    position: absolute; right: 1.1rem; bottom: 5.4rem; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); box-shadow: var(--shadow-md); font-size: 1.1rem; z-index: 5;
}

/* --- Composer ---------------------------------------------------------------- */
.composer { flex-shrink: 0; padding: .6rem .8rem; border-top: 1px solid var(--border); background: var(--surface); padding-bottom: max(.6rem, env(safe-area-inset-bottom)); }
@media (min-width: 1100px) { .composer { padding-left: max(.8rem, calc((100% - 960px) / 2)); padding-right: max(.8rem, calc((100% - 960px) / 2)); } }
.composer-box { display: flex; align-items: flex-end; gap: .5rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 16px; padding: .35rem .35rem .35rem .9rem; transition: border-color .12s, box-shadow .12s; }
.composer-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }
textarea#input { flex: 1; border: 0; background: transparent; resize: none; min-height: 40px; max-height: 220px; padding: .55rem 0; line-height: 1.45; font-size: 1rem; }
.composer-box { flex-direction: column; align-items: stretch; padding-left: .35rem; }
.composer-row { display: flex; align-items: flex-end; gap: .4rem; }
.attach-btn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; color: var(--text-dim); flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; transition: background .12s, color .12s; }
.attach-btn:hover { background: var(--surface-2); color: var(--text); }
.attach-btn.has-items { color: var(--accent); }
.attach-strip { display: flex; flex-wrap: wrap; gap: .5rem; padding: .45rem .35rem .15rem; }
.attach-strip[hidden], .drop-overlay[hidden] { display: none; }
.attach-thumb { position: relative; width: 72px; height: 72px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); flex-shrink: 0; }
.attach-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-thumb .rm { position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: rgba(8,6,16,.7); color: #fff; font-size: .8rem; line-height: 20px; padding: 0; cursor: pointer; }
.attach-thumb .rm:hover { background: rgba(8,6,16,.9); }
.attach-thumb .sz { position: absolute; left: 0; right: 0; bottom: 0; font-size: .6rem; padding: 1px 4px; background: rgba(8,6,16,.55); color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attach-thumb.busy::after { content: ''; position: absolute; inset: 0; background: rgba(255,255,255,.35); }
.drop-overlay { position: fixed; inset: 0; z-index: 150; display: flex; align-items: center; justify-content: center; background: rgba(8,6,16,.45); backdrop-filter: blur(2px); pointer-events: none; }
.drop-overlay > div { padding: 1rem 1.6rem; border-radius: 14px; border: 2px dashed var(--accent); background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-lg); }
.msg-images { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .45rem; }
.msg-images:first-child { margin-top: 0; }
.msg-images a { display: block; border-radius: 10px; overflow: hidden; border: 1px solid rgba(255,255,255,.25); background: rgba(0,0,0,.12); max-width: 100%; }
.msg-images img { display: block; width: auto; height: auto; max-width: min(320px, 100%); max-height: 260px; object-fit: contain; }
.msg-images .expired { display: inline-flex; align-items: center; gap: .35rem; padding: .5rem .7rem; font-size: .78rem; opacity: .75; border-radius: 10px; border: 1px dashed rgba(255,255,255,.35); }
.msg.user .msg-content:empty { display: none; }
textarea#input:focus { outline: none; }
button#send-btn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--accent-grad); color: #fff; font-size: 1rem; flex-shrink: 0; box-shadow: var(--shadow-sm); transition: transform .08s, opacity .12s; }
button#send-btn:hover { filter: brightness(1.06); }
button#send-btn:active { transform: translateY(1px); }
.composer-hint { font-size: .72rem; color: var(--text-faint); padding: .3rem .4rem 0; min-height: 1rem; }

/* --- Dialogs ------------------------------------------------------------------ */
.dialog-backdrop { display: none; position: fixed; inset: 0; background: rgba(8, 6, 16, .55); z-index: 200; align-items: center; justify-content: center; padding: 1rem; backdrop-filter: blur(2px); }
.dialog-backdrop.open { display: flex; }
.dialog { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 16px; padding: 1.3rem 1.4rem; width: 100%; max-width: 420px; box-shadow: var(--shadow-lg); animation: pop .14s ease-out; }
@keyframes pop { from { transform: translateY(6px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.dialog-title { margin: 0 0 .4rem; font-size: 1.08rem; font-weight: 700; word-break: break-word; }
.dialog-meta { margin: 0 0 .4rem; font-size: .8rem; color: var(--text-dim); }
.dialog-desc { margin: 0 0 .9rem; font-size: .9rem; line-height: 1.45; color: var(--text-dim); }
.dialog-desc:empty { display: none; }
.dialog-links { display: flex; flex-direction: column; gap: .45rem; margin-bottom: 1rem; }
.dialog-link { display: block; padding: .55rem .8rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--accent); text-decoration: none; font-size: .9rem; font-weight: 500; }
.dialog-link:hover { background: var(--surface-3); }
.dialog-error { margin: .4rem 0 .8rem; padding: .5rem .7rem; border-radius: 8px; background: var(--danger-soft); color: var(--danger); font-size: .85rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .8rem; }

/* --- Toasts ------------------------------------------------------------------- */
.toasts { position: fixed; top: .9rem; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: .4rem; max-width: min(92vw, 520px); pointer-events: none; }
.toast { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 10px; box-shadow: var(--shadow-lg); font-size: .85rem; padding: .6rem .9rem; opacity: 0; transform: translateY(-8px); transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: none; }
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }

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