/* AEEH Doc Assistant v1 */

.aeeh-doc-container {
    --c-accent: #7c3aed;
    --c-accent-h: #6d28d9;
    --c-accent-l: #f3eeff;
    --c-bg: #ffffff;
    --c-bg2: #f5f7f9;
    --c-border: #e2e6ea;
    --c-text: #2d3339;
    --c-muted: #8a929a;
    --c-radius: 10px;
    --c-sidebar: 230px;

    display: flex;
    border: 1px solid var(--c-border);
    border-radius: 12px;
    overflow: hidden;
    background: var(--c-bg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--c-text);
    position: relative;
}

/* ─── Login required ─── */
.aeeh-doc-login-required {
    text-align: center; padding: 48px 24px;
    background: var(--c-bg2); border: 1px solid var(--c-border); border-radius: 12px;
}
.aeeh-doc-login-required a {
    display: inline-block; margin-top: 12px; padding: 10px 24px;
    background: #7c3aed; color: #fff; text-decoration: none;
    border-radius: 8px; font-weight: 500;
}
.aeeh-doc-login-required a:hover { background: #6d28d9; }

/* ─── Sidebar ─── */
.aeeh-doc-sidebar {
    width: var(--c-sidebar); min-width: var(--c-sidebar);
    background: var(--c-bg2); border-right: 1px solid var(--c-border);
    display: flex; flex-direction: column;
    transition: margin-left 0.2s ease;
}
.aeeh-doc-sidebar.aeeh-doc-collapsed { margin-left: calc(-1 * var(--c-sidebar)); }

.aeeh-doc-sidebar-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 12px; border-bottom: 1px solid var(--c-border);
}
.aeeh-doc-sidebar-label {
    font-size: 11px; font-weight: 700; letter-spacing: 0.06em; color: var(--c-muted);
}

.aeeh-doc-conv-list { flex: 1; overflow-y: auto; padding: 6px; }
.aeeh-doc-empty { padding: 20px 10px; color: var(--c-muted); font-size: 13px; text-align: center; }

.aeeh-doc-conv-item {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 10px; margin-bottom: 2px;
    border-radius: 7px; cursor: pointer; transition: background 0.1s;
}
.aeeh-doc-conv-item:hover { background: #e8ecf0; }
.aeeh-doc-conv-item.aeeh-doc-active { background: var(--c-accent-l); }

.aeeh-doc-conv-title {
    flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 13px; color: var(--c-text);
}
.aeeh-doc-conv-del {
    opacity: 0; border: none; background: none; color: var(--c-muted);
    cursor: pointer; padding: 2px; display: flex; transition: opacity 0.1s;
}
.aeeh-doc-conv-item:hover .aeeh-doc-conv-del { opacity: 1; }
.aeeh-doc-conv-del:hover { color: #d04848; }

/* ─── Main panel ─── */
.aeeh-doc-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ─── TOP Toolbar ─── */
.aeeh-doc-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 10px; border-bottom: 1px solid var(--c-border);
    background: var(--c-bg); min-height: 40px; flex-shrink: 0;
}
.aeeh-doc-toolbar-left,
.aeeh-doc-toolbar-right { display: flex; align-items: center; gap: 2px; }
.aeeh-doc-toolbar-sep { width: 1px; height: 18px; background: var(--c-border); margin: 0 5px; }

/* Shared icon button */
.aeeh-doc-icon-btn {
    width: 30px; height: 30px; border: none; background: none;
    border-radius: 6px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--c-muted); transition: all 0.12s; padding: 0;
}
.aeeh-doc-icon-btn:hover { background: var(--c-bg2); color: var(--c-text); }
.aeeh-doc-icon-btn.aeeh-doc-on { color: var(--c-accent); background: var(--c-accent-l); }

/* ─── Messages ─── */
.aeeh-doc-messages {
    flex: 1; overflow-y: auto; padding: 20px 18px;
    display: flex; flex-direction: column; gap: 16px;
}

/* Welcome */
.aeeh-doc-welcome {
    text-align: center; color: var(--c-muted);
    margin: auto 0; padding: 30px 20px;
}
.aeeh-doc-welcome-icon { margin-bottom: 10px; color: var(--c-accent); opacity: 0.5; }
.aeeh-doc-welcome-title { margin: 0; font-size: 16px; color: var(--c-text); }
.aeeh-doc-welcome-sub { margin: 4px 0 0; font-size: 13px; color: var(--c-muted); }

/* Message rows */
.aeeh-doc-msg { display: flex; gap: 10px; max-width: 88%; }
.aeeh-doc-msg-user { align-self: flex-end; flex-direction: row-reverse; }
.aeeh-doc-msg-bot { align-self: flex-start; }

.aeeh-doc-avatar {
    width: 28px; height: 28px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.aeeh-doc-msg-user .aeeh-doc-avatar { background: var(--c-accent); color: #fff; }
.aeeh-doc-msg-bot .aeeh-doc-avatar { background: var(--c-accent-l); color: var(--c-accent); }

.aeeh-doc-msg-body { flex: 1; min-width: 0; }
.aeeh-doc-bubble {
    padding: 10px 14px; border-radius: var(--c-radius);
    word-wrap: break-word; overflow-wrap: break-word;
}
.aeeh-doc-msg-user .aeeh-doc-bubble {
    background: var(--c-accent); color: #fff; border-bottom-right-radius: 3px;
}
.aeeh-doc-msg-bot .aeeh-doc-bubble {
    background: var(--c-bg2); color: var(--c-text);
    border: 1px solid var(--c-border); border-bottom-left-radius: 3px;
}

/* Markdown inside bot bubble - reset Divi overrides */
.aeeh-doc-msg-bot .aeeh-doc-bubble { font-weight: 400 !important; }
.aeeh-doc-msg-bot .aeeh-doc-bubble p,
.aeeh-doc-msg-bot .aeeh-doc-bubble span,
.aeeh-doc-msg-bot .aeeh-doc-bubble li,
.aeeh-doc-msg-bot .aeeh-doc-bubble div { font-weight: 400 !important; }
.aeeh-doc-msg-bot .aeeh-doc-bubble strong,
.aeeh-doc-msg-bot .aeeh-doc-bubble b { font-weight: 700 !important; }
.aeeh-doc-msg-bot .aeeh-doc-bubble p { margin: 0 0 8px; }
.aeeh-doc-msg-bot .aeeh-doc-bubble p:last-child { margin-bottom: 0; }
.aeeh-doc-msg-bot .aeeh-doc-bubble ul,
.aeeh-doc-msg-bot .aeeh-doc-bubble ol { margin: 4px 0; padding-left: 20px; }
.aeeh-doc-msg-bot .aeeh-doc-bubble code {
    background: #e5e8ec; padding: 1px 5px; border-radius: 4px; font-size: 13px;
}
.aeeh-doc-msg-bot .aeeh-doc-bubble pre {
    background: #1e2530; color: #c8d0da; padding: 12px; border-radius: 8px;
    overflow-x: auto; margin: 8px 0;
}
.aeeh-doc-msg-bot .aeeh-doc-bubble pre code { background: none; padding: 0; color: inherit; }
.aeeh-doc-msg-bot .aeeh-doc-bubble a { color: var(--c-accent); }

/* ─── File chips (attached files) ─── */
.aeeh-doc-file-chips {
    display: flex; flex-wrap: wrap; gap: 6px;
    padding: 8px 12px; border-bottom: 1px solid var(--c-border);
    background: var(--c-bg2);
}
.aeeh-doc-file-chip {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 10px; background: var(--c-accent-l); color: var(--c-accent);
    border-radius: 16px; font-size: 12px; font-weight: 500;
    max-width: 200px;
}
.aeeh-doc-file-chip-name {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.aeeh-doc-file-chip-size {
    color: var(--c-muted); font-size: 11px; font-weight: 400;
}
.aeeh-doc-file-chip-remove {
    border: none; background: none; color: var(--c-accent);
    cursor: pointer; padding: 0; display: flex; font-size: 16px; line-height: 1;
    opacity: 0.6; transition: opacity 0.1s;
}
.aeeh-doc-file-chip-remove:hover { opacity: 1; }

/* File chips in user message bubbles */
.aeeh-doc-msg-files {
    display: flex; flex-wrap: wrap; gap: 4px;
    margin-bottom: 6px;
}
.aeeh-doc-msg-file-chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px; background: rgba(255,255,255,0.2); color: #fff;
    border-radius: 12px; font-size: 11px;
}
.aeeh-doc-msg-file-chip svg { opacity: 0.7; }

/* ─── Drop zone ─── */
.aeeh-doc-drop-zone {
    position: absolute; inset: 0; z-index: 20;
    background: rgba(124, 58, 237, 0.08);
    border: 2px dashed var(--c-accent);
    border-radius: 12px;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 8px; color: var(--c-accent); font-size: 14px; font-weight: 500;
}

/* ─── Typing ─── */
.aeeh-doc-typing {
    padding: 4px 20px 6px; display: flex; gap: 6px; align-items: center;
}
.aeeh-doc-dot {
    width: 6px; height: 6px; background: var(--c-accent); border-radius: 50%; opacity: 0.4;
    animation: aeeh-doc-pulse 1.4s infinite ease-in-out both;
}
.aeeh-doc-dot:nth-child(1) { animation-delay: -0.32s; }
.aeeh-doc-dot:nth-child(2) { animation-delay: -0.16s; }
.aeeh-doc-typing-label { font-size: 12px; color: var(--c-muted); }
@keyframes aeeh-doc-pulse {
    0%,80%,100% { transform: scale(0.6); opacity: 0.3; }
    40% { transform: scale(1); opacity: 0.8; }
}

/* ─── Bottom bar ─── */
.aeeh-doc-bottom {
    border-top: 1px solid var(--c-border); background: var(--c-bg); flex-shrink: 0;
}

/* Input row */
.aeeh-doc-input-row {
    display: flex !important; align-items: flex-end; gap: 8px; padding: 10px 12px;
    flex-wrap: nowrap; overflow: visible;
}

/* Attach button */
.aeeh-doc-attach-btn {
    width: 36px !important; min-width: 36px !important; height: 36px !important;
    border: 1px solid var(--c-border) !important; background: var(--c-bg2) !important;
    color: var(--c-muted) !important; border-radius: 10px !important;
    cursor: pointer; display: flex !important; align-items: center; justify-content: center;
    transition: all 0.12s; flex-shrink: 0; padding: 0 !important; margin: 0 !important;
}
.aeeh-doc-attach-btn:hover { color: var(--c-accent) !important; border-color: var(--c-accent) !important; background: var(--c-accent-l) !important; }

.aeeh-doc-input-row textarea {
    flex: 1 1 auto; min-width: 0; border: 1px solid var(--c-border); border-radius: 10px;
    padding: 9px 12px; font-size: 14px; font-family: inherit;
    resize: none; max-height: 140px; line-height: 1.45;
    outline: none; transition: border-color 0.15s; background: var(--c-bg2);
    box-sizing: border-box;
}
.aeeh-doc-input-row textarea:focus { border-color: var(--c-accent); background: var(--c-bg); }

.aeeh-doc-send-btn {
    width: 36px !important; min-width: 36px !important; height: 36px !important; border: none !important;
    background: var(--c-accent) !important; color: #fff !important; border-radius: 10px !important;
    cursor: pointer; display: flex !important; align-items: center; justify-content: center;
    transition: background 0.12s; flex-shrink: 0; flex-grow: 0;
    padding: 0 !important; margin: 0 !important;
    visibility: visible !important; opacity: 1 !important;
}
.aeeh-doc-send-btn:hover { background: var(--c-accent-h) !important; }
.aeeh-doc-send-btn:disabled { background: #c5cdd5 !important; cursor: not-allowed; }

/* ─── Toast ─── */
.aeeh-doc-toast {
    position: absolute; bottom: 80px; left: 50%; transform: translateX(-50%);
    background: var(--c-text); color: #fff; padding: 6px 16px;
    border-radius: 20px; font-size: 12px; font-weight: 500;
    opacity: 0; transition: opacity 0.2s; pointer-events: none; z-index: 10;
}
.aeeh-doc-toast.aeeh-doc-show { opacity: 1; }

/* ─── Help popup ─── */
.aeeh-doc-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.35); z-index: 99999;
}
.aeeh-doc-popup {
    display: none; position: fixed; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: #fff; border-radius: 14px; padding: 26px;
    max-width: 420px; width: 92%; max-height: 80vh; overflow-y: auto;
    z-index: 100000; box-shadow: 0 12px 40px rgba(0,0,0,0.18);
}
.aeeh-doc-popup-close {
    position: absolute; top: 12px; right: 16px;
    border: none; background: none; font-size: 22px; cursor: pointer; color: #999;
}
.aeeh-doc-popup h3 { margin: 0 0 14px; font-size: 17px; font-weight: 700; color: #2d3339; }
.aeeh-doc-help-block { margin-bottom: 16px; }
.aeeh-doc-help-block h4 { margin: 0 0 6px; font-size: 12px; color: #8a929a; text-transform: uppercase; letter-spacing: 0.05em; }
.aeeh-doc-help-block p { margin: 0; font-size: 13px; color: #555; line-height: 1.5; }
.aeeh-doc-help-grid { display: flex; flex-direction: column; gap: 5px; }
.aeeh-doc-help-item { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #2d3339; }
.aeeh-doc-help-item kbd {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 28px; height: 24px; padding: 0 6px;
    background: #f5f7f9; border: 1px solid #e2e6ea;
    border-radius: 5px; font-size: 13px; font-family: inherit; color: #2d3339;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .aeeh-doc-sidebar {
        position: absolute; left: 0; top: 0; bottom: 0;
        z-index: 10; box-shadow: 2px 0 12px rgba(0,0,0,0.1);
    }
    .aeeh-doc-sidebar.aeeh-doc-collapsed { margin-left: calc(-1 * var(--c-sidebar)); box-shadow: none; }
    .aeeh-doc-msg { max-width: 95%; }
    .aeeh-doc-toolbar { padding: 4px 6px; }
    .aeeh-doc-icon-btn { width: 28px; height: 28px; }
}

/* ─── Scrollbar ─── */
.aeeh-doc-messages::-webkit-scrollbar,
.aeeh-doc-conv-list::-webkit-scrollbar { width: 5px; }
.aeeh-doc-messages::-webkit-scrollbar-thumb,
.aeeh-doc-conv-list::-webkit-scrollbar-thumb { background: #d0d4d8; border-radius: 3px; }
.aeeh-doc-messages::-webkit-scrollbar-track,
.aeeh-doc-conv-list::-webkit-scrollbar-track { background: transparent; }
