/* F21: Document Chat Panel */

/* ---- Action grid (6 inline chips) ---- */
.mybutler-action-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 0;
}
.mybutler-action-card {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
    font-size: 13px;
}
.mybutler-action-card:hover:not(.locked):not(.disabled) {
    background: #eff6ff;
    border-color: #3b82f6;
}
.mybutler-action-card:active:not(.locked):not(.disabled) {
    transform: scale(0.97);
}
.mybutler-action-card .action-card-icon {
    font-size: 14px;
    line-height: 1;
}
.mybutler-action-card .action-card-label {
    font-size: 12px;
    font-weight: 500;
    color: #334155;
    white-space: nowrap;
}
.mybutler-action-card .action-card-lock {
    font-size: 9px;
    opacity: 0.5;
    margin-left: -2px;
}
.mybutler-action-card.locked {
    opacity: 0.45;
    cursor: not-allowed;
}
.mybutler-action-card.locked:hover {
    background: #f8fafc;
    border-color: #e2e8f0;
}
.mybutler-action-card.disabled:not(.locked) {
    opacity: 0.35;
    cursor: default;
}

/* ---- Multi-doc selection toolbar ---- */
.mybutler-selection-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 6px;
    margin-bottom: 10px;
    font-size: 13px;
    color: #1e40af;
}
.mybutler-selection-bar .selection-count {
    font-weight: 600;
}
.mybutler-selection-bar .mybutler-btn {
    font-size: 12px;
    padding: 4px 12px;
}
.mybutler-selection-bar .selection-close {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: #64748b;
    padding: 0 4px;
}
.mybutler-selection-bar .selection-close:hover {
    color: #1e293b;
}

/* Checkbox column */
.col-select {
    width: 32px;
    text-align: center;
    padding: 4px 6px !important;
}
.col-select input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
}
.col-select input[type="checkbox"]:disabled {
    cursor: not-allowed;
    opacity: 0.4;
}

/* ---- Chat panel (slide-in) ---- */
.mybutler-chat-panel {
    position: fixed;
    top: 0;
    right: -420px;
    width: 400px;
    max-width: 100vw;
    height: 100vh;
    background: #fff;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    transition: right 0.3s ease;
}
.mybutler-chat-panel.open {
    right: 0;
}

/* Chat header */
.mybutler-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
    flex-shrink: 0;
}
.mybutler-chat-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #1e293b;
}
.mybutler-chat-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #64748b;
    padding: 0 4px;
    line-height: 1;
}
.mybutler-chat-close:hover {
    color: #1e293b;
}

/* Document pills (multi-doc) */
.mybutler-chat-doc-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 16px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
    flex-shrink: 0;
}
.mybutler-chat-doc-pill {
    font-size: 11px;
    background: #e2e8f0;
    color: #475569;
    padding: 3px 8px;
    border-radius: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

/* Suggested prompts */
.mybutler-chat-suggestions {
    padding: 12px 16px;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}
.mybutler-chat-suggestion {
    display: block;
    width: 100%;
    text-align: left;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 6px;
    font-size: 13px;
    color: #334155;
    cursor: pointer;
    transition: background 0.15s;
}
.mybutler-chat-suggestion:last-child {
    margin-bottom: 0;
}
.mybutler-chat-suggestion:hover {
    background: #e2e8f0;
    border-color: #cbd5e1;
}

/* Messages area */
.mybutler-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.mybutler-chat-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #94a3b8;
    font-size: 14px;
    text-align: center;
    padding: 20px;
}

/* Message bubbles */
.mybutler-chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
}
.mybutler-chat-msg.user {
    align-self: flex-end;
    background: #3b82f6;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.mybutler-chat-msg.assistant {
    align-self: flex-start;
    background: #f1f5f9;
    color: #1e293b;
    border-bottom-left-radius: 4px;
}

/* Page reference highlights */
.mybutler-chat-page-ref {
    background: #dbeafe;
    color: #1e40af;
    padding: 1px 4px;
    border-radius: 3px;
    font-weight: 500;
    font-size: 0.95em;
}

/* Copy button on assistant messages */
.mybutler-chat-msg.assistant {
    position: relative;
}
.mybutler-chat-copy {
    position: absolute;
    top: 6px;
    right: 6px;
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #64748b;
    padding: 4px 6px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
    line-height: 1;
}
.mybutler-chat-msg.assistant:hover .mybutler-chat-copy {
    opacity: 1;
}
.mybutler-chat-copy:hover {
    color: #475569;
    background: #e2e8f0;
}
.mybutler-chat-copy.copied {
    opacity: 1;
    color: #16a34a;
}

/* Typing indicator */
.mybutler-chat-typing {
    align-self: flex-start;
    padding: 10px 14px;
    background: #f1f5f9;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    font-size: 13px;
    color: #94a3b8;
    font-style: italic;
}

/* Input bar */
.mybutler-chat-input-bar {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
    flex-shrink: 0;
}
.mybutler-chat-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 14px;
    resize: none;
    min-height: 38px;
    max-height: 100px;
    font-family: inherit;
    outline: none;
}
.mybutler-chat-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}
.mybutler-chat-send {
    background: #3b82f6;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    align-self: flex-end;
}
.mybutler-chat-send:hover {
    background: #2563eb;
}
.mybutler-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Page range bar */
.mybutler-chat-page-range {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
    font-size: 13px;
    flex-shrink: 0;
}
.mybutler-chat-page-range label {
    color: #64748b;
    font-weight: 500;
    white-space: nowrap;
}
.mybutler-chat-page-range input[type="number"] {
    width: 60px;
    padding: 4px 6px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 13px;
    text-align: center;
}
.mybutler-chat-page-range .range-sep {
    color: #94a3b8;
}
.mybutler-chat-page-range .mybutler-chat-page-clear {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
}
.mybutler-chat-page-range .mybutler-chat-page-clear:hover {
    color: #ef4444;
}

/* Footer actions (export + clear) */
.mybutler-chat-footer-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.mybutler-chat-export {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
}
.mybutler-chat-export:hover {
    color: #475569;
}

/* Footer (usage counter + clear) */
.mybutler-chat-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    border-top: 1px solid #e2e8f0;
    font-size: 12px;
    color: #94a3b8;
    flex-shrink: 0;
}
.mybutler-chat-clear {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 12px;
    padding: 0;
}
.mybutler-chat-clear:hover {
    color: #ef4444;
}

/* Overlay */
.mybutler-chat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    z-index: 9999;
    display: none;
}
.mybutler-chat-overlay.visible {
    display: block;
}

/* ---- Responsive ---- */
@media (max-width: 480px) {
    .mybutler-chat-panel {
        width: 100vw;
        right: -100vw;
    }
}
