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

:root {
    --primary-color: #2563eb;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-primary: #f9fafb;
    --bg-secondary: #ffffff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.dark {
    --primary-color: #3b82f6;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --border-color: #334155;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.3), 0 1px 2px 0 rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Login Page */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-box {
    background: var(--bg-secondary);
    padding: 3rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
    max-width: 400px;
    width: 100%;
    text-align: center;
}

.login-box h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.google-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem 1.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.google-button:hover {
    background: var(--bg-primary);
    box-shadow: var(--shadow);
}

.error-message {
    background: #fee2e2;
    color: #991b1b;
    padding: 0.75rem;
    border-radius: 0.375rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.loading {
    margin-top: 2rem;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(249, 250, 251, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    text-align: center;
    background: var(--bg-secondary);
    padding: 3rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
}

.loading-spinner p {
    color: var(--text-secondary);
    font-size: 1rem;
    margin-top: 1rem;
}

.spinner {
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Dashboard */
.navbar {
    background: linear-gradient(to right, #1e293b, #0f172a);
    border-bottom: 1px solid #334155;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar h1 {
    font-size: 1.5rem;
    color: white;
    font-weight: 600;
}

.nav-links {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.nav-link {
    color: #cbd5e1;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    transition: all 0.2s;
}

.nav-link:hover {
    background: rgba(51, 65, 85, 0.5);
    color: white;
}

.nav-link.active {
    background: rgba(59, 130, 246, 0.2);
    color: white;
    border-bottom: 2px solid #3b82f6;
}

/* Theme Toggle Button */
.theme-toggle {
    padding: 0.5rem;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #cbd5e1;
    border-radius: 9999px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    background: rgba(51, 65, 85, 0.5);
    color: white;
}

.theme-toggle svg {
    width: 1.25rem;
    height: 1.25rem;
}

.dark .dark-mode-icon {
    display: none;
}

.dark .light-mode-icon {
    display: block;
}

.light-mode-icon {
    display: none;
}

.dark-mode-icon {
    display: block;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-email {
    color: #cbd5e1;
    font-size: 0.875rem;
}

.logout-link {
    color: #cbd5e1;
    text-decoration: none;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    transition: all 0.2s;
}

.logout-link:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

.container {
    max-width: 1800px;
    margin: 0 auto;
    padding: 2rem;
    width: 95%;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-secondary);
    border-radius: 0.5rem;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    width: 3rem;
    height: 3rem;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-icon.active {
    background: rgba(37, 99, 235, 0.1);
}

.stat-icon.completed {
    background: rgba(16, 185, 129, 0.1);
}

.stat-icon.failed {
    background: rgba(239, 68, 68, 0.1);
}

.stat-icon.time {
    background: rgba(245, 158, 11, 0.1);
}

.stat-icon.domains {
    background: rgba(99, 102, 241, 0.1);
}

.stat-icon.issues {
    background: rgba(217, 70, 239, 0.1);
}

.stat-content {
    flex: 1;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 0.25rem;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
    white-space: nowrap;
}

/* Sections */
.section {
    background: var(--bg-secondary);
    border-radius: 0.5rem;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.section h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.section-description {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 1rem;
    margin-top: -0.5rem;
}

.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
}

/* Badges */
.badge-warning {
    background: var(--warning-color);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    margin-left: 0.5rem;
}

.badge-danger {
    background: var(--danger-color);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    margin-left: 0.5rem;
}

.badge-info {
    background: var(--primary-color);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    margin-left: 0.5rem;
}

.overdue-badge {
    background: #fee2e2;
    color: var(--danger-color);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    font-weight: 600;
}

.blocking-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    cursor: pointer;
}

.blocking-link:hover {
    text-decoration: underline;
}

/* Scheduled Scans Styling */
.row-overdue {
    background: #fef2f2 !important;
    border-left: 3px solid var(--danger-color);
}

.dark .row-overdue {
    background: rgba(239, 68, 68, 0.1) !important;
}

.row-upcoming {
    background: #f0f9ff !important;
    border-left: 3px solid var(--primary-color);
}

.dark .row-upcoming {
    background: rgba(59, 130, 246, 0.1) !important;
}

.status-indicator {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.status-overdue {
    background: var(--danger-color);
}

.status-upcoming {
    background: var(--primary-color);
}

.time-overdue {
    color: var(--danger-color);
    font-weight: 600;
}

.time-upcoming {
    color: var(--primary-color);
    font-weight: 500;
}

.text-danger {
    color: var(--danger-color);
}

.text-info {
    color: var(--primary-color);
}

.text-secondary {
    color: var(--text-secondary);
}

/* Tables */
.table-container {
    overflow-x: auto;
}

.scan-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.scan-table thead {
    background: var(--bg-primary);
}

.scan-table th {
    text-align: left;
    padding: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
}

.scan-table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.scan-table tbody tr.clickable {
    cursor: pointer;
    transition: background-color 0.2s;
}

.scan-table tbody tr.clickable:hover {
    background-color: var(--bg-primary);
}

/* Progress Bar */
.progress-bar {
    position: relative;
    height: 1.5rem;
    background: var(--bg-primary);
    border-radius: 0.25rem;
    overflow: hidden;
    margin-bottom: 0.25rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), #3b82f6);
    transition: width 0.3s;
}

.progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
}

.progress-detail {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Status Badge */
.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-badge.running,
.status-badge.active {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary-color);
}

.status-badge.completed {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success-color);
}

.status-badge.failed {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
}

.status-badge.aborted {
    background: rgba(107, 114, 128, 0.1);
    color: var(--text-secondary);
}

/* Buttons */
.btn-primary {
    padding: 0.5rem 1rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.25rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-primary:hover {
    background: #1d4ed8;
}

.btn-secondary {
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: var(--bg-primary);
}

.btn-danger {
    padding: 0.5rem 1rem;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 0.25rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-small {
    padding: 0.375rem 0.75rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-right: 0.25rem;
}

.btn-small:hover {
    background: #1d4ed8;
}

.btn-danger-small {
    padding: 0.375rem 0.75rem;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-danger-small:hover {
    background: #dc2626;
}

.btn-trigger {
    background: var(--success-color);
}

.btn-trigger:hover {
    background: #059669;
}

.btn-back {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0 0.5rem 0 0;
}

.btn-back:hover {
    text-decoration: underline;
}

.btn-abort {
    padding: 0.375rem 0.75rem;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-right: 0.25rem;
}

.btn-abort:hover {
    background: #dc2626;
}

.btn-ramp {
    padding: 0.375rem 0.75rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-ramp:hover {
    background: #1d4ed8;
}

/* Dropdown Menu */
.actions-cell {
    position: relative;
}

.dropdown {
    position: relative;
    display: inline-block;
}

.btn-dropdown {
    padding: 0.25rem 0.5rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.btn-dropdown:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

.dropdown-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 0.25rem);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    box-shadow: var(--shadow-lg);
    min-width: 150px;
    z-index: 1000;
    overflow: hidden;
}

.dropdown-item {
    display: block;
    width: 100%;
    padding: 0.5rem 1rem;
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: background-color 0.2s;
}

.dropdown-item:hover {
    background: var(--bg-primary);
}

.dropdown-item-danger {
    color: var(--danger-color);
}

.dropdown-item-danger:hover {
    background: #fef2f2;
}

.text-secondary {
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-top: 0.125rem;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 0.5rem;
    max-width: 1200px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.5rem;
    margin: 0;
}

.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.btn-link {
    padding: 0.5rem 1rem;
    background: var(--primary-color);
    color: white;
    text-decoration: none;
    border-radius: 0.375rem;
    font-weight: 500;
    font-size: 0.875rem;
    transition: background-color 0.2s;
}

.btn-link:hover {
    background: #1d4ed8;
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
    padding: 0;
    width: 2rem;
    height: 2rem;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

.detail-section {
    background: var(--bg-primary);
    padding: 1.5rem;
    border-radius: 0.5rem;
}

.detail-section h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.detail-section dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.5rem 1rem;
}

.detail-section dt {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.detail-section dd {
    color: var(--text-primary);
    font-size: 0.875rem;
}

.detail-section pre {
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: 0.25rem;
    overflow-x: auto;
    font-size: 0.75rem;
    line-height: 1.5;
}

.error-section {
    background: #fee2e2;
}

.error-section pre {
    background: white;
    color: #991b1b;
}

/* DataTables Custom Styling */
.dataTables_wrapper {
    padding: 0;
}

.dataTables_filter {
    margin-bottom: 1rem;
}

.dataTables_filter input {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    font-size: 0.875rem;
    margin-left: 0.5rem;
}

.dataTables_paginate {
    margin-top: 1rem;
}

.dataTables_paginate .paginate_button {
    padding: 0.375rem 0.75rem;
    margin: 0 0.25rem;
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    cursor: pointer;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.dataTables_paginate .paginate_button:hover {
    background: var(--bg-primary);
}

.dataTables_paginate .paginate_button.current {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.dataTables_paginate .paginate_button.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

table.dataTable thead th {
    cursor: pointer;
}

table.dataTable thead .sorting:after,
table.dataTable thead .sorting_asc:after,
table.dataTable thead .sorting_desc:after {
    opacity: 0.3;
    margin-left: 0.5rem;
}

table.dataTable thead .sorting_asc:after {
    opacity: 1;
}

table.dataTable thead .sorting_desc:after {
    opacity: 1;
}

/* Version Footer */
.version-footer {
    position: fixed;
    bottom: 0.5rem;
    right: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    border: 1px solid var(--border-color);
    z-index: 1000;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.version-footer:hover {
    opacity: 1;
}

/* Active Scans Table Column Alignment */
.scan-table td:nth-child(4), /* Progress column */
.scan-table th:nth-child(4),
.scan-table td:nth-child(5), /* Workers column */
.scan-table th:nth-child(5) {
    text-align: center;
}

.scan-table td:nth-child(8), /* Rate column */
.scan-table th:nth-child(8),
.scan-table td:nth-child(9), /* Issues column */
.scan-table th:nth-child(9) {
    text-align: right;
}

.scan-table td:nth-child(10), /* Actions column - Active Scans (Dashboard) */
.scan-table th:nth-child(10) {
    text-align: right;
}

/* Scans Table (on Scans page) - 8 columns */
#scansTable td:nth-child(8),
#scansTable th:nth-child(8) {
    text-align: right;
}

/* Organizations Table - 7 columns */
#orgsTable td:nth-child(7),
#orgsTable th:nth-child(7) {
    text-align: right;
}

/* Responsive */
@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }

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

    .container {
        padding: 1rem;
    }
}
