/* Meta Ads Viewer - Custom Styles */

:root {
    --primary-color: #6b6b6b;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --info-color: #17a2b8;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
    --light-color: #f8f9fa;
    --dark-color: #343a40;
    --bg-dark: #000000;
    --text-light: #e0e0e0;
    --card-bg: #ffffff;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-light);
    min-height: 100vh;
}

/* Navigation */
.navbar-brand {
    font-weight: 600;
    font-size: 1.5rem;
}

/* Cards */
.card {
    border: none;
    background-color: var(--card-bg);
    box-shadow: 0 0.125rem 0.25rem rgba(255, 255, 255, 0.1);
    transition: box-shadow 0.15s ease-in-out;
}

.card:hover {
    box-shadow: 0 0.5rem 1rem rgba(255, 255, 255, 0.2);
}

/* Cluster Cards */
.cluster-card {
    transition: transform 0.2s ease-in-out;
    padding-top: 1rem;
}

.cluster-card:hover {
    transform: translateY(-5px);
}

.card-img-container {
    position: relative;
    overflow: hidden;
    border-radius: 0.375rem 0.375rem 0 0;
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f8f9fa;
}

.cluster-image {
    width: 100%;
    max-height: 300px;
    object-fit: contain;
    transition: opacity 0.3s ease;
    opacity: 0.9;
    background-color: #f8f9fa;
}

.cluster-image:hover {
    opacity: 1;
}

.no-image {
    height: 300px;
    background-color: #f8f9fa;
    border: 2px dashed #dee2e6;
}

.no-image-large {
    height: 300px;
    background-color: #f8f9fa;
    border: 2px dashed #dee2e6;
    border-radius: 8px;
}

.quality-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 0.75rem;
}

.video-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Video styling */
.cluster-video {
    width: 100%;
    height: 300px;
    object-fit: cover;
    opacity: 0.9;
    transition: opacity 0.2s ease-in-out;
}

.cluster-video:hover {
    opacity: 1;
}

/* Video thumbnail with play overlay */
.video-thumbnail-container {
    position: relative;
    cursor: pointer;
    width: 100%;
    height: 100%;
}

.video-play-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
    pointer-events: none;
    transition: all 0.3s ease;
}

.video-thumbnail-container:hover .video-play-overlay {
    color: rgba(255, 255, 255, 1);
    transform: translate(-50%, -50%) scale(1.1);
}

/* Video placeholder styling */
.video-placeholder {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
}

.video-placeholder-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.video-placeholder .text-muted {
    color: rgba(255, 255, 255, 0.6) !important;
}

.video-placeholder:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

@media (max-width: 768px) {
    .video-placeholder {
        min-height: 250px;
    }
}

@media (max-width: 576px) {
    .video-placeholder {
        min-height: 200px;
    }
}

/* Lazy loading image placeholder */
.lazy-load {
    opacity: 0;
    transition: opacity 0.3s ease-in;
}

.lazy-load[src] {
    opacity: 1;
}

/* Metadata styling */
.metadata-item {
    margin-bottom: 0.5rem;
}

.metadata-item small {
    display: block;
    font-size: 0.75rem;
    margin-bottom: 0.25rem;
}

.info-item {
    margin-bottom: 1rem;
}

.info-item label {
    display: block;
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

/* Page names */
.page-names {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.page-names .badge {
    font-size: 0.75rem;
}

/* Date range */
.date-range {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    background-color: #f8f9fa;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    border: 1px solid #dee2e6;
    color: #212529;
}

/* Detail page */
.detail-image {
    max-width: 100%;
    height: auto;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

/* JSON sections */
.json-section {
    background-color: #f8f9fa;
    padding: 1rem;
    border-radius: 0.375rem;
    border-left: 4px solid var(--primary-color);
    color: #212529;
}

.json-section strong {
    color: var(--dark-color);
}

/* Form styling */
.form-select:focus,
.form-control:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(107, 107, 107, 0.25);
}

/* Buttons */
.btn {
    border-radius: 0.375rem;
    font-weight: 500;
    transition: all 0.15s ease-in-out;
}

.btn-primary {
    background-color: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
}

.btn-primary:hover {
    background-color: #555555 !important;
    border-color: #555555 !important;
    transform: translateY(-1px);
}

.btn-primary:focus,
.btn-primary:active {
    background-color: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
    box-shadow: 0 0 0 0.2rem rgba(107, 107, 107, 0.25) !important;
}

.btn-primary:disabled {
    background-color: #4a4a4a !important;
    border-color: #4a4a4a !important;
}

/* Loading states */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .card-img-container {
        min-height: 250px;
    }

    .cluster-image {
        max-height: 250px;
    }

    .no-image {
        height: 250px;
    }

    .card-body {
        padding: 0.75rem;
    }

    .btn-group-vertical .btn {
        font-size: 0.875rem;
    }

    .navbar-brand {
        font-size: 1.25rem;
    }
}

@media (max-width: 576px) {
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .card-body {
        padding: 0.5rem;
    }

    .card-img-container {
        min-height: 200px;
    }

    .cluster-image {
        max-height: 200px;
    }

    .no-image {
        height: 200px;
    }

    .metadata-item {
        margin-bottom: 0.25rem;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card {
    animation: fadeIn 0.5s ease-out;
}

/* Alert styling */
.alert {
    border: none;
    border-radius: 0.5rem;
}

.alert-warning {
    background-color: #fff3cd;
    color: #856404;
}

.alert-info {
    background-color: #d1ecf1;
    color: #0c5460;
}

/* Dark theme text colors */
h1, h2, h3, h4, h5, h6 {
    color: var(--text-light);
}

p, span, div {
    color: var(--text-light);
}

/* Keep card text dark */
.card h1, .card h2, .card h3, .card h4, .card h5, .card h6,
.card p, .card span, .card div {
    color: #212529;
}

/* Card header with dark background should have white text */
.card-header.text-white,
.card-header.text-white h1,
.card-header.text-white h2,
.card-header.text-white h3,
.card-header.text-white h4,
.card-header.text-white h5,
.card-header.text-white h6 {
    color: #ffffff !important;
}

/* Form controls on dark background */
.form-label {
    color: var(--text-light);
}

.form-select, .form-control {
    background-color: #1a1a1a;
    color: var(--text-light);
    border-color: #444;
}

.form-select:focus, .form-control:focus {
    background-color: #1a1a1a;
    color: var(--text-light);
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(107, 107, 107, 0.25);
}

.form-select option {
    background-color: #1a1a1a;
    color: var(--text-light);
}

/* Footer */
footer {
    margin-top: auto;
    background-color: #0a0a0a !important;
    border-top: 1px solid #222;
}

footer .text-muted {
    color: #999 !important;
}

/* Code blocks */
pre {
    font-size: 0.875rem;
    max-height: 400px;
    overflow-y: auto;
    background-color: #1a1a1a;
    color: var(--text-light);
    border: 1px solid #333;
}

/* Links on dark background */
a:not(.btn):not(.nav-link):not(.navbar-brand) {
    color: #9b9b9b;
}

a:not(.btn):not(.nav-link):not(.navbar-brand):hover {
    color: #c0c0c0;
}

/* Badge variations */
.badge {
    font-size: 0.75rem;
    font-weight: 500;
}

/* Utility classes */
.text-monospace {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
}

.border-left-primary {
    border-left: 4px solid var(--primary-color) !important;
}

.border-left-success {
    border-left: 4px solid var(--success-color) !important;
}

.border-left-info {
    border-left: 4px solid var(--info-color) !important;
}

.border-left-warning {
    border-left: 4px solid var(--warning-color) !important;
}

/* ==================== */
/* Table View Styles    */
/* ==================== */

/* Table thumbnail */
.table-thumbnail {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 4px;
    transition: transform 0.2s ease;
}

.table-thumbnail:hover {
    transform: scale(1.1);
}

.table-thumbnail-placeholder {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border: 1px dashed #dee2e6;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6c757d;
    font-size: 1.25rem;
}

.table-thumbnail-placeholder.video-type {
    background: linear-gradient(135deg, #e7f0fd 0%, #d0e2fc 100%);
    color: #0d6efd;
}

.table-thumbnail-placeholder.image-type {
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
    color: #198754;
}

/* Sparkline charts */
.sparkline-chart {
    display: block;
    vertical-align: middle;
}

.col-spend_index_trend {
    min-width: 90px;
}

/* View toggle buttons */
#grid-view-btn.active,
#table-view-btn.active {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

/* Column selector popover */
.column-selector-popover {
    min-width: 180px;
    max-height: 300px;
    overflow-y: auto;
    color: #212529;
}

.column-selector-popover .form-check {
    margin-bottom: 0.25rem;
}

.column-selector-popover .form-check-label {
    color: #212529;
}

/* DataTable customizations */
#table-view-container .card {
    background-color: var(--card-bg);
}

#clusters-table {
    color: #212529;
}

#clusters-table thead th {
    background-color: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
    font-weight: 600;
    white-space: nowrap;
    font-size: 0.875rem;
}

#clusters-table tbody td {
    vertical-align: middle;
    white-space: nowrap;
    font-size: 0.875rem;
}

#clusters-table tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/* DataTables search and controls styling */
.dataTables_wrapper .dataTables_filter input {
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 0.375rem 0.75rem;
    margin-left: 0.5rem;
}

.dataTables_wrapper .dataTables_length select {
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
}

.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    margin-top: 1rem;
    padding: 0 1rem;
}

/* Responsive table */
@media (max-width: 768px) {
    .table-thumbnail {
        width: 40px;
        height: 40px;
    }

    .table-thumbnail-placeholder {
        width: 40px;
        height: 40px;
    }

    #clusters-table {
        font-size: 0.8rem;
    }

    #clusters-table thead th,
    #clusters-table tbody td {
        font-size: 0.8rem;
    }
}

/* Score Distribution Stacked Bars - Differential Analysis */
.score-distribution-bar {
    display: flex;
    height: 24px;
    border-radius: 4px;
    overflow: hidden;
    background-color: #e9ecef;
}

.score-segment {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    transition: opacity 0.2s;
}

.score-segment:hover {
    opacity: 0.85;
}

.score-label {
    font-size: 10px;
    font-weight: bold;
    color: white;
    text-shadow: 0 0 2px rgba(0,0,0,0.5);
}

/* Score colors - gradient from red (0) to green (10) */
.score-0  { background-color: #dc3545; }
.score-1  { background-color: #e04a4a; }
.score-2  { background-color: #e4624f; }
.score-3  { background-color: #e87a54; }
.score-4  { background-color: #ec9259; }
.score-5  { background-color: #f0aa5e; }
.score-6  { background-color: #c4b050; }
.score-7  { background-color: #98b642; }
.score-8  { background-color: #6cbc34; }
.score-9  { background-color: #40c226; }
.score-10 { background-color: #28a745; }

/* Score legend badges */
.score-legend-0  { background-color: #dc3545; color: white; }
.score-legend-1  { background-color: #e04a4a; color: white; }
.score-legend-2  { background-color: #e4624f; color: white; }
.score-legend-3  { background-color: #e87a54; color: white; }
.score-legend-4  { background-color: #ec9259; color: white; }
.score-legend-5  { background-color: #f0aa5e; color: white; }
.score-legend-6  { background-color: #c4b050; color: white; }
.score-legend-7  { background-color: #98b642; color: white; }
.score-legend-8  { background-color: #6cbc34; color: white; }
.score-legend-9  { background-color: #40c226; color: white; }
.score-legend-10 { background-color: #28a745; color: white; }

.segment-card {
    border-left: 3px solid #6c757d;
}

.segment-card:hover {
    border-left-color: #0d6efd;
}

/* ============================================================================
   Chat Component Styles
   ============================================================================ */

.chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1050;
    font-family: inherit;
}

.chat-container.chat-collapsed .chat-panel {
    display: none;
}

.chat-container.chat-expanded .chat-toggle-btn {
    display: none;
}

/* Toggle Button */
.chat-toggle-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    padding: 12px 24px;
    border-radius: 25px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
    font-size: 14px;
    font-weight: 500;
}

.chat-toggle-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

.chat-toggle-btn:active {
    transform: translateY(0);
}

/* Chat Panel */
.chat-panel {
    position: relative;
    width: 400px;
    height: 520px;
    min-width: 320px;
    min-height: 300px;
    max-width: 800px;
    max-height: 80vh;
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Resize handle (top-left corner) */
.chat-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    width: 20px;
    height: 20px;
    cursor: nw-resize;
    z-index: 20;
    border-top-left-radius: 12px;
}

.chat-resize-handle::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    width: 8px;
    height: 8px;
    border-left: 2px solid rgba(255, 255, 255, 0.6);
    border-top: 2px solid rgba(255, 255, 255, 0.6);
}

.chat-resize-handle:hover::before {
    border-color: rgba(255, 255, 255, 0.9);
}

.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h6 {
    font-weight: 600;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8f9fa;
}

.chat-message {
    margin-bottom: 12px;
    max-width: 88%;
}

.chat-message.user {
    margin-left: auto;
}

.chat-message.assistant {
    margin-right: auto;
}

.message-content {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    color: #212529;
}

.chat-message.user .message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.assistant .message-content {
    background: white;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
}

.chat-input-container {
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #e0e0e0;
}

.chat-input-container .input-group {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border-radius: 8px;
    overflow: hidden;
}

.chat-input-container .form-control {
    border: 1px solid #e0e0e0;
    border-right: none;
    padding: 10px 14px;
}

.chat-input-container .form-control:focus {
    box-shadow: none;
    border-color: #667eea;
}

.chat-input-container .btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    padding: 10px 16px;
}

.chat-input-container .btn-primary:hover {
    opacity: 0.9;
}

/* Loading state */
.chat-message.loading .message-content {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #6c757d;
}

.typing-indicator {
    display: flex;
    gap: 4px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #667eea;
    border-radius: 50%;
    display: inline-block;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

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

/* Responsive adjustments */
@media (max-width: 480px) {
    .chat-panel {
        width: calc(100vw - 40px);
        height: calc(100vh - 100px);
        max-height: 600px;
    }

    .chat-container {
        right: 10px;
        bottom: 10px;
    }
}