/* Contact Extractor Styles */

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: #f5f6fa;
    color: #333;
    line-height: 1.5;
}

/* ===== Layout ===== */
.page-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* ===== Tabs ===== */
.tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #e9ecef;
    margin-bottom: 20px;
    overflow-x: auto;
}

.tab-btn {
    padding: 10px 20px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: #7f8c8d;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    white-space: nowrap;
    transition: color 0.2s, border-color 0.2s;
    font-family: inherit;
}

.tab-btn:hover {
    color: #3498db;
}

.tab-btn.active {
    color: #3498db;
    border-bottom-color: #3498db;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ===== Stats Cards ===== */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.stat-card .stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 4px;
}

.stat-card .stat-label {
    font-size: 0.75rem;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===== DataTable customisation ===== */
.contacts-table-wrapper {
    background: #fff;
    border-radius: 10px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

table.dataTable thead th {
    border-bottom: 2px solid #e9ecef;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #7f8c8d;
}

table.dataTable tbody tr {
    cursor: pointer;
    transition: background-color 0.15s;
}

table.dataTable tbody tr:hover {
    background-color: #f0f4f8;
}

table.dataTable tbody td {
    font-size: 0.85rem;
    color: #2c3e50;
    border-top-color: #e9ecef;
}

/* Score badge */
.score-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    min-width: 32px;
    text-align: center;
}

.score-high { background: #55efc4; color: #155724; }
.score-medium { background: #ffeaa7; color: #856404; }
.score-low { background: #fab1a0; color: #721c24; }

/* Tags */
.tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    background: #e9ecef;
    color: #495057;
    margin: 1px 2px;
}

/* ===== Buttons ===== */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
}

.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: #3498db; color: white; }
.btn-primary:hover { background: #2980b9; }
.btn-warning { background: #f39c12; color: white; }
.btn-warning:hover { background: #e08e0b; }
.btn-danger { background: #e74c3c; color: white; }
.btn-danger:hover { background: #c0392b; }
.btn-secondary { background: #95a5a6; color: white; }
.btn-secondary:hover { background: #7f8c8d; }
.btn-success { background: #27ae60; color: white; }
.btn-success:hover { background: #219a52; }

/* ===== Scan Status ===== */
.scan-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.scan-controls h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 12px;
}

.scan-users-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.scan-user-card {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 14px;
    border: 1px solid #e9ecef;
    transition: border-color 0.2s;
}

.scan-user-card:hover {
    border-color: #3498db;
}

.scan-user-card .user-email {
    font-weight: 600;
    font-size: 0.85rem;
    color: #2c3e50;
    margin-bottom: 6px;
    word-break: break-all;
}

.scan-user-card .user-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.status-complete { background: #55efc4; color: #155724; }
.status-scanning { background: #74b9ff; color: #004085; }
.status-paused { background: #ffeaa7; color: #856404; }
.status-error { background: #fab1a0; color: #721c24; }
.status-not_started { background: #dfe6e9; color: #636e72; }
.status-has_more { background: #81ecec; color: #0c5460; }

.scan-user-card .user-meta {
    font-size: 0.75rem;
    color: #95a5a6;
    margin-top: 6px;
}

/* ===== Charts ===== */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
}

.chart-card {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.chart-card h3 {
    margin: 0 0 16px 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #2c3e50;
}

.chart-container {
    position: relative;
    height: 300px;
}

/* ===== Export Tab ===== */
.export-form {
    max-width: 600px;
    background: #fff;
    border-radius: 10px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

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

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    font-size: 0.85rem;
    color: #555;
}

.form-group select,
.form-group input[type="number"],
.form-group input[type="text"] {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.85rem;
    box-sizing: border-box;
    font-family: inherit;
}

.form-group select:focus,
.form-group input:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52,152,219,0.15);
}

.checkbox-group {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 6px;
}

.checkbox-group label {
    font-weight: normal;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.8rem;
}

/* ===== Contact Detail Lightbox ===== */
.lightbox-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 10000;
    justify-content: center;
    align-items: flex-start;
    padding: 40px 20px;
    overflow-y: auto;
}

.lightbox-overlay.active {
    display: flex;
}

.lightbox-content {
    background: #fff;
    border-radius: 12px;
    width: 100%;
    max-width: 700px;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.lightbox-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid #e9ecef;
}

.lightbox-header h2 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
    color: #2c3e50;
}

.lightbox-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #95a5a6;
    padding: 4px 8px;
    line-height: 1;
    transition: color 0.2s;
}

.lightbox-close:hover {
    color: #2c3e50;
}

.lightbox-body {
    padding: 24px;
}

.detail-grid {
    display: grid;
    gap: 16px;
}

.detail-row {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 8px;
    align-items: start;
}

.detail-label {
    font-weight: 600;
    font-size: 0.75rem;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.detail-value {
    font-size: 0.85rem;
    color: #2c3e50;
}

.detail-value .editable {
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.detail-value .editable:hover {
    border-color: #ddd;
    background: #f8f9fa;
}

.detail-value input.edit-input {
    width: 100%;
    padding: 4px 8px;
    border: 1px solid #3498db;
    border-radius: 4px;
    font-size: 0.85rem;
    box-sizing: border-box;
    font-family: inherit;
}

.comm-summary {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #e9ecef;
}

.comm-summary h4 {
    margin: 0 0 12px 0;
    font-size: 0.95rem;
    color: #2c3e50;
}

.comm-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
}

.comm-stat {
    text-align: center;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 6px;
}

.comm-stat .value {
    font-size: 1.2rem;
    font-weight: 700;
    color: #2c3e50;
}

.comm-stat .label {
    font-size: 0.7rem;
    color: #7f8c8d;
    text-transform: uppercase;
}

.lightbox-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #e9ecef;
}

/* ===== Confirmation Overlay ===== */
.confirm-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 20000;
    justify-content: center;
    align-items: center;
}

.confirm-overlay.active {
    display: flex;
}

.confirm-box {
    background: #fff;
    border-radius: 12px;
    padding: 30px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

.confirm-box p {
    margin: 0 0 20px 0;
    font-size: 0.9rem;
    color: #333;
}

.confirm-box .confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* ===== DataTables Overrides ===== */
.dataTables_wrapper .dataTables_filter input {
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.85rem;
    font-family: inherit;
}

.dataTables_wrapper .dataTables_filter input:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52,152,219,0.15);
}

.dataTables_wrapper .dataTables_length select {
    padding: 4px 8px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.85rem;
    font-family: inherit;
}

.dataTables_wrapper .dataTables_info {
    font-size: 0.8rem;
    color: #7f8c8d;
}

.dataTables_wrapper .dataTables_length label,
.dataTables_wrapper .dataTables_filter label {
    font-size: 0.8rem;
    color: #7f8c8d;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    border-radius: 4px !important;
    font-size: 0.8rem;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: #3498db !important;
    color: white !important;
    border-color: #3498db !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background: #f0f4f8 !important;
    color: #333 !important;
    border-color: #ddd !important;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .page-container {
        padding: 12px;
    }

    .tab-btn {
        padding: 8px 14px;
        font-size: 0.8rem;
    }

    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .detail-row {
        grid-template-columns: 1fr;
    }

    .detail-label {
        margin-bottom: -8px;
    }

    .scan-users-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .stats-row {
        grid-template-columns: 1fr;
    }
}

/* ============================
   Dark Mode
   ============================ */
[data-theme="dark"] body {
    background: #1a1a2e;
    color: #e0e0e0;
}

[data-theme="dark"] .stat-card,
[data-theme="dark"] .contacts-table-wrapper,
[data-theme="dark"] .chart-card,
[data-theme="dark"] .export-form {
    background: #222240;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

[data-theme="dark"] .scan-user-card {
    background: #2d2d44;
    border-color: #3a3a55;
}

[data-theme="dark"] .scan-user-card:hover {
    border-color: #3498db;
}

[data-theme="dark"] .stat-card .stat-value {
    color: #e0e0e0;
}

[data-theme="dark"] .stat-card .stat-label {
    color: #a0a0b0;
}

[data-theme="dark"] .tab-bar {
    border-bottom-color: #3a3a55;
}

[data-theme="dark"] .tab-btn {
    color: #7a7a8e;
}

[data-theme="dark"] .tab-btn:hover {
    color: #74b9ff;
}

[data-theme="dark"] .tab-btn.active {
    color: #74b9ff;
    border-bottom-color: #74b9ff;
}

[data-theme="dark"] table.dataTable {
    background-color: #222240;
}

[data-theme="dark"] table.dataTable thead th {
    border-bottom-color: #3a3a55;
    color: #a0a0b0;
}

[data-theme="dark"] table.dataTable tbody tr:hover {
    background-color: #2d2d44;
}

[data-theme="dark"] table.dataTable tbody td {
    color: #e0e0e0;
    border-top-color: #3a3a55;
}

/* DataTables row striping in dark mode */
[data-theme="dark"] table.dataTable tbody tr.odd {
    background-color: #222240;
}

[data-theme="dark"] table.dataTable tbody tr.even {
    background-color: #272747;
}

[data-theme="dark"] table.dataTable tbody tr.odd:hover,
[data-theme="dark"] table.dataTable tbody tr.even:hover {
    background-color: #2d2d44;
}

[data-theme="dark"] .tag {
    background: #3a3a55;
    color: #a0a0b0;
}

[data-theme="dark"] .lightbox-content,
[data-theme="dark"] .confirm-box {
    background: #222240;
    color: #e0e0e0;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

[data-theme="dark"] .lightbox-header {
    border-bottom-color: #3a3a55;
}

[data-theme="dark"] .lightbox-header h2 {
    color: #e0e0e0;
}

[data-theme="dark"] .lightbox-close {
    color: #7a7a8e;
}

[data-theme="dark"] .lightbox-close:hover {
    color: #e0e0e0;
}

[data-theme="dark"] .detail-label {
    color: #a0a0b0;
}

[data-theme="dark"] .detail-value {
    color: #e0e0e0;
}

[data-theme="dark"] .detail-value .editable:hover {
    border-color: #3a3a55;
    background: #2d2d44;
}

[data-theme="dark"] .detail-value input.edit-input {
    background: #2d2d44;
    border-color: #74b9ff;
    color: #e0e0e0;
}

[data-theme="dark"] .comm-stat {
    background: #2d2d44;
}

[data-theme="dark"] .comm-stat .value {
    color: #e0e0e0;
}

[data-theme="dark"] .comm-stat .label {
    color: #a0a0b0;
}

[data-theme="dark"] .comm-summary,
[data-theme="dark"] .lightbox-actions {
    border-top-color: #3a3a55;
}

[data-theme="dark"] .chart-card h3 {
    color: #e0e0e0;
}

[data-theme="dark"] .form-group select,
[data-theme="dark"] .form-group input[type="number"],
[data-theme="dark"] .form-group input[type="text"] {
    background: #2d2d44;
    border-color: #3a3a55;
    color: #e0e0e0;
}

[data-theme="dark"] .form-group label {
    color: #a0a0b0;
}

[data-theme="dark"] .confirm-box p {
    color: #e0e0e0;
}

/* DataTables dark mode overrides */
[data-theme="dark"] .dataTables_wrapper .dataTables_filter input,
[data-theme="dark"] .dataTables_wrapper .dataTables_length select {
    background: #2d2d44;
    border-color: #3a3a55;
    color: #e0e0e0;
}

[data-theme="dark"] .dataTables_wrapper .dataTables_info,
[data-theme="dark"] .dataTables_wrapper .dataTables_length label,
[data-theme="dark"] .dataTables_wrapper .dataTables_filter label {
    color: #a0a0b0;
}

[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button {
    color: #a0a0b0 !important;
}

[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: #3498db !important;
    color: white !important;
    border-color: #3498db !important;
}

[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background: #2d2d44 !important;
    color: #e0e0e0 !important;
    border-color: #3a3a55 !important;
}

/* Merge prompt input dark mode */
[data-theme="dark"] .merge-input,
[data-theme="dark"] .confirm-box input {
    background: #2d2d44;
    border-color: #3a3a55;
    color: #e0e0e0;
}

/* Scan controls heading dark mode */
[data-theme="dark"] .scan-controls h3,
[data-theme="dark"] #scan-status-content h3 {
    color: #e0e0e0;
}

[data-theme="dark"] .scan-user-card .user-email {
    color: #e0e0e0;
}

[data-theme="dark"] .scan-user-card .user-meta {
    color: #7a7a8e;
}
