/* Chatbot Widget Styles */

.chatbot-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9998;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Chatbot Toggle Button */
.chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
    transition: all 0.3s ease;
    position: relative;
}

.chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.6);
}

.chatbot-toggle:active {
    transform: scale(0.95);
}

/* Notification Badge */
.chatbot-notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background-color: #ef4444;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    border: 2px solid white;
}

.chatbot-notification-badge.hidden {
    display: none;
}

/* Chatbot Window */
.chatbot-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 760px;
    max-width: calc(100vw - 48px);
    height: 600px;
    background-color: #1f2937;
    border-radius: 12px;
    box-shadow: 0 5px 40px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    border: 1px solid #374151;
    overflow: hidden;
    animation: slideUp 0.3s ease-out;
}

.chatbot-window.hidden {
    display: none;
}

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

/* Chatbot Header */
.chatbot-header {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    padding: 16px;
    border-bottom: 1px solid #1e40af;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chatbot-title {
    color: white;
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chatbot-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.chatbot-close-btn:hover {
    color: #dbeafe;
}

/* Messages Container */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background-color: #111827;
}

/* Scrollbar styling */
.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: #1f2937;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #4b5563;
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

/* Message Styling */
.chatbot-message {
    display: flex;
    gap: 8px;
    animation: fadeIn 0.3s ease-in;
}

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

.chatbot-message.user-message {
    justify-content: flex-end;
}

.chatbot-message.bot-message {
    justify-content: flex-start;
}

.message-content {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    word-wrap: break-word;
    line-height: 1.4;
    font-size: 13px;
}

.user-message .message-content {
    background-color: #3b82f6;
    color: white;
    border-bottom-right-radius: 2px;
}

.bot-message .message-content {
    background-color: #374151;
    color: #f3f4f6;
    border-bottom-left-radius: 2px;
}

/* Table responses should be a single full-width panel, not side-by-side blocks */
.chatbot-message.bot-message.table-response {
    width: 100%;
}

.chatbot-message.bot-message.table-response .message-content {
    width: 100%;
    max-width: 100%;
    padding: 0;
    background: transparent;
    border-radius: 0;
}

.chatbot-message.bot-message.table-response .chatbot-table-container {
    margin: 0;
}

/* Quick Actions */
.quick-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.quick-action-btn {
    background-color: #1f2937;
    border: 1px solid #4b5563;
    color: #e5e7eb;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.quick-action-btn:hover {
    background-color: #2d3748;
    border-color: #3b82f6;
    color: #3b82f6;
}

/* Input Area */
.chatbot-input-area {
    padding: 12px;
    border-top: 1px solid #374151;
    background-color: #0f1419;
}

.chatbot-input-container {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.chatbot-input {
    flex: 1;
    background-color: #1f2937;
    color: #f3f4f6;
    border: 1px solid #374151;
    border-radius: 8px;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 13px;
    resize: none;
    max-height: 100px;
    min-height: 40px;
    outline: none;
    transition: border-color 0.2s;
}

.chatbot-input:focus {
    border-color: #3b82f6;
}

.chatbot-input::placeholder {
    color: #9ca3af;
}

.chatbot-send-btn {
    background-color: #3b82f6;
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 14px;
    flex-shrink: 0;
}

.chatbot-send-btn:hover {
    background-color: #2563eb;
}

.chatbot-send-btn:active {
    transform: scale(0.95);
}

/* Suggestions */
.chatbot-suggestions {
    margin-top: 8px;
    text-align: center;
}

/* Loading Indicator */
.chatbot-message.loading .message-content {
    display: flex;
    gap: 4px;
    align-items: center;
}

.loading-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #9ca3af;
    animation: bounce 1.4s infinite;
}

.loading-dot:nth-child(1) { animation-delay: -0.32s; }
.loading-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-8px); }
}

/* Responsive Design */
@media (max-width: 767px) {
    /* Keep launcher above bottom nav/safe area */
    .chatbot-widget {
        bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
        right: 12px !important;
        left: auto !important;
        z-index: 10020 !important;
    }

    /* Force viewport-anchored sheet layout on mobile */
    #chatbot-window.chatbot-window,
    .chatbot-window {
        position: fixed !important;
        inset: auto 8px calc(74px + env(safe-area-inset-bottom, 0px)) 8px !important;
        width: auto !important;
        min-width: 0 !important;
        max-width: none !important;
        height: min(68dvh, 560px) !important;
        min-height: 320px !important;
        border-radius: 14px !important;
        box-shadow: 0 10px 44px rgba(0, 0, 0, 0.58) !important;
    }

    .chatbot-header {
        padding: 12px 14px;
    }

    .chatbot-messages {
        padding: 12px;
    }

    .chatbot-input-area {
        padding: 10px;
    }

    .chatbot-input {
        font-size: 16px;
    }

    .chatbot-suggestions {
        display: none;
    }

    .message-content {
        max-width: 90%;
    }
}

@media (max-width: 380px) {
    #chatbot-window.chatbot-window,
    .chatbot-window {
        inset: auto 6px calc(72px + env(safe-area-inset-bottom, 0px)) 6px !important;
        height: min(70dvh, 520px) !important;
        min-height: 300px !important;
    }
}

/* Error Message */
.message-error .message-content {
    background-color: #7f1d1d;
    color: #fee2e2;
    border-left: 3px solid #ef4444;
}

/* Success Message */
.message-success .message-content {
    background-color: #064e3b;
    color: #d1fae5;
    border-left: 3px solid #10b981;
}

/* Link Styling */
.message-content a {
    color: #60a5fa;
    text-decoration: underline;
    cursor: pointer;
}

.message-content a:hover {
    color: #93c5fd;
}

/* Code Block */
.message-content code {
    background-color: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
}

/* Upgrade Options */
.upgrade-options {
    padding: 12px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(37, 99, 235, 0.1));
    border: 1px solid #3b82f6;
    border-radius: 8px;
    margin: 12px 0;
    animation: fadeIn 0.3s ease-in;
}

.upgrade-options p {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: #f3f4f6;
    font-weight: 500;
}

.upgrade-options a,
.upgrade-options button {
    transition: all 0.2s ease;
}

.upgrade-options button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* Token Display */
#token-display {
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    background-color: rgba(59, 130, 246, 0.2);
    border-radius: 4px;
    display: inline-block;
    margin-left: 8px;
    transition: color 0.3s ease, background-color 0.3s ease;
}

#token-display.warning {
    background-color: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
}

#token-display.critical {
    background-color: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

/* Disabled Input State */
.chatbot-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: #111827;
}

.chatbot-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ========================================
   TABLE STYLING FOR CHATBOT RESPONSES
   ======================================== */

/* Table Container */
.chatbot-table-container {
    margin: 16px 0;
    border-radius: 8px;
    overflow: hidden;
    background: linear-gradient(135deg, #0f172a 0%, #1a1f35 100%);
    border: 1px solid #374151;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    animation: slideUpTable 0.3s ease-out;
}

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

/* Table Title */
.table-title {
    padding: 16px 20px;
    font-size: 14px;
    font-weight: 600;
    color: #e5e7eb;
    background: linear-gradient(90deg, #1e3a8a 0%, #0c4a6e 100%);
    border-bottom: 1px solid #1e40af;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    opacity: 0.95;
}

/* Data Table */
.chatbot-data-table {
    width: 100%;
    border-collapse: collapse;
    background: #0f172a;
    table-layout: auto;
}

.chatbot-data-table th {
    background: linear-gradient(90deg, #1f2937 0%, #111827 100%);
    color: #9ca3af;
    font-weight: 600;
    font-size: 12px;
    padding: 14px 16px;
    text-align: left;
    border-bottom: 2px solid #374151;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chatbot-data-table td {
    padding: 12px 16px;
    font-size: 13px;
    color: #d1d5db;
    border-bottom: 1px solid #1f2937;
}

/* Table Row Styling */
.chatbot-data-table tbody tr {
    transition: all 0.2s ease;
    background-color: #0f172a;
}

.chatbot-data-table tbody tr.even {
    background-color: #111827;
}

.chatbot-data-table tbody tr.odd {
    background-color: #0f172a;
}

/* Hover Effect for Regular Rows */
.chatbot-data-table tbody tr:hover {
    background-color: #1f2937;
}

/* Drilldown Rows (Clickable) */
.chatbot-data-table.drilldown tbody tr.clickable-row {
    cursor: pointer;
    transition: all 0.2s ease;
}

.chatbot-data-table.drilldown tbody tr.clickable-row:hover {
    background-color: rgba(59, 130, 246, 0.1);
    border-left: 4px solid #3b82f6;
    padding-left: 12px;
}

.chatbot-data-table.drilldown tbody tr.clickable-row:active {
    background-color: rgba(59, 130, 246, 0.2);
}

/* Table Links (with arrow icons) */
.table-link {
    color: #60a5fa;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.table-link:hover {
    color: #93c5fd;
    text-decoration: underline;
}

.table-link:active {
    color: #3b82f6;
}

/* Bold Text in Tables */
.chatbot-data-table strong {
    color: #f3f4f6;
    font-weight: 600;
}

/* Table Status/Signal Badges */
.chatbot-data-table td:contains("Positive"),
.chatbot-data-table td:contains("High"),
.chatbot-data-table td:contains("Success") {
    color: #4ade80;
}

.chatbot-data-table td:contains("Negative"),
.chatbot-data-table td:contains("Risk"),
.chatbot-data-table td:contains("Warning") {
    color: #f87171;
}

.chatbot-data-table td:contains("Neutral"),
.chatbot-data-table td:contains("Moderate"),
.chatbot-data-table td:contains("Info") {
    color: #60a5fa;
}

/* Comparison Table Specific */
.chatbot-data-table.comparison {
    background: #0f172a;
}

.chatbot-data-table.comparison thead {
    background: linear-gradient(90deg, #1e3a8a 0%, #0c4a6e 100%);
}

/* Analysis Table Specific */
.chatbot-data-table.analysis {
    background: #0f172a;
}

.chatbot-data-table.analysis thead {
    background: linear-gradient(90deg, #1e40af 0%, #1e3a8a 100%);
}

/* Recommendation Table Specific */
.chatbot-data-table.recommendation {
    background: #0f172a;
}

.chatbot-data-table.recommendation thead {
    background: linear-gradient(90deg, #065f46 0%, #047857 100%);
}

.chatbot-data-table.recommendation tbody tr.even {
    background-color: rgba(5, 150, 105, 0.05);
}

/* Action Buttons Below Table */
.table-action-buttons {
    padding: 16px 20px;
    display: flex;
    gap: 12px;
    justify-content: flex-start;
    border-top: 1px solid #374151;
    background: #111827;
}

.table-action-buttons .btn {
    flex: 0 1 auto;
    padding: 8px 16px;
    font-size: 12px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.table-action-buttons .btn-primary {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
}

.table-action-buttons .btn-primary:hover {
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
    transform: translateY(-2px);
}

.table-action-buttons .btn-success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

.table-action-buttons .btn-success:hover {
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
    transform: translateY(-2px);
}

.table-action-buttons .btn-info {
    background: linear-gradient(135deg, #06b6d4 0%, #0891b2 100%);
    color: white;
}

.table-action-buttons .btn-info:hover {
    box-shadow: 0 4px 12px rgba(6, 182, 212, 0.4);
    transform: translateY(-2px);
}

.table-action-buttons .btn:active {
    transform: translateY(0);
}

/* Responsive Tables for Mobile */
@media (max-width: 640px) {
    .chatbot-message.bot-message.table-response .message-content {
        max-width: 100%;
    }

    .chatbot-table-container {
        margin: 12px 0;
        border-radius: 6px;
    }

    .table-title {
        padding: 12px 14px;
        font-size: 12px;
    }

    .chatbot-data-table th {
        padding: 10px 12px;
        font-size: 11px;
    }

    .chatbot-data-table td {
        padding: 10px 12px;
        font-size: 12px;
    }

    .chatbot-data-table.drilldown tbody tr.clickable-row:hover {
        border-left-width: 3px;
    }

    .table-action-buttons {
        padding: 12px 14px;
        flex-direction: column;
    }

    .table-action-buttons .btn {
        width: 100%;
        padding: 10px 12px;
    }

    /* Horizontal scroll for wide tables */
    .chatbot-data-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    .chatbot-data-table td,
    .chatbot-data-table th {
        white-space: nowrap;
    }
}

/* Print Styling */
@media print {
    .chatbot-table-container {
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid #d1d5db;
    }

    .table-action-buttons {
        display: none;
    }

    .chatbot-data-table {
        color: #000;
        background: #fff;
    }

    .chatbot-data-table th {
        background: #f3f4f6 !important;
        color: #000 !important;
        border-color: #d1d5db !important;
    }

    .chatbot-data-table td {
        border-color: #e5e7eb !important;
        color: #000 !important;
    }
}
