:root {
    --red: #C41E24;
    --red-dark: #9f171c;
    --ink: #1f2937;
    --muted: #6b7280;
    --line: #e5e7eb;
    --bg: #f6f7f9;
    --white: #ffffff;
    --green: #147a42;
    --green-bg: #eaf7ef;
    --danger: #b42318;
    --danger-bg: #fff0ee;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--ink);
}

a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    min-height: 72px;
    padding: 12px 5%;
    background: var(--white);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--ink);
}
.brand:hover { text-decoration: none; }
.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--red);
    color: white;
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 22px;
}
.brand strong { display: block; }
.brand small { display: block; color: var(--muted); margin-top: 2px; }

nav {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}
.user-chip {
    padding: 8px 11px;
    background: #f3f4f6;
    border-radius: 999px;
    font-size: 13px;
}
.inline-form { display: inline; }
.link-button {
    border: 0;
    background: none;
    color: var(--red);
    cursor: pointer;
    font: inherit;
    padding: 0;
}

.page-shell {
    width: min(1180px, 92%);
    margin: 36px auto 60px;
    min-height: calc(100vh - 170px);
}

footer {
    padding: 20px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
}

h1 { margin: 7px 0 10px; font-size: clamp(28px, 4vw, 42px); }
h2 { margin: 0 0 7px; }
p { line-height: 1.55; }

.eyebrow {
    color: var(--red);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .12em;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }
.optional { color: var(--muted); font-weight: normal; }

.welcome {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

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

.module-card {
    min-height: 190px;
    padding: 28px;
    border-radius: 18px;
    background: var(--white);
    border: 1px solid var(--line);
    box-shadow: 0 8px 28px rgba(31,41,55,.06);
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 20px;
    align-items: center;
    color: var(--ink);
    transition: transform .15s ease, box-shadow .15s ease;
}
.module-card:hover {
    text-decoration: none;
    transform: translateY(-2px);
    box-shadow: 0 12px 36px rgba(31,41,55,.10);
}
.module-card h2 { font-size: 26px; }
.module-card p { color: var(--muted); margin: 0; }
.module-icon {
    width: 62px;
    height: 62px;
    border-radius: 16px;
    background: #fdebed;
    color: var(--red);
    display: grid;
    place-items: center;
    font-weight: 900;
    font-size: 24px;
}
.module-icon.large { margin: 0 auto 16px; }
.arrow { color: var(--red); font-size: 32px; }

.admin-panel,
.form-card,
.auth-card,
.table-card,
.role-help,
.empty-state {
    margin-top: 28px;
    padding: 28px;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: 0 8px 28px rgba(31,41,55,.05);
}

.admin-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.auth-card,
.form-card {
    width: min(620px, 100%);
    margin-left: auto;
    margin-right: auto;
}
.auth-card { margin-top: 70px; }
.auth-card.wide { width: min(720px, 100%); }

.stack-form {
    display: grid;
    gap: 16px;
    margin-top: 24px;
}

label {
    font-weight: 700;
    font-size: 14px;
}
input, select {
    width: 100%;
    margin-top: 7px;
    padding: 12px 13px;
    border: 1px solid #cfd4dc;
    border-radius: 9px;
    font: inherit;
    background: white;
}
input:focus, select:focus {
    outline: 2px solid rgba(196, 30, 36, .16);
    border-color: var(--red);
}
.check-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.check-row input { width: auto; margin: 0; }

.primary-button,
.secondary-button {
    display: inline-block;
    border-radius: 9px;
    padding: 11px 16px;
    font-weight: 800;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 14px;
}
.primary-button {
    background: var(--red);
    color: white;
}
.primary-button:hover {
    background: var(--red-dark);
    text-decoration: none;
}
.secondary-button {
    background: white;
    color: var(--ink);
    border-color: #cfd4dc;
}
.secondary-button:hover {
    text-decoration: none;
    border-color: #9ca3af;
}
.button-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.page-heading {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 20px;
    margin-bottom: 20px;
}

.table-card { overflow-x: auto; padding: 0; }
table {
    width: 100%;
    border-collapse: collapse;
    min-width: 780px;
}
th, td {
    padding: 15px 18px;
    text-align: left;
    border-bottom: 1px solid var(--line);
}
th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .05em;
}
tr:last-child td { border-bottom: 0; }

.badge {
    display: inline-block;
    padding: 5px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
}
.badge.success { background: var(--green-bg); color: var(--green); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }

.role-grid {
    margin-top: 18px;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px;
}
.role-grid div {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
}
.role-grid strong, .role-grid span { display: block; }
.role-grid span { color: var(--muted); font-size: 13px; margin-top: 6px; line-height: 1.4; }

.flash-stack { display: grid; gap: 10px; margin-bottom: 18px; }
.flash {
    padding: 12px 15px;
    border-radius: 9px;
    border: 1px solid var(--line);
    background: white;
}
.flash.success { background: var(--green-bg); color: var(--green); border-color: #bfe3cd; }
.flash.danger { background: var(--danger-bg); color: var(--danger); border-color: #ffd0ca; }
.flash.warning { background: #fff8e6; color: #7a5400; border-color: #f2dfa4; }

.empty-state { text-align: center; padding: 70px 28px; }

hr {
    border: 0;
    border-top: 1px solid var(--line);
    margin: 5px 0;
}

@media (max-width: 820px) {
    .topbar { align-items: flex-start; flex-direction: column; }
    nav { width: 100%; }
    .module-grid { grid-template-columns: 1fr; }
    .admin-panel, .page-heading { align-items: flex-start; flex-direction: column; }
    .role-grid { grid-template-columns: 1fr 1fr; }
}


/* Phase 2 */
.filter-card,
.info-card {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: 0 8px 28px rgba(31,41,55,.05);
}
.filter-card {
    padding: 20px;
    margin-bottom: 22px;
}
.filter-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr;
    gap: 14px;
    margin-bottom: 14px;
}
.wide-form { width: min(900px, 100%); }
.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
textarea {
    width: 100%;
    margin-top: 7px;
    padding: 12px 13px;
    border: 1px solid #cfd4dc;
    border-radius: 9px;
    font: inherit;
    resize: vertical;
}
textarea:focus {
    outline: 2px solid rgba(196, 30, 36, .16);
    border-color: var(--red);
}
.profile-grid,
.master-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.master-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: 22px;
}
.info-card { padding: 24px; }
.info-card dl { margin: 18px 0 0; }
.info-card dl div {
    display: grid;
    grid-template-columns: 150px 1fr;
    gap: 12px;
    padding: 11px 0;
    border-bottom: 1px solid var(--line);
}
.info-card dl div:last-child { border-bottom: 0; }
.info-card dt { color: var(--muted); font-size: 13px; font-weight: 700; }
.info-card dd { margin: 0; font-weight: 700; }
.clean-list {
    list-style: none;
    padding: 0;
    margin: 12px 0 0;
}
.clean-list li {
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}
.clean-list li:last-child { border-bottom: 0; }
.clean-list strong,
.clean-list span { display: block; }
.clean-list span { color: var(--muted); font-size: 13px; margin-top: 4px; }
.empty-row { text-align: center; color: var(--muted); padding: 35px !important; }
.empty-state.compact { padding: 38px 28px; }

@media (max-width: 900px) {
    .filter-grid,
    .two-col,
    .profile-grid,
    .master-grid {
        grid-template-columns: 1fr;
    }
}


/* Excel / CSV import */
.import-note,
.warning-card,
.confirm-import-card {
    border-radius: 14px;
    padding: 18px;
    border: 1px solid var(--line);
}
.import-note { background: #f8fafc; }
.import-note p { margin-bottom: 0; }
.import-help { margin-top: 22px; }
.three-col-info {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin: 18px 0;
}
.three-col-info div {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px;
}
.three-col-info strong,
.three-col-info span { display: block; }
.three-col-info span { color: var(--muted); font-size: 13px; line-height: 1.5; margin-top: 6px; }
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}
.kpi-card {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 18px;
    box-shadow: 0 8px 28px rgba(31,41,55,.04);
}
.kpi-card span { display: block; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.kpi-card strong { display: block; margin-top: 7px; font-size: 28px; }
.kpi-card strong.kpi-text { font-size: 16px; line-height: 1.4; }
.import-summary-grid { margin-bottom: 22px; }
.warning-card { background: #fff8e6; border-color: #f2dfa4; margin-bottom: 22px; }
.warning-card h2 { font-size: 18px; }
.warning-card ul { margin-bottom: 0; }
.warning-card li { margin: 7px 0; line-height: 1.45; }
.import-preview-table { margin-top: 0; }
.confirm-import-card {
    margin-top: 22px;
    background: var(--white);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    box-shadow: 0 8px 28px rgba(31,41,55,.05);
}
.confirm-import-card h2 { margin-bottom: 4px; }
.confirm-import-card p { margin: 0; }
.import-result { padding-top: 45px; }
.result-kpis { margin: 28px auto; max-width: 1050px; grid-template-columns: repeat(5, minmax(0, 1fr)); text-align: left; }
.center-buttons { justify-content: center; }

@media (max-width: 900px) {
    .three-col-info,
    .kpi-grid,
    .result-kpis { grid-template-columns: 1fr; }
    .confirm-import-card { align-items: flex-start; flex-direction: column; }
}

/* Phase 3 - Fee Ledger */
.form-section-title {
    margin: 4px 0 0;
    font-size: 20px;
}
.section-divider {
    border-top: 1px solid var(--line);
    margin: 14px 0 6px;
}
.section-heading-row {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 16px;
}
.section-heading-row h2 { margin: 4px 0 0; }
.mini-title {
    font-size: 16px;
    margin: 8px 0 -2px;
}
.span-two { grid-column: 1 / -1; }
.form-actions { margin-top: 6px; }

.summary-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}
.summary-card {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 8px 24px rgba(31,41,55,.04);
}
.summary-card span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 10px;
}
.summary-card strong { font-size: 23px; }
.summary-card.highlight { border-color: #bfe3cd; background: #fbfffc; }
.summary-card.clear { border-color: #bfe3cd; }
.summary-card.due { border-color: #ffd0ca; background: #fffafa; }
.summary-card.due strong, .amount-due { color: var(--danger); }
.summary-card.clear strong, .amount-paid { color: var(--green); }

.notice-card {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px 16px;
    margin: 0 0 22px;
    display: flex;
    gap: 8px;
    flex-direction: column;
}
.warning-card { background: #fff8e6; border-color: #f2dfa4; }
.info-card-lite { background: #f7f9fc; }
.profile-spacing { margin-top: 20px; }
.ledger-section { margin-top: 30px; }

.ledger-list { display: grid; gap: 12px; margin-top: 14px; }
.ledger-item {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: start;
}
.ledger-item strong, .ledger-item span { display: block; }
.ledger-item span { color: var(--muted); font-size: 12px; margin-top: 4px; }
.ledger-amounts { text-align: right; }
.ledger-amounts strong { font-size: 17px; }
.void-row { opacity: .58; text-decoration-color: #9ca3af; }

.inline-void-form, .compact-void {
    display: flex;
    gap: 6px;
    align-items: center;
}
.inline-void-form input, .compact-void input {
    width: 120px;
    min-width: 100px;
    margin: 0;
    padding: 7px 8px;
    font-size: 12px;
}
.compact-void { grid-column: 1 / -1; }
.compact-void input { flex: 1; }
.text-danger-button {
    border: 0;
    background: transparent;
    color: var(--danger);
    font-weight: 800;
    cursor: pointer;
    padding: 6px 2px;
}

.payment-balance-banner {
    display: grid;
    grid-template-columns: repeat(4, minmax(0,1fr));
    gap: 12px;
    background: #f7f9fc;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 16px;
    margin: 18px 0 24px;
}
.payment-balance-banner span,
.payment-balance-banner strong { display: block; }
.payment-balance-banner span { color: var(--muted); font-size: 12px; font-weight: 700; margin-bottom: 5px; }

.receipt-card {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: 0 8px 28px rgba(31,41,55,.06);
    padding: 34px;
    max-width: 900px;
    margin: 20px auto;
}
.receipt-header {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    border-bottom: 2px solid var(--ink);
    padding-bottom: 18px;
    margin-bottom: 22px;
}
.receipt-header h1 { margin-bottom: 0; }
.receipt-number { text-align: right; }
.receipt-number span, .receipt-number strong { display: block; }
.receipt-number span { color: var(--muted); font-size: 12px; margin-bottom: 5px; }
.receipt-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px 28px;
}
.receipt-grid div, .receipt-summary div {
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
}
.receipt-grid span, .receipt-grid strong,
.receipt-summary span, .receipt-summary strong { display: block; }
.receipt-grid span, .receipt-summary span { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.receipt-amount {
    text-align: center;
    margin: 28px 0;
    padding: 24px;
    background: #f7f9fc;
    border-radius: 14px;
}
.receipt-amount span, .receipt-amount strong { display: block; }
.receipt-amount span { color: var(--muted); font-weight: 700; }
.receipt-amount strong { font-size: 38px; margin-top: 6px; }
.receipt-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}
.receipt-note { margin-top: 22px; }
.receipt-footer {
    margin-top: 28px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
}
.void-banner {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid #ffd0ca;
    padding: 12px;
    font-weight: 900;
    text-align: center;
    margin-bottom: 20px;
}

@media (max-width: 1050px) {
    .summary-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .payment-balance-banner { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 700px) {
    .summary-grid,
    .payment-balance-banner,
    .receipt-grid,
    .receipt-summary { grid-template-columns: 1fr; }
    .section-heading-row,
    .receipt-header,
    .receipt-footer { align-items: flex-start; flex-direction: column; }
    .receipt-number { text-align: left; }
    .span-two { grid-column: auto; }
}

@media print {
    body { background: white; }
    .topbar, footer, .no-print, .flash-stack { display: none !important; }
    .page-shell { width: 100%; margin: 0; }
    .receipt-card { border: 0; box-shadow: none; margin: 0; max-width: none; }
}
