:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --text: #1a2332;
    --muted: #5c6b7a;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #059669;
    --danger: #dc2626;
    --warning: #d97706;
    --border: #e2e8f0;
    --shadow: 0 4px 20px rgba(15, 23, 42, 0.08);
    --radius: 12px;
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    width: min(1100px, 92%);
    margin: 0 auto;
    padding-left: max(4%, env(safe-area-inset-left));
    padding-right: max(4%, env(safe-area-inset-right));
}

.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

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

.brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    text-decoration: none;
    color: inherit;
}

.brand-icon {
    font-size: 1.75rem;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.brand-text small {
    color: var(--muted);
    font-size: 0.8rem;
}

.main-nav {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.main-nav a {
    text-decoration: none;
    color: var(--muted);
    padding: 0.45rem 0.85rem;
    border-radius: 8px;
    font-size: 0.92rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.main-nav a:hover,
.main-nav a.active {
    background: #eff6ff;
    color: var(--primary);
}

/* Mobile bottom navigation */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 24px rgba(15, 23, 42, 0.1);
    padding: 0.35rem 0 calc(0.35rem + env(safe-area-inset-bottom));
    justify-content: space-around;
    align-items: stretch;
}

.bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    padding: 0.4rem 0.25rem;
    min-height: 52px;
    text-decoration: none;
    color: var(--muted);
    font-size: 0.65rem;
    font-weight: 600;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.bottom-nav a.active {
    color: var(--primary);
}

.bottom-nav .nav-icon {
    font-size: 1.25rem;
    line-height: 1;
}

.bottom-nav a.active .nav-icon {
    transform: scale(1.1);
}

.main-content {
    flex: 1;
    padding: 1.75rem 0 3rem;
}

.site-footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 1rem 0;
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
}

.page-header {
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
}

.subtitle {
    color: var(--muted);
    margin-top: 0.25rem;
}

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

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stats-grid.compact {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow);
}

.stat-card.highlight {
    border-color: #93c5fd;
    background: linear-gradient(135deg, #eff6ff, #fff);
}

.stat-card.paid {
    border-color: #6ee7b7;
    background: #ecfdf5;
}

.stat-card.unpaid {
    border-color: #fcd34d;
    background: #fffbeb;
}

.stat-label {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.stat-value {
    display: block;
    font-size: 1.35rem;
    font-weight: 700;
    margin-top: 0.25rem;
}

.stat-card small {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.78rem;
    color: var(--muted);
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.35rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.25rem;
}

.card h2,
.card h3 {
    margin-bottom: 0.85rem;
    font-size: 1.1rem;
}

.big-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
    margin: 0.5rem 0;
}

.muted {
    color: var(--muted);
}

.action-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toolbar {
    display: flex;
    gap: 0.65rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.55rem 1.1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: transform 0.1s, background 0.15s;
    font-family: inherit;
}

.btn:hover {
    transform: translateY(-1px);
}

@media (hover: none) {
    .btn:hover {
        transform: none;
    }

    .btn:active {
        opacity: 0.85;
    }
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: #e2e8f0;
    color: var(--text);
}

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-sm {
    padding: 0.3rem 0.65rem;
    font-size: 0.8rem;
}

.btn-block {
    width: 100%;
}

.payment-form {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.alert {
    padding: 0.85rem 1rem;
    border-radius: 8px;
    margin-bottom: 1.25rem;
    font-size: 0.92rem;
}

.alert-success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.alert ul {
    margin-left: 1.2rem;
}

.form-card {
    max-width: 560px;
}

.form-group {
    margin-bottom: 1.1rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.88rem;
    margin-bottom: 0.35rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.hint {
    display: block;
    margin-top: 0.3rem;
    color: var(--muted);
    font-size: 0.8rem;
}

.preview-box {
    background: #f8fafc;
    border-radius: 8px;
    padding: 0.85rem 1rem;
}

.preview-amount {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.form-actions {
    display: flex;
    gap: 0.65rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

.month-picker {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.month-picker select {
    padding: 0.45rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th,
td {
    padding: 0.65rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    background: #f8fafc;
    font-weight: 600;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
}

.total-row td {
    background: #f1f5f9;
    border-top: 2px solid var(--border);
}

.notes-cell {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
    font-size: 0.85rem;
}

.empty-state {
    color: var(--muted);
    margin-bottom: 1rem;
}

.info-card ul {
    margin-left: 1.25rem;
    color: var(--muted);
}

.info-card li {
    margin-bottom: 0.4rem;
}

/* Report */
.report-document {
    padding: 2rem;
}

.report-header {
    text-align: center;
    margin-bottom: 1.75rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--text);
}

.report-header h2 {
    font-size: 1.5rem;
}

.report-meta {
    color: var(--muted);
    font-size: 0.85rem;
    margin-top: 0.35rem;
}

.report-summary-box {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.report-stat {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
    text-align: center;
}

.report-stat span {
    display: block;
    font-size: 0.75rem;
    color: var(--muted);
    text-transform: uppercase;
}

.report-stat strong {
    display: block;
    margin-top: 0.25rem;
    font-size: 1rem;
}

.report-stat.payment-due {
    background: #eff6ff;
    border-color: #93c5fd;
}

.report-stat.payment-due strong {
    font-size: 1.2rem;
    color: var(--primary);
}

.status-badge.paid {
    background: #ecfdf5;
    border-color: #6ee7b7;
}

.status-badge.unpaid {
    background: #fffbeb;
    border-color: #fcd34d;
}

.report-table {
    margin-bottom: 1.5rem;
}

.report-footer {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px dashed var(--border);
}

.payment-box {
    text-align: center;
}

.payable-amount {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
    margin-top: 0.35rem;
}

.payment-note {
    color: var(--muted);
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

.inline-payment-form .form-group {
    max-width: 400px;
}

.entry-date-day {
    display: none;
}

/* ——— Mobile & tablet ——— */
@media (max-width: 768px) {
    .desktop-nav {
        display: none;
    }

    .bottom-nav {
        display: flex;
    }

    body {
        padding-bottom: calc(4.5rem + env(safe-area-inset-bottom));
    }

    .main-content {
        padding: 1rem 0 1.5rem;
    }

    .site-header {
        padding-top: env(safe-area-inset-top);
    }

    .header-inner {
        flex-direction: row;
        align-items: center;
        padding: 0.65rem 0;
    }

    .brand-text strong {
        font-size: 0.95rem;
    }

    .page-header h1 {
        font-size: 1.35rem;
    }

    .row-between {
        flex-direction: column;
        align-items: stretch;
    }

    .month-picker {
        width: 100%;
    }

    .month-picker select {
        flex: 1;
        min-height: 44px;
        font-size: 16px;
    }

    .stats-grid,
    .stats-grid.compact {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.65rem;
    }

    .stat-card {
        padding: 0.85rem 0.9rem;
    }

    .stat-value {
        font-size: 1.15rem;
    }

    .grid-2 {
        grid-template-columns: 1fr;
        gap: 0.85rem;
    }

    .card {
        padding: 1rem;
        margin-bottom: 0.85rem;
    }

    .big-number {
        font-size: 1.65rem;
    }

    .toolbar {
        flex-direction: column;
    }

    .toolbar .btn,
    .action-list .btn,
    .form-actions .btn,
    .payment-form .btn {
        width: 100%;
        min-height: 48px;
        font-size: 1rem;
    }

    .form-card {
        max-width: none;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        min-height: 48px;
        font-size: 16px;
        padding: 0.75rem 0.85rem;
    }

    .form-group textarea {
        min-height: 80px;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
    }

    .btn-sm {
        min-height: 40px;
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }

    .preview-amount {
        font-size: 1.75rem;
    }

    .report-document {
        padding: 1rem;
    }

    .report-header h2 {
        font-size: 1.2rem;
    }

    .report-summary-box {
        grid-template-columns: repeat(2, 1fr);
    }

    .payable-amount {
        font-size: 1.65rem;
    }

    .inline-payment-form .form-group {
        max-width: none;
    }

    .site-footer {
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
    }

    .footer-text {
        font-size: 0.75rem;
    }

    /* Card-style tables on mobile */
    .responsive-table thead,
    .hide-mobile {
        display: none;
    }

    .responsive-table tbody tr {
        display: block;
        margin-bottom: 0.75rem;
        padding: 0.75rem;
        background: #f8fafc;
        border: 1px solid var(--border);
        border-radius: 10px;
    }

    .responsive-table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.75rem;
        padding: 0.45rem 0;
        border-bottom: 1px solid #e8edf3;
        text-align: right;
        font-size: 0.95rem;
        white-space: normal;
    }

    .responsive-table tbody td:last-child {
        border-bottom: none;
    }

    .responsive-table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.78rem;
        color: var(--muted);
        text-transform: uppercase;
        letter-spacing: 0.03em;
        text-align: left;
        flex-shrink: 0;
    }

    .responsive-table tbody td[data-label=""]::before,
    .responsive-table tbody td.cell-action::before {
        display: none;
    }

    .responsive-table tbody td.cell-action {
        justify-content: stretch;
        padding-top: 0.6rem;
    }

    .responsive-table tbody td.cell-action .btn {
        width: 100%;
    }

    .responsive-table .notes-cell {
        max-width: none;
        white-space: normal;
        word-break: break-word;
    }

    .entry-date-day {
        display: inline;
        margin-left: 0.35rem;
        color: var(--muted);
        font-size: 0.85rem;
    }

    .desktop-only-foot {
        display: none;
    }

    .table-wrap {
        overflow-x: visible;
    }
}

@media (max-width: 380px) {
    .stats-grid,
    .stats-grid.compact {
        grid-template-columns: 1fr;
    }

    .bottom-nav .nav-label {
        font-size: 0.58rem;
    }
}

@media print {
    .site-header,
    .site-footer,
    .print-hide,
    .main-nav,
    .bottom-nav,
    .toolbar,
    .alert {
        display: none !important;
    }

    body {
        padding-bottom: 0;
    }

    .responsive-table thead {
        display: table-header-group !important;
    }

    .responsive-table tbody tr {
        display: table-row !important;
    }

    .responsive-table tbody td {
        display: table-cell !important;
        border-bottom: 1px solid var(--border);
    }

    .responsive-table tbody td::before {
        display: none !important;
    }

    .hide-mobile {
        display: table-cell !important;
    }

    .desktop-only-foot {
        display: table-footer-group !important;
    }

    body {
        background: #fff;
    }

    .main-content {
        padding: 0;
    }

    .report-document {
        box-shadow: none;
        border: none;
    }
}

