:root {
    --sidebar: #243142;
    --sidebar-active: #2f80ed;
    --bg: #f4f6f9;
    --surface: #ffffff;
    --border: #dfe5ec;
    --text: #1f2937;
    --muted: #6b7280;
    --topbar: #ffffff;
    --input: #ffffff;
}

body {
    background: var(--bg);
    color: var(--text);
}

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

.theme-dark {
    --bg: #111827;
    --surface: #182235;
    --border: #2d3b50;
    --text: #eef2f7;
    --muted: #a7b2c2;
    --topbar: #182235;
    --input: #111827;
}

.sidebar {
    width: 270px;
    background: var(--sidebar);
    color: #fff;
    padding: 18px 14px;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1030;
    transition: width .2s ease, transform .2s ease;
}

.brand-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-size: 1.15rem;
    font-weight: 700;
    text-decoration: none;
    padding: 8px 6px 8px 10px;
    min-width: 0;
    flex: 1;
}

.brand span,
.sidebar .nav-link span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.brand img {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    object-fit: contain;
    background: #fff;
    padding: 3px;
    flex: 0 0 auto;
}

.sidebar-collapse-btn {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 8px;
    color: #fff;
    background: rgba(255,255,255,.12);
    display: grid;
    place-items: center;
}

.sidebar .nav-link {
    color: #dbe4ef;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar .nav-link i {
    font-size: 1.1rem;
    min-width: 22px;
    text-align: center;
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active {
    background: var(--sidebar-active);
    color: #fff;
}

.content {
    margin-left: 270px;
    min-width: 0;
    flex: 1;
    transition: margin-left .2s ease;
}

.topbar {
    min-height: 72px;
    background: var(--topbar);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 24px;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.page {
    padding: 24px;
}

.surface {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 18px;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}

.theme-dark .surface,
.theme-dark .metric,
.theme-dark .table,
.theme-dark .modal-content,
.theme-dark .dropdown-menu {
    color: var(--text);
}

.theme-dark .text-muted,
.theme-dark .form-text,
.theme-dark .detail-label,
.theme-dark .metric span {
    color: var(--muted) !important;
}

.theme-dark .form-control,
.theme-dark .form-select {
    background-color: var(--input);
    border-color: var(--border);
    color: var(--text);
}

.theme-dark .table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text);
    --bs-table-border-color: var(--border);
    --bs-table-hover-color: var(--text);
    --bs-table-hover-bg: rgba(255,255,255,.04);
}

.sidebar-collapsed .sidebar {
    width: 82px;
}

.sidebar-collapsed .content {
    margin-left: 82px;
}

.sidebar-collapsed .brand span,
.sidebar-collapsed .sidebar .nav-link span {
    display: none;
}

.sidebar-collapsed .brand {
    justify-content: center;
    padding-inline: 0;
}

.sidebar-collapsed .brand-row {
    justify-content: center;
    flex-direction: column;
}

.sidebar-collapsed .sidebar .nav-link {
    justify-content: center;
    padding-inline: 8px;
}

.filters {
    display: grid;
    grid-template-columns: 2fr repeat(4, minmax(150px, 1fr)) auto;
    gap: 10px;
    margin-bottom: 16px;
}

.dashboard-heading {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 18px;
    align-items: end;
}

.dashboard-filters {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    display: grid;
    grid-template-columns: repeat(6, minmax(120px, 1fr)) auto;
    gap: 12px;
    align-items: end;
}

.dashboard-filters .form-label {
    color: var(--muted);
    font-size: .78rem;
    margin-bottom: 4px;
}

.form-grid,
.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.span-2 {
    grid-column: span 2;
}

.installments-editor {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.installments-editor .table {
    margin: 0;
}

.installments-editor th,
.installments-editor td {
    padding: 10px 12px;
}

.installment-number {
    width: 90px;
}

.installments-editor input {
    min-width: 150px;
}

.detail-label {
    color: #6b7280;
    display: block;
    font-size: .82rem;
    margin-bottom: 4px;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.metric {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--sidebar-active);
    border-radius: 8px;
    padding: 16px;
}

.metric span {
    color: #6b7280;
    font-size: .85rem;
}

.metric strong {
    display: block;
    font-size: 1.4rem;
    margin-top: 4px;
}

.settings-logo {
    width: 92px;
    height: 92px;
    object-fit: contain;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    padding: 8px;
}

.dashboard-settings-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.settings-panel {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
}

.settings-panel h3 {
    font-size: .95rem;
    margin-bottom: 12px;
}

.settings-panel .form-check {
    margin-bottom: 8px;
}

.report-filters {
    grid-template-columns: repeat(2, minmax(180px, 260px)) auto;
    justify-content: start;
}

.report-document {
    padding: 24px;
}

.report-document-header {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 16px;
    align-items: center;
    padding-bottom: 18px;
    margin-bottom: 18px;
    border-bottom: 2px solid var(--border);
}

.report-document-header img {
    width: 72px;
    height: 72px;
    object-fit: contain;
}

.report-document-header strong,
.report-document-header span {
    display: block;
}

.report-document-header h2 {
    font-size: 1.25rem;
    margin: 4px 0;
}

.report-summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.report-summary div {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
}

.report-summary span,
.report-summary strong {
    display: block;
}

.report-summary span {
    color: var(--muted);
    font-size: .76rem;
    text-transform: uppercase;
}

.report-summary-wide {
    grid-column: 1 / -1;
}

.report-table {
    font-size: .86rem;
}

.financial-report-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding-bottom: 18px;
    margin-bottom: 18px;
    border-bottom: 2px solid var(--border);
}

.financial-report-header img {
    width: 72px;
    height: 72px;
    object-fit: contain;
}

.financial-report-header strong,
.financial-report-header span {
    display: block;
}

.financial-report-header h2 {
    font-size: 1.25rem;
    margin: 3px 0;
}

.financial-report-table {
    font-size: .82rem;
}

.signature-section {
    margin-top: 36px;
    break-inside: avoid;
}

.signature-section h3 {
    font-size: 1rem;
    margin-bottom: 18px;
}

.signature-row {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(220px, .8fr);
    gap: 28px;
    align-items: end;
    margin: 22px 0;
}

.signature-line {
    border-top: 1px solid currentColor;
    padding-top: 4px;
    text-align: center;
    font-size: .75rem;
}

.tithe-receipt {
    max-width: 900px;
    margin: 0 auto;
    padding: 30px;
}

.receipt-header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 18px;
    align-items: center;
    border-bottom: 2px solid var(--border);
    padding-bottom: 20px;
}

.receipt-header img {
    width: 82px;
    height: 82px;
    object-fit: contain;
}

.receipt-header h1 {
    font-size: 1.35rem;
    margin: 0 0 4px;
}

.receipt-header span,
.receipt-number span {
    display: block;
    font-size: .82rem;
}

.receipt-number {
    text-align: right;
}

.receipt-value {
    border: 2px solid var(--border);
    font-size: 1.5rem;
    font-weight: 700;
    padding: 10px 18px;
    margin: 28px 0;
    text-align: center;
}

.receipt-text {
    font-size: 1.05rem;
    line-height: 1.8;
}

.receipt-details {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-top: 24px;
}

.receipt-details div {
    border: 1px solid var(--border);
    padding: 12px;
}

.receipt-details span,
.receipt-details strong {
    display: block;
}

.receipt-details span {
    color: var(--muted);
    font-size: .75rem;
}

.receipt-notes {
    margin-top: 18px;
}

.receipt-signatures {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 70px;
    margin-top: 80px;
    text-align: center;
}

.receipt-signature-line {
    border-top: 1px solid currentColor;
    display: block;
    margin-bottom: 8px;
}

.receipt-signatures strong,
.receipt-signatures small {
    display: block;
}

.chart-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #f4f6f9, #dce8f9);
    padding: 20px;
}

.login-card {
    width: min(430px, 100%);
}

@media (max-width: 1100px) {
    .metric-grid,
    .chart-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .filters {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-heading {
        grid-template-columns: 1fr;
    }

    .dashboard-filters {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform .2s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-collapsed .sidebar {
        width: 270px;
    }

    .sidebar-collapsed .brand span,
    .sidebar-collapsed .sidebar .nav-link span {
        display: inline;
    }

    .content {
        margin-left: 0;
    }

    .page,
    .topbar {
        padding: 16px;
    }

    .metric-grid,
    .chart-grid,
    .form-grid,
    .detail-grid,
    .filters,
    .dashboard-filters,
    .dashboard-settings-grid,
    .report-summary {
        grid-template-columns: 1fr;
    }

    .span-2 {
        grid-column: span 1;
    }

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

    .receipt-header,
    .receipt-details,
    .receipt-signatures {
        grid-template-columns: 1fr;
    }

    .receipt-number {
        text-align: left;
    }
}

@media print {
    .sidebar,
    .topbar,
    .report-toolbar,
    .report-tabs,
    .report-actions,
    .receipt-actions,
    .report-filters,
    .no-print {
        display: none !important;
    }

    body,
    .content,
    .page {
        background: #fff !important;
        color: #000 !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .financial-report {
        border: 0;
        box-shadow: none;
        padding: 0;
    }

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

    .report-document-header {
        grid-template-columns: auto 1fr;
        border-color: #111;
    }

    .report-document-header img {
        width: 72px;
        height: 72px;
    }

    .report-summary {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }

    .report-summary div {
        border-color: #999;
        border-radius: 0;
        padding: 7px 9px;
    }

    .report-summary span {
        color: #333 !important;
    }

    .report-table-wrap {
        overflow: visible !important;
    }

    .report-table {
        width: 100% !important;
        border-collapse: collapse !important;
        font-size: 9pt;
    }

    .report-table th {
        background: #efefef !important;
        color: #000 !important;
    }

    .report-table th,
    .report-table td {
        border: 1px solid #999 !important;
        padding: 5px 6px !important;
        vertical-align: top;
    }

    .report-table tr {
        break-inside: avoid;
    }

    .tithe-receipt {
        border: 0;
        box-shadow: none;
        max-width: none;
        padding: 0;
    }

    .financial-report-table {
        font-size: 9pt;
    }

    .financial-report-table tr {
        break-inside: avoid;
    }
}
