/* chat.css — page /chat coach IA */

/* When inside app-shell, chat fills the content-body; standalone it fills viewport */
.chat-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 0;
    gap: 0;
    /* Fill content-body when inside app-shell */
    height: calc(100dvh - 60px); /* header ~60px */
}

/* When inside app-shell content-body, remove its default padding */
.content-body:has(.chat-layout) {
    padding: 0;
    max-width: none;
}

/* ── Sidebar sessions ──────────────────────────────────────── */
.chat-sidebar {
    background: var(--surface-1, #0f0f0f);
    border-right: 1px solid var(--border, #1f1f1f);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.chat-sidebar-head {
    padding: 12px;
    border-bottom: 1px solid var(--border, #1f1f1f);
}

.chat-new-btn {
    width: 100%;
    background: var(--accent, #c9a840);
    color: #0a0a0a;
    border: none;
    border-radius: 8px;
    padding: 10px 12px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: filter 0.15s;
}
.chat-new-btn:hover { filter: brightness(1.1); }

.chat-sessions {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
}
.chat-sessions-empty {
    padding: 16px;
    color: var(--text-dim, #888);
    font-size: 13px;
    text-align: center;
}

.chat-session-item {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text, #e5e5e5);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 4px;
    cursor: pointer;
    font-size: 13px;
    line-height: 1.35;
    transition: background 0.12s, border-color 0.12s;
    position: relative;
}
.chat-session-item:hover {
    background: var(--surface-2, #1a1a1a);
}
.chat-session-item.active {
    background: var(--surface-2, #1a1a1a);
    border-color: var(--accent, #c9a840);
}
.chat-session-title {
    font-weight: 600;
    color: var(--text, #e5e5e5);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-session-meta {
    font-size: 11px;
    color: var(--text-dim, #888);
    margin-top: 3px;
}
.chat-session-delete {
    position: absolute;
    top: 6px;
    right: 6px;
    background: transparent;
    border: none;
    color: var(--text-dim, #888);
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    display: none;
}
.chat-session-item:hover .chat-session-delete { display: inline-block; }
.chat-session-delete:hover { background: var(--danger, #a33); color: #fff; }

/* ── Zone principale ───────────────────────────────────────── */
.chat-main {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    background: var(--surface-0, #0a0a0a);
}

.chat-header-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border, #1f1f1f);
    min-height: 48px;
}
.chat-sidebar-toggle {
    display: none;
    background: transparent;
    border: 1px solid var(--border, #1f1f1f);
    color: var(--text, #e5e5e5);
    font-size: 18px;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
}
.chat-current-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--text, #e5e5e5);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.chat-usage-meter {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--surface-2, #1a1a1a);
    border: 1px solid var(--border, #252525);
    border-radius: 999px;
    font-size: 12px;
    font-family: 'Geist Mono', ui-monospace, Menlo, monospace;
    white-space: nowrap;
    cursor: help;
}
.chat-usage-cost {
    color: var(--accent, #c9a840);
    font-weight: 700;
}
.chat-usage-tokens {
    color: var(--text-dim, #888);
}
.chat-usage-meter.warming {
    animation: chat-usage-pulse 1.2s ease-in-out infinite;
}
@keyframes chat-usage-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.chat-welcome {
    text-align: center;
    padding: 40px 16px;
    color: var(--text-dim, #888);
}
.chat-welcome h2 {
    color: var(--accent, #c9a840);
    font-size: 20px;
    margin: 0 0 12px 0;
}
.chat-welcome p { font-size: 14px; margin: 6px 0; }
.chat-welcome-hint { font-size: 12px; font-style: italic; opacity: 0.7; }

.chat-msg {
    max-width: 82%;
    padding: 12px 14px;
    border-radius: 12px;
    line-height: 1.5;
    font-size: 14px;
    word-wrap: break-word;
}
.chat-msg-user {
    align-self: flex-end;
    background: var(--accent, #c9a840);
    color: #0a0a0a;
    border-bottom-right-radius: 4px;
    font-weight: 500;
}
.chat-msg-assistant {
    align-self: flex-start;
    background: var(--surface-2, #1a1a1a);
    color: var(--text, #e5e5e5);
    border: 1px solid var(--border, #252525);
    border-bottom-left-radius: 4px;
}
.chat-msg-assistant strong { color: var(--accent, #c9a840); }
.chat-msg-assistant p { margin: 0 0 8px 0; }
.chat-msg-assistant p:last-child { margin-bottom: 0; }
.chat-msg-assistant ul, .chat-msg-assistant ol { margin: 6px 0 8px 18px; padding: 0; }
.chat-msg-assistant li { margin: 3px 0; }
.chat-msg-assistant h1, .chat-msg-assistant h2, .chat-msg-assistant h3 {
    margin: 10px 0 6px 0; font-size: 15px; color: var(--accent, #c9a840);
}
.chat-msg-assistant code {
    background: rgba(201, 168, 64, 0.12);
    color: var(--accent, #c9a840);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 12.5px;
    font-family: 'Geist Mono', ui-monospace, Menlo, monospace;
}
.chat-msg-assistant a {
    color: var(--accent, #c9a840);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.chat-msg-assistant a:hover { filter: brightness(1.15); }

/* ── Tableaux markdown ────────────────────────────────────── */
.chat-md-table-wrap {
    margin: 10px -4px;
    overflow-x: auto;
    max-width: 100%;
    /* Scrollbar discrete */
    scrollbar-width: thin;
}
.chat-md-table {
    border-collapse: collapse;
    font-size: 12.5px;
    min-width: 100%;
    background: rgba(255, 255, 255, 0.015);
    border-radius: 6px;
    overflow: hidden;
}
.chat-md-table thead {
    background: rgba(201, 168, 64, 0.1);
}
.chat-md-table th {
    padding: 7px 10px;
    text-align: left;
    font-weight: 700;
    color: var(--accent, #c9a840);
    border-bottom: 1px solid rgba(201, 168, 64, 0.3);
    white-space: nowrap;
}
.chat-md-table td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border, #252525);
    color: var(--text, #e5e5e5);
    vertical-align: top;
}
.chat-md-table tbody tr:last-child td {
    border-bottom: none;
}
.chat-md-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}
.chat-md-table strong { color: var(--accent, #c9a840); }

/* Tableaux dans la bulle streaming : meme style */
.chat-msg-streaming .chat-md-table-wrap,
.chat-msg-streaming .chat-md-table {
    font-size: 12.5px;
}

.chat-tool-calls {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding: 4px 10px;
    background: rgba(201, 168, 64, 0.08);
    border: 1px solid rgba(201, 168, 64, 0.25);
    border-radius: 999px;
    font-size: 11px;
    color: var(--accent, #c9a840);
    font-family: 'Geist Mono', ui-monospace, Menlo, monospace;
    cursor: help;
    white-space: nowrap;
}
.chat-tool-calls-ico { font-size: 12px; }
.chat-tool-calls-list { opacity: 0.95; }

/* ── Streaming bubble (pendant generation) ────────────────── */
.chat-msg-streaming .chat-stream-status {
    font-size: 11px;
    color: var(--text-dim, #888);
    font-style: italic;
    margin-bottom: 6px;
}
.chat-msg-streaming .chat-stream-status::after {
    content: '';
    display: inline-block;
    animation: chat-dots 1.2s infinite;
}
.chat-msg-streaming .chat-stream-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 8px;
}
.chat-msg-streaming .chat-stream-tool-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: rgba(201, 168, 64, 0.12);
    border: 1px solid rgba(201, 168, 64, 0.35);
    border-radius: 999px;
    font-size: 10px;
    color: var(--accent, #c9a840);
    font-family: 'Geist Mono', ui-monospace, Menlo, monospace;
    opacity: 0.7;
    transition: opacity 0.2s;
}
.chat-msg-streaming .chat-stream-tool-tag.done {
    opacity: 1;
    background: rgba(61, 170, 116, 0.12);
    border-color: rgba(61, 170, 116, 0.35);
    color: var(--status-green, #3daa74);
}
.chat-stream-tool-ico { font-size: 11px; }
.chat-msg-streaming .chat-stream-body {
    font-size: 14px;
    line-height: 1.5;
}
.chat-msg-streaming .chat-stream-body strong { color: var(--accent, #c9a840); }
.chat-msg-streaming .chat-stream-body p { margin: 0 0 8px 0; }
.chat-msg-streaming .chat-stream-body ul,
.chat-msg-streaming .chat-stream-body ol { margin: 6px 0 8px 18px; padding: 0; }

.chat-msg-error {
    align-self: center;
    background: rgba(180, 60, 60, 0.15);
    color: #f88;
    border: 1px solid #a33;
    font-size: 13px;
    padding: 8px 12px;
}

.chat-typing {
    align-self: flex-start;
    color: var(--text-dim, #888);
    font-size: 13px;
    font-style: italic;
    padding: 8px 14px;
}
.chat-typing::after {
    content: '';
    display: inline-block;
    animation: chat-dots 1.2s infinite;
}
@keyframes chat-dots {
    0%, 20% { content: ''; }
    40% { content: '.'; }
    60% { content: '..'; }
    80%, 100% { content: '...'; }
}

/* ── Raccourcis rapides ───────────────────────────────────── */
.chat-shortcuts {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 16px 0 16px;
    background: var(--surface-1, #0f0f0f);
    border-top: 1px solid var(--border, #1f1f1f);
}
.chat-shortcut {
    background: var(--surface-2, #1a1a1a);
    color: var(--text, #e5e5e5);
    border: 1px solid var(--border, #252525);
    border-radius: 999px;
    padding: 5px 11px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.12s, border-color 0.12s, transform 0.08s;
}
.chat-shortcut:hover {
    background: var(--surface-3, #242424);
    border-color: var(--accent, #c9a840);
}
.chat-shortcut:active {
    transform: scale(0.96);
}

/* ── Composer ──────────────────────────────────────────────── */
.chat-composer {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border, #1f1f1f);
    background: var(--surface-1, #0f0f0f);
    align-items: flex-end;
}
.chat-input {
    flex: 1;
    background: var(--surface-0, #0a0a0a);
    color: var(--text, #e5e5e5);
    border: 1px solid var(--border, #252525);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    min-height: 42px;
    max-height: 200px;
    line-height: 1.4;
}
.chat-input:focus {
    outline: none;
    border-color: var(--accent, #c9a840);
}
.chat-send-btn {
    background: var(--accent, #c9a840);
    color: #0a0a0a;
    border: none;
    border-radius: 10px;
    padding: 0 18px;
    height: 42px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
}
.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Responsive mobile ─────────────────────────────────────── */
@media (max-width: 767px) {
    .chat-layout {
        /* Account for header + bottom-nav */
        height: calc(100dvh - 60px - var(--bottom-nav-h, 64px));
    }
}

@media (max-width: 720px) {
    .chat-usage-meter {
        padding: 5px 8px;
        font-size: 11px;
    }
    .chat-usage-tokens {
        display: none;
    }
    .chat-layout {
        grid-template-columns: 1fr;
        position: relative;
    }
    .chat-sidebar {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 78%;
        max-width: 300px;
        z-index: 10;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 2px 0 12px rgba(0,0,0,0.4);
    }
    .chat-sidebar.open { transform: translateX(0); }
    .chat-sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }
    .chat-msg { max-width: 92%; }
}
