/* =================================================================
   Claude Chat — メインスタイルシート
   ================================================================= */

:root {
    --bg: #0a0a1a;
    --sidebar-bg: #111122;
    --panel-bg: #1a1a3a;
    --accent: #d97706;
    --accent2: #7c3aed;
    --text: #e0e0e0;
    --text-muted: #9499a6;
    --border: #2a2a4a;
    --user-bubble: #1d2557;
    --ai-bubble: #161630;
    --input-bg: #0e1020;
    --hover: #ffffff12;
    --scrollbar: #2a2a4a;
    --code-bg: #0d1117;
    --radius: 12px;
    --sidebar-w: 280px;
    --transition: .15s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    font-size: 14px;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--scrollbar);
    border-radius: 3px;
}

/* =================================================================
   認証ゲート
   ================================================================= */

#auth-gate {
    position: fixed;
    inset: 0;
    z-index: 20000;
    display: none;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    color: var(--text);
}

#auth-panel {
    width: min(420px, calc(100vw - 32px));
    padding: 28px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--input-bg, var(--panel, var(--bg)));
    box-shadow: 0 24px 80px rgba(0, 0, 0, .34);
}

#auth-panel h1 {
    margin-bottom: 10px;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 0;
}

#auth-panel p {
    margin-bottom: 18px;
    color: var(--text-muted, var(--muted, #888));
    line-height: 1.6;
}

#auth-panel p.error {
    color: #ff8a8a;
}

#auth-form {
    display: flex;
    gap: 10px;
}

#auth-password-input {
    flex: 1;
    min-width: 0;
    height: 42px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

#auth-password-input:focus {
    outline: none;
    border-color: var(--accent);
}

#auth-submit {
    height: 42px;
    padding: 0 18px;
    border: 0;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

#auth-submit:disabled {
    cursor: wait;
    opacity: .72;
}

body.auth-locked #auth-gate {
    display: flex;
}

body.auth-locked #sidebar,
body.auth-locked #main,
body.auth-locked #sidebar-backdrop,
body.auth-locked .shell {
    display: none !important;
}

/* Sidebar */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    width: min(84vw, var(--sidebar-w));
    min-width: min(84vw, var(--sidebar-w));
    max-width: min(84vw, var(--sidebar-w));
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    border-radius: 0 20px 20px 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateX(0);
    transition: transform .25s ease, box-shadow .25s ease;
    box-shadow: 0 28px 90px rgba(0, 0, 0, 0.38);
}

#sidebar.collapsed {
    transform: translateX(calc(-100% - 24px));
    box-shadow: none;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: none;
    border: 0;
    padding: 0;
    background: rgba(0, 0, 0, 0.36);
    cursor: pointer;
}

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

#sidebar-header {
    padding: 16px 14px 12px;
    padding-top: max(16px, env(safe-area-inset-top));
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
}

#sidebar-header .logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    flex: 1;
}

#btn-new-chat {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    transition: opacity var(--transition);
}

#btn-new-chat:hover {
    opacity: .85;
}

#dir-section {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    display: none;
}

#dir-section label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    display: block;
    margin-bottom: 6px;
}

#dir-display {
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 12px;
    color: var(--text);
    word-break: break-all;
    cursor: pointer;
    min-height: 32px;
    transition: border-color .2s;
}

#dir-display:hover {
    border-color: var(--accent);
}

#dir-display.placeholder {
    color: var(--text-muted);
}

#session-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px 8px;
}

.sidebar-footer-button {
    margin: 0 12px 12px;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    padding: 10px 12px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: background var(--transition), border-color var(--transition), opacity var(--transition);
}

.sidebar-footer-button:hover {
    background: var(--hover);
    border-color: var(--accent);
}

.session-item {
    border-radius: 8px;
    padding: 8px 10px;
    margin-bottom: 4px;
    cursor: pointer;
    transition: background var(--transition);
    border: 1px solid transparent;
}

.session-item:hover {
    background: var(--hover);
}

.session-item.active {
    background: var(--panel-bg);
    border-color: var(--accent2);
}

.session-item .s-title {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-item .s-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 6px;
}

.session-item .s-time {
    color: var(--accent);
    font-weight: 500;
    flex-shrink: 0;
}

.session-item .s-dir {
    opacity: 0.7;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-item .s-id {
    font-size: 9px;
    color: #888;
    opacity: 0;
    font-family: monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: opacity var(--transition);
    margin-top: 1px;
}

.session-item:hover .s-id {
    opacity: 0.7;
}

.session-item .s-actions {
    display: none;
    flex-shrink: 0;
    gap: 4px;
}

.session-item:hover .s-actions {
    display: flex;
}

.s-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    font-size: 12px;
    border-radius: 4px;
}

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

.s-title-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.session-item.running {
    border-left: 3px solid #d97706;
    padding-left: 7px;
}

.s-running-dots {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    flex-shrink: 0;
}

.s-running-dots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #d97706;
    animation: typing-bounce 1.2s infinite ease-in-out;
}

.s-running-dots span:nth-child(1) {
    animation-delay: 0s;
}

.s-running-dots span:nth-child(2) {
    animation-delay: .2s;
}

.s-running-dots span:nth-child(3) {
    animation-delay: .4s;
}

/* Main */
#main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#chat-header {
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
    display: flex;
    align-items: center;
    gap: 10px;
}

#btn-toggle-sidebar {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    padding: 4px;
    transition: color var(--transition);
}

#btn-toggle-sidebar:hover {
    color: var(--text);
}

#chat-title {
    flex: 0 1 auto;
    min-width: 0;
    font-size: 15px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#thread-id {
    flex: 0 1 320px;
    min-width: 120px;
    max-width: 360px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--text-muted);
    cursor: pointer;
    font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 11px;
    line-height: 1.2;
    overflow: hidden;
    padding: 3px 6px;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#thread-id:hover {
    color: var(--text);
    border-color: var(--accent);
}

#header-dir {
    flex: 1;
    min-width: 0;
    font-size: 11px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#model-select {
    flex-shrink: 0;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 4px 8px;
    font-size: 12px;
    outline: none;
    cursor: pointer;
}

/* Messages */
#messages {
    flex: 1;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#messages.empty::after {
    content: 'メッセージを送信してClaudeと会話を始めましょう';
    color: var(--text-muted);
    font-size: 14px;
    text-align: center;
    margin: auto;
    display: block;
    padding: 60px 0;
}

.turn-block {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    min-width: 0;
}

.turn-zone {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    min-width: 0;
}

#generating-indicator {
    padding: 0 16px 8px;
    display: none;
}

#generating-indicator .msg-row {
    max-width: 900px;
}

.msg-row {
    display: flex;
    gap: 10px;
    max-width: 900px;
    width: 100%;
    min-width: 0;
}

.msg-row.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.msg-row.assistant {
    align-self: flex-start;
}

.msg-row>div {
    min-width: 0;
}

.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    margin-top: 2px;
    font-weight: 700;
}

.msg-row.user .msg-avatar {
    background: var(--accent);
    color: #fff;
}

.msg-row.assistant .msg-avatar {
    background: var(--accent2);
    color: #fff;
}

.msg-row.assistant .msg-avatar.avatar-blue {
    background: linear-gradient(135deg, #001233 0%, #38b6ff 100%);
    box-shadow: 0 4px 14px rgba(56, 182, 255, 0.45);
}

.msg-row.assistant .msg-avatar.avatar-purple {
    background: linear-gradient(135deg, #18002a 0%, #da00ff 100%);
    box-shadow: 0 4px 14px rgba(218, 0, 255, 0.45);
}

.msg-row.assistant .msg-avatar.avatar-yellow {
    background: linear-gradient(135deg, #d48806 0%, #fadb14 100%);
    box-shadow: 0 4px 14px rgba(250, 219, 20, 0.45);
    color: #333;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
}

.msg-title {
    margin-bottom: 6px;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: none;
}

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

.msg-content.streaming-plain {
    white-space: pre-wrap;
}

.msg-bubble {
    background: var(--ai-bubble);
    border-radius: var(--radius);
    padding: 10px 14px;
    max-width: 100%;
    min-width: 0;
    width: fit-content;
    word-break: break-word;
    line-height: 1.6;
    border: 1px solid var(--border);
    overflow: hidden;
}

.msg-row.user .msg-bubble {
    background: var(--user-bubble);
    border-color: #2d4a70;
    width: fit-content;
    max-width: 100%;
    word-break: break-word;
    white-space: pre-wrap;
}

.msg-row.user.pending-message .msg-bubble {
    opacity: 0.55;
    border-style: dashed;
    border-color: #5a7a9a;
    position: relative;
}

.msg-row.user.pending-message .msg-bubble::after {
    content: ' ...';
    font-size: 11px;
    color: var(--text-muted);
}

.msg-row.assistant .msg-bubble {
    border-left: 3px solid var(--accent2);
}

.msg-bubble>* {
    min-width: 0;
    max-width: 100%;
}

.msg-bubble p {
    margin: 0 0 8px;
}

.msg-bubble p:last-child {
    margin-bottom: 0;
}

.msg-bubble pre {
    background: var(--code-bg);
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
    margin: 8px 0;
    border: 1px solid #30363d;
}

.msg-bubble code {
    font-family: 'Cascadia Code', 'Fira Code', Consolas, monospace;
    font-size: 13px;
}

.msg-bubble :not(pre)>code {
    background: var(--code-bg);
    padding: 1px 5px;
    border-radius: 4px;
}

/* ファイルリンク */
.inline-file-link {
    color: inherit;
    text-decoration: none;
}

.inline-file-link .inline-code {
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 0.12em;
}

.inline-file-image-preview {
    display: block;
    width: fit-content;
    max-width: 300px;
    margin: 8px 0;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--code-bg);
    cursor: zoom-in;
    overflow: hidden;
}

.msg-bubble .inline-file-image-preview img {
    display: block;
    max-width: 300px;
    max-height: 250px;
    width: auto;
    height: auto;
    margin: 0;
    border: 0;
    border-radius: 0;
}

.file-image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(3, 7, 18, 0.86);
}

.file-image-lightbox.open {
    display: flex;
}

.file-image-lightbox-panel {
    max-width: min(96vw, 1200px);
    max-height: 94vh;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel-bg);
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
    overflow: hidden;
}

.file-image-lightbox-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.file-image-lightbox-title {
    color: var(--text-muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-image-lightbox-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.file-image-lightbox-open,
.file-image-lightbox-close {
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--code-bg);
    padding: 4px 8px;
    font-size: 12px;
    text-decoration: none;
    cursor: pointer;
}

.file-image-lightbox-img {
    display: block;
    max-width: 96vw;
    max-height: calc(94vh - 46px);
    object-fit: contain;
    background: #050814;
}

.msg-bubble ul,
.msg-bubble ol {
    padding-left: 20px;
    margin: 6px 0;
}

.msg-bubble li {
    margin: 3px 0;
}

.msg-bubble h1,
.msg-bubble h2,
.msg-bubble h3 {
    margin: 10px 0 6px;
}

.msg-bubble table {
    border-collapse: collapse;
    margin: 8px 0;
}

.msg-bubble th,
.msg-bubble td {
    border: 1px solid var(--border);
    padding: 5px 10px;
}

.msg-bubble th {
    background: var(--code-bg);
}

.msg-bubble img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 8px 0;
    cursor: pointer;
    border: 1px solid var(--border);
}

.msg-bubble a {
    color: #60a5fa;
    text-decoration: none;
}

.msg-bubble a:hover {
    text-decoration: underline;
}

.msg-bubble blockquote {
    border-left: 3px solid var(--accent2);
    padding-left: 12px;
    color: var(--text-muted);
    margin: 6px 0;
}

.msg-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    padding: 0 2px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.msg-time {
    white-space: nowrap;
}

.msg-row.user .msg-meta {
    justify-content: flex-end;
}

.msg-copy-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    padding: 1px 5px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity .2s, background var(--transition);
}

.msg-row:hover .msg-copy-btn {
    opacity: 1;
}

.msg-copy-btn:hover {
    background: #30363d;
    color: var(--text);
}

.typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 2px 2px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(1) {
    animation-delay: 0s;
}

.typing-dots span:nth-child(2) {
    animation-delay: .2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: .4s;
}

@keyframes typing-bounce {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.3;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

#pending-banner {
    display: none;
    align-items: flex-start;
    gap: 8px;
    background: rgba(217, 119, 6, 0.08);
    border: 1px solid rgba(217, 119, 6, 0.25);
    border-radius: var(--radius);
    padding: 8px 12px;
    margin-bottom: 10px;
    font-size: 12px;
    color: var(--text-muted);
}

#pending-banner.visible {
    display: flex;
}

#pending-text {
    flex: 1;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 80px;
    overflow-y: auto;
    line-height: 1.4;
}

#pending-text::before {
    content: '送信待ち: ';
    color: var(--accent);
    font-weight: 600;
}

#btn-clear-pending {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 0 4px;
    flex-shrink: 0;
    line-height: 1;
    transition: color .2s;
}

#btn-clear-pending:hover {
    color: #e05c5c;
}

.btn-stop-gen {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 6px;
    transition: color .2s, background .2s;
    margin-top: 4px;
}

.btn-stop-gen:hover {
    color: #e05c5c;
    background: rgba(224, 92, 92, 0.12);
}

.code-wrap {
    position: relative;
    min-width: 0;
    max-width: 100%;
}

.code-wrap pre {
    max-width: 100%;
}

.code-wrap pre code {
    display: block;
    width: max-content;
    min-width: 100%;
    white-space: pre;
    overflow-wrap: normal;
    word-break: normal;
}

.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #30363d;
    border: none;
    color: var(--text-muted);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    opacity: 0;
    transition: opacity .2s;
}

.code-wrap:hover .copy-btn {
    opacity: 1;
}

.copy-btn:hover {
    color: var(--text);
}

/* Input area */
#input-area {
    background: var(--sidebar-bg);
    border-top: 1px solid var(--border);
    padding: 14px 16px;
}

#input-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

#msg-input {
    flex: 1;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    padding: 10px 14px;
    resize: none;
    outline: none;
    min-height: 44px;
    max-height: 200px;
    line-height: 1.5;
    font-family: inherit;
    transition: border-color .2s;
}

#msg-input:focus {
    border-color: var(--accent);
}

#msg-input::placeholder {
    color: var(--text-muted);
}

.voice-progress {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    min-height: 18px;
    margin-top: 6px;
    padding-right: 2px;
    font-size: 11px;
    line-height: 1.25;
    color: var(--text-muted);
    text-align: right;
}

.voice-progress-step {
    font-weight: 600;
    color: var(--accent);
}

.voice-progress-detail {
    max-width: min(460px, 70vw);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#btn-voice,
#btn-quick-prompt,
#btn-send {
    background: var(--accent);
    border: none;
    border-radius: 10px;
    width: 44px;
    height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity .2s;
}

#btn-voice {
    background: var(--panel-bg);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: none;
    transition: background-color .18s ease, border-color .18s ease, color .18s ease, opacity .18s ease;
}

#btn-quick-prompt {
    background: var(--panel-bg);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: none;
    transition: background-color .18s ease, border-color .18s ease, color .18s ease, opacity .18s ease;
}

#btn-voice:hover,
#btn-quick-prompt:hover,
#btn-send:hover {
    opacity: .85;
}

#btn-voice:disabled,
#btn-quick-prompt:disabled,
#btn-send:disabled {
    opacity: .4;
    cursor: default;
}

#btn-voice.recording {
    background: #dc2626;
    color: #fff;
    border-color: #ef4444;
    animation: reconnect-pulse 1.2s ease-in-out infinite;
}

#btn-voice.transcribing {
    background: var(--text-muted);
    color: #fff;
}

.voice-btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    line-height: 1;
}

.voice-icon {
    width: 24px;
    height: 24px;
    fill: currentColor;
    display: none;
}

#btn-voice .voice-icon-idle {
    display: block;
}

#btn-voice.recording .voice-icon-idle,
#btn-voice.transcribing .voice-icon-idle {
    display: none;
}

#btn-voice.recording .voice-icon-recording {
    display: block;
}

#btn-voice.transcribing .voice-icon-transcribing {
    display: block;
}

#btn-send.reconnecting {
    opacity: .6;
    animation: reconnect-pulse 1.2s ease-in-out infinite;
    background: var(--text-muted);
}

@keyframes reconnect-pulse {

    0%,
    100% {
        opacity: .4;
    }

    50% {
        opacity: .8;
    }
}

#btn-send svg {
    width: 20px;
    height: 20px;
    fill: white;
}

.quick-prompt-control {
    position: relative;
    display: inline-flex;
    align-items: flex-end;
    flex-shrink: 0;
}

.quick-prompt-icon {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

.quick-prompt-menu {
    position: absolute;
    right: 0;
    bottom: calc(100% + 8px);
    z-index: 80;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 156px;
    max-width: min(240px, calc(100vw - 24px));
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-bg);
    box-shadow: 0 16px 42px rgba(0, 0, 0, 0.36);
}

.quick-prompt-menu[hidden] {
    display: none;
}

.quick-prompt-item {
    width: 100%;
    min-height: 34px;
    padding: 7px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 11px;
    text-align: left;
    white-space: nowrap;
    cursor: pointer;
}

.quick-prompt-item:hover,
.quick-prompt-item:focus-visible {
    background: rgba(99, 102, 241, 0.16);
    outline: none;
}

/* Dir modal */
#dir-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: #00000088;
    z-index: 100;
    align-items: center;
    justify-content: center;
}

#dir-modal.open {
    display: flex;
}

#dir-panel {
    background: var(--sidebar-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    width: 540px;
    max-width: 96vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#dir-panel-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
}

#dir-panel-header h2 {
    flex: 1;
    font-size: 15px;
}

#btn-dir-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
}

#dir-path-input-row {
    display: flex;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    flex: 0 0 auto;
}

#dir-workspace-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--input-bg);
    flex: 0 0 auto;
}

.workspace-btn {
    background: var(--panel-bg);
    border: 1px solid var(--accent);
    border-radius: 16px;
    color: var(--accent);
    padding: 4px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.workspace-btn:hover {
    background: var(--accent);
    color: #fff;
}

#dir-path-input {
    flex: 1;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 7px 10px;
    font-size: 13px;
    outline: none;
    transition: border-color .2s;
}

#dir-path-input:focus {
    border-color: var(--accent);
}

#btn-dir-go {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 7px 14px;
    cursor: pointer;
    font-size: 13px;
    transition: background var(--transition);
}

#btn-dir-go:hover {
    background: var(--hover);
}

#dir-breadcrumb {
    padding: 10px 14px;
    font-size: 12px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    flex: 0 0 auto;
    white-space: normal;
    overflow-x: hidden;
    overflow-y: auto;
    min-height: 48px;
    max-height: 112px;
    line-height: 1.5;
    overflow-wrap: anywhere;
    word-break: break-word;
}

#dir-breadcrumb span {
    cursor: pointer;
    color: var(--accent);
    display: inline-flex;
    align-items: center;
    padding: 1px 4px;
    border-radius: 4px;
}

#dir-breadcrumb span:hover {
    text-decoration: underline;
}

#dir-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 6px 8px;
}

.dir-entry {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background var(--transition);
    font-size: 13px;
}

.dir-entry:hover {
    background: var(--hover);
}

.dir-entry .icon {
    font-size: 16px;
    flex-shrink: 0;
}

.dir-entry .up {
    color: var(--text-muted);
}

#dir-panel-footer {
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    align-items: center;
    flex: 0 0 auto;
}

#dir-selected-label {
    flex: 1;
    font-size: 12px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#btn-dir-confirm {
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: #fff;
    padding: 8px 18px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    transition: opacity var(--transition);
}

#btn-dir-confirm:hover {
    opacity: .85;
}

#btn-dir-cancel {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    padding: 8px 14px;
    cursor: pointer;
    font-size: 13px;
    transition: color var(--transition);
}

#btn-dir-cancel:hover {
    color: var(--text);
}

/* Rename modal */
#rename-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: #00000088;
    z-index: 200;
    align-items: center;
    justify-content: center;
}

#rename-modal.open {
    display: flex;
}

#rename-panel {
    background: var(--sidebar-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    width: 380px;
    max-width: 96vw;
}

#rename-panel h3 {
    margin-bottom: 12px;
    font-size: 15px;
}

#rename-input {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 8px 12px;
    font-size: 14px;
    outline: none;
    margin-bottom: 14px;
    transition: border-color .2s;
}

#rename-input:focus {
    border-color: var(--accent);
}

#rename-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.modal-btn-ok {
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: #fff;
    padding: 7px 18px;
    cursor: pointer;
    font-weight: 600;
    transition: opacity var(--transition);
}

.modal-btn-ok:hover {
    opacity: .85;
}

.modal-btn-cancel {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    padding: 7px 14px;
    cursor: pointer;
    transition: color var(--transition);
}

.modal-btn-cancel:hover {
    color: var(--text);
}

/* Tool cards */
.tool-card-row {
    display: flex;
    gap: 10px;
    max-width: 900px;
    width: 100%;
    align-self: flex-start;
}

.tool-card-row .msg-avatar {
    width: 32px;
    min-width: 32px;
    height: 0;
    margin: 0;
    overflow: hidden;
    visibility: hidden;
}

.tool-card {
    background: #0d1117;
    border: 1px solid #30363d;
    border-left: 2px solid #d97706;
    border-radius: 6px;
    overflow: hidden;
    font-size: 11px;
    max-width: calc(100% - 50px);
    flex: 1;
    min-width: 0;
    transition: border-color .2s;
}

.tool-card.completed {
    border-left-color: #3fb950;
}

.tool-card.denied {
    border-left-color: #f85149;
}

.tool-card-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    cursor: pointer;
    user-select: none;
    background: #161b22;
    transition: background var(--transition);
}

.tool-card-header:hover {
    background: #1c2128;
}

.tool-card-main {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1 1 auto;
    min-width: 0;
}

.tool-card-name {
    font-weight: 600;
    color: #79c0ff;
    font-family: 'Cascadia Code', Consolas, monospace;
    flex: 0 0 auto;
    font-size: 11px;
    white-space: nowrap;
}

.tool-card-summary {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 12px;
    color: #8b949e;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
}

.tool-card-status {
    font-size: 10px;
    color: #8b949e;
    white-space: nowrap;
}

.tool-card-toggle {
    font-size: 9px;
    color: #8b949e;
    transition: transform .2s;
}

.tool-card-toggle.open {
    transform: rotate(90deg);
}

.tool-card-body {
    display: none;
    padding: 6px 8px;
    border-top: 1px solid #30363d;
}

.tool-card-body.open {
    display: block;
}

.tool-card-args {
    background: #0d1117;
    border-radius: 4px;
    padding: 6px;
    font-size: 11px;
    color: #c9d1d9;
    white-space: pre-wrap;
    overflow-x: auto;
    max-height: 150px;
    margin: 0;
    font-family: 'Cascadia Code', Consolas, monospace;
}

/* Subagent cards */
.subagent-card {
    border-left-color: #8b5cf6;
    cursor: default;
}

.subagent-card .tool-card-header {
    cursor: default;
}

.subagent-card .tool-card-header:hover {
    background: #161b22;
}

.subagent-card .tool-card-summary {
    flex: 0 1 auto;
    color: #8b949e;
}

.subagent-card.completed {
    border-left-color: #3fb950;
}

/* Thinking */
.thinking-block {
    align-self: flex-start;
    max-width: 900px;
    width: 100%;
    padding-left: 42px;
    margin: 4px 0;
}

.thinking-header {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 10px;
    padding: 2px 9px;
    font-size: 11px;
    color: #8b949e;
    cursor: pointer;
    user-select: none;
    transition: border-color var(--transition), color var(--transition);
}

.thinking-header:hover {
    border-color: #8b949e;
    color: #c9d1d9;
}

.thinking-toggle {
    font-size: 9px;
}

.thinking-body {
    display: none;
    margin-top: 4px;
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 6px;
    padding: 8px;
    font-size: 12px;
    color: #8b949e;
    white-space: pre-wrap;
    overflow-x: auto;
    max-height: 250px;
    font-family: 'Cascadia Code', Consolas, monospace;
}

.thinking-body.open {
    display: block;
}

/* Usage pills */
.raw-event-row {
    align-self: flex-start;
    max-width: 900px;
    width: 100%;
    padding-left: 42px;
}

.raw-event-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 10px;
    padding: 2px 9px;
    font-size: 11px;
    color: #8b949e;
    cursor: pointer;
    transition: border-color var(--transition), color var(--transition);
}

.raw-event-pill:hover {
    border-color: #8b949e;
    color: #c9d1d9;
}

.raw-event-detail {
    display: none;
    margin-top: 4px;
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 6px;
    padding: 8px;
    font-size: 11px;
    color: #b0b8c1;
    white-space: pre-wrap;
    overflow-x: auto;
    max-height: 150px;
    font-family: 'Cascadia Code', Consolas, monospace;
}

.raw-event-detail.open {
    display: block;
}

/* Error modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.modal-overlay.open {
    display: flex;
}

.modal-panel {
    background: var(--sidebar-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 90%;
    max-width: 500px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
}

.error-panel {
    border-top: 4px solid var(--accent);
}

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

.modal-header h3 {
    margin: 0;
    font-size: 16px;
}

.modal-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
}

.modal-body {
    padding: 20px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
}

.modal-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

.settings-panel {
    max-width: 420px;
}

.settings-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.settings-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.settings-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.settings-select {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    padding: 10px 12px;
    font-size: 14px;
    outline: none;
}

.settings-select:focus {
    border-color: var(--accent);
}

.settings-unavailable {
    color: var(--text-muted);
}

/* Plan Approval Banner */
.plan-approval-banner {
    background: var(--panel-bg);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 16px;
    margin: 12px 48px;
    text-align: center;
}

.plan-approval-text {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 12px;
}

.plan-approval-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.plan-btn {
    padding: 8px 20px;
    border-radius: 8px;
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition);
}

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

.plan-btn-approve:hover {
    opacity: 0.85;
}

.plan-btn-reject {
    background: transparent;
    color: var(--text-muted);
    border-color: var(--border);
}

.plan-btn-reject:hover {
    background: var(--hover);
}

/* AskUserQuestion UI */
.ask-question-container {
    margin: 12px 48px;
}

.ask-question-block {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 8px;
}

.ask-question-header {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 12px;
}

.ask-question-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ask-question-btn {
    text-align: left;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    transition: all var(--transition);
}

.ask-question-btn:hover {
    background: var(--hover);
    border-color: var(--accent);
}

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

.ask-question-btn.selected .ask-question-desc {
    color: rgba(255, 255, 255, 0.85);
}

.ask-question-desc {
    font-size: 11px;
    color: var(--text-muted);
    display: block;
    margin-top: 4px;
}

.ask-question-other {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ask-question-other-label {
    font-size: 11px;
    color: var(--text-muted);
}

.ask-question-other-input {
    width: 100%;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    box-sizing: border-box;
}

.ask-question-other-input:focus {
    outline: none;
    border-color: var(--accent);
}

.ask-question-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.ask-question-submit,
.ask-question-skip {
    padding: 8px 20px;
    border-radius: 8px;
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all var(--transition);
}

.ask-question-submit {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.ask-question-submit:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.ask-question-submit:not(:disabled):hover {
    filter: brightness(1.1);
}

.ask-question-skip {
    background: transparent;
    color: var(--text-muted);
}

.ask-question-skip:hover {
    background: var(--hover);
}
