:root {
    --primary: #0F172A;
    --primary-light: #334155;
    --bg: #FAFAFA; /* Soft premium off-white */
    --surface: #FFFFFF;
    --text-main: #18181B;
    --text-muted: #71717A;
    --border: #E4E4E7;
    --border-light: #F4F4F5;
    --success: #10B981;
    --shadow-soft: 0 4px 20px -2px rgba(0, 0, 0, 0.03);
    --shadow-hover: 0 10px 30px -5px rgba(0, 0, 0, 0.05);
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg);
    color: var(--text-main);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    font-feature-settings: "cv02", "cv03", "cv04", "cv11";
}

/* Elegant Buttons */
.download-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: linear-gradient(135deg, #18181B 0%, #3F3F46 100%);
    color: white;
    border: none;
    padding: 0.5rem 1.25rem;
    border-radius: 9999px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.85rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.download-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.15);
}
.download-btn:active {
    transform: translateY(0);
}

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

/* Header - Modern Glassmorphism */
.app-header {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text-main);
    padding: 1.25rem 0;
    border-bottom: 1px solid rgba(0,0,0,0.04);
    margin-bottom: 3rem;
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.app-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #111;
}

.last-updated {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
    font-weight: 400;
}

.month-badge {
    background: var(--surface);
    color: var(--text-main);
    padding: 0.4rem 1.2rem;
    border-radius: 9999px;
    font-weight: 500;
    font-size: 0.85rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-soft);
}

/* Dashboard States */
.dashboard-hidden { display: none; }

/* Loader */
.loader-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8rem 0;
    text-align: center;
}
.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--text-main);
    border-radius: 50%;
    animation: spin 0.8s cubic-bezier(0.5, 0.1, 0.4, 0.9) infinite;
    margin-bottom: 1.5rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Summary Cards - Minimalist & Spacious */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    border: 1px solid rgba(0,0,0,0.03);
    transition: all 0.3s ease;
}

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

.summary-cards .card {
    padding: 1.75rem 2rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.card-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #F4F4F5;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.card-info h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.08em;
    font-weight: 600;
    margin-bottom: 0.4rem;
}

.card-info p {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.04em;
    line-height: 1;
}

/* Main Grid Layout */
.bottom-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 2rem;
    align-items: start;
    margin-bottom: 4rem;
}

.sidebar-card, .table-card {
    padding: 2rem;
}

.sidebar-card h2, .table-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-main);
    letter-spacing: -0.01em;
}
.table-header {
    margin-bottom: 1.5rem;
}

.sidebar-card > div#historyToggleBtn {
    margin-bottom: 1rem !important;
    padding-bottom: 1rem !important;
    border-bottom: 1px solid var(--border-light) !important;
}

/* Individual Cost Table - Sleek styling */
.cost-table {
    width: 100%;
    border-collapse: collapse;
}
.cost-table th {
    text-align: right;
    padding-bottom: 1rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
}
.cost-table th:first-child { text-align: left; }
.cost-table td {
    padding: 1rem 0;
    text-align: right;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-main);
}
.cost-table td:first-child { text-align: left; font-weight: 500; }
.cost-table tbody tr:last-child td {
    border-top: 2px solid var(--border);
    border-bottom: none;
    font-weight: 700;
    padding-top: 1.25rem;
}

/* MEAL TRACKER TABLE */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
table.meal-table {
    width: 100%;
    text-align: center;
}
.meal-table {
    border-collapse: collapse;
    border: 2px solid #111;
}
.meal-table th, .meal-table td {
    border: 1px solid #111;
    color: #111;
    padding: 0.875rem 0.5rem;
    white-space: nowrap;
}
.meal-table th:first-child, .meal-table td:first-child {
    text-align: left;
}
.meal-table thead th {
    background-color: #E2E8F0;
    color: #111;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid #111;
    position: sticky;
    top: 0;
    z-index: 10;
}
.sub-header th {
    font-size: 0.75rem;
    color: #111;
    font-weight: 600;
}
.meal-table tbody tr {
    transition: background-color 0.15s ease;
}
.meal-table tbody tr:hover {
    background-color: var(--bg);
}
.sticky-col {
    position: sticky;
    left: 0;
    background-color: #E2E8F0;
    z-index: 20;
    font-weight: 700;
    border-right: 2px solid #111 !important;
}
.meal-table tbody td.sticky-col {
    background-color: #F8FAFC;
    z-index: 10;
    color: #111;
    font-weight: 600;
}

/* History Component - Minimalist Timeline */
.history-container {
    max-height: 350px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    padding-right: 1rem;
    margin-top: 1rem;
}
.history-container::-webkit-scrollbar { width: 4px; }
.history-container::-webkit-scrollbar-thumb { background-color: var(--border); border-radius: 4px; }

.history-item {
    padding-left: 1.25rem;
    position: relative;
}
.history-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.3rem;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--border);
    box-shadow: 0 0 0 4px var(--surface);
    transition: background 0.2s ease;
}
.history-item::after {
    content: '';
    position: absolute;
    left: 2px;
    top: 1rem;
    bottom: -1.5rem;
    width: 2px;
    background: var(--border-light);
}
.history-item:last-child::after { display: none; }
.history-item:hover::before { background: var(--text-main); }

.history-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    font-weight: 500;
    letter-spacing: 0.02em;
}
.history-action {
    color: var(--text-main);
    word-break: break-word;
    line-height: 1.5;
    font-size: 0.85rem;
}

/* Mobile Responsiveness */
@media (max-width: 1024px) {
    .bottom-grid {
        grid-template-columns: 1fr;
    }
}
@media (max-width: 768px) {
    .container {
        padding: 0 0.5rem;
    }
    .app-header {
        padding: 1rem 1rem;
        margin-bottom: 1.5rem;
    }
    .app-header h1 {
        font-size: 1.2rem;
    }
    .summary-cards {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    .card, .sidebar-card, .table-card {
        padding: 1.25rem;
        border-radius: 0.75rem;
    }
    
    /* MEAL TABLE FORCE FIT */
    .table-responsive {
        overflow-x: hidden;
    }
    .meal-table {
        table-layout: fixed;
        width: 100%;
        font-size: 0.55rem; 
    }
    .meal-table th, .meal-table td {
        padding: 0.1rem 0.05rem; 
        white-space: normal;
        word-break: break-all;
        border: 1px solid #111;
        line-height: 1.1;
    }
    .meal-table thead th {
        font-size: 0.5rem;
        padding: 0.2rem 0;
        letter-spacing: 0.02em;
    }
    .sub-header th {
        font-size: 0.45rem;
    }
}

/* Print Styles */
@media print {
    body { background-color: #FFFFFF; color: #000000; margin: 0; padding: 0; }
    .app-header, .summary-cards, .bottom-grid, .download-btn, #loader { display: none !important; }
    .main-content, .table-card { box-shadow: none !important; border: none !important; padding: 0 !important; margin: 0; }
    .table-responsive { overflow: visible !important; }
    .meal-table { width: 100%; border: 2px solid #000; border-radius: 0; }
    .meal-table th, .meal-table td { border: 1px solid #000; color: #000; padding: 0.2rem !important; }
    .meal-table thead th { background-color: #f3f3f3 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .sticky-col { position: static !important; border-right: 1px solid #000 !important; }
}
