/* ═══════════════════════════════════════════════════════
   DESKLOG AI CHAT — Modern, Theme-Consistent Design
   Colors: var(--primary-color) #81B504 | var(--secondary-color) #045ba0
   ═══════════════════════════════════════════════════════ */

/* ─── CSS Variables for AI Chat ────────────────────── */
:root {
    --ai-green: #81B504;
    --ai-green-dark: #628a03;
    --ai-green-light: #9ada05;
    --ai-blue: #045ba0;
    --ai-blue-dark: #024173;
    --ai-blue-light: #0673c9;
    --ai-bg: #f8fafc;
    --ai-panel-bg: rgba(255, 255, 255, 0.85);
    --ai-panel-blur: blur(24px);
    --ai-bubble-user: linear-gradient(135deg, var(--ai-green) 0%, #689203 100%);
    --ai-bubble-ai: rgba(255, 255, 255, 0.9);
    --ai-shadow-sm: 0 4px 12px rgba(4, 91, 160, 0.04);
    --ai-shadow-md: 0 12px 32px rgba(4, 91, 160, 0.12);
    --ai-shadow-lg: 0 24px 48px rgba(4, 91, 160, 0.18);
    --ai-radius: 20px;
    --ai-radius-lg: 24px;
    --ai-radius-sm: 12px;
    --ai-transition: 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    --ai-border: 1px solid rgba(255, 255, 255, 0.6);
}

/* ─── Header Trigger Button ─────────────────────────── */
.ai-header-trigger {
    display: flex !important;
    align-items: center;
    padding: 6px 10px !important;
    cursor: pointer;
    text-decoration: none !important;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.ai-header-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 30px;
    background: linear-gradient(135deg, var(--ai-green), var(--ai-blue));
    color: #fff;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 10px rgba(129, 181, 4, 0.3), 0 2px 10px rgba(4, 91, 160, 0.15);
    transition: transform var(--ai-transition), box-shadow var(--ai-transition);
    position: relative;
}

.ai-header-icon::after {
    content: '';
    position: absolute;
    top: -3px;
    right: -3px;
    width: 9px;
    height: 9px;
    background: #ff5252;
    border-radius: 50%;
    border: 2px solid var(--ai-blue);
    animation: aiPulse 2s infinite;
}

@keyframes aiPulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.5;
        transform: scale(0.85);
    }
}

.ai-header-trigger:hover .ai-header-icon,
.ai-header-trigger:focus .ai-header-icon {
    transform: scale(1.12) translateY(-1px);
    box-shadow: 0 4px 16px rgba(129, 181, 4, 0.4), 0 4px 16px rgba(4, 91, 160, 0.2);
}

/* ─── Overlay ───────────────────────────────────────── */
.ai-chat-overlay {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 10001;
    background: rgba(4, 30, 55, 0.3);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    display: flex;
    justify-content: flex-end;
    animation: aiOverlayIn 0.3s ease-out;
}

@keyframes aiOverlayIn {
    from {
        opacity: 0;
        backdrop-filter: blur(0px);
    }

    to {
        opacity: 1;
        backdrop-filter: blur(12px);
    }
}

/* ─── Panel ─────────────────────────────────────────── */
.ai-chat-panel {
    width: 100%;
    max-width: 720px;
    height: 100%;
    background: var(--ai-panel-bg);
    -webkit-backdrop-filter: var(--ai-panel-blur);
    backdrop-filter: var(--ai-panel-blur);
    display: flex;
    flex-direction: row;
    box-shadow: var(--ai-shadow-lg);
    animation: aiSlideIn 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    overflow: hidden;
    border-left: var(--ai-border);
    position: relative;
}

.ai-chat-main {
    flex: 1 1 auto;
    min-width: 320px;
    display: flex;
    flex-direction: column;
    background: transparent;
    overflow: hidden;
}

/* When the viewport is too narrow to fit sidebar + main side-by-side,
   the sidebar collapses automatically (handled in media queries below). */

@keyframes aiSlideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ─── Header ────────────────────────────────────────── */
.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--ai-blue) 0%, var(--ai-blue-dark) 100%);
    color: #fff;
    flex-shrink: 0;
    min-height: 70px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(4, 91, 160, 0.2);
}

/* Subtle gradient shimmer on header */
.ai-chat-header::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(129, 181, 4, 0.15) 0%, transparent 60%);
    animation: aiHeaderShimmer 8s linear infinite;
}

@keyframes aiHeaderShimmer {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.ai-chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
    position: relative;
    z-index: 1;
}

.ai-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--ai-green), var(--ai-green-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 13px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(129, 181, 4, 0.35);
    position: relative;
}

/* Online status dot on avatar */
.ai-chat-avatar::after {
    content: '';
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 10px;
    height: 10px;
    background: #4caf50;
    border-radius: 50%;
    border: 2px solid var(--ai-blue);
}

.ai-chat-title {
    font-weight: 700;
    font-size: 15px;
    line-height: 1.2;
    letter-spacing: 0.2px;
}

.ai-chat-subtitle {
    font-size: 11px;
    opacity: 0.75;
    line-height: 1.2;
    margin-top: 2px;
}

.ai-chat-header-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.ai-chat-btn-icon {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border-radius: var(--ai-radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all var(--ai-transition);
    touch-action: manipulation;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.ai-chat-btn-icon:hover,
.ai-chat-btn-icon:focus {
    background: rgba(129, 181, 4, 0.35);
    transform: scale(1.05);
    outline: none;
}

.ai-chat-btn-icon:focus-visible {
    outline: 2px solid var(--ai-green);
    outline-offset: 2px;
}

.ai-chat-btn-icon:active {
    transform: scale(0.95);
}

/* ─── Messages Container ───────────────────────────── */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px 20px;
    background: transparent;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    position: relative;
}

.ai-chat-messages::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image:
        radial-gradient(circle at 15% 30%, rgba(129, 181, 4, 0.04) 0%, transparent 40%),
        radial-gradient(circle at 85% 70%, rgba(4, 91, 160, 0.04) 0%, transparent 40%);
    pointer-events: none;
    z-index: 0;
}

.ai-chat-messages>* {
    position: relative;
    z-index: 1;
}

.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(4, 91, 160, 0.15);
    border-radius: 10px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(4, 91, 160, 0.25);
}

/* ─── Welcome Screen ───────────────────────────────── */
.ai-chat-welcome {
    text-align: center;
    padding: 32px 16px 24px;
}

.ai-chat-welcome.hidden {
    display: none;
}

.ai-chat-welcome-icon {
    width: 68px;
    height: 68px;
    margin: 0 auto 20px;
    background: linear-gradient(135deg, var(--ai-blue), var(--ai-green));
    border-radius: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 8px 25px rgba(4, 91, 160, 0.25), 0 6px 15px rgba(129, 181, 4, 0.2);
    animation: aiWelcomeFloat 3s ease-in-out infinite;
}

@keyframes aiWelcomeFloat {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-6px);
    }
}

.ai-chat-welcome-icon i {
    font-size: 28px !important;
    color: #fff !important;
}

.ai-chat-welcome h4 {
    font-size: 18px;
    color: var(--ai-blue-dark);
    margin: 0 0 8px;
    font-weight: 700;
}

.ai-chat-welcome p {
    font-size: 14px;
    color: #64748b;
    line-height: 1.6;
    margin: 0 0 24px;
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
}

.ai-chat-suggestions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 320px;
    margin: 0 auto;
}

.ai-chat-suggestions button {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 48px;
    padding: 12px 20px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    background: #fff;
    border-radius: 16px;
    font-size: 14px;
    color: #334155;
    cursor: pointer;
    transition: all var(--ai-transition);
    text-align: left;
    width: 100%;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    box-shadow: var(--ai-shadow-sm);
}

.ai-chat-suggestions button i {
    color: var(--ai-blue);
    width: 20px;
    text-align: center;
    flex-shrink: 0;
    font-size: 16px;
    opacity: 0.8;
}

.ai-chat-suggestions button:hover,
.ai-chat-suggestions button:focus {
    border-color: rgba(129, 181, 4, 0.3);
    color: var(--ai-blue-dark);
    background: linear-gradient(to right, #ffffff, #f8fbf6);
    transform: translateY(-2px);
    box-shadow: var(--ai-shadow-md);
    outline: none;
}

.ai-chat-suggestions button:hover i,
.ai-chat-suggestions button:focus i {
    color: var(--ai-green);
    transform: scale(1.1);
    opacity: 1;
}

.ai-chat-suggestions button:active {
    transform: translateY(0);
    background: #f1f5f9;
}

/* ─── Chat Bubbles ──────────────────────────────────── */
.ai-chat-msg {
    margin-bottom: 14px;
    animation: aiFadeSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    max-width: 100%;
}

@keyframes aiFadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* User bubble */
.ai-chat-msg-user {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.ai-chat-msg-user .ai-chat-bubble {
    background: var(--ai-bubble-user);
    color: #fff;
    border-radius: var(--ai-radius-lg) var(--ai-radius-lg) 6px var(--ai-radius-lg);
    max-width: 85%;
    padding: 13px 18px;
    font-size: 14.5px;
    line-height: 1.6;
    box-shadow: 0 4px 16px rgba(129, 181, 4, 0.25);
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* Assistant bubble */
.ai-chat-msg-assistant {
    display: flex;
    justify-content: flex-start;
    gap: 12px;
    align-items: flex-start;
    max-width: 100%;
}

.ai-chat-msg-assistant .ai-chat-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--ai-blue), var(--ai-green));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
    box-shadow: 0 4px 10px rgba(4, 91, 160, 0.2);
}

.ai-chat-msg-assistant .ai-chat-msg-avatar svg {
    width: 16px;
    height: 16px;
}

.ai-chat-msg-assistant .ai-chat-content {
    max-width: calc(100% - 46px);
    min-width: 0;
}

.ai-chat-msg-assistant .ai-chat-bubble {
    background: var(--ai-bubble-ai);
    color: #1e293b;
    border-radius: var(--ai-radius-lg) var(--ai-radius-lg) var(--ai-radius-lg) 6px;
    padding: 14px 20px;
    font-size: 14.5px;
    line-height: 1.65;
    box-shadow: var(--ai-shadow-sm);
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    border: 1px solid rgba(0, 0, 0, 0.04);
}

/* ─── Message Footer (time + copy) ─────────────────── */
.ai-chat-msg-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
    padding: 0 4px;
}

.ai-chat-msg-time {
    font-size: 10px;
    color: #94a3b8;
    line-height: 1;
    margin-top: 4px;
}

.ai-chat-msg-user .ai-chat-msg-time {
    text-align: right;
    color: #94a3b8;
}

/* Action buttons (copy etc.) */
.ai-chat-msg-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity var(--ai-transition);
}

.ai-chat-msg-assistant:hover .ai-chat-msg-actions {
    opacity: 1;
}

.ai-chat-action-btn {
    border: none;
    background: none;
    color: #94a3b8;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 8px;
    transition: all var(--ai-transition);
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-action-btn:hover {
    color: var(--ai-blue);
    background: rgba(4, 91, 160, 0.08);
    transform: scale(1.1);
}

.ai-chat-action-btn:active {
    transform: scale(0.9);
}

.ai-action-success {
    color: var(--ai-green) !important;
}

/* Typewriter reveal */
.ai-chat-typewriter {
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.ai-chat-typewriter.ai-chat-typewriter-done {
    opacity: 1;
    transform: translateY(0);
}

/* ─── Markdown in Bubbles ───────────────────────────── */
.ai-chat-bubble p {
    margin: 0 0 8px;
}

.ai-chat-bubble p:last-child {
    margin: 0;
}

.ai-chat-bubble strong {
    font-weight: 700;
    color: var(--ai-blue-dark);
}

.ai-chat-bubble em {
    font-style: italic;
}

.ai-chat-bubble code {
    background: rgba(4, 91, 160, 0.07);
    color: var(--ai-blue);
    padding: 2px 6px;
    border-radius: 5px;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 12px;
    word-break: break-all;
}

/* ─── Code Blocks with Header ──────────────────────── */
.ai-code-block {
    margin: 10px 0;
    border-radius: var(--ai-radius-sm);
    overflow: hidden;
    border: 1px solid #1e293b;
    box-shadow: var(--ai-shadow-sm);
}

.ai-code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: #1e293b;
    border-bottom: 1px solid #334155;
    min-height: 32px;
}

.ai-code-lang {
    font-size: 10px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ai-code-copy {
    border: none;
    background: rgba(255,255,255,0.06);
    color: #64748b;
    cursor: pointer;
    padding: 3px 8px;
    font-size: 11px;
    border-radius: 6px;
    transition: all var(--ai-transition);
    display: flex;
    align-items: center;
    gap: 4px;
}

.ai-code-copy:hover {
    background: rgba(255,255,255,0.12);
    color: #e2e8f0;
}

.ai-code-copy.ai-action-success {
    color: var(--ai-green) !important;
}

.ai-code-block pre {
    margin: 0;
    border: none;
    border-radius: 0;
}

.ai-chat-bubble pre {
    background: #0f172a;
    color: #e2e8f0;
    padding: 12px 14px;
    border-radius: var(--ai-radius-sm);
    overflow-x: auto;
    margin: 10px 0;
    font-size: 12px;
    line-height: 1.55;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    border: 1px solid #1e293b;
}

.ai-chat-bubble pre code {
    background: none;
    color: inherit;
    padding: 0;
    font-size: inherit;
}

.ai-chat-bubble h3 {
    font-size: 15px;
    font-weight: 700;
    margin: 12px 0 6px;
    color: var(--ai-blue);
}

.ai-chat-bubble h4 {
    font-size: 14px;
    font-weight: 700;
    margin: 10px 0 4px;
    color: var(--ai-blue-dark);
}

/* ─── Lists ────────────────────────────────────────── */
.ai-chat-bubble ul,
.ai-chat-bubble ol {
    margin: 8px 0;
    padding-left: 0;
    list-style: none;
}

.ai-chat-bubble ol {
    counter-reset: ai-list;
}

.ai-chat-bubble li {
    margin-bottom: 6px;
    font-size: 13px;
    line-height: 1.55;
    padding: 8px 12px 8px 14px;
    background: linear-gradient(135deg, rgba(4, 91, 160, 0.03), rgba(129, 181, 4, 0.03));
    border-radius: var(--ai-radius-sm);
    border-left: 3px solid var(--ai-blue);
    position: relative;
    transition: all var(--ai-transition);
}

.ai-chat-bubble li:hover {
    background: linear-gradient(135deg, rgba(4, 91, 160, 0.06), rgba(129, 181, 4, 0.06));
    border-left-color: var(--ai-green);
}

.ai-chat-bubble ol>li {
    counter-increment: ai-list;
    padding-left: 32px;
}

.ai-chat-bubble ol>li::before {
    content: counter(ai-list);
    position: absolute;
    left: 8px;
    top: 8px;
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, var(--ai-blue), var(--ai-green));
    color: #fff;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.ai-chat-bubble ul>li {
    padding-left: 10px;
}

.ai-chat-bubble a {
    color: var(--ai-blue);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 1px dashed rgba(4, 91, 160, 0.3);
    transition: all var(--ai-transition);
}

.ai-chat-bubble a:hover {
    color: var(--ai-green);
    border-bottom-color: var(--ai-green);
}

/* ─── Tables — Horizontally Scrollable ──────────────── */
.ai-chat-table-wrap {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    margin: 10px -4px;
    padding: 2px 4px 6px;
    max-width: 100%;
}

.ai-chat-bubble table {
    border-collapse: separate;
    border-spacing: 0;
    margin: 0;
    font-size: 12px;
    min-width: 280px;
    width: max-content;
    max-width: none;
    border-radius: var(--ai-radius-sm);
    overflow: hidden;
    box-shadow: var(--ai-shadow-sm);
}

.ai-chat-bubble th {
    background: linear-gradient(135deg, var(--ai-blue), var(--ai-blue-dark));
    color: #fff;
    padding: 8px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    white-space: nowrap;
    position: sticky;
    top: 0;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.ai-chat-bubble td {
    padding: 7px 12px;
    border-bottom: 1px solid #f1f5f9;
    font-size: 12px;
    white-space: nowrap;
    color: #475569;
}

.ai-chat-bubble tr:nth-child(even) td {
    background: #f8fafc;
}

.ai-chat-bubble tr:hover td {
    background: #eff6ff;
}

.ai-chat-bubble tr:last-child td {
    border-bottom: none;
}

/* ─── Tool Call Badges ──────────────────────────────── */
.ai-chat-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 8px;
}

.ai-chat-tool-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    background: linear-gradient(135deg, rgba(4, 91, 160, 0.08), rgba(129, 181, 4, 0.08));
    border-radius: 8px;
    font-size: 10px;
    color: var(--ai-blue);
    font-weight: 600;
    white-space: nowrap;
    border: 1px solid rgba(4, 91, 160, 0.12);
    text-transform: capitalize;
    letter-spacing: 0.2px;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    animation: aiFadeSlideIn 0.3s ease backwards;
}

.ai-chat-tool-badge i {
    font-size: 9px;
    color: var(--ai-green);
}

/* ─── Loading Skeleton ──────────────────────────────── */
.ai-chat-loading {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 14px;
    animation: aiFadeSlideIn 0.3s ease;
}

.ai-chat-loading-avatar {
    width: 32px;
    height: 32px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--ai-blue), var(--ai-green));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(4, 91, 160, 0.2);
    animation: aiAvatarPulse 2s ease-in-out infinite;
}

.ai-chat-loading-avatar svg {
    width: 16px;
    height: 16px;
}

@keyframes aiAvatarPulse {
    0%, 100% { box-shadow: 0 4px 10px rgba(4, 91, 160, 0.2); }
    50% { box-shadow: 0 4px 20px rgba(129, 181, 4, 0.35); }
}

.ai-chat-loading-bubble {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    max-width: calc(100% - 46px);
}

.ai-chat-loading-content {
    background: rgba(255,255,255,0.9);
    border-radius: var(--ai-radius-lg) var(--ai-radius-lg) var(--ai-radius-lg) 6px;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border: 1px solid rgba(0,0,0,0.04);
    box-shadow: var(--ai-shadow-sm);
}

.ai-chat-shimmer-line {
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
    background-size: 200% 100%;
    animation: aiShimmer 1.5s ease-in-out infinite;
}

@keyframes aiShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.ai-chat-loading-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 4px;
}

.ai-chat-loading-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ai-green);
    animation: aiDotPulse 1.2s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes aiDotPulse {
    0%, 100% { transform: scale(1); opacity: 0.6; }
    50% { transform: scale(1.3); opacity: 1; }
}

.ai-chat-loading-label {
    font-size: 11px;
    color: #94a3b8;
    font-weight: 500;
    transition: opacity 0.3s ease;
}

/* ─── Status Indicator Dots ────────────────────────── */
.ai-status-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 2px;
    vertical-align: middle;
}

.ai-status-ready {
    background: #4caf50;
    box-shadow: 0 0 4px rgba(76, 175, 80, 0.4);
}

.ai-status-thinking {
    background: #fbbf24;
    box-shadow: 0 0 4px rgba(251, 191, 36, 0.4);
    animation: aiDotPulse 1s ease-in-out infinite;
}

/* ─── Input Area ────────────────────────────────────── */
.ai-chat-input-area {
    padding: 16px 20px 14px;
    background: var(--ai-panel-bg);
    flex-shrink: 0;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.03);
    -webkit-backdrop-filter: var(--ai-panel-blur);
    backdrop-filter: var(--ai-panel-blur);
    position: relative;
    z-index: 2;
}

.ai-chat-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 10px 14px 10px 20px;
    background: #ffffff;
    border-radius: 28px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    transition: all var(--ai-transition);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02), var(--ai-shadow-sm);
}

.ai-chat-input-wrap:focus-within {
    border-color: var(--ai-blue-light);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.01), 0 0 0 4px rgba(4, 91, 160, 0.1);
    background: #fff;
}

#aiChatInput {
    flex: 1;
    border: none;
    background: none;
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 120px;
    font-family: inherit;
    color: #1e293b;
    padding: 6px 0;
    min-height: 32px;
}

#aiChatInput::placeholder {
    color: #94a3b8;
}

#aiChatSend {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border: none;
    background: linear-gradient(135deg, var(--ai-blue), var(--ai-green));
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 15px;
    transition: all var(--ai-transition);
    touch-action: manipulation;
    box-shadow: 0 3px 10px rgba(4, 91, 160, 0.25);
}

#aiChatSend:hover,
#aiChatSend:focus {
    transform: scale(1.08);
    box-shadow: 0 4px 16px rgba(4, 91, 160, 0.35);
    outline: none;
}

#aiChatSend:focus-visible {
    outline: 2px solid var(--ai-blue);
    outline-offset: 2px;
}

#aiChatSend:active {
    transform: scale(0.94);
}

#aiChatSend:disabled {
    opacity: 0.25;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.ai-chat-input-hint {
    text-align: center;
    padding-top: 6px;
}

.ai-chat-input-hint span {
    font-size: 10px;
    color: #94a3b8;
}

.ai-chat-input-hint kbd {
    display: inline-block;
    padding: 1px 5px;
    background: #e2e8f0;
    border-radius: 4px;
    font-size: 9px;
    font-family: inherit;
    color: #64748b;
    border: 1px solid #cbd5e1;
    box-shadow: 0 1px 0 #cbd5e1;
}

/* ─── Error ─────────────────────────────────────────── */
.ai-chat-error {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    background: linear-gradient(135deg, #fef2f2, #fff5f5);
    border: 1px solid #fecaca;
    border-radius: var(--ai-radius-sm);
    padding: 14px 16px;
    margin-bottom: 12px;
    animation: aiFadeSlideIn 0.3s ease;
    box-shadow: var(--ai-shadow-sm);
}

.ai-chat-error-icon {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.25);
}

.ai-chat-error-body {
    flex: 1;
    min-width: 0;
}

.ai-chat-error-text {
    color: #991b1b;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
    margin-bottom: 8px;
}

.ai-chat-error-retry {
    border: 1px solid #fca5a5;
    background: #fff;
    color: #dc2626;
    cursor: pointer;
    padding: 5px 14px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 8px;
    transition: all var(--ai-transition);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.ai-chat-error-retry:hover {
    background: #fef2f2;
    border-color: #ef4444;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.15);
}

.ai-chat-error-retry:active {
    transform: translateY(0);
}

/* ═══════════════════════════════════════════════════════
   FULLSCREEN MODE
   ═══════════════════════════════════════════════════════ */
.ai-chat-fullscreen {
    max-width: 100vw !important;
    width: 100vw !important;
    animation: aiExpandFull 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes aiExpandFull {
    from {
        max-width: 660px;
    }

    to {
        max-width: 100vw;
    }
}

.ai-chat-fullscreen .ai-chat-sidebar {
    width: 280px;
    flex: 0 0 280px;
}

.ai-chat-fullscreen .ai-chat-messages {
    padding: 24px;
}

.ai-chat-fullscreen .ai-chat-msg-user .ai-chat-bubble,
.ai-chat-fullscreen .ai-chat-msg-assistant .ai-chat-bubble {
    max-width: 700px;
}

.ai-chat-fullscreen .ai-chat-msg-user {
    padding-right: 10%;
}

.ai-chat-fullscreen .ai-chat-msg-assistant {
    padding-left: 2%;
}

.ai-chat-fullscreen .ai-chat-input-area {
    padding: 14px 20%;
}

.ai-chat-fullscreen .ai-chat-input-hint {
    padding-top: 6px;
}

.ai-chat-fullscreen .ai-chat-welcome {
    padding: 60px 20px 40px;
}

.ai-chat-fullscreen .ai-chat-welcome h4 {
    font-size: 22px;
}

.ai-chat-fullscreen .ai-chat-welcome p {
    font-size: 15px;
    max-width: 450px;
}

.ai-chat-fullscreen .ai-chat-suggestions {
    flex-direction: row;
    flex-wrap: wrap;
    max-width: 560px;
    gap: 10px;
}

.ai-chat-fullscreen .ai-chat-suggestions button {
    flex: 0 0 auto;
    width: auto;
}

.ai-chat-fullscreen .ai-chat-bubble table {
    width: auto;
    min-width: 300px;
}

/* Fullscreen on tablet */
@media (max-width: 768px) {
    .ai-chat-fullscreen .ai-chat-input-area {
        padding: 12px 16px;
    }

    .ai-chat-fullscreen .ai-chat-msg-user {
        padding-right: 5%;
    }

    .ai-chat-fullscreen .ai-chat-suggestions {
        flex-direction: column;
    }
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE — Mobile First
   ═══════════════════════════════════════════════════════ */

/* Touch devices — always show copy button */
@media (hover: none) {
    .ai-chat-copy-btn {
        opacity: 1;
    }
}

/* Large phones */
@media (max-width: 480px) {
    .ai-chat-panel {
        max-width: 100vw;
    }

    .ai-chat-messages {
        padding: 12px 10px;
    }

    .ai-chat-msg-user .ai-chat-bubble {
        max-width: 90%;
        font-size: 15px;
    }

    .ai-chat-msg-assistant .ai-chat-bubble {
        font-size: 15px;
    }

    .ai-chat-bubble table {
        font-size: 11px;
    }

    .ai-chat-bubble th,
    .ai-chat-bubble td {
        padding: 5px 8px;
    }

    .ai-chat-suggestions {
        max-width: 100%;
    }

    .ai-chat-input-area {
        padding: 10px 10px 8px;
    }

    #aiChatInput {
        font-size: 16px;
    }

    /* Prevents iOS zoom */

    .ai-chat-input-hint {
        display: none;
    }

    .ai-chat-welcome {
        padding: 24px 12px 18px;
    }

    .ai-chat-welcome h4 {
        font-size: 17px;
    }

    .ai-chat-welcome p {
        font-size: 14px;
    }
}

/* Very small phones */
@media (max-width: 360px) {
    .ai-chat-header {
        padding: 10px 12px;
        min-height: 56px;
    }

    .ai-chat-avatar {
        width: 34px;
        height: 34px;
        font-size: 11px;
        border-radius: 10px;
    }

    .ai-chat-title {
        font-size: 14px;
    }

    .ai-chat-msg-assistant .ai-chat-msg-avatar {
        width: 26px;
        height: 26px;
        font-size: 8px;
        border-radius: 8px;
    }

    .ai-chat-msg-assistant .ai-chat-content {
        max-width: calc(100% - 38px);
    }
}

/* Desktop — wider panel to fit sidebar + main column */
@media (min-width: 768px) {
    .ai-chat-panel {
        max-width: 720px;
    }
}

@media (min-width: 1200px) {
    .ai-chat-panel {
        max-width: 760px;
    }
}

/* ═══════════════════════════════════════════════════════
   DARK MODE
   ═══════════════════════════════════════════════════════ */
body.dark-mode .ai-chat-panel {
    background: rgba(15, 23, 42, 0.85);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
}

body.dark-mode .ai-chat-header {
    background: linear-gradient(135deg, #0b233f 0%, #061224 100%);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

body.dark-mode .ai-chat-header::before {
    background: radial-gradient(circle, rgba(129, 181, 4, 0.1) 0%, transparent 60%);
}

body.dark-mode .ai-chat-messages {
    background: transparent;
    background-image:
        radial-gradient(ellipse at 15% 30%, rgba(129, 181, 4, 0.03) 0%, transparent 40%),
        radial-gradient(ellipse at 85% 70%, rgba(4, 91, 160, 0.03) 0%, transparent 40%);
}

body.dark-mode .ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(129, 181, 4, 0.15);
}

body.dark-mode .ai-chat-msg-assistant .ai-chat-bubble {
    background: rgba(30, 41, 59, 0.95);
    color: #f1f5f9;
    border-color: #334155;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

body.dark-mode .ai-chat-msg-user .ai-chat-bubble {
    background: linear-gradient(135deg, #2a5a10, #163806);
    box-shadow: 0 4px 16px rgba(129, 181, 4, 0.15);
}

body.dark-mode .ai-chat-input-area {
    background: rgba(15, 23, 42, 0.85);
    border-color: rgba(255, 255, 255, 0.05);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.2);
}

body.dark-mode .ai-chat-input-wrap {
    background: #1e293b;
    border-color: #334155;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.2);
}

body.dark-mode .ai-chat-input-wrap:focus-within {
    border-color: var(--ai-blue-light);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3), 0 0 0 4px rgba(4, 91, 160, 0.15);
    background: #0f172a;
}

body.dark-mode #aiChatInput {
    color: #e2e8f0;
}

body.dark-mode #aiChatInput::placeholder {
    color: #4a5568;
}

body.dark-mode .ai-chat-welcome h4 {
    color: #f8fafc;
}

body.dark-mode .ai-chat-welcome p {
    color: #94a3b8;
}

body.dark-mode .ai-chat-welcome-icon {
    box-shadow: 0 8px 25px rgba(4, 91, 160, 0.25), 0 6px 15px rgba(129, 181, 4, 0.15);
}

body.dark-mode .ai-chat-suggestions button {
    background: rgba(30, 41, 59, 0.8);
    color: #cbd5e1;
    border-color: #334155;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

body.dark-mode .ai-chat-suggestions button:hover {
    background: rgba(12, 45, 77, 0.9);
    border-color: var(--ai-blue-light);
    color: #bae6fd;
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.3);
}

body.dark-mode .ai-chat-bubble strong {
    color: #93c5fd;
}

body.dark-mode .ai-chat-bubble h3,
body.dark-mode .ai-chat-bubble h4 {
    color: #93c5fd;
}

body.dark-mode .ai-chat-bubble code {
    background: rgba(4, 91, 160, 0.15);
    color: var(--ai-green-light);
}

body.dark-mode .ai-chat-bubble pre {
    background: #020617;
    border-color: #1e293b;
}

body.dark-mode .ai-chat-bubble li {
    background: linear-gradient(135deg, rgba(4, 91, 160, 0.06), rgba(129, 181, 4, 0.04));
    border-left-color: var(--ai-blue-light);
}

body.dark-mode .ai-chat-bubble li:hover {
    background: linear-gradient(135deg, rgba(4, 91, 160, 0.1), rgba(129, 181, 4, 0.06));
    border-left-color: var(--ai-green);
}

body.dark-mode .ai-chat-bubble a {
    color: #93c5fd;
    border-bottom-color: rgba(147, 197, 253, 0.3);
}

body.dark-mode .ai-chat-bubble a:hover {
    color: var(--ai-green-light);
}

body.dark-mode .ai-chat-bubble td {
    border-color: #334155;
    color: #cbd5e1;
}

body.dark-mode .ai-chat-bubble tr:nth-child(even) td {
    background: #1e293b;
}

body.dark-mode .ai-chat-bubble tr:hover td {
    background: #0c2d4d;
}

body.dark-mode .ai-chat-bubble th {
    background: linear-gradient(135deg, var(--ai-blue-dark), #032d50);
}

body.dark-mode .ai-chat-bubble table {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

body.dark-mode .ai-chat-tool-badge {
    background: linear-gradient(135deg, rgba(4, 91, 160, 0.12), rgba(129, 181, 4, 0.08));
    color: #93c5fd;
    border-color: rgba(4, 91, 160, 0.2);
}

body.dark-mode .ai-chat-tool-badge i {
    color: var(--ai-green-light);
}

body.dark-mode .ai-chat-error {
    background: linear-gradient(135deg, #1a0a0a, #1c0808);
    border-color: #5c2020;
}

body.dark-mode .ai-chat-error-icon {
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.2);
}

body.dark-mode .ai-chat-error-text {
    color: #fca5a5;
}

body.dark-mode .ai-chat-error-retry {
    background: rgba(30, 41, 59, 0.8);
    border-color: #5c2020;
    color: #fca5a5;
}

body.dark-mode .ai-chat-error-retry:hover {
    background: #2d1010;
    border-color: #ef4444;
}

body.dark-mode .ai-chat-loading-content {
    background: rgba(30, 41, 59, 0.9);
    border-color: #334155;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

body.dark-mode .ai-chat-shimmer-line {
    background: linear-gradient(90deg, #334155 25%, #475569 50%, #334155 75%);
    background-size: 200% 100%;
}

body.dark-mode .ai-chat-loading-label {
    color: #64748b;
}

body.dark-mode .ai-code-block {
    border-color: #334155;
}

body.dark-mode .ai-code-header {
    background: #0f172a;
    border-bottom-color: #1e293b;
}

body.dark-mode .ai-chat-action-btn {
    color: #475569;
}

body.dark-mode .ai-chat-action-btn:hover {
    color: #93c5fd;
    background: rgba(4, 91, 160, 0.12);
}

body.dark-mode .ai-chat-msg-time {
    color: #4a5568;
}

body.dark-mode .ai-chat-copy-btn {
    color: #334155;
}

body.dark-mode .ai-chat-copy-btn:hover {
    color: #93c5fd;
    background: rgba(4, 91, 160, 0.1);
}

body.dark-mode .ai-chat-input-hint span {
    color: #334155;
}

body.dark-mode .ai-chat-input-hint kbd {
    background: #1e293b;
    color: #64748b;
    border-color: #334155;
    box-shadow: 0 1px 0 #334155;
}

body.dark-mode .ai-header-icon {
    box-shadow: 0 2px 10px rgba(129, 181, 4, 0.15), 0 2px 10px rgba(4, 91, 160, 0.1);
}

body.dark-mode .ai-header-icon::after {
    border-color: #0f172a;
}

body.dark-mode .ai-chat-avatar::after {
    border-color: #0c2d4d;
}

/* ═══════════════════════════════════════════════════════
   REDUCED MOTION (Accessibility)
   ═══════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {

    .ai-chat-overlay,
    .ai-chat-panel,
    .ai-chat-msg,
    .ai-chat-fullscreen,
    .ai-chat-loading,
    .ai-chat-welcome-icon,
    .ai-chat-tool-badge,
    .ai-chat-loading-avatar,
    .ai-chat-loading-dot,
    .ai-chat-shimmer-line,
    .ai-status-thinking {
        animation: none !important;
    }

    .ai-chat-suggestions button,
    .ai-chat-btn-icon,
    .ai-chat-action-btn,
    .ai-chat-error-retry,
    .ai-chat-typewriter,
    #aiChatSend {
        transition: none !important;
    }

    .ai-chat-typewriter {
        opacity: 1 !important;
        transform: none !important;
    }

    .ai-header-icon::after,
    .ai-chat-header::before {
        animation: none !important;
    }

    .ai-chat-messages {
        scroll-behavior: auto;
    }
}

/* ═══════════════════════════════════════════════════════
   SESSIONS SIDEBAR
   ═══════════════════════════════════════════════════════ */
.ai-chat-sidebar {
    width: 220px;
    flex: 0 0 220px;
    display: flex;
    flex-direction: column;
    background: rgba(248, 250, 252, 0.7);
    border-right: 1px solid rgba(4, 91, 160, 0.08);
    transition: flex-basis var(--ai-transition), width var(--ai-transition), opacity 0.2s ease, border-right-color 0.2s ease;
    overflow: hidden;
    min-width: 0;
}

.ai-chat-sidebar-collapsed .ai-chat-sidebar {
    flex: 0 0 0;
    width: 0;
    border-right-color: transparent;
    opacity: 0;
}

.ai-chat-sidebar-collapsed .ai-chat-sidebar-show {
    display: inline-flex !important;
}

/* Sidebar header — light, matches the main header height (70px) */
.ai-chat-sidebar-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 12px;
    min-height: 70px;
    background: transparent;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(4, 91, 160, 0.06);
    position: relative;
    z-index: 1;
}

.ai-chat-new-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 12px;
    border: 1px solid rgba(4, 91, 160, 0.12);
    border-radius: 10px;
    background: #fff;
    color: var(--ai-blue-dark);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
    box-shadow: 0 1px 2px rgba(4, 91, 160, 0.04);
}

.ai-chat-new-btn:hover {
    background: linear-gradient(135deg, rgba(129, 181, 4, 0.08), rgba(4, 91, 160, 0.08));
    border-color: rgba(4, 91, 160, 0.2);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(4, 91, 160, 0.1);
}

.ai-chat-new-btn i {
    font-size: 11px;
    color: var(--ai-green-dark);
}

.ai-chat-sidebar-toggle {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(4, 91, 160, 0.06);
    color: var(--ai-blue);
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.18s ease, color 0.18s ease;
}

.ai-chat-sidebar-toggle:hover {
    background: rgba(4, 91, 160, 0.12);
}

/* Show-sidebar button (lives in the main header when collapsed) */
.ai-chat-sidebar-show {
    margin-right: 4px;
}

.ai-chat-sessions {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 8px 12px;
}

.ai-chat-sessions::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-sessions::-webkit-scrollbar-thumb {
    background: rgba(4, 91, 160, 0.18);
    border-radius: 3px;
}

.ai-chat-sessions::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chat-session {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px 9px 12px;
    margin: 2px 0;
    border-radius: 10px;
    cursor: pointer;
    color: #334155;
    transition: background 0.15s ease, color 0.15s ease;
    font-size: 13px;
    line-height: 1.35;
}

.ai-chat-session::before {
    content: '';
    position: absolute;
    left: 4px;
    top: 50%;
    transform: translateY(-50%) scaleY(0);
    width: 3px;
    height: 18px;
    background: var(--ai-green);
    border-radius: 2px;
    transition: transform 0.18s ease;
}

.ai-chat-session:hover {
    background: rgba(4, 91, 160, 0.06);
    color: #1e293b;
}

.ai-chat-session.is-active {
    background: rgba(4, 91, 160, 0.09);
    color: var(--ai-blue-dark);
    font-weight: 600;
}

.ai-chat-session.is-active::before {
    transform: translateY(-50%) scaleY(1);
}

.ai-chat-session-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    font-size: 12px;
    transition: color 0.15s ease;
}

.ai-chat-session:hover .ai-chat-session-icon,
.ai-chat-session.is-active .ai-chat-session-icon {
    color: var(--ai-blue);
}

.ai-chat-session-title {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-chat-session-delete {
    width: 26px;
    height: 26px;
    border: none;
    background: transparent;
    color: #94a3b8;
    border-radius: 6px;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
    font-size: 12px;
}

.ai-chat-session:hover .ai-chat-session-delete,
.ai-chat-session.is-active .ai-chat-session-delete {
    opacity: 1;
    pointer-events: auto;
}

.ai-chat-session-delete:hover {
    background: rgba(239, 68, 68, 0.12);
    color: #dc2626;
}

.ai-chat-sessions-group {
    padding: 14px 12px 6px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: #94a3b8;
    font-weight: 700;
}

.ai-chat-sessions-group:first-child {
    padding-top: 6px;
}

.ai-chat-sessions-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 56px 16px;
    color: #94a3b8;
    font-size: 12.5px;
    text-align: center;
}

.ai-chat-sessions-empty i {
    font-size: 28px;
    opacity: 0.4;
    color: var(--ai-blue);
}

.ai-chat-sidebar-loading {
    padding: 12px 10px;
}

.ai-chat-sidebar-loading-row {
    height: 32px;
    margin: 4px 0;
    border-radius: 8px;
    background: linear-gradient(90deg, rgba(4, 91, 160, 0.05) 0%, rgba(4, 91, 160, 0.12) 50%, rgba(4, 91, 160, 0.05) 100%);
    background-size: 200% 100%;
    animation: aiShimmer 1.4s ease-in-out infinite;
}

/* ═══════════════════════════════════════════════════════
   DELETE CONFIRM MODAL
   ═══════════════════════════════════════════════════════ */
.ai-chat-confirm {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 30;
    padding: 16px;
    animation: aiOverlayIn 0.2s ease-out;
}

.ai-chat-confirm-box {
    background: #fff;
    border-radius: 16px;
    padding: 24px 24px 20px;
    width: min(380px, 100%);
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.6);
    animation: aiFadeSlideIn 0.25s ease-out;
}

.ai-chat-confirm-title {
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-chat-confirm-title i {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(220, 38, 38, 0.1);
    color: #dc2626;
    border-radius: 9px;
    font-size: 14px;
}

.ai-chat-confirm-text {
    font-size: 13px;
    color: #64748b;
    line-height: 1.5;
    margin: 0 0 20px;
    word-break: break-word;
}

.ai-chat-confirm-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.ai-chat-confirm-cancel,
.ai-chat-confirm-delete {
    padding: 9px 18px;
    border: none;
    border-radius: 9px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.ai-chat-confirm-cancel {
    background: #f1f5f9;
    color: #475569;
}

.ai-chat-confirm-cancel:hover {
    background: #e2e8f0;
}

.ai-chat-confirm-delete {
    background: #dc2626;
    color: #fff;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.25);
}

.ai-chat-confirm-delete:hover {
    background: #b91c1c;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(220, 38, 38, 0.35);
}

.ai-chat-confirm-delete:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ─── Dark mode for sidebar ─────────────────────────── */
body.dark-mode .ai-chat-sidebar {
    background: rgba(15, 23, 42, 0.92);
    border-right-color: rgba(255, 255, 255, 0.06);
}

body.dark-mode .ai-chat-sidebar-header {
    background: transparent;
    border-bottom-color: rgba(255, 255, 255, 0.05);
}

body.dark-mode .ai-chat-new-btn {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
}

body.dark-mode .ai-chat-new-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.16);
}

body.dark-mode .ai-chat-sidebar-toggle {
    background: rgba(255, 255, 255, 0.05);
    color: #cbd5e1;
}

body.dark-mode .ai-chat-sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

body.dark-mode .ai-chat-session {
    color: #cbd5e1;
}

body.dark-mode .ai-chat-session:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #f1f5f9;
}

body.dark-mode .ai-chat-session.is-active {
    background: rgba(129, 181, 4, 0.14);
    color: #fff;
}

body.dark-mode .ai-chat-session-icon {
    color: #64748b;
}

body.dark-mode .ai-chat-sessions-group {
    color: #64748b;
}

body.dark-mode .ai-chat-sessions-empty {
    color: #64748b;
}

body.dark-mode .ai-chat-sessions::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
}

body.dark-mode .ai-chat-confirm-box {
    background: #1e293b;
    border-color: rgba(255, 255, 255, 0.08);
}

body.dark-mode .ai-chat-confirm-title {
    color: #f1f5f9;
}

body.dark-mode .ai-chat-confirm-title i {
    background: rgba(220, 38, 38, 0.18);
}

body.dark-mode .ai-chat-confirm-text {
    color: #94a3b8;
}

body.dark-mode .ai-chat-confirm-cancel {
    background: #334155;
    color: #e2e8f0;
}

body.dark-mode .ai-chat-confirm-cancel:hover {
    background: #475569;
}

/* ─── Responsive — sidebar overlays once it would crowd the main column ─── */
@media (max-width: 820px) {
    .ai-chat-panel {
        max-width: 100vw;
    }

    .ai-chat-sidebar {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 20;
        width: 260px;
        flex-basis: 260px;
        box-shadow: 8px 0 24px rgba(4, 30, 55, 0.22);
        background: rgba(248, 250, 252, 0.96);
        -webkit-backdrop-filter: blur(8px);
        backdrop-filter: blur(8px);
        transition: transform var(--ai-transition), opacity 0.2s ease;
    }

    .ai-chat-sidebar-collapsed .ai-chat-sidebar {
        transform: translateX(-100%);
        opacity: 0;
        flex-basis: 260px;
        width: 260px;
        pointer-events: none;
    }

    .ai-chat-sidebar-show {
        display: inline-flex !important;
    }

    body.dark-mode .ai-chat-sidebar {
        background: rgba(15, 23, 42, 0.96);
    }
}

/* ─── Match sidebar header to compact main header on tiny phones ─── */
@media (max-width: 360px) {
    .ai-chat-sidebar-header {
        padding: 10px 10px;
        min-height: 56px;
    }

    .ai-chat-new-btn {
        padding: 7px 10px;
        font-size: 12px;
    }
}
