/* EvidencePulse Modern Styling & Animations */
.ep-layout {
    --accent: #009ca6;
    --user-bubble-bg: #f0fdfa;
    --assistant-bubble-bg: #ffffff;
    --chat-bg: #ffffff;
    --sidebar-bg: #f8fafc;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --input-bg: #f8fafc;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    
    display: flex; height: 85vh; min-height: 620px; max-height: 920px;
    background: var(--chat-bg); color: var(--text-primary);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    border: 1px solid var(--border-color); border-radius: 16px;
    overflow: hidden; position: relative; box-shadow: 0 10px 25px -5px rgba(0,0,0,0.05);
    transition: background 0.3s ease, color 0.3s ease;
}

/* Dark Mode Theme Overrides */
.ep-layout[data-theme="dark"] {
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --input-bg: #1e293b;
    --chat-bg: #0f172a;
    --sidebar-bg: #1e293b;
    --user-bubble-bg: #134e4a;
    --assistant-bubble-bg: #1e293b;
}

/* No Sidebar Setting */
.ep-layout.no-sidebar .ep-sidebar { display: none !important; }
.ep-layout.no-sidebar .ep-menu-btn { display: none !important; }

/* Sidebar */
.ep-sidebar {
    width: 280px; background: var(--sidebar-bg); border-right: 1px solid var(--border-color);
    display: flex; flex-direction: column; transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), width 0.3s ease;
    z-index: 20; flex-shrink: 0;
}
.ep-sidebar.collapsed { width: 0; overflow: hidden; transform: translateX(-100%); border-right: none; }
.ep-sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border-color); }
.ep-projects-label { color: var(--text-primary); font-size: 14px; font-weight: 700; letter-spacing: 0.01em; }
.ep-sidebar-header-controls { display: flex; align-items: center; gap: 6px; }
.ep-project-create-btn, .ep-sidebar-close,
.ep-project-rename, .ep-project-delete {
    width: 30px; height: 30px; padding: 0; border: 1px solid var(--border-color); border-radius: 8px;
    background: var(--input-bg); color: var(--text-secondary); cursor: pointer; display: inline-flex;
    align-items: center; justify-content: center; transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.ep-project-create-btn:hover, .ep-sidebar-close:hover,
.ep-project-rename:hover { color: var(--accent); border-color: var(--accent); }
.ep-project-delete:hover { color: #ef4444; border-color: #ef4444; }
.ep-project-create-btn:focus-visible, .ep-sidebar-close:focus-visible,
.ep-project-rename:focus-visible, .ep-project-delete:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ep-project-create-btn:disabled { opacity: 0.5; cursor: wait; }
.ep-project-create-btn svg, .ep-sidebar-close svg { width: 17px; height: 17px; }
.ep-sidebar-close { display: none; }
.ep-sidebar-overlay { display: none; }
.ep-new-btn {
    flex: 1; padding: 10px 14px; background: var(--accent); color: #ffffff;
    border: none; border-radius: 10px; cursor: pointer; display: flex; align-items: center;
    gap: 8px; font-weight: 600; font-size: 14px; transition: transform 0.15s ease, opacity 0.15s ease;
    box-shadow: 0 2px 5px rgba(0,0,0,0.08);
}
.ep-new-btn:hover { opacity: 0.92; transform: translateY(-1px); }

.ep-search-wrap { padding: 12px 16px 8px; }
.ep-search-wrap input {
    width: 100%; padding: 8px 12px; border: 1px solid var(--border-color);
    border-radius: 8px; font-size: 13px; background: var(--input-bg); color: var(--text-primary);
    outline: none; transition: border-color 0.2s;
}
.ep-search-wrap input:focus { border-color: var(--accent); }

.ep-history-list { flex: 1; overflow-y: auto; padding: 8px 12px; }
.ep-project-group { margin: 4px 0 12px; }
.ep-project-heading {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 6px 8px; color: var(--text-secondary); font-size: 11.5px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.045em;
}
.ep-project-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ep-project-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.ep-project-rename, .ep-project-delete { width: 24px; height: 24px; border-radius: 6px; font-size: 13px; }
.ep-project-empty { padding: 8px 12px 10px; color: var(--text-secondary); font-size: 12px; font-style: italic; }
.ep-hist-item {
    display: flex; justify-content: space-between; align-items: center; padding: 10px 12px;
    cursor: pointer; border-radius: 8px; font-size: 13.5px; color: var(--text-primary); gap: 8px;
    margin-bottom: 4px; transition: background 0.15s ease;
}
.ep-hist-item:hover, .ep-hist-item.active { background: rgba(0,156,166,0.12); color: var(--accent); }
.ep-hist-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.ep-hist-actions { display: flex; align-items: center; gap: 3px; flex-shrink: 0; }
.ep-hist-project-control {
    position: relative; width: 28px; height: 26px; flex: 0 0 28px; display: inline-flex;
    align-items: center; justify-content: center; border: 1px solid var(--border-color); border-radius: 6px;
    background: var(--input-bg); color: var(--text-secondary); transition: color 0.15s ease, border-color 0.15s ease;
}
.ep-hist-project-control > svg { width: 15px; height: 15px; pointer-events: none; }
.ep-hist-project-control:hover { color: var(--accent); border-color: var(--accent); }
.ep-hist-project-control:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.ep-hist-project-select {
    position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; border-radius: inherit;
    appearance: none; -webkit-appearance: none; background: transparent; color: transparent; font: inherit; cursor: pointer;
}
.ep-hist-project-select option { background: var(--input-bg); color: var(--text-primary); }
.ep-hist-project-select:focus-visible { outline: none; }
.ep-hist-project-select:disabled { cursor: wait; }
.ep-hist-del { color: var(--text-secondary); background: none; border: none; cursor: pointer; opacity: 0; transition: opacity 0.15s; padding: 4px; }
.ep-hist-item:hover .ep-hist-del { opacity: 1; }
.ep-hist-del:focus-visible { opacity: 1; }
.ep-hist-del:hover { color: #ef4444; }
.ep-hist-item:focus-visible, .ep-menu-btn:focus-visible, .ep-header-new-chat-btn:focus-visible,
.ep-hist-del:focus-visible, .ep-att-remove:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 2px;
}

/* Main Chat Container - Responsive Full Real Estate */
.ep-main { flex: 1; display: flex; flex-direction: column; background: var(--chat-bg); min-width: 0; width: 100%; }
.ep-header { padding: 14px 20px; border-bottom: 1px solid var(--border-color); display: flex; align-items: center; justify-content: space-between; }
.ep-menu-btn { background: none; border: none; cursor: pointer; padding: 6px; color: var(--text-secondary); border-radius: 8px; display: flex; align-items: center; }
.ep-menu-btn:hover { background: rgba(0,0,0,0.05); color: var(--text-primary); }
.ep-title { margin: 0; font-size: 17px; font-weight: 600; color: var(--text-primary); flex: 1; margin-left: 10px; }

.ep-header-actions { display: flex; align-items: center; gap: 10px; }
.ep-header-new-chat-btn {
    padding: 8px 14px; background: var(--accent); color: #ffffff;
    border: none; border-radius: 10px; cursor: pointer; display: flex; align-items: center;
    gap: 6px; font-weight: 600; font-size: 13.5px; transition: transform 0.15s ease, opacity 0.15s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}
.ep-header-new-chat-btn:hover { opacity: 0.92; transform: translateY(-1px); }
.ep-header-new-chat-btn svg { width: 15px; height: 15px; }

.ep-theme-btn { background: none; border: 1px solid var(--border-color); padding: 6px 10px; border-radius: 8px; cursor: pointer; color: var(--text-secondary); display: flex; align-items: center; gap: 4px; }
.ep-theme-btn:hover { color: var(--text-primary); border-color: var(--accent); }
.ep-layout[data-theme="dark"] .ep-icon-sun { display: block; }
.ep-layout[data-theme="dark"] .ep-icon-moon { display: none; }
.ep-layout[data-theme="light"] .ep-icon-sun { display: none; }
.ep-layout[data-theme="light"] .ep-icon-moon { display: block; }

/* Evidence Rating Meter Top Bar */
.ep-meter-container {
    padding: 10px 20px; background: var(--input-bg); border-bottom: 1px solid var(--border-color);
    display: flex; flex-direction: column; gap: 6px; transition: background 0.3s;
}
.ep-meter-header { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; font-weight: 600; color: var(--text-primary); }
.ep-meter-val { font-family: monospace; font-size: 13px; color: var(--accent); }
.ep-meter-track { height: 7px; background: var(--border-color); border-radius: 999px; overflow: hidden; position: relative; }
.ep-meter-fill {
    height: 100%; background: linear-gradient(90deg, #38bdf8 0%, var(--accent) 50%, #10b981 100%);
    border-radius: 999px; transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Chat Area & Messages - Uses FULL Width Real Estate */
.ep-chat-area { flex: 1; overflow-y: auto; padding: 24px 20px; display: flex; flex-direction: column; gap: 20px; scroll-behavior: smooth; position: relative; }
.ep-welcome-screen { margin: auto; text-align: center; color: var(--text-secondary); max-width: 600px; animation: fadeIn 0.4s ease; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; }
.ep-welcome-icon { width: 64px; height: 64px; margin: 0 auto 16px; background: rgba(0,156,166,0.1); border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.ep-prompt-chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 24px; }
.ep-chip { background: var(--input-bg); border: 1px solid var(--border-color); color: var(--text-primary); padding: 10px 16px; border-radius: 20px; font-size: 13.5px; cursor: pointer; transition: background 0.2s, border-color 0.2s; }
.ep-chip:hover { background: rgba(0,156,166,0.08); border-color: var(--accent); }

.ep-row { display: flex; flex-direction: column; max-width: 100%; margin: 0; width: 100%; animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1); }
.ep-row.user { align-items: flex-end; }
.ep-row.assistant { align-items: flex-start; }

.ep-bubble-wrap { position: relative; max-width: 100%; width: 100%; }
.ep-row.user .ep-bubble-wrap { max-width: 90%; width: auto; }
.ep-bubble {
    padding: 16px 22px; border-radius: 18px; font-size: 15px; line-height: 1.7;
    position: relative; box-shadow: var(--shadow-sm); word-break: break-word; width: 100%; box-sizing: border-box;
}
.ep-bubble p { margin: 0 0 12px 0; }
.ep-bubble p:last-child { margin-bottom: 0; }
.ep-bubble ul, .ep-bubble ol { margin: 8px 0 12px 20px; padding: 0; }
.ep-bubble li { margin-bottom: 4px; }

/* Markdown Table & Chart Styling (Full Width & No Header Wrap) */
.ep-table-wrap {
    position: relative; margin: 16px 0; overflow-x: auto; border: 1px solid var(--border-color);
    border-radius: 10px; box-shadow: var(--shadow-sm); background: var(--assistant-bubble-bg); width: 100%;
}
.ep-bubble table {
    width: 100%; border-collapse: collapse; font-size: 13.5px; table-layout: auto; margin: 0;
}
.ep-bubble th, .ep-bubble td {
    padding: 10px 16px; border: 1px solid var(--border-color); text-align: left;
    word-break: normal; hyphens: none; -webkit-hyphens: none;
}
.ep-bubble th {
    background: rgba(0,156,166,0.08); font-weight: 600; color: var(--text-primary);
    white-space: nowrap; word-break: keep-all;
}

/* Hover Copy Button on Tables */
.ep-table-copy-btn {
    position: absolute; top: 8px; right: 8px; background: var(--chat-bg);
    border: 1px solid var(--border-color); border-radius: 6px; padding: 4px 10px;
    font-size: 11px; cursor: pointer; color: var(--text-secondary); opacity: 0;
    transition: opacity 0.2s ease, transform 0.15s ease; box-shadow: 0 2px 5px rgba(0,0,0,0.1); z-index: 10;
}
.ep-table-wrap:hover .ep-table-copy-btn { opacity: 1; }
.ep-table-copy-btn:hover { color: var(--accent); border-color: var(--accent); transform: scale(1.05); }

.ep-row.user .ep-bubble { background: var(--user-bubble-bg); color: var(--text-primary); border-bottom-right-radius: 4px; border: 1px solid rgba(0,156,166,0.2); }
.ep-row.assistant .ep-bubble { background: var(--assistant-bubble-bg); color: var(--text-primary); border: 1px solid var(--border-color); border-bottom-left-radius: 4px; }

/* Inline Citations & Highlight */
.ep-inline-ref { color: var(--accent); text-decoration: none; font-weight: 600; cursor: pointer; padding: 0 2px; }
.ep-inline-ref:hover { text-decoration: underline; }
.ep-ref-highlight { background: rgba(0, 156, 166, 0.15); border-radius: 4px; transition: background 0.3s ease; }

/* Hover Copy Button */
.ep-copy-btn {
    position: absolute; top: -14px; right: 12px; background: var(--chat-bg); border: 1px solid var(--border-color);
    border-radius: 6px; padding: 4px 8px; font-size: 11px; cursor: pointer; color: var(--text-secondary);
    opacity: 0; transition: opacity 0.2s ease, transform 0.15s ease; display: flex; align-items: center; gap: 4px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.08); z-index: 5;
}
.ep-bubble-wrap:hover .ep-copy-btn { opacity: 1; }
.ep-copy-btn:hover { color: var(--accent); border-color: var(--accent); transform: scale(1.05); }

/* User Feedback Actions (Thumbs Up/Down) */
.ep-feedback-wrapper { margin-top: 10px; border-top: 1px solid var(--border-color); padding-top: 8px; }
.ep-feedback-actions { display: flex; gap: 8px; justify-content: flex-start; }
.ep-feedback-btn {
    background: transparent; border: 1px solid var(--border-color); border-radius: 4px; 
    padding: 6px 10px; cursor: pointer; color: var(--text-secondary); 
    display: flex; align-items: center; gap: 4px; transition: all 0.2s ease;
}
.ep-feedback-btn:hover { background: rgba(0,0,0,0.05); color: var(--text-primary); }
.ep-feedback-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.ep-feedback-form { margin-top: 8px; display: none; flex-direction: column; gap: 8px; max-width: 400px; }
.ep-feedback-form.show { display: flex; }
.ep-feedback-textarea {
    width: 100%; border: 1px solid var(--border-color); border-radius: 6px; padding: 8px; 
    font-size: 13px; resize: vertical; min-height: 50px; background: var(--input-bg); 
    color: var(--text-primary); font-family: inherit;
}
.ep-feedback-submit {
    align-self: flex-start; background: var(--accent); color: #fff; border: none; 
    border-radius: 6px; padding: 6px 12px; font-size: 12px; cursor: pointer; font-weight: 600;
}
.ep-feedback-submit:hover { opacity: 0.9; }

/* Gemini Thinking Wave Shimmer Animation */
.ep-thinking-card { display: flex; align-items: center; gap: 12px; padding: 12px 18px; }
.ep-gemini-wave { display: flex; align-items: center; gap: 6px; }
.ep-wave-bar {
    width: 6px; height: 22px; border-radius: 3px; background: linear-gradient(180deg, var(--accent) 0%, #38bdf8 100%);
    animation: wavePulse 1.2s infinite ease-in-out;
}
.ep-wave-bar:nth-child(2) { animation-delay: 0.15s; }
.ep-wave-bar:nth-child(3) { animation-delay: 0.30s; }
.ep-wave-bar:nth-child(4) { animation-delay: 0.45s; }

@keyframes wavePulse {
    0%, 100% { transform: scaleY(0.4); opacity: 0.5; }
    50% { transform: scaleY(1.1); opacity: 1; }
}

/* Input Area */
.ep-input-container { padding: 16px 20px; background: var(--chat-bg); border-top: 1px solid var(--border-color); }
.ep-attachments { display: flex; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.ep-att-badge { background: var(--input-bg); padding: 5px 12px; border-radius: 12px; font-size: 12px; display: flex; align-items: center; gap: 6px; border: 1px solid var(--border-color); color: var(--text-primary); }
.ep-att-remove { cursor: pointer; color: #ef4444; font-weight: bold; background: none; border: 0; padding: 2px; line-height: 1; }

.ep-input-box {
    display: flex; align-items: flex-end; gap: 10px; background: var(--input-bg);
    border: 1px solid var(--border-color); border-radius: 22px; padding: 8px 14px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.ep-input-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,156,166,0.15); }
.ep-upload-btn { cursor: pointer; padding: 8px; color: var(--text-secondary); border-radius: 50%; display: flex; align-items: center; justify-content: center; margin-bottom: 2px; }
.ep-upload-btn:hover { background: rgba(0,0,0,0.05); color: var(--text-primary); }

.ep-input {
    flex: 1; border: none; background: transparent; outline: none; resize: none;
    font-size: 15px; max-height: 180px; padding: 8px 0; font-family: inherit; color: var(--text-primary);
    overflow-y: auto; line-height: 1.5;
}

.ep-send-btn {
    background: var(--accent); border: none; border-radius: 50%; width: 38px; height: 38px; margin-bottom: 2px;
    display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0;
    transition: transform 0.15s ease, opacity 0.2s ease, background 0.2s; color: #ffffff;
}
.ep-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ep-send-btn.generating { background: #ef4444; }
.ep-send-btn.generating .ep-send-icon { display: none; }
.ep-send-btn.generating .ep-stop-icon { display: block; }
.ep-stop-icon { display: none; }

.ep-disclaimer { text-align: center; font-size: 11.5px; color: var(--text-secondary); margin-top: 10px; line-height: 1.4; }
.ep-refs-list { margin-top: 14px; border-top: 1px solid var(--border-color); padding-top: 10px; font-size: 13px; color: var(--text-secondary); }
.ep-refs-list a { color: var(--accent); text-decoration: none; font-weight: 500; }
.ep-refs-list a:hover { text-decoration: underline; }
.ep-ref-item { padding: 4px; margin-bottom: 2px; border-radius: 4px; }

/* Paywall */
.ep-paywall-card { background: #fff8f6; border: 1px solid #fed7aa; border-radius: 12px; padding: 24px; text-align: center; margin: 20px auto; max-width: 500px; }
.ep-paywall-card h4 { margin: 0 0 10px; font-size: 18px; color: #9a3412; }
.ep-paywall-card p { margin: 0 0 16px; font-size: 14px; color: #431407; }
.ep-paywall-btn { display: inline-block; padding: 10px 20px; background: var(--accent); color: #fff; text-decoration: none; border-radius: 8px; font-weight: 600; font-size: 14px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* Mobile Optimizations */
@media (max-width: 768px) {
    body.ep-sidebar-modal-open { overflow: hidden; touch-action: none; }
    .ep-layout {
        height: auto !important;
        min-height: var(--mobile-min-height, 450px) !important;
        max-height: none !important;
        border-radius: 12px;
        overflow: visible;
    }
    .ep-main { flex: 1 1 auto; min-height: var(--mobile-min-height, 450px); }
    .ep-sidebar {
        position: fixed; left: 0; top: 0; bottom: 0; height: 100dvh; transform: translateX(-100%);
        width: 290px; max-width: 86vw; box-shadow: 4px 0 20px rgba(0,0,0,0.15); border-right: none;
        z-index: 1001; overflow: hidden;
    }
    .ep-sidebar.open { transform: translateX(0); }
    .ep-sidebar-close { display: inline-flex; width: 44px; height: 44px; }
    .ep-sidebar-overlay {
        position: fixed; inset: 0; width: 100%; height: 100%; padding: 0; border: 0;
        background: rgba(15, 23, 42, 0.42); cursor: pointer; z-index: 1000;
    }
    .ep-layout.sidebar-open .ep-sidebar-overlay { display: block; }
    .ep-sidebar-overlay:focus-visible { outline: 3px solid var(--accent); outline-offset: -4px; }
    .ep-history-list { overflow-y: auto; }
    .ep-hist-del { opacity: 1; }
    .ep-project-create-btn { width: 44px; height: 44px; }
    .ep-project-rename, .ep-project-delete { width: 36px; height: 36px; }
    .ep-hist-project-control { width: 36px; height: 36px; flex-basis: 36px; }
    .ep-hist-del { min-width: 36px; min-height: 36px; }
    .ep-bubble-wrap { max-width: 100%; width: 100%; }
    .ep-row.user .ep-bubble-wrap { max-width: 95%; }
    
    .ep-welcome-screen { padding: 24px 10px; justify-content: center; height: auto; min-height: 260px; margin: 0 auto; }
    .ep-welcome-screen.hide-icon-mobile .ep-welcome-icon { display: none !important; }
    .ep-welcome-screen h3 { font-size: 18px; margin: 0 0 6px 0; }
    .ep-welcome-screen p { font-size: 13px; margin: 0 0 10px 0; }
    
    .ep-prompt-chips { gap: 6px; margin-top: 12px; }
    .ep-chip { font-size: 12px; padding: 6px 12px; border-radius: 16px; }
    .ep-chat-area { flex: 0 0 auto; min-height: 280px; overflow-y: visible; padding: 14px 12px; gap: 14px; }
    .ep-input-container { padding: 10px 12px; }
    .ep-input-box { padding: 6px 10px; border-radius: 18px; }
    .ep-input { font-size: 14px; }
    .ep-send-btn { width: 34px; height: 34px; }
    .ep-meter-container { padding: 8px 12px; }
    .ep-header { padding: 10px 14px; }
    .ep-title { font-size: 15px; }
    .ep-menu-btn { width: 44px; height: 44px; padding: 10px; justify-content: center; }
    
    .ep-header-new-chat-btn span { display: none; }
    .ep-header-new-chat-btn { width: 44px; height: 44px; padding: 10px; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
    .ep-layout, .ep-layout *, .ep-layout *::before, .ep-layout *::after {
        animation: none !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
