@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Outfit:wght@600;700&display=swap');

:root {
    --primary: #394484;
    --primary-light: #5c67b3;
    --primary-dark: #2a3366;
    --secondary: #6366f1;
    --bg-main: #f8fafc;
    --bg-sidebar: #ffffff;
    --surface: #ffffff;
    --text-main: #111827;
    --text-muted: #64748b;
    --accent-green: #10b981;
    --accent-red: #ef4444;
    --border-color: #e2e8f0;
    --radius: 12px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

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

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
.logo-text {
    font-family: 'Outfit', sans-serif;
}

.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--bg-sidebar);
    padding: 2.5rem 1.5rem;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    height: 100vh;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 3.5rem;
}

.logo-icon {
    width: 38px;
    height: 38px;
    /*background: linear-gradient(135deg, var(--primary), var(--primary-light));*/
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.logo img {
    max-width: 100%;
    height: auto;
    object-fit: contain;
}

nav ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

nav a {
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 500;
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

nav li.active a {
    background-color: #f1f5f9;
    color: var(--primary);
}

nav a:hover:not(.active) {
    background-color: #f8fafc;
    color: var(--text-main);
    transform: translateX(4px);
}

.sync-status {
    margin-top: auto;
    padding-top: 2rem;
}

#sync-btn {
    width: 100%;
    padding: 0.85rem;
    border: none;
    border-radius: var(--radius);
    background: var(--primary);
    color: white;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 14px 0 rgba(57, 68, 132, 0.3);
}

#sync-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px 0 rgba(57, 68, 132, 0.4);
}

#sync-btn:active {
    transform: translateY(0);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2.5rem 3.5rem;
    width: 100%;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 3rem;
}

header h2 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.25rem;
}

header p {
    color: var(--text-muted);
    font-size: 1.1rem;
}

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

.month-filter {
    padding: 0.65rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--surface);
    color: var(--primary);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    outline: none;
    transition: all 0.2s;
}

.month-filter:hover {
    border-color: var(--primary);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 50px;
}

.avatar {
    width: 32px;
    height: 32px;
    background: #e2e8f0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--primary);
    font-size: 0.75rem;
}

/* Base Card */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    padding: 1.75rem;
    transition: box-shadow 0.3s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.75rem;
    margin-bottom: 2.5rem;
}

.stat-card {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

.stat-main {
    display: flex;
    flex-direction: column;
}

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.liters {
    background: #eff6ff;
    color: #2563eb;
}

.cost {
    background: #fdf2f8;
    color: #db2777;
}

.performance {
    background: #ecfdf5;
    color: #059669;
}

.distance {
    background: #fff7ed;
    color: #ea580c;
}

.stat-info h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-info p {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-main);
    font-family: 'Outfit', sans-serif;
}

/* Charts */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.75rem;
    margin-bottom: 2.5rem;
}

.chart-container {
    min-height: 400px;
    display: flex;
    flex-direction: column;
}

.chart-container h3 {
    font-size: 1.1rem;
    margin-bottom: 2rem;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chart-wrapper {
    flex: 1;
    position: relative;
    height: 450px;
}

/* Table Section */
.table-section {
    padding: 0;
    overflow: hidden;
}

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

.table-header h3 {
    font-size: 1.1rem;
}

.search-wrapper {
    position: relative;
}

.search-wrapper i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.table-header input {
    padding: 0.65rem 1rem 0.65rem 2.8rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: #f8fafc;
    width: 320px;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.table-header input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(57, 68, 132, 0.1);
}

.table-wrapper {
    overflow-x: auto;
    overflow-y: auto;
    max-height: 620px;
    /* Approximately 10 records + header */
    position: relative;
}

table {
    width: 100%;
    border-collapse: separate;
    /* Changed for better sticky header compatibility */
    border-spacing: 0;
}

th {
    position: sticky;
    top: 0;
    z-index: 10;
    text-align: left;
    padding: 1rem 1.75rem;
    background: #fcfcfd;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: 1.15rem 1.75rem;
    border-bottom: 1px solid #f8fafc;
    font-size: 0.95rem;
    color: #334155;
}

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

tr:hover td {
    background-color: #fcfcfd;
}

.badge {
    padding: 0.35rem 0.75rem;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.badge.high {
    background: #d1fae5;
    color: #065f46;
}

.badge.low {
    background: #fee2e2;
    color: #991b1b;
}

.gps-badge {
    background-color: #dcfce7;
    color: #15803d;
    border: 1px solid #bbf7d0;
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    margin-left: 0.5rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.gps-badge i {
    width: 12px;
    height: 12px;
    display: inline-block;
    vertical-align: middle;
}

/* Sortable Headers */
th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s;
    position: sticky;
    top: 0;
    z-index: 10;
    padding-right: 25px !important;
}

th.sortable:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

th.sortable i {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    transition: transform 0.3s, opacity 0.3s;
}

th.sortable.asc i {
    transform: translateY(-50%) rotate(180deg);
}

.map-btn {
    transition: color 0.2s, transform 0.2s;
}

.map-btn:hover {
    color: var(--primary-light) !important;
    transform: scale(1.2);
}

.spin {
    animation: spin-anim 1.5s linear infinite;
    display: inline-block;
}

@keyframes spin-anim {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Custom Searchable Select (Combobox) */
.searchable-select-container {
    position: relative;
    width: 500px;
    display: inline-block;
}

.searchable-select-trigger {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.65rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--surface);
    color: var(--primary);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.searchable-select-trigger:hover {
    border-color: var(--primary);
}

.searchable-select-trigger .dropdown-chevron {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.searchable-select-container.open .searchable-select-trigger .dropdown-chevron {
    transform: rotate(180deg);
}

.searchable-select-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    margin-top: 4px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 100;
    display: flex;
    flex-direction: column;
    max-height: 300px;
    overflow: hidden;
}

.searchable-select-dropdown .search-wrapper {
    position: relative;
    padding: 8px;
    border-bottom: 1px solid var(--border-color);
}

.searchable-select-dropdown .search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    color: var(--text-muted);
    pointer-events: none;
}

.searchable-select-dropdown .search-input {
    width: 100%;
    padding: 0.5rem 0.75rem 0.5rem 2rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.85rem;
    outline: none;
    background: #f8fafc;
}

.searchable-select-dropdown .search-input:focus {
    border-color: var(--primary);
    background: #ffffff;
    box-shadow: 0 0 0 2px rgba(57, 68, 132, 0.1);
}

.searchable-select-dropdown .options-list {
    overflow-y: auto;
    max-height: 220px;
}

.searchable-select-dropdown .option-item {
    padding: 0.65rem 1rem;
    font-size: 0.9rem;
    color: var(--text-main);
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.searchable-select-dropdown .option-item:hover {
    background: #f1f5f9;
    color: var(--primary);
}

.searchable-select-dropdown .option-item.selected {
    background: #eff6ff;
    color: var(--primary);
    font-weight: 600;
}

/* Hourly Distribution Modal */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    background: var(--surface);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    width: 90%;
    max-width: 850px;
    max-height: 85vh;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    transform: translateY(20px);
    transition: transform 0.3s ease;
    overflow: hidden;
}

.modal-backdrop.active .modal-card {
    transform: translateY(0);
}

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

.modal-header h3 {
    font-size: 1.1rem;
    margin: 0;
    color: var(--primary);
}

.modal-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.modal-close-btn:hover {
    background: #f1f5f9;
    color: var(--text-main);
}

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

.modal-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    gap: 1rem;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.modal-loader-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #e2e8f0;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin-anim 1s linear infinite;
}

.modal-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1.5rem;
}

.modal-table th {
    background: #f8fafc;
    position: static; /* override sticky on modal table */
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
}

.modal-table td {
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    border-bottom: 1px solid #f1f5f9;
}

.modal-table tr:hover td {
    background-color: #f8fafc;
}

/* Hourly Action button */
.btn-hourly-action {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--primary);
    padding: 6px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s, transform 0.15s;
}

.btn-hourly-action:hover {
    background: #eff6ff;
    color: var(--primary-light);
    transform: scale(1.1);
}