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

/* -----------------------------------------------------------------
   デザイントークン（CSS 変数）
   ----------------------------------------------------------------- */
:root {
    /* カラーパレット */
    --bg: #1a1a2e;
    --sidebar-bg: #16213e;
    --panel-bg: #0f3460;
    --accent: #e94560;
    --accent2: #533483;
    --text: #e0e0e0;
    --text-muted: #9499a6;
    --border: #2a2a4a;
    --user-bubble: #1d3557;
    --ai-bubble: #162032;
    --input-bg: #0e1628;
    --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: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    font-size: 14px;
}

#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);
    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);
    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 #dir-modal,
body.auth-locked #model-settings-modal,
body.auth-locked #error-modal {
    display: none !important;
}

/* -----------------------------------------------------------------
   スクロールバー
   ----------------------------------------------------------------- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

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

/* -----------------------------------------------------------------
   サイドバー
   ----------------------------------------------------------------- */
#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, .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, .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;
}

.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;
}

.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 #4dbb72;
    padding-left: 7px;
    /* border 分だけ補正 */
}

/* サイドバー実行中ドットインジケーター */
.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: #4dbb72;
    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 {
    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: 1 1 auto;
    min-width: 0;
    font-size: 15px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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


/* -----------------------------------------------------------------
   モデルピッカー（カスタムドロップダウン）
   ----------------------------------------------------------------- */
.model-picker {
    position: relative;
    flex-shrink: 0;
}

.model-picker-btn {
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 5px 8px;
    font-size: 12px;
    outline: none;
    cursor: pointer;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    max-width: 280px;
    transition: border-color .15s;
}

.model-picker-copy {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
    gap: 1px;
}

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

.model-picker-arrow {
    font-size: 10px;
    color: var(--text-muted);
    flex-shrink: 0;
}

#model-picker-label {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#model-picker-meta {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-muted);
    font-size: 10px;
}

.model-picker-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: var(--sidebar-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    min-width: 200px;
    max-width: 280px;
    max-height: 360px;
    overflow-y: auto;
    z-index: 500;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
    padding: 4px 0;
}

.mp-group-header {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .6px;
    padding: 8px 12px 3px;
}

.mp-model-with-efforts {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    padding: 5px 12px 2px;
    opacity: .7;
    cursor: default;
}

.mp-model-with-efforts.current-model {
    font-weight: 700;
    opacity: 1;
}

.mp-item {
    font-size: 12px;
    color: var(--text);
    padding: 6px 12px;
    cursor: pointer;
    transition: background var(--transition);
    border-radius: 4px;
    margin: 0 4px;
}

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

.mp-item.selected {
    color: var(--accent);
    font-weight: 600;
}

.mp-effort-item {
    padding-left: 24px;
    font-size: 11px;
    color: var(--text-muted);
}

.mp-effort-item:hover {
    color: var(--text);
}

.mp-effort-item.selected {
    color: var(--accent);
    font-weight: 600;
}

/* -----------------------------------------------------------------
   メッセージ一覧
   ----------------------------------------------------------------- */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

/* ターンブロック: 1ターン分（user + thinking + tools + assistant + usage）をまとめる */
.turn-block {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

/* ターンブロック内ゾーン: misc(上) → thinking(中) → response(下) の順で表示 */
.turn-zone {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

/* 空のゾーンは js で style.display='none' を設定・解除するようになりました */
/* .turn-zone:empty { display: none; } */

/* 生成中インジケーター（#messages の外、スクロール領域に含まれない） */
#generating-indicator {
    padding: 0 16px 8px;
    display: none;
    /* show/hide は JS で style.display を切り替え */
}

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

/* メッセージ行 */
.msg-row {
    display: flex;
    gap: 10px;
    max-width: 900px;
    width: 100%;
}

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

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

/* アバター */
.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;
}

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

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

/* バブル */
.msg-bubble {
    background: var(--ai-bubble);
    border-radius: var(--radius);
    padding: 10px 14px;
    max-width: calc(100% - 50px);
    word-break: break-word;
    line-height: 1.6;
    border: 1px solid var(--border);
}

.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);
}

/* Markdown 内コンテンツ */
.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;
    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 blockquote {
    border-left: 3px solid var(--accent2);
    padding-left: 12px;
    color: var(--text-muted);
    margin: 6px 0;
}

.msg-bubble .katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 2px 0;
}

.msg-bubble .katex-error {
    color: #ff8a8a;
    background: transparent;
}

/* メタ行（タイムスタンプ・コピーボタン） */
.msg-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    padding: 0 2px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.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);
}

/* タイピングアニメーション（3点点滅） */
.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(--text-muted);
    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(88, 166, 255, 0.08);
    border: 1px solid rgba(88, 166, 255, 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: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 15px;
    padding: 2px 8px;
    border-radius: 6px;
    transition: color .2s, background .2s;
    margin-top: 4px;
}

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

@keyframes blink {

    0%,
    100% {
        opacity: .2
    }

    50% {
        opacity: 1
    }
}

/* コードブロック コピーボタン */
.code-wrap {
    position: relative;
}

.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 {
    background: var(--sidebar-bg);
    border-top: 1px solid var(--border);
    padding: 14px 16px;
}

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

.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;
}

#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);
}

#btn-voice,
#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-voice:hover,
#btn-send:hover {
    opacity: .85;
}

#btn-voice: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;
}

/* -----------------------------------------------------------------
   ディレクトリ選択モーダル
   ----------------------------------------------------------------- */
#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 {
    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);
}

/* -----------------------------------------------------------------
   権限確認カード
   ----------------------------------------------------------------- */
.msg-row.permission-request .perm-card {
    background: #161b22;
    border: 1px solid #f0883e;
    border-radius: var(--radius);
    padding: 12px 14px;
    max-width: 560px;
}

.perm-title {
    font-weight: 600;
    color: #f0883e;
    margin-bottom: 6px;
    font-size: 14px;
}

.perm-tool {
    font-size: 13px;
    margin-bottom: 6px;
    color: var(--text);
}

.perm-tool code {
    background: var(--code-bg);
    padding: 1px 5px;
    border-radius: 4px;
}

.perm-args {
    background: var(--code-bg);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 12px;
    color: var(--text-muted);
    overflow-x: auto;
    max-height: 140px;
    margin: 6px 0 10px;
    white-space: pre-wrap;
    word-break: break-all;
}

.perm-actions {
    display: flex;
    gap: 8px;
}

.perm-btn {
    border: none;
    border-radius: 6px;
    padding: 5px 16px;
    font-size: 13px;
    cursor: pointer;
    font-weight: 500;
    transition: background var(--transition);
}

.perm-btn.allow {
    background: #238636;
    color: #fff;
}

.perm-btn.allow:hover {
    background: #2ea043;
}

.perm-btn.deny {
    background: #da3633;
    color: #fff;
}

.perm-btn.deny:hover {
    background: #f85149;
}

.perm-result {
    font-size: 13px;
    padding: 4px 0;
}

.perm-result.allow {
    color: #3fb950;
}

.perm-result.deny {
    color: #f85149;
}

/* -----------------------------------------------------------------
   ツール実行カード
   ----------------------------------------------------------------- */
.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.websearch-card {
    border-left-color: #1f6feb;
    max-width: min(520px, calc(100% - 50px));
}

.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-name {
    font-weight: 600;
    color: #79c0ff;
    font-family: 'Cascadia Code', Consolas, monospace;
    flex: 0 0 auto;
    font-size: 11px;
    white-space: nowrap;
}

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

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

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

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

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

.tool-card.websearch-card .tool-card-header {
    padding: 3px 7px;
}

.tool-card.websearch-card .tool-card-name {
    font-size: 10px;
}

.tool-card.websearch-card .tool-card-summary {
    font-size: 11px;
}

.tool-card.websearch-card .tool-card-status {
    font-size: 9px;
}

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

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

.tool-card-live {
    font-size: 12px;
    color: #8b949e;
    margin-bottom: 10px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
}

.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;
}

.tool-card-output {
    display: none;
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 4px;
    padding: 8px;
    font-size: 11px;
    color: #c9d1d9;
    white-space: pre-wrap;
    overflow: auto;
    max-height: 220px;
    margin: 10px 0 0;
    font-family: 'Cascadia Code', Consolas, monospace;
}

.tool-card-output:not(:empty) {
    display: block;
}

/* -----------------------------------------------------------------
   ローイベント ピル / thinking ブロック
   ----------------------------------------------------------------- */
.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;
}

.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;
}

/* -----------------------------------------------------------------
   エラーモーダル用スタイル
   ----------------------------------------------------------------- */
.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;
}

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

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

/* =================================================================
   モデル設定ボタンとモーダル
   ================================================================= */

.model-settings-btn {
    width: calc(100% - 16px);
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    padding: 8px 10px;
    margin: 8px 8px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition);
}

.model-settings-btn:hover {
    background: var(--hover);
    color: var(--text);
    border-color: var(--accent2);
}

/* Model Settings Modal */
#model-settings-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: #00000088;
    z-index: 200;
    align-items: center;
    justify-content: center;
}

#model-settings-modal.open {
    display: flex;
}

#model-settings-panel {
    background: var(--sidebar-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 400px;
    max-width: 90vw;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

#model-settings-header h3 {
    margin: 0;
    font-size: 16px;
    flex: 1;
}

#btn-model-settings-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#btn-model-settings-close:hover {
    color: var(--text);
}

#model-settings-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
}

.settings-section-block {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 12px 12px;
}

.settings-section-block+.settings-section-block {
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.settings-section-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .6px;
}

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

.settings-field-label {
    font-size: 12px;
    color: var(--text);
}

.settings-field-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-field-select:focus {
    border-color: var(--accent);
}

.settings-field-unavailable {
    color: var(--text-muted);
    font-size: 13px;
}

#model-settings-checkbox-group {
    display: flex;
    flex-direction: column;
}

.ms-group-header {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .6px;
    padding: 8px 12px 3px;
}

.ms-checkbox-item {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    cursor: pointer;
    transition: background var(--transition);
    font-size: 13px;
    color: var(--text);
    user-select: none;
}

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

.ms-checkbox {
    width: 16px;
    height: 16px;
    margin-right: 8px;
    cursor: pointer;
    accent-color: var(--accent);
}

.ms-checkbox-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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