/* ===== CSS Variables & Reset ===== */
:root {
    /* Primary -- modern indigo-blue */
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --primary-50: #e0e7ff;
    --primary-100: #c7d2fe;

    /* Status colors */
    --success: #059669;
    --success-light: #ecfdf5;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --warning: #d97706;
    --warning-light: #fffbeb;

    /* Gray scale -- warm slate tones */
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;

    /* Layout tokens */
    --sidebar-width: 260px;
    --topbar-height: 60px;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    /* Shadows -- modern layered */
    --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.04);

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.6;
    display: flex;
    min-height: 100vh;
    font-feature-settings: 'tnum' 1, 'ss01' 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    letter-spacing: -0.006em;
}

::selection {
    background: var(--primary-100);
    color: var(--primary-dark);
}

::placeholder {
    color: var(--gray-400);
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #0f172a 0%, #1e1b4b 100%);
    color: white;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    transition: transform var(--transition-slow);
    overflow-y: auto;
    border-right: 1px solid rgba(255,255,255,0.06);
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

.sidebar-header {
    padding: 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header h2 {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
    background: linear-gradient(135deg, #c7d2fe, #e0e7ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.sidebar-toggle:hover { background: rgba(255,255,255,0.1); color: white; }

#sidebarClose { display: none; }

.nav-menu {
    list-style: none;
    padding: 12px 0;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--gray-400);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition-fast);
    border-left: 3px solid transparent;
    margin: 2px 8px 2px 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.nav-link:hover {
    color: white;
    background: rgba(255,255,255,0.06);
}

.nav-link.active {
    color: white;
    background: rgba(79,70,229,0.15);
    border-left-color: var(--primary);
}

.nav-icon {
    width: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.85;
    flex-shrink: 0;
}

.nav-link.active .nav-icon { opacity: 1; }

/* ===== Main Content ===== */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
}

.topbar {
    height: var(--topbar-height);
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    padding: 0 28px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar h1 {
    font-size: 18px;
    font-weight: 600;
    flex: 1;
    letter-spacing: -0.02em;
    color: var(--gray-900);
}

.topbar .sidebar-toggle { color: var(--gray-700); display: none; }
.topbar-right { font-size: 13px; color: var(--gray-500); font-weight: 500; }

.page-content {
    padding: 28px;
    animation: pageIn 0.25s ease;
}

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

/* ===== Cards ===== */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
    border: 1px solid var(--gray-100);
    transition: box-shadow var(--transition-base);
}

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

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--gray-200);
}

.card-header h3 {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--gray-900);
}

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

.stat-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    text-align: center;
    border: 1px solid var(--gray-100);
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), #818cf8);
    border-radius: var(--radius) var(--radius) 0 0;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* Clickable stat cards */
.stat-clickable {
    cursor: pointer;
    user-select: none;
}
.stat-clickable:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(79, 70, 229, 0.15);
    border-color: var(--primary-light, #c7d2fe);
}
.stat-clickable:active {
    transform: translateY(0);
}
.stat-click-hint {
    font-size: 11px;
    color: var(--gray-400);
    margin-top: 6px;
    opacity: 0;
    transition: opacity 0.2s;
}
.stat-clickable:hover .stat-click-hint {
    opacity: 1;
    color: var(--primary);
}

.stat-value {
    font-size: 30px;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 13px;
    color: var(--gray-500);
    margin-top: 6px;
    font-weight: 500;
}

/* ===== Form Styles ===== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

select, input[type="text"], input[type="number"], input[type="date"], textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    transition: all var(--transition-fast);
    background: white;
    color: var(--gray-900);
    line-height: 1.5;
}

select:hover, input:hover, textarea:hover {
    border-color: var(--gray-400);
}

select:focus, input:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

input[type="number"] { text-align: right; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
    letter-spacing: -0.01em;
    position: relative;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 1px 2px rgba(79, 70, 229, 0.3);
}
.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.35);
    transform: translateY(-1px);
}
.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(79, 70, 229, 0.3);
}

.btn-success {
    background: var(--success);
    color: white;
    box-shadow: 0 1px 2px rgba(5, 150, 105, 0.3);
}
.btn-success:hover {
    background: #047857;
    box-shadow: 0 2px 8px rgba(5, 150, 105, 0.35);
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--danger);
    color: white;
    box-shadow: 0 1px 2px rgba(220, 38, 38, 0.3);
}
.btn-danger:hover {
    background: #b91c1c;
    transform: translateY(-1px);
}

.btn-outline {
    background: white;
    color: var(--primary);
    border: 1px solid var(--gray-300);
}
.btn-outline:hover {
    background: var(--primary-light);
    border-color: var(--primary);
}

.btn-sm { padding: 5px 12px; font-size: 12px; border-radius: 6px; }
.btn-icon { padding: 6px; min-width: 32px; justify-content: center; }

/* ===== Sub-tabs (Pill Style) ===== */
.sub-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    overflow-x: auto;
    padding: 4px;
    background: var(--gray-100);
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
}

.sub-tab {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-600);
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.sub-tab:hover {
    color: var(--gray-900);
    background: rgba(255,255,255,0.5);
}

.sub-tab.active {
    color: var(--primary);
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    font-weight: 600;
}

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

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

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}

thead th {
    background: var(--gray-50);
    padding: 12px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}

tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
    color: var(--gray-700);
}

tbody tr:hover { background: var(--gray-50); }

tbody tr:nth-child(even) {
    background: rgba(248, 250, 252, 0.5);
}
tbody tr:nth-child(even):hover {
    background: var(--gray-50);
}

td.number, th.number { text-align: right; }

td input[type="number"] {
    padding: 6px 8px;
    min-width: 90px;
    font-size: 13px;
}

/* ===== Summary Box ===== */
.summary-box {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 16px;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 14px;
}

.summary-row.total {
    border-top: 2px solid var(--gray-300);
    margin-top: 8px;
    padding-top: 12px;
    font-weight: 700;
    font-size: 16px;
}

.summary-row.highlight {
    color: var(--primary);
    font-weight: 600;
}

.summary-row.danger { color: var(--danger); font-weight: 600; }
.summary-row.success { color: var(--success); font-weight: 600; }

.summary-label { color: var(--gray-700); }
.summary-value { font-weight: 600; font-variant-numeric: tabular-nums; }

/* Tax entry form in tax reports page */
.tax-entry-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
}
.tax-entry-table th,
.tax-entry-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--gray-200);
    text-align: left;
}
.tax-entry-table th {
    background: var(--gray-50);
    font-weight: 600;
    font-size: 13px;
    color: var(--gray-700);
}
.tax-entry-table input[type="number"] {
    max-width: 120px;
}
.tax-entry-table select {
    width: 100%;
    max-width: 220px;
    padding: 4px 6px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 13px;
}
.tax-entry-auto-calc {
    color: var(--gray-500);
    font-variant-numeric: tabular-nums;
    font-size: 13px;
}
.tax-entry-total td {
    border-top: 2px solid var(--gray-400);
    font-weight: 600;
}

/* ===== Badges ===== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-warning { background: var(--warning-light); color: var(--warning); }

/* ===== Section Header ===== */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.section-header h3 { font-size: 15px; font-weight: 600; }

/* ===== Expense Category Chips ===== */
.chip-group { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

/* ===== Finance Summary Panel ===== */
.finance-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.finance-panel {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    border: 1px solid var(--gray-100);
}

.finance-panel h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--gray-200);
}

/* ===== Fuel Type Colors ===== */
.fuel-diesel { border-left: 4px solid #10b981; }
.fuel-gasohol95 { border-left: 4px solid #3b82f6; }
.fuel-gasohol91 { border-left: 4px solid #f59e0b; }
.fuel-benzyne95 { border-left: 4px solid #8b5cf6; }
.fuel-e20 { border-left: 4px solid #ef4444; }
.fuel-dieselpremium { border-left: 4px solid #06b6d4; }
.fuel-gasohol95p { border-left: 4px solid #6366f1; }
.fuel-lpg { border-left: 4px solid #78716c; }

/* ===== Alert/Toast ===== */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 14px 24px;
    border-radius: var(--radius);
    color: white;
    font-size: 14px;
    font-weight: 500;
    z-index: 9999;
    animation: toastSlideIn 0.3s ease, toastFadeOut 0.3s ease 2.7s;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }

@keyframes toastSlideIn {
    from { transform: translateY(-20px) translateX(20px); opacity: 0; }
    to { transform: translateY(0) translateX(0); opacity: 1; }
}
@keyframes toastFadeOut {
    from { opacity: 1; }
    to { opacity: 0; transform: translateY(-10px); }
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray-500);
}

.empty-state p { font-size: 14px; margin-top: 8px; }

/* ===== History List ===== */
.history-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-200);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.history-item:hover { background: var(--gray-50); }

.history-date {
    font-size: 13px;
    color: var(--gray-600);
    min-width: 90px;
}

.history-station { font-weight: 600; flex: 1; }
.history-amount { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    #sidebarClose { display: flex; }
    .topbar .sidebar-toggle { display: flex; }
    .main-content { margin-left: 0; }
    .page-content { padding: 16px; }
    .form-row { grid-template-columns: 1fr; }
    .finance-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .cash-shift-grid { grid-template-columns: 1fr !important; }
}

/* ===== Print ===== */
@media print {
    .sidebar, .topbar, .btn, .sub-tabs { display: none !important; }
    .main-content { margin-left: 0; }
    .card { box-shadow: none; border: 1px solid #ddd; }
    .stat-card::before { display: none; }
}

/* ===== Variance Highlighting ===== */
.variance-positive { color: var(--success); }
.variance-negative { color: var(--danger); font-weight: 600; }

/* ===== Low Stock Warning (< 3000 liters) ===== */
.stock-low-cell { border: 2px solid var(--danger) !important; border-radius: var(--radius); background: #fff5f5; color: var(--danger); font-weight: 600; }

/* ===== Compare Stations Page ===== */
.compare-station-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
}
.compare-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    cursor: pointer;
    transition: all 150ms;
    font-size: 0.9rem;
}
.compare-checkbox:hover { background: var(--gray-50); border-color: var(--primary); }
.compare-checkbox input:checked + span { color: var(--primary); font-weight: 600; }
.compare-table { width: 100%; border-collapse: collapse; }
.compare-table th, .compare-table td { padding: 3px 10px; border-bottom: 1px solid var(--gray-200); font-size: 14px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; }
.compare-table thead th { background: #f8fafc; font-weight: 600; position: sticky; top: 0; }

/* Thai date input: native input visible but text transparent, Thai overlay on top */
.thai-date-native {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    background: #fff;
    font-size: 15px;
    cursor: pointer;
    color: transparent;
}
.thai-date-native:focus { border-color: var(--primary); outline: none; }
.thai-date-native:hover { border-color: var(--primary); }
.thai-date-native::-webkit-datetime-edit { color: transparent; }
.thai-date-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: calc(100% - 40px);
    height: 100%;
    padding: 10px 14px;
    font-size: 15px;
    pointer-events: none;
    display: flex;
    align-items: center;
    color: var(--gray-800);
    white-space: nowrap;
}

@media (max-width: 768px) {
    .compare-station-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Meter Warning ===== */
.meter-warning {
    display: inline-block;
    background: #fef3c7;
    color: #92400e;
    font-size: 0.8rem;
    padding: 4px 10px;
    border-radius: 6px;
    border-left: 3px solid #f59e0b;
    line-height: 1.5;
}

/* ===== Chart Drill-Down Modal ===== */
/* ===== Full-page Drill-Down ===== */
.drill-fullpage {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: var(--gray-50, #f8fafc);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.drill-fullpage.active {
    transform: translateX(0);
}
.drill-fullpage-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 24px;
    background: white;
    border-bottom: 1px solid var(--gray-200);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    flex-shrink: 0;
}
.drill-fullpage-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--gray-800);
    margin: 0;
    flex: 1;
}
.drill-back-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    padding: 8px 16px;
    border-radius: 8px;
    flex-shrink: 0;
}
.drill-record-count {
    background: var(--primary);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
}
.drill-fullpage-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    -webkit-overflow-scrolling: touch;
}
.drill-fullpage-body .table-wrapper {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    overflow-x: auto;
}
.drill-fullpage-body table {
    width: 100%;
    font-size: 14px;
    border-collapse: collapse;
}
.drill-fullpage-body thead th {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--gray-500);
    padding: 12px 16px;
    background: var(--gray-50, #f8fafc);
    border-bottom: 2px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 1;
    white-space: nowrap;
}
.drill-fullpage-body td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-100);
    white-space: nowrap;
}
.drill-fullpage-body tbody tr:hover {
    background: var(--gray-50, #f8fafc);
}
.drill-total-row {
    background: linear-gradient(135deg, #eef2ff, #e0e7ff) !important;
    font-weight: 600;
}
.drill-total-row td {
    border-bottom: 2px solid var(--primary) !important;
    padding: 14px 16px !important;
    color: var(--primary-dark);
}
.drill-fullpage-body .btn-sm {
    padding: 6px 14px;
    font-size: 12px;
    border-radius: 6px;
    background: var(--primary);
    color: white;
    border: none;
    cursor: pointer;
    transition: background 0.15s;
}
.drill-fullpage-body .btn-sm:hover {
    background: var(--primary-dark);
}
@media (max-width: 768px) {
    .drill-fullpage-header {
        padding: 12px 16px;
        gap: 10px;
    }
    .drill-fullpage-header h2 {
        font-size: 15px;
    }
    .drill-back-btn {
        padding: 6px 12px;
        font-size: 13px;
    }
    .drill-fullpage-body {
        padding: 12px;
    }
    .drill-fullpage-body thead th,
    .drill-fullpage-body td {
        padding: 10px 12px;
        font-size: 13px;
    }
}

/* ===== Loading ===== */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--gray-300);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ===== Fuel Price Input Row ===== */
.price-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.price-input-row label {
    min-width: 140px;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-700);
}

.price-input-row input {
    max-width: 120px;
}

/* ===== Tank Group ===== */
.tank-group {
    margin-bottom: 24px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    overflow: hidden;
}

.tank-group-header {
    background: var(--gray-100);
    padding: 10px 16px;
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tank-group-body { padding: 12px 16px; }

/* ===== Delete button for rows ===== */
.btn-delete-row {
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    font-size: 18px;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.btn-delete-row:hover { background: var(--danger-light); color: var(--danger); }

/* ===== Modal Overlay ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    animation: fadeIn 0.15s ease;
}

.modal {
    background: white;
    border-radius: var(--radius-lg);
    padding: 28px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    animation: scaleIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

.modal h3 { margin-bottom: 16px; }
.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* ===== Summary Tab Utility Classes ===== */
.price-header-flex {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--gray-200);
}

.price-header-flex h4 { margin: 0; border: none; padding: 0; }

.fuel-price-updated {
    font-size: 11px;
    color: var(--gray-500);
    margin-top: 2px;
}

.price-warning {
    padding: 10px 14px;
    background: var(--warning-light);
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 12px;
    color: var(--warning);
}

.actual-cash-section {
    margin-top: 16px;
    padding: 20px;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
}

.actual-cash-section h4 {
    margin-bottom: 12px;
    font-size: 15px;
    font-weight: 600;
    border: none;
    padding: 0;
}

.cash-shift-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.cash-shift-box {
    padding: 14px;
    background: var(--gray-50);
    border-radius: var(--radius-sm);
    border: 1px solid var(--gray-200);
}

.cash-shift-label {
    font-size: 13px;
    color: var(--gray-600);
    margin-bottom: 6px;
    font-weight: 500;
}

.cash-shift-input {
    font-size: 16px;
    font-weight: 600;
    width: 100%;
}

.slip-container { margin-top: 10px; }

.slip-thumbnail {
    max-width: 120px;
    max-height: 80px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--gray-300);
    cursor: pointer;
    transition: opacity var(--transition-fast);
}

.slip-thumbnail:hover { opacity: 0.85; }

.slip-wrapper {
    position: relative;
    display: inline-block;
}

.slip-delete-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.compact-input { max-width: 120px; }
.remark-input { max-width: 300px; }

.table-row-clickable { cursor: pointer; }
.table-row-summary { background: var(--gray-100); font-weight: 600; }

.info-banner {
    margin-bottom: 16px;
    padding: 10px 14px;
    background: var(--primary-light);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.form-actions {
    margin-top: 20px;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* Focus-visible accessibility */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

:focus:not(:focus-visible) {
    outline: none;
}

/* Table footer style */
tfoot tr {
    background: var(--gray-100);
    font-weight: 700;
}

tfoot td {
    padding: 10px 14px;
    border-top: 2px solid var(--gray-200);
}

/* ===== Dashboard Filters & Charts ===== */
.dashboard-filters {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-100);
    padding: 16px 20px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-600);
    white-space: nowrap;
}

.filter-group select,
.filter-group input {
    width: auto;
    min-width: 140px;
    padding: 7px 12px;
    font-size: 13px;
}

.period-tabs {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    background: var(--gray-100);
    border-radius: var(--radius-sm);
    border: 1px solid var(--gray-200);
}

.period-tab {
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-600);
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: 6px;
    font-family: inherit;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.period-tab:hover {
    color: var(--gray-900);
}

.period-tab.active {
    color: var(--primary);
    background: white;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    font-weight: 600;
}

.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 14px;
    margin-bottom: 16px;
}

.chart-section {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-100);
    padding: 14px;
    transition: box-shadow var(--transition-base);
}

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

.chart-section.full-width {
    grid-column: 1 / -1;
}

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

.chart-header h3 {
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-800);
    letter-spacing: -0.01em;
}

.chart-type-btns {
    display: flex;
    gap: 4px;
    padding: 2px;
    background: var(--gray-100);
    border-radius: 6px;
}

.chart-type-btn {
    padding: 5px 8px;
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: 4px;
    color: var(--gray-500);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.chart-type-btn:hover {
    color: var(--gray-700);
}

.chart-type-btn.active {
    background: white;
    color: var(--primary);
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.chart-container {
    position: relative;
    width: 100%;
    min-height: 180px;
}

.chart-container canvas {
    width: 100% !important;
}

.chart-no-data {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 8px;
    min-height: 200px;
    color: var(--gray-400);
    font-size: 14px;
    background: var(--gray-50);
    border-radius: 8px;
    border: 1px dashed var(--gray-200);
}

@media (max-width: 768px) {
    .charts-grid { grid-template-columns: 1fr; }
    .dashboard-filters { flex-direction: column; align-items: stretch; }
    .filter-group { flex-wrap: wrap; }
    .filter-group select,
    .filter-group input { min-width: 100%; }
    .chart-container { min-height: 160px; }
}

/* ===== TAX REPORT STYLES ===== */
.tax-report {
    background: #fff;
    padding: 24px;
    border-radius: 12px;
    border: 1px solid var(--gray-200);
    margin-top: 16px;
    overflow-x: auto;
}
.tax-report-header {
    text-align: center;
    margin-bottom: 16px;
}
.tax-report-header h2 {
    font-size: 16px;
    font-weight: 700;
    margin: 0 0 8px;
}
.tax-report-meta {
    font-size: 13px;
    line-height: 1.6;
    position: relative;
    text-align: left;
}
.tax-report-meta p {
    margin: 0;
}
.tax-report-meta-toprow {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 16px;
    margin-bottom: 4px;
}
.tax-report-section-label {
    display: inline-block;
    border: 2px solid var(--primary);
    color: var(--primary);
    font-weight: 700;
    padding: 2px 16px;
    border-radius: 4px;
    font-size: 15px;
    flex-shrink: 0;
}
.tax-report-table {
    border-collapse: collapse;
    font-size: 12px;
    margin-top: 12px;
    table-layout: auto;
    width: 100%;
}
.tax-report-table .col-no-width { width: 30px; }
.tax-report-table .col-meter { }
.tax-report-table .col-liters { }
.tax-report-table .col-baht { }
.tax-report-table th,
.tax-report-table td {
    border: 1px solid var(--gray-300);
    padding: 4px 6px;
    text-align: center;
}
.tax-report-table td {
    white-space: nowrap;
}
.tax-report-table th {
    background: var(--gray-50);
    font-weight: 600;
    font-size: 11px;
}
.tax-report-table td.number {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.tax-report-table .tax-summary-row {
    background: var(--gray-50);
    font-weight: 600;
}
.tax-report-table .tax-summary-row td {
    border-top: 2px solid var(--gray-400);
}
.tax-report-table .tax-summary-row td,
.tax-report-table .summary-label {
    font-size: 12px;
}
.tax-report-table .col-no {
    width: 36px;
    min-width: 36px;
    max-width: 50px;
}
.tax-report-table .summary-label {
    text-align: left;
    white-space: nowrap;
    font-size: 11px;
}
.report-b-table td:first-child,
.report-b-table th:first-child {
    text-align: left;
    white-space: normal;
    word-break: keep-all;
    overflow-wrap: break-word;
}
.tax-report-vat-summary {
    margin-top: 12px;
    padding: 8px 12px;
    background: #f0f0ff;
    border-radius: 8px;
    font-size: 14px;
    text-align: center;
}
.tax-report-vat-totals {
    margin-top: 12px;
    padding: 10px 16px;
    background: #f0f0ff;
    border-radius: 8px;
    font-size: 13px;
}
.vat-detail-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 3px 0;
}
.vat-detail-row span:first-child {
    min-width: 280px;
}
.vat-detail-row strong {
    min-width: 100px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.vat-detail-row.vat-input {
    border-top: 1px solid var(--gray-300);
    margin-top: 4px;
    padding-top: 6px;
}
.tax-report-bottom-section {
    display: flex;
    gap: 16px;
    margin-top: 16px;
    align-items: flex-start;
}
.tax-report-invoices {
    flex: 1;
    min-width: 0;
}
.invoice-section-title {
    font-size: 12px;
    font-weight: 600;
    margin: 12px 0 4px;
    color: var(--gray-700);
}
.invoice-section-title:first-child {
    margin-top: 0;
}
.invoice-detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}
.invoice-detail-table td {
    padding: 3px 5px;
    border: 1px solid var(--gray-300);
    white-space: nowrap;
}
.invoice-detail-table td.inv-val {
    min-width: 40px;
    text-align: center;
    font-weight: 600;
}
.tax-report-invoice-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 16px;
}
.tax-report-invoice-block {
    padding: 12px;
    background: var(--gray-50);
    border-radius: 8px;
    border: 1px solid var(--gray-200);
}
.tax-report-invoice-block h4 {
    font-size: 13px;
    font-weight: 600;
    margin: 0 0 8px;
    color: var(--primary);
}
.tax-report-invoice-block p {
    font-size: 12px;
    margin: 2px 0;
}
.tax-report-prices {
    flex-shrink: 0;
    width: 200px;
    padding: 12px;
    background: var(--gray-50);
    border-radius: 8px;
    border: 1px solid var(--gray-200);
}
.tax-report-prices h4 {
    font-size: 13px;
    font-weight: 600;
    margin: 0 0 8px;
    color: var(--primary);
}
.tax-report-prices p {
    font-size: 12px;
    margin: 4px 0;
    display: flex;
    justify-content: space-between;
    gap: 8px;
}
.tax-report-prices .price-label {
    font-weight: 600;
}
.tax-report-prices .price-value {
    text-align: right;
}
.tax-report-delivery {
    margin-top: 12px;
    padding: 12px;
    border-top: 1px dashed var(--gray-300);
}

/* Print overlay (hidden on screen) */
#tax-print-overlay { display: none; }

/* Print styles for tax reports */
@media print {
    @page { size: A4 landscape; margin: 5mm; }

    /* Hide everything except the print overlay */
    body > *:not(#tax-print-overlay) { display: none !important; }
    #tax-print-overlay { display: block !important; }

    .print-page {
        page-break-after: always;
    }
    .print-page:last-child {
        page-break-after: auto;
    }

    .tax-report {
        border: none;
        border-radius: 0;
        padding: 0;
        margin: 0;
        box-shadow: none;
        overflow: visible !important;
    }
    .tax-report-table th,
    .tax-report-table td { border-color: #000; }
}

@media (max-width: 768px) {
    .tax-report-invoice-section { grid-template-columns: 1fr; }
}

/* ===== Login Page ===== */
.login-page {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, #1e1b4b 100%);
    z-index: 9999;
}
.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-header {
    text-align: center;
    margin-bottom: 32px;
}
.login-header h1 {
    font-size: 22px;
    color: var(--primary);
    margin: 12px 0 4px;
}
.login-header p {
    color: var(--gray-500);
    font-size: 14px;
    margin: 0;
}
.login-form .form-group {
    margin-bottom: 16px;
}
.login-form input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 15px;
    box-sizing: border-box;
}
.login-form input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* ===== User Info in Topbar ===== */
.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 12px;
}
#userDisplayName {
    font-size: 13px;
    color: var(--gray-600);
    font-weight: 500;
}
.role-badge {
    font-size: 11px;
    padding: 2px 10px;
    border-radius: 12px;
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}
.btn-logout {
    background: none;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    padding: 4px 12px;
    font-size: 12px;
    cursor: pointer;
    color: var(--gray-600);
    transition: all 0.15s;
}
.btn-logout:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Force Sync button (visible to all users) */
.btn-sync {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #ecfdf5;
    border: 1px solid #10b981;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    color: #065f46;
    transition: all 0.15s;
    margin-right: 8px;
}
.btn-sync:hover {
    background: #10b981;
    color: white;
}
.btn-sync:active {
    transform: scale(0.96);
}
.btn-sync .sync-icon {
    font-size: 14px;
    line-height: 1;
    display: inline-block;
}
.btn-sync.syncing .sync-icon {
    animation: spin 1s linear infinite;
}
.btn-sync.has-pending {
    background: #fef3c7;
    border-color: #f59e0b;
    color: #92400e;
}
.btn-sync.has-pending:hover {
    background: #f59e0b;
    color: white;
}
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
@media (max-width: 640px) {
    .btn-sync .sync-label { display: none; }
    .btn-sync { padding: 6px 8px; }
}

/* Reload-from-Supabase button */
.btn-reload {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #eff6ff;
    border: 1px solid #3b82f6;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    color: #1e40af;
    transition: all 0.15s;
    margin-right: 8px;
}
.btn-reload:hover {
    background: #3b82f6;
    color: white;
}
.btn-reload:active {
    transform: scale(0.96);
}
.btn-reload .reload-icon {
    font-size: 14px;
    line-height: 1;
    display: inline-block;
}
@media (max-width: 640px) {
    .btn-reload .reload-label { display: none; }
    .btn-reload { padding: 6px 8px; }
}

/* Section Toggle Grid */
.section-toggle-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
}
.section-toggle-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.15s;
    user-select: none;
}
.section-toggle-item:hover {
    background: var(--gray-100);
}
.section-toggle-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    border-top: 1px solid var(--gray-200);
    flex-wrap: wrap;
}
.pagination-btn {
    min-width: 36px;
    height: 36px;
    border: 1px solid var(--gray-200);
    background: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--gray-600);
    transition: all 0.15s;
}
.pagination-btn:hover:not(:disabled):not(.active) {
    background: var(--gray-100);
    border-color: var(--gray-300);
}
.pagination-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    font-weight: 600;
}
.pagination-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.pagination-dots {
    padding: 0 4px;
    color: var(--gray-400);
}

@media (max-width: 768px) {
    .login-card { margin: 16px; padding: 28px; }
    .user-info { display: none; }
}
