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

body {
    font-family: "Noto Sans Lao", "Phetsarath OT", sans-serif;
    background: #f0f2f5;
    color: #333;
    line-height: 1.6;
}

/* Nav */
nav {
    background: #1a73e8;
    color: #fff;
    padding: 0.8rem 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.nav-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.logo {
    color: #fff;
    text-decoration: none;
    font-size: 1.3rem;
    font-weight: bold;
}
.nav-links a {
    color: rgba(255,255,255,0.9);
    text-decoration: none;
    margin-left: 1.2rem;
    font-size: 0.95rem;
}
.nav-links a:hover {
    color: #fff;
    text-decoration: underline;
}

/* Main */
main {
    max-width: 1000px;
    margin: 1.5rem auto;
    padding: 0 1rem;
}

h1 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: #1a73e8;
}

/* Alert */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }

/* Header row */
.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.total-box {
    background: #1a73e8;
    color: #fff;
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    font-size: 1.1rem;
}

/* Table */
table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
th, td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid #eee;
}
th {
    background: #f8f9fa;
    font-weight: 600;
    font-size: 0.9rem;
    color: #555;
}
tr:hover { background: #f8f9ff; }
.text-right { text-align: right; }
.text-muted { color: #999; font-size: 0.85rem; }

/* Badge */
.badge {
    background: #e8f0fe;
    color: #1a73e8;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.85rem;
    white-space: nowrap;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.9rem;
    transition: opacity 0.2s;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: #1a73e8; color: #fff; }
.btn-secondary { background: #6c757d; color: #fff; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-edit { background: #ffc107; color: #333; }
.btn-delete { background: #dc3545; color: #fff; }
.actions { white-space: nowrap; }

/* Form */
.expense-form {
    background: #fff;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    max-width: 600px;
}
.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    margin-bottom: 0.3rem;
    font-weight: 600;
    font-size: 0.9rem;
    color: #555;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #1a73e8;
    box-shadow: 0 0 0 2px rgba(26,115,232,0.2);
}
.form-row {
    display: flex;
    gap: 1rem;
}
.form-row .form-group { flex: 1; }
.form-row-4 { display: flex; gap: 0.6rem; align-items: flex-end; }
.form-group-unit { flex: 0.8; }
.form-row-3x { display: flex; gap: 0.8rem; }
.total-display { background: #e8f0fe !important; font-weight: 700; color: #1a73e8 !important; }
.text-over { color: #dc3545 !important; }
.progress-over { background: linear-gradient(90deg, #dc3545, #e85d6f) !important; }
.form-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* Inline form */
.inline-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}
.inline-form input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
}

/* Progress bar */
.progress-bar {
    position: relative;
    background: #e9ecef;
    border-radius: 10px;
    height: 24px;
    min-width: 120px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #1a73e8, #4dabf7);
    border-radius: 10px;
    transition: width 0.3s;
}
.progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.75rem;
    font-weight: 600;
    color: #333;
}

/* Stat cards */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: #fff;
    border-radius: 10px;
    padding: 1.2rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border-left: 4px solid #ddd;
}
.stat-primary { border-left-color: #1a73e8; }
.stat-info { border-left-color: #17a2b8; }
.stat-warning { border-left-color: #ffc107; }
.stat-danger { border-left-color: #dc3545; }
.stat-label { font-size: 0.8rem; color: #888; margin-bottom: 0.3rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: #333; }
.stat-unit { font-size: 0.8rem; color: #999; margin-top: 0.1rem; }

/* Section title */
.section-title {
    font-size: 1.15rem;
    color: #333;
    margin: 2rem 0 0.8rem;
    padding-bottom: 0.4rem;
    border-bottom: 2px solid #e9ecef;
}

/* Total row */
.total-row { background: #f8f9fa; }
.total-row td { border-top: 2px solid #dee2e6; }

/* Date range label */
.date-range-label { font-size: 0.85rem; color: #888; margin-bottom: 1rem; }

/* Filter form */
.filter-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.filter-form select {
    padding: 0.4rem 0.6rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.9rem;
    background: #fff;
}

/* Category detail cards */
.category-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}
.category-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    overflow: hidden;
}
.category-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1rem;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
}
.category-card-total { font-weight: 600; color: #1a73e8; font-size: 0.95rem; }
.mini-table { box-shadow: none; margin: 0; }
.mini-table td { padding: 0.5rem 0.8rem; font-size: 0.85rem; }

/* Monthly bar chart */
.monthly-chart {
    background: #fff;
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.bar-row {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.4rem 0;
}
.bar-label { width: 80px; font-size: 0.8rem; color: #666; text-align: right; flex-shrink: 0; }
.bar-track {
    flex: 1;
    background: #e9ecef;
    border-radius: 6px;
    height: 22px;
    overflow: hidden;
}
.bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #1a73e8, #4dabf7);
    border-radius: 6px;
    min-width: 2px;
    transition: width 0.3s;
}
.bar-value { width: 110px; font-size: 0.8rem; font-weight: 600; color: #333; text-align: right; flex-shrink: 0; }

/* Filter bar */
.filter-bar {
    background: #fff;
    border-radius: 8px;
    padding: 0.8rem 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.filter-form-full {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}
.filter-group input,
.filter-group select {
    padding: 0.45rem 0.6rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.9rem;
    background: #fff;
}
.filter-group input { min-width: 180px; }
.no-wrap { white-space: nowrap; }
.col-num { width: 40px; color: #aaa; }

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}
.page-link {
    display: inline-block;
    padding: 0.4rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    text-decoration: none;
    color: #1a73e8;
    font-size: 0.85rem;
    background: #fff;
}
.page-link:hover { background: #e8f0fe; }
.page-link.active { background: #1a73e8; color: #fff; border-color: #1a73e8; }
.page-ellipsis { padding: 0.4rem 0.3rem; color: #999; }
.page-info { margin-left: auto; font-size: 0.8rem; color: #888; }

/* Category inline edit */
.cat-edit-form {
    display: inline-flex;
    gap: 0.3rem;
    align-items: center;
}
.cat-edit-input {
    padding: 0.3rem 0.5rem;
    border: 1px solid #1a73e8;
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
    width: 180px;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem;
    background: #fff;
    border-radius: 8px;
    color: #666;
}
.empty-state a { color: #1a73e8; }

/* Nav toggle (hamburger) */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.2rem 0.5rem;
}

/* Mobile show/hide helpers */
.show-mobile { display: none; }

/* Table horizontal scroll on mid-size */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Mobile expense cards */
.expense-card {
    background: #fff;
    border-radius: 8px;
    padding: 0.8rem 1rem;
    margin-bottom: 0.6rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.expense-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.3rem;
}
.expense-card-date { font-size: 0.8rem; color: #888; }
.expense-card-desc { font-size: 0.95rem; margin-bottom: 0.2rem; }
.expense-card-qty { font-size: 0.8rem; color: #888; margin-bottom: 0.4rem; }
.expense-card-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.expense-card-amount { font-size: 1.1rem; font-weight: 700; color: #1a73e8; }
.expense-card-actions { display: flex; gap: 0.3rem; }
.expense-card-note { font-size: 0.8rem; color: #999; margin-top: 0.3rem; padding-top: 0.3rem; border-top: 1px solid #f0f0f0; }
.total-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
    font-size: 0.95rem;
    border-top: 2px solid #dee2e6;
}

/* Mobile summary cards */
.summary-card {
    background: #fff;
    border-radius: 8px;
    padding: 0.8rem 1rem;
    margin-bottom: 0.6rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.summary-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.summary-card-pct { font-weight: 700; color: #1a73e8; font-size: 1rem; }
.summary-card-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    font-size: 0.85rem;
}

/* ===== Tablet (max 768px) ===== */
@media (max-width: 768px) {
    .stat-cards { grid-template-columns: 1fr 1fr; }
    .category-details { grid-template-columns: 1fr; }
    .bar-label { width: 60px; font-size: 0.75rem; }
    .bar-value { width: 90px; font-size: 0.75rem; }
    .header-row { flex-direction: column; align-items: flex-start; }
    .filter-form { flex-wrap: wrap; }
}

/* ===== Mobile (max 600px) ===== */
@media (max-width: 600px) {
    /* Nav */
    .nav-toggle { display: block; }
    .nav-links {
        display: none;
        width: 100%;
        flex-direction: column;
        gap: 0;
        padding-top: 0.5rem;
    }
    .nav-links.open { display: flex; }
    .nav-links a {
        margin: 0;
        padding: 0.6rem 0;
        border-top: 1px solid rgba(255,255,255,0.15);
        text-align: center;
    }
    .nav-container { flex-wrap: wrap; }

    /* Typography */
    h1 { font-size: 1.2rem; }
    main { padding: 0 0.6rem; margin: 1rem auto; }

    /* Stat cards */
    .stat-cards { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
    .stat-card { padding: 0.8rem; }
    .stat-value { font-size: 1.2rem; }

    /* Filter */
    .filter-bar { padding: 0.6rem; }
    .filter-form-full { flex-direction: column; align-items: stretch; }
    .filter-group { width: 100%; }
    .filter-group input,
    .filter-group select { width: 100%; min-width: auto; }
    .filter-form { flex-direction: column; align-items: stretch; }
    .filter-form select { width: 100%; }

    /* Hide desktop table, show mobile cards */
    .hide-mobile { display: none !important; }
    .show-mobile { display: block !important; }

    /* Forms */
    .form-row { flex-direction: column; gap: 0; }
    .form-row-3x { flex-direction: column; gap: 0; }
    .form-row-4 { flex-direction: column; gap: 0; }
    .form-group-unit { flex: 1; }
    .expense-form { max-width: 100%; padding: 1rem; }
    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; text-align: center; }

    /* Inline form (categories) */
    .inline-form { flex-direction: column; }
    .inline-form input { width: 100%; }

    /* Bar chart */
    .bar-row { gap: 0.4rem; }
    .bar-label { width: 50px; font-size: 0.7rem; }
    .bar-value { width: 80px; font-size: 0.7rem; }
    .monthly-chart { padding: 0.6rem; }

    /* Category cards */
    .category-details { grid-template-columns: 1fr; gap: 0.6rem; }
    .mini-table td { padding: 0.4rem 0.6rem; font-size: 0.8rem; }

    /* Pagination */
    .pagination { justify-content: center; }
    .page-info { margin-left: 0; width: 100%; text-align: center; margin-top: 0.3rem; }

    /* Progress bar */
    .progress-bar { min-width: 80px; height: 20px; }
    .progress-text { font-size: 0.65rem; }

    /* Section title */
    .section-title { font-size: 1rem; margin: 1.5rem 0 0.6rem; }
}
