/* RiQ Analysis Modal Styles */

.riq-analysis-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.riq-analysis-modal {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 900px;
    max-height: 85vh;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease-out;
    transition: width 0.3s ease, max-width 0.3s ease, max-height 0.3s ease;
}

.riq-analysis-modal.expanded {
    width: 95%;
    max-width: 1800px;
    max-height: 95vh;
}

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

.riq-modal-header {
    background: linear-gradient(135deg, #9a4054 0%, #c4576a 100%);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.riq-modal-branding {
    display: flex;
    align-items: center;
    gap: 12px;
}

.riq-modal-branding .codeiq-logo {
    height: 32px;
    filter: brightness(0) invert(1);
    opacity: 0.95;
}

.modal-title {
    font-size: 20px;
    font-weight: 600;
}

.riq-modal-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
}

.riq-modal-expand,
.riq-modal-close {
    background: none;
    border: none;
    color: white;
    font-size: 32px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
    transition: transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.riq-modal-expand svg {
    width: 20px;
    height: 20px;
    fill: white;
    transition: transform 0.3s ease;
}

.riq-analysis-modal.expanded .riq-modal-expand svg {
    transform: rotate(180deg);
}

.riq-modal-expand:hover,
.riq-modal-close:hover {
    transform: scale(1.1);
}

.riq-modal-avatar {
    display: flex;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(180deg, #c4576a 0%, white 100%);
}

.riq-modal-avatar img {
    width: 80px;
    height: 80px;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.2));
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.riq-modal-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* Menu */
.riq-menu {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.riq-menu h3 {
    text-align: center;
    color: #1a1a1a;
    margin-bottom: 8px;
}

.riq-action-button {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    border: 2px solid #d4d0c8;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.riq-action-button:hover {
    border-color: #c4576a;
    background: #fef5fb;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(196, 87, 106, 0.2);
}

.button-icon {
    font-size: 32px;
    flex-shrink: 0;
}

.button-text {
    flex: 1;
}

.button-text strong {
    display: block;
    font-size: 16px;
    color: #1a1a1a;
    margin-bottom: 4px;
}

.button-text span {
    display: block;
    font-size: 14px;
    color: #6b6b6b;
}

/* Analyzing state */
.riq-analyzing {
    text-align: center;
    padding: 40px 20px;
}

/* Scoped to RiQ analyzing state to avoid affecting other spinners */
.riq-analyzing .spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f5f2ed;
    border-top: 4px solid #c4576a;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.riq-analyzing h3 {
    color: #1a1a1a;
    margin-bottom: 8px;
}

.riq-analyzing p {
    color: #6b6b6b;
}

/* Results */
.riq-results {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.riq-summary {
    background: #f8f9ff;
    padding: 20px;
    border-radius: 8px;
}

.riq-summary h3 {
    margin: 0 0 16px 0;
    color: #1a1a1a;
    text-align: center;
}

.summary-stats {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-bottom: 20px;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px;
    background: white;
    border-radius: 8px;
    min-width: 100px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.stat-number {
    font-size: 32px;
    font-weight: 700;
    line-height: 1;
}

.stat.correct .stat-number { color: #10b981; }
.stat.questionable .stat-number { color: #f59e0b; }
.stat.incorrect .stat-number { color: #ef4444; }

.stat-label {
    font-size: 14px;
    color: #6b6b6b;
    margin-top: 4px;
}

.key-issues {
    background: white;
    padding: 16px;
    border-radius: 6px;
    border-left: 4px solid #f59e0b;
}

.key-issues strong {
    display: block;
    margin-bottom: 8px;
    color: #1a1a1a;
}

.key-issues ul {
    margin: 0;
    padding-left: 20px;
}

.key-issues li {
    color: #3d3d3d;
    margin: 4px 0;
}

/* Transaction cards */
.riq-transaction-reviews {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.assessment-group h4 {
    margin: 0 0 12px 0;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 16px;
}

.incorrect-group h4 {
    background: #fee2e2;
    color: #991b1b;
}

.questionable-group h4 {
    background: #fef3c7;
    color: #92400e;
}

.riq-transaction-card {
    background: white;
    border: 1px solid #d4d0c8;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    transition: all 0.2s;
}

.riq-transaction-card:hover {
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.riq-transaction-card.applied {
    border-color: #10b981;
    background: #f0fdf4;
}

.riq-transaction-card.kept {
    opacity: 0.6;
}

.txn-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    gap: 12px;
}

.txn-description {
    font-weight: 600;
    color: #1a1a1a;
    flex: 1;
}

.txn-amount {
    font-weight: 700;
    color: #667eea;
    white-space: nowrap;
}

.current-coding {
    margin-bottom: 12px;
    padding: 12px;
    background: #faf8f5;
    border-radius: 6px;
}

.current-coding strong {
    display: block;
    margin-bottom: 8px;
    color: #3d3d3d;
    font-size: 14px;
}

.account-badge, .vat-badge, .confidence-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    margin-right: 8px;
    font-weight: 500;
}

.account-badge {
    background: #d4d0c8;
    color: #1a1a1a;
}

.account-badge.suggested {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #10b981;
}

.vat-badge {
    background: #dbeafe;
    color: #1e40af;
}

.vat-badge.suggested {
    background: #bfdbfe;
    color: #1e3a8a;
    border: 1px solid #3b82f6;
}

.confidence-badge {
    background: #fef3c7;
    color: #92400e;
}

.riq-reasoning {
    background: #fef5fb;
    padding: 12px;
    border-radius: 6px;
    margin: 12px 0;
    border-left: 3px solid #c4576a;
}

.riq-reasoning strong {
    display: block;
    margin-bottom: 8px;
    color: #3d3d3d;
}

.riq-reasoning p {
    margin: 8px 0;
    color: #6b6b6b;
    line-height: 1.6;
}

.riq-reasoning ul {
    margin: 8px 0;
    padding-left: 24px;
    color: #6b6b6b;
}

.riq-reasoning li {
    margin: 4px 0;
    line-height: 1.6;
}

.riq-reasoning strong {
    color: #1a1a1a;
    font-weight: 600;
}

.riq-suggestion {
    padding: 12px;
    background: #f0fdf4;
    border-radius: 6px;
    border-left: 3px solid #10b981;
    margin: 12px 0;
}

.riq-suggestion strong {
    display: block;
    margin-bottom: 8px;
    color: #065f46;
}

.txn-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 12px;
}

.codeiq-button-sm {
    padding: 8px 16px;
    font-size: 14px;
    border-radius: 6px;
    cursor: pointer;
    border: none;
    font-weight: 500;
    transition: all 0.2s;
}

.codeiq-button-primary {
    background: linear-gradient(135deg, #9a4054 0%, #c4576a 100%);
    color: white;
}

.codeiq-button-primary:hover {
    background: linear-gradient(135deg, #5a4570 0%, #ff3aa0 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(196, 87, 106, 0.3);
}

.codeiq-button-secondary {
    background: white;
    color: #9a4054;
    border: 1px solid #9a4054;
}

.codeiq-button-secondary:hover {
    background: #fef5fb;
    border-color: #c4576a;
    color: #c4576a;
}

.applied-badge, .kept-badge {
    color: #10b981;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
}

.kept-badge {
    color: #6b6b6b;
}

/* Results actions */
.riq-results-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding-top: 20px;
    border-top: 1px solid #d4d0c8;
}

.codeiq-button {
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

/* No results / Error */
.riq-no-results, .riq-error {
    text-align: center;
    padding: 40px 20px;
}

.riq-no-results h3, .riq-error h3 {
    color: #1a1a1a;
    margin-bottom: 16px;
}

.riq-error p {
    color: #ef4444;
    margin-bottom: 16px;
}

/* Transaction Chat */
.riq-transaction-chat {
    display: flex;
    flex-direction: column;
    gap: 16px;
    height: 100%;
}

.chat-transaction-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: #f8f9ff;
    border-radius: 8px;
}

.chat-transaction-header h4 {
    margin: 0;
    font-size: 16px;
    color: #1a1a1a;
}

.chat-current-coding {
    padding: 12px;
    background: #faf8f5;
    border-radius: 6px;
}

.chat-current-coding strong {
    display: block;
    margin-bottom: 8px;
    color: #3d3d3d;
    font-size: 14px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: white;
    border: 1px solid #d4d0c8;
    border-radius: 8px;
    min-height: 200px;
}

.chat-message {
    margin-bottom: 16px;
    padding: 12px;
    border-radius: 8px;
}

.chat-message.riq-message {
    background: #fef5fb;
    border-left: 3px solid #c4576a;
}

.chat-message.user-message {
    background: #f0fdf4;
    border-left: 3px solid #10b981;
}

.chat-message.error-message {
    background: #fee2e2;
    border-left: 3px solid #ef4444;
}

.message-content {
    color: #3d3d3d;
    line-height: 1.6;
}

.message-content p {
    margin: 8px 0;
}

.message-content ul {
    margin: 8px 0;
    padding-left: 24px;
}

.message-content li {
    margin: 4px 0;
}

.message-content strong {
    font-weight: 600;
    color: #1a1a1a;
}

.chat-input-area {
    display: flex;
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid #d4d0c8;
}

.chat-input-area input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #c4c0b8;
    border-radius: 6px;
    font-size: 14px;
}

.chat-input-area input:focus {
    outline: none;
    border-color: #c4576a;
}

.chat-input-area button {
    padding: 10px 20px;
    background: linear-gradient(135deg, #9a4054 0%, #c4576a 100%);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
}

.chat-input-area button:hover {
    background: linear-gradient(135deg, #5a4570 0%, #ff3aa0 100%);
}

/* RiQ Action Buttons in Transaction Table */

/* Per-transaction RiQ image button - just the image, no box */
.btn-riq-img {
    width: 24px;
    height: 24px;
    cursor: pointer;
    transition: all 0.2s;
    opacity: 0.8;
}

.btn-riq-img:hover {
    opacity: 1;
    transform: scale(1.15);
}

.btn-riq-img:active {
    transform: scale(1.05);
}

/* Action column for per-transaction buttons */
.col-actions {
    text-align: center;
    min-width: 40px;
    vertical-align: middle;
}

.actions-cell {
    padding: 8px;
}

/* "Analyse with RiQ" button above table - Special AI Feature */
.btn-analyse-riq {
    background: white;
    color: #c4576a;
    border: 1.5px solid #c4576a;
    padding: 9px 18px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-left: auto;
    letter-spacing: -0.01em;
}

.btn-analyse-riq:hover {
    background: #fef2f7;
    border-color: #9a4054;
    color: #9a4054;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(196, 87, 106, 0.12);
}

.btn-analyse-riq:active {
    transform: translateY(0);
    box-shadow: none;
}

/* Responsive adjustments for buttons */
@media (max-width: 768px) {
    .btn-analyse-riq {
        padding: 9px 16px;
        font-size: 13px;
        min-width: 120px;
    }

    .btn-riq-img {
        width: 20px;
        height: 20px;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .riq-analysis-modal {
        width: 95%;
        max-height: 90vh;
    }

    .summary-stats {
        flex-wrap: wrap;
    }

    .stat {
        min-width: 80px;
    }

    .txn-header {
        flex-direction: column;
    }

    .txn-actions {
        flex-direction: column;
    }

    .codeiq-button-sm {
        width: 100%;
    }

    .chat-transaction-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .chat-input-area {
        flex-direction: column;
    }

    .chat-input-area button {
        width: 100%;
    }
}

/* Transaction row highlighting (advisory mode) */
.transaction-row.riq-highlighted {
    background: linear-gradient(90deg, #fef5fb 0%, #fef5fb 50%, white 100%);
    animation: highlightPulse 3s ease-out;
    border-left: 4px solid #c4576a;
}

@keyframes highlightPulse {
    0% {
        box-shadow: 0 0 20px rgba(196, 87, 106, 0.8);
    }
    50% {
        box-shadow: 0 0 10px rgba(196, 87, 106, 0.4);
    }
    100% {
        box-shadow: none;
    }
}

.transaction-row.riq-flagged {
    background: #fef3c7;
    border-left: 4px solid #f59e0b;
}

/* Advisory note in RiQ suggestions */
.suggestion-note {
    font-size: 12px;
    color: #6b6b6b;
    font-style: italic;
    margin-top: 8px;
}

/* Business Context Section */
.business-context-section {
    background: #faf8f5;
    border: 1px solid #d4d0c8;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 24px;
}

.business-context-section h4 {
    font-size: 15px;
    font-weight: 600;
    color: #3d3d3d;
    margin: 0 0 4px 0;
}

.business-context-section .context-optional {
    font-size: 12px;
    font-weight: 400;
    color: #6b6b6b;
    font-style: italic;
}

.context-form {
    margin-top: 16px;
}

.context-form .form-group {
    margin-bottom: 16px;
}

.context-form .form-group:last-of-type {
    margin-bottom: 12px;
}

.context-form label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #3d3d3d;
    margin-bottom: 6px;
}

.context-form .context-input {
    width: 100%;
    padding: 8px 12px;
    border: 1.5px solid #c4c0b8;
    border-radius: 6px;
    font-size: 14px;
    color: #1a1a1a;
    transition: border-color 0.15s ease;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

.context-form .context-input:focus {
    outline: none;
    border-color: #9a4054;
    box-shadow: 0 0 0 3px rgba(154, 64, 84, 0.1);
}

.context-form textarea.context-input {
    resize: vertical;
    min-height: 60px;
}

.save-context-btn {
    padding: 9px 18px;
    background: #9a4054;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.save-context-btn:hover {
    background: #9a4054;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(154, 64, 84, 0.25);
}

.save-context-btn.small {
    padding: 8px 16px;
    font-size: 13px;
}

.riq-menu-divider {
    height: 1px;
    background: #d4d0c8;
    margin: 24px 0;
}

/* Compact collapsible version for single transaction chat */
.business-context-section.compact {
    padding: 0;
    background: transparent;
    border: none;
    margin-bottom: 16px;
}

.business-context-section.compact .context-form {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.3s ease, opacity 0.3s ease, margin-top 0.3s ease;
    margin-top: 0;
}

.business-context-section.compact.expanded .context-form {
    max-height: 400px;
    opacity: 1;
    margin-top: 16px;
}

.context-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #faf8f5;
    border: 1px solid #d4d0c8;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
}

.context-toggle:hover {
    background: #f5f2ed;
    border-color: #c4c0b8;
}

.context-toggle span:first-child {
    font-size: 13px;
    font-weight: 500;
    color: #3d3d3d;
}

.context-toggle .toggle-arrow {
    font-size: 12px;
    color: #6b6b6b;
    transition: transform 0.3s ease;
}

.business-context-section.compact.expanded .toggle-arrow {
    transform: rotate(180deg);
}
