:root {
    --background: 0 0% 100%;
    --foreground: 222.2 84% 4.9%;
    --card: 0 0% 100%;
    --card-foreground: 222.2 84% 4.9%;
    --popover: 0 0% 100%;
    --popover-foreground: 222.2 84% 4.9%;
    --primary: 222.2 47.4% 11.2%;
    --primary-foreground: 210 40% 98%;
    --secondary: 210 40% 96.1%;
    --secondary-foreground: 222.2 47.4% 11.2%;
    --muted: 210 40% 96.1%;
    --muted-foreground: 215.4 16.3% 46.9%;
    --accent: 210 40% 96.1%;
    --accent-foreground: 222.2 47.4% 11.2%;
    --destructive: 0 84.2% 60.2%;
    --destructive-foreground: 210 40% 98%;
    --border: 214.3 31.8% 91.4%;
    --input: 214.3 31.8% 91.4%;
    --ring: 222.2 84% 4.9%;
    --radius: 0.5rem;
}

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

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

.dashboard-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

/* Header */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.header-logo-title {
    display: flex;
    align-items: center;
    gap: 16px;
}

.dashboard-logo {
    height: 60px;
    width: auto;
    object-fit: contain;
}

.header-left h1 {
    font-size: 30px;
    font-weight: 700;
    letter-spacing: -0.025em;
    margin-bottom: 4px;
}

.subtitle {
    color: hsl(var(--muted-foreground));
    font-size: 14px;
}

.time-period-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.button-group {
    display: flex;
    gap: 4px;
    background: hsl(var(--muted));
    padding: 4px;
    border-radius: var(--radius);
}

.period-btn {
    padding: 6px 12px;
    border: none;
    background: transparent;
    color: hsl(var(--foreground));
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: calc(var(--radius) - 2px);
    transition: all 0.2s;
}

.period-btn:hover {
    background: hsl(var(--accent));
}

.period-btn.active {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
}

.custom-date-picker {
    position: relative;
}

.custom-date-picker.hidden {
    display: none;
}

.date-picker-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border: 1px solid hsl(var(--border));
    background: hsl(var(--background));
    border-radius: var(--radius);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.date-picker-btn:hover {
    background: hsl(var(--accent));
}

.date-picker-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: hsl(var(--popover));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    z-index: 50;
    min-width: 300px;
}

.date-picker-dropdown.hidden {
    display: none;
}

.date-inputs {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 12px;
}

.date-inputs label {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
    display: block;
}

.date-inputs input[type="date"] {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    font-size: 14px;
}

.apply-btn {
    width: 100%;
    padding: 8px 16px;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

.apply-btn:hover {
    opacity: 0.9;
}

/* Quick Stats Grid */
.quick-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.metric-card {
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    padding: 24px;
    cursor: pointer;
    transition: all 0.2s;
}

.metric-card:hover {
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

.metric-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.metric-title {
    font-size: 14px;
    font-weight: 500;
    color: hsl(var(--foreground));
}

.metric-icon {
    width: 16px;
    height: 16px;
    stroke-width: 2;
}

.metric-icon.success {
    color: #16a34a;
}

.metric-icon.warning {
    color: #ca8a04;
}

.metric-icon.default {
    color: hsl(var(--muted-foreground));
}

.metric-value {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}

.metric-description {
    font-size: 12px;
    color: hsl(var(--muted-foreground));
    margin-bottom: 8px;
}

.metric-trend {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
}

.metric-trend.up {
    color: #16a34a;
}

.metric-trend.down {
    color: #dc2626;
}

.trend-icon {
    width: 12px;
    height: 12px;
    stroke-width: 2;
}

/* Main Content Grid */
.main-content-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 24px;
    margin-bottom: 24px;
}

.content-card {
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    overflow: hidden;
}

.card-header {
    padding: 24px 24px 0 24px;
    margin-bottom: 16px;
}

.card-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
}

.title-icon {
    width: 20px;
    height: 20px;
    stroke-width: 2;
}

.card-description {
    font-size: 14px;
    color: hsl(var(--muted-foreground));
}

.card-content {
    padding: 0 24px 24px 24px;
}

.metric-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid hsl(var(--border));
    cursor: pointer;
    transition: background 0.2s;
}

.metric-row:hover {
    background: hsl(var(--accent));
    margin: 0 -12px;
    padding: 12px;
    border-radius: var(--radius);
}

.metric-row:last-child {
    border-bottom: none;
}

.metric-row-label {
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

.metric-row-label .icon {
    width: 12px;
    height: 12px;
}

.badge {
    padding: 2px 10px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 600;
}

.badge.secondary {
    background: hsl(var(--secondary));
    color: hsl(var(--secondary-foreground));
}

.badge.destructive {
    background: hsl(var(--destructive));
    color: hsl(var(--destructive-foreground));
}

.badge.outline {
    border: 1px solid hsl(var(--border));
    background: transparent;
}

.badge.success {
    background: #dcfce7;
    color: #166534;
}

.divider {
    margin: 16px 0;
    padding-top: 16px;
    border-top: 1px solid hsl(var(--border));
}

.progress-item {
    margin-bottom: 16px;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.progress-label {
    font-size: 14px;
    font-weight: 500;
}

.progress-value {
    font-size: 14px;
    font-weight: 700;
}

.progress-bar-container {
    width: 100%;
    height: 8px;
    background: hsl(var(--secondary));
    border-radius: 9999px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: hsl(var(--primary));
    transition: width 0.3s;
    border-radius: 9999px;
}

.progress-bar.success {
    background: #16a34a;
}

.progress-bar.destructive {
    background: #dc2626;
}

.progress-subtitle {
    font-size: 12px;
    color: hsl(var(--muted-foreground));
    margin-top: 4px;
}

.performance-box {
    padding: 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.performance-box.success {
    background: #f0fdf4;
}

.performance-box.destructive {
    background: #fef2f2;
}

.performance-box .box-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.performance-box .box-title {
    font-size: 14px;
    font-weight: 500;
}

.performance-box.success .box-title {
    color: #166534;
}

.performance-box.destructive .box-title {
    color: #991b1b;
}

.performance-box .box-value {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.performance-box.success .box-value {
    color: #166534;
}

.performance-box.destructive .box-value {
    color: #991b1b;
}

.performance-box .box-subtitle {
    font-size: 12px;
    margin-top: 8px;
}

.performance-box.success .box-subtitle {
    color: #15803d;
}

.performance-box.destructive .box-subtitle {
    color: #b91c1c;
}

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

.metrics.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th,
.data-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid hsl(var(--border));
}

.data-table th {
    background: hsl(var(--muted));
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 10;
}

.filter-row th {
    background: hsl(var(--card));
    padding: 8px;
}

.column-filter {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid hsl(var(--border));
    border-radius: 4px;
    font-size: 13px;
    background: white;
}

.column-filter:focus {
    outline: none;
    border-color: hsl(var(--primary));
}

.column-filter::placeholder {
    color: #9ca3af;
    font-size: 12px;
}

.metrics-table {
    width: 100%;
    max-width: 600px;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
}

.metrics-table thead {
    background: linear-gradient(to bottom, hsl(var(--primary)), hsl(var(--primary) / 0.9));
    color: white;
}

.metrics-table thead th {
    padding: 10px 12px;
    font-weight: 600;
    text-align: center;
    font-size: 13px;
    letter-spacing: 0.025em;
}

.metrics-table thead th:first-child {
    text-align: left;
}

.metrics-table tbody tr {
    background: hsl(var(--card));
    transition: all 0.15s;
}

.metrics-table tbody tr:nth-child(even) {
    background: hsl(var(--muted) / 0.3);
}

.metrics-table tbody tr:hover {
    background: hsl(var(--muted));
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.metrics-table tbody td {
    padding: 8px 12px;
    border-bottom: 1px solid hsl(var(--border));
    font-size: 13px;
    vertical-align: middle;
}

.metrics-table tbody td:first-child {
    font-weight: 500;
    color: hsl(var(--foreground));
    text-align: left;
}

.metrics-table tbody td:last-child {
    text-align: center;
}

.metrics-table tr:last-child td {
    border-bottom: none;
}

.metrics-table .text-center {
    text-align: center;
    font-weight: 600;
    font-size: 14px;
}

.metrics-table .text-success {
    color: #16a34a;
    font-weight: 600;
}

.metrics-table .text-destructive {
    color: #dc2626;
    font-weight: 600;
}

.metrics-table .text-warning {
    color: #ea580c;
    font-weight: 600;
}

.metrics-table .text-warning {
    color: #ca8a04;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: hsl(var(--background));
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s ease-out;
}

.loading-screen.fade-out {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    text-align: center;
}

.loading-spinner-large {
    width: 60px;
    height: 60px;
    border: 4px solid hsl(var(--muted));
    border-top: 4px solid hsl(var(--primary));
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: hsl(var(--card));
    border-radius: var(--radius);
    width: 90%;
    max-width: 1000px;
    max-height: 85vh;
    overflow: hidden;
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1);
    display: flex;
    flex-direction: column;
}

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

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.export-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #16a34a;
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.export-btn:hover {
    background: #15803d;
}

.export-btn .icon {
    width: 16px;
    height: 16px;
}

.modal-close {
    background: hsl(var(--secondary));
    border: none;
    color: hsl(var(--foreground));
    font-size: 24px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: hsl(var(--muted));
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.loading-spinner {
    text-align: center;
    padding: 40px;
}

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

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

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

.data-table th {
    background: hsl(var(--muted));
    padding: 12px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    border-bottom: 2px solid hsl(var(--border));
}

.data-table td {
    padding: 14px 12px;
    border-bottom: 1px solid hsl(var(--border));
    font-size: 14px;
}

.data-table tr:hover {
    background: hsl(var(--accent));
}

.status-badge {
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}

.status-badge.completed {
    background: #dcfce7;
    color: #166534;
}

.status-badge.cancelled {
    background: #fee2e2;
    color: #991b1b;
}

.icon {
    width: 16px;
    height: 16px;
    stroke-width: 2;
}

.info-tooltip {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.info-icon {
    width: 16px;
    height: 16px;
    color: hsl(var(--muted-foreground));
    cursor: help;
    transition: color 0.2s;
}

.info-icon:hover {
    color: hsl(var(--primary));
}

.tooltip-text {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: hsl(var(--popover));
    color: hsl(var(--popover-foreground));
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    line-height: 1.5;
    white-space: normal;
    width: 280px;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    border: 1px solid hsl(var(--border));
    z-index: 1000;
    transition: opacity 0.2s, visibility 0.2s;
}

.tooltip-text::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: hsl(var(--popover));
}

.info-tooltip:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}

.tooltip-formula {
    background: hsl(var(--muted));
    padding: 6px 8px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 12px;
    margin: 6px 0;
    display: block;
}

.dashboard-footer {
    margin-top: 30px;
    padding: 20px 24px;
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    color: hsl(var(--muted-foreground));
    flex-wrap: wrap;
    gap: 12px;
}

#ksaDateTime {
    font-weight: 600;
    color: hsl(var(--foreground));
}

@media (max-width: 768px) {
    .dashboard-container {
        padding: 16px;
    }

    .dashboard-header {
        flex-direction: column;
    }
    
    .header-logo-title {
        flex-direction: column;
        text-align: center;
    }
    
    .dashboard-logo {
        height: 50px;
    }

    .main-content-grid {
        grid-template-columns: 1fr;
    }

    .quick-stats-grid {
        grid-template-columns: 1fr;
    }
    
    .footer-content {
        flex-direction: column;
        text-align: center;
    }
}
