/* CSS Variables */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #22c55e;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* Header */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.header-actions {
    display: flex;
    gap: 0.75rem;
}

/* Buttons */
.btn {
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

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

.btn-secondary {
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

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

.btn-small {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

/* Main Content */
.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

/* Upload Section */
.upload-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 200px);
}

.upload-container {
    width: 100%;
    max-width: 600px;
}

.drop-zone {
    background: var(--surface);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 3rem 2rem;
    text-align: center;
    transition: all 0.2s ease;
    cursor: pointer;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.02);
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.upload-icon {
    width: 64px;
    height: 64px;
    color: var(--secondary-color);
}

.drop-zone h2 {
    font-size: 1.25rem;
    color: var(--text-primary);
}

.drop-zone p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.file-hint {
    font-size: 0.75rem !important;
    color: var(--secondary-color) !important;
}

.privacy-notice {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1.5rem;
    padding: 0.75rem 1rem;
    background: rgba(34, 197, 94, 0.1);
    border-radius: var(--radius-md);
    color: var(--success-color);
    font-size: 0.8125rem;
}

.privacy-notice svg {
    width: 16px;
    height: 16px;
}

/* Loading Section */
.loading-section {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 200px);
}

.loading-container {
    text-align: center;
    max-width: 400px;
}

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

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

.loading-container h2 {
    margin-bottom: 0.5rem;
}

.loading-container p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.progress-bar {
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    margin-top: 1.5rem;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color);
    transition: width 0.3s ease;
}

.progress-text {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Dashboard Section */
.dashboard-section {
    animation: fadeIn 0.3s ease;
}

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

/* Summary Bar */
.summary-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    padding: 1.25rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.stat-card.flagged {
    border-left: 4px solid var(--danger-color);
}

.stat-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

/* Filters Bar */
.filters-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    padding: 1rem 1.25rem;
    background: var(--surface);
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.toggle-group {
    display: flex;
    gap: 0.25rem;
}

.toggle-btn {
    padding: 0.375rem 0.75rem;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.toggle-btn:hover {
    background: var(--border-color);
}

.toggle-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.slider-container input[type="range"] {
    width: 150px;
}

#riskSliderValue {
    font-size: 0.875rem;
    font-weight: 500;
    min-width: 40px;
}

.search-input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    width: 200px;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.export-group {
    margin-left: auto;
}

.export-buttons {
    display: flex;
    gap: 0.5rem;
}

/* Table */
.table-container {
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.client-table {
    width: 100%;
    border-collapse: collapse;
}

.client-table th,
.client-table td {
    padding: 0.875rem 1rem;
    text-align: left;
}

.client-table th {
    background: var(--background);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.client-table th:hover {
    background: var(--border-color);
}

.sort-icon {
    margin-left: 0.25rem;
    opacity: 0.5;
}

.client-table th.sorted-asc .sort-icon::after {
    content: ' ▲';
}

.client-table th.sorted-desc .sort-icon::after {
    content: ' ▼';
}

.client-table tbody tr {
    border-top: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.15s ease;
}

.client-table tbody tr:hover {
    background: var(--background);
}

.client-table td {
    font-size: 0.875rem;
}

/* Risk Score Cell */
.risk-score {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.risk-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.risk-low { background: var(--success-color); }
.risk-medium { background: var(--warning-color); }
.risk-high { background: var(--danger-color); }

/* Status Badge */
.status-badge {
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

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

.status-badge.normal {
    background: rgba(34, 197, 94, 0.1);
    color: var(--success-color);
}

/* Client Type Badge */
.client-type-badge {
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
}

.client-type-badge.corporate {
    background: rgba(99, 102, 241, 0.1);
    color: #6366f1;
}

.client-type-badge.natural {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning-color);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
    padding: 1rem;
}

#pageInfo {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 1000;
    padding: 2rem;
    overflow-y: auto;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 1100px;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
    animation: modalSlide 0.2s ease;
}

.modal-small {
    max-width: 600px;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 10;
}

.modal-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.modal-title h2 {
    font-size: 1.25rem;
}

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

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0.25rem 0.5rem;
}

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

.modal-body {
    padding: 1.5rem;
}

/* Risk Overview */
.risk-overview {
    display: flex;
    align-items: center;
    gap: 2rem;
    padding: 1.5rem;
    background: var(--background);
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
}

.risk-score-large {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.score-value {
    font-size: 3rem;
    font-weight: 700;
    line-height: 1;
}

.score-value.low { color: var(--success-color); }
.score-value.medium { color: var(--warning-color); }
.score-value.high { color: var(--danger-color); }

.score-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.flag-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
}

.flag-status.flagged {
    background: rgba(239, 68, 68, 0.1);
}

.flag-status.normal {
    background: rgba(34, 197, 94, 0.1);
}

.flag-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.flag-status.flagged .flag-indicator {
    background: var(--danger-color);
}

.flag-status.normal .flag-indicator {
    background: var(--success-color);
}

.flag-text {
    font-weight: 500;
}

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

.flag-status.normal .flag-text {
    color: var(--success-color);
}

/* Charts */
.charts-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.chart-container {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.25rem;
}

.chart-container.full-width {
    margin-bottom: 1.5rem;
}

.chart-container h3 {
    font-size: 0.9375rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.chart-container canvas {
    max-height: 250px;
}

/* Details Grid */
.details-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.detail-card {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.25rem;
}

.detail-card h3 {
    font-size: 0.9375rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.detail-table {
    width: 100%;
    font-size: 0.8125rem;
}

.detail-table th,
.detail-table td {
    padding: 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.detail-table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
}

/* Flags List */
.flags-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.flag-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--background);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
}

.flag-item.warning {
    background: rgba(245, 158, 11, 0.1);
    border-left: 3px solid var(--warning-color);
}

.flag-item.danger {
    background: rgba(239, 68, 68, 0.1);
    border-left: 3px solid var(--danger-color);
}

.no-flags {
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-align: center;
    padding: 1rem;
}

/* Round Trips List */
.round-trips-list {
    max-height: 200px;
    overflow-y: auto;
}

.round-trip-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.75rem;
    background: rgba(239, 68, 68, 0.05);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    font-size: 0.8125rem;
}

.round-trip-item strong {
    color: var(--text-primary);
}

.round-trip-item span {
    color: var(--text-secondary);
}

.round-trip-item .days {
    color: var(--danger-color);
    font-weight: 500;
}

/* Factor Scores */
.factor-scores {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.factor-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.factor-label {
    flex: 0 0 140px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.factor-bar {
    flex: 1;
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.factor-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

.factor-fill.low { background: var(--success-color); }
.factor-fill.medium { background: var(--warning-color); }
.factor-fill.high { background: var(--danger-color); }

.factor-value {
    flex: 0 0 40px;
    text-align: right;
    font-size: 0.8125rem;
    font-weight: 500;
}

/* Settings Modal */
.settings-hint {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.weight-sliders {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.weight-item {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.weight-item label {
    flex: 0 0 160px;
    font-size: 0.875rem;
}

.weight-item input[type="range"] {
    flex: 1;
}

.weight-value {
    flex: 0 0 40px;
    text-align: right;
    font-weight: 500;
}

.weight-total {
    text-align: right;
    font-weight: 600;
    padding: 0.75rem;
    background: var(--background);
    border-radius: var(--radius-sm);
    margin-bottom: 1.5rem;
}

.threshold-settings {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.threshold-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.threshold-item label {
    font-size: 0.875rem;
}

.threshold-item input {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    width: 100px;
}

.api-settings {
    margin-bottom: 1.5rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    cursor: pointer;
}

.settings-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

/* Responsive */
@media (max-width: 1024px) {
    .charts-row {
        grid-template-columns: 1fr;
    }

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

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 1rem;
    }

    .filters-bar {
        flex-direction: column;
    }

    .export-group {
        margin-left: 0;
    }

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

    .modal {
        padding: 1rem;
    }

    .modal-content {
        max-height: calc(100vh - 2rem);
    }

    .risk-overview {
        flex-direction: column;
        text-align: center;
    }
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.masked {
    filter: blur(5px);
    user-select: none;
}
