:root {
    --bg: #f3f7fc;
    --surface: rgba(255, 255, 255, 0.92);
    --surface-strong: #ffffff;
    --border: #d5e2ef;
    --text: #172235;
    --muted: #5c6b7e;
    --brand: #256eb8;
    --brand-dark: #174b82;
    --accent: #c98222;
    --danger: #c4544c;
    --danger-soft: #f9e5e2;
    --success: #2b7a68;
    --success-soft: #e1f3ee;
    --info: #dcecff;
    --shadow: 0 16px 36px rgba(27, 49, 78, 0.1);
    --radius: 8px;
    --radius-sm: 8px;
    --font-sans: "Aptos", "Trebuchet MS", "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-sans);
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(37, 110, 184, 0.12), transparent 32%),
        radial-gradient(circle at top right, rgba(201, 130, 34, 0.11), transparent 28%),
        linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
}

a {
    color: var(--brand-dark);
    text-decoration-thickness: 1.5px;
    text-underline-offset: 0.18em;
}

a:hover,
a:focus-visible {
    color: var(--brand);
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
.button-link {
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--brand) 0%, #4c8fd0 100%);
    color: #fff;
    padding: 0.85rem 1.2rem;
    cursor: pointer;
    font-weight: 700;
    box-shadow: 0 12px 24px rgba(37, 110, 184, 0.18);
    min-height: 44px;
    text-align: center;
    text-decoration: none;
}

button:hover,
button:focus-visible,
.button-link:hover,
.button-link:focus-visible {
    background: linear-gradient(135deg, var(--brand-dark) 0%, var(--brand) 100%);
    color: #fff;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(201, 130, 34, 0.35);
    outline-offset: 2px;
}

input,
select,
textarea {
    width: 100%;
    margin-top: 0.45rem;
    padding: 0.85rem 0.95rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: #f9fbfe;
    color: var(--text);
}

textarea {
    resize: vertical;
}

.app-shell {
    width: min(1180px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 2rem 0 3rem;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-end;
    margin-bottom: 1.5rem;
}

.topbar h1,
.hero-card h2,
.panel h2,
.panel h3,
.receipt-card h2 {
    margin: 0;
    line-height: 1.1;
    overflow-wrap: anywhere;
}

.topbar h1 {
    font-size: 1.7rem;
}

.hero-card h2 {
    font-size: 1.45rem;
}

.panel h2,
.receipt-card h2 {
    font-size: 1.3rem;
}

.panel h3 {
    font-size: 1.1rem;
}

.topbar__nav {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.topbar__nav a {
    padding: 0.7rem 1rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.65);
    text-decoration: none;
    border: 1px solid rgba(213, 226, 239, 0.8);
    min-height: 44px;
    display: inline-flex;
    align-items: center;
}

.topbar__nav a.is-active {
    background: #eaf3ff;
    border-color: rgba(37, 110, 184, 0.2);
    color: var(--brand-dark);
    font-weight: 700;
}

.menu-toggle,
.drawer-menu,
.drawer-backdrop {
    display: none;
}

.menu-toggle {
    align-items: center;
    gap: 0.55rem;
}

.menu-toggle__icon,
.menu-toggle__icon::before,
.menu-toggle__icon::after {
    display: block;
    width: 1.1rem;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
}

.menu-toggle__icon {
    position: relative;
}

.menu-toggle__icon::before,
.menu-toggle__icon::after {
    content: "";
    position: absolute;
    left: 0;
}

.menu-toggle__icon::before {
    top: -0.38rem;
}

.menu-toggle__icon::after {
    top: 0.38rem;
}

.drawer-menu__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.drawer-menu__close {
    min-height: 40px;
    padding: 0.65rem 0.9rem;
}

.drawer-menu__nav {
    display: grid;
    gap: 0.65rem;
    margin-top: 1rem;
}

.drawer-menu__nav a {
    min-height: 46px;
    display: flex;
    align-items: center;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #f9fbfe;
    color: var(--text);
    font-weight: 700;
    text-decoration: none;
}

.drawer-menu__nav a.is-active {
    background: #eaf3ff;
    border-color: rgba(37, 110, 184, 0.2);
    color: var(--brand-dark);
}

.eyebrow {
    margin: 0 0 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.78rem;
    color: var(--brand);
    font-weight: 700;
}

.muted,
.panel p,
.summary-item p,
.stat-card p,
.empty-state,
td span,
.student-summary span,
.receipt-grid span,
.receipt-notes span {
    color: var(--muted);
}

.flash {
    margin-bottom: 1rem;
    padding: 1rem 1.2rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-strong);
}

.flash ul {
    margin: 0.5rem 0 0;
    padding-left: 1.2rem;
}

.flash--success {
    border-color: rgba(43, 122, 104, 0.24);
    background: var(--success-soft);
}

.flash--error {
    border-color: rgba(196, 84, 76, 0.25);
    background: var(--danger-soft);
}

.page-content {
    display: grid;
    gap: 1.5rem;
}

.hero-card,
.panel,
.receipt-card {
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.7);
    box-shadow: var(--shadow);
    border-radius: var(--radius);
    backdrop-filter: blur(8px);
}

.hero-card {
    display: grid;
    grid-template-columns: 1.6fr 0.8fr;
    gap: 1.5rem;
    padding: 1.75rem;
}

.hero-card--landing {
    grid-template-columns: 1fr;
}

.inline-form {
    display: grid;
    gap: 0.65rem;
    align-content: start;
}

.inline-form label {
    font-weight: 600;
}

.stats-grid,
.panel-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

.panel-grid--wide {
    grid-template-columns: minmax(300px, 0.9fr) minmax(0, 1.4fr);
}

.stat-card {
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(213, 226, 239, 0.78);
    border-radius: var(--radius);
    padding: 1.2rem;
    box-shadow: var(--shadow);
}

.stat-card span,
.student-summary span,
.receipt-grid span {
    display: block;
    font-size: 0.88rem;
    margin-bottom: 0.35rem;
}

.stat-card strong,
.student-summary strong,
.receipt-grid strong {
    display: block;
    font-size: 1.7rem;
}

.panel,
.receipt-card {
    padding: 1.5rem;
}

.panel__header,
.receipt-card__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.helper-pill {
    border-radius: 999px;
    padding: 0.45rem 0.8rem;
    background: #eaf3ff;
    color: var(--brand-dark);
    font-weight: 700;
    white-space: nowrap;
}

.legend,
.receipt-actions,
.tracker-toolbar {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    align-items: center;
}

.tracker-toolbar {
    justify-content: space-between;
    margin-bottom: 1rem;
}

.landing-card-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.landing-card {
    display: grid;
    gap: 0.65rem;
    min-height: 15rem;
    padding: 1.25rem;
    border: 1px solid rgba(213, 226, 239, 0.78);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.9);
    box-shadow: var(--shadow);
    color: var(--text);
    text-decoration: none;
}

.landing-card:hover,
.landing-card:focus-visible {
    border-color: rgba(37, 110, 184, 0.3);
    color: var(--text);
    transform: translateY(-2px);
}

.landing-card__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: var(--radius);
    background: #eaf3ff;
    color: var(--brand-dark);
    font-weight: 800;
}

.landing-card__label {
    color: var(--brand);
    font-size: 0.82rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.landing-card strong {
    display: block;
    font-size: 1.35rem;
    line-height: 1.15;
    overflow-wrap: anywhere;
}

.summary-list {
    display: grid;
    gap: 0.85rem;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    padding: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: rgba(249, 251, 254, 0.9);
}

.summary-item h4 {
    margin: 0 0 0.25rem;
}

.summary-item__metrics {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
}

.summary-money {
    font-weight: 700;
    margin-left: 0.35rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 0.45rem 0.75rem;
    font-size: 0.86rem;
    font-weight: 700;
    white-space: nowrap;
    max-width: 100%;
}

.badge--paid {
    background: var(--success-soft);
    color: var(--success);
}

.badge--upcoming {
    background: #eaf3ff;
    color: #245f9f;
}

.badge--pending {
    background: var(--danger-soft);
    color: var(--danger);
}

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

.form-grid label {
    font-weight: 600;
}

.field-error {
    display: block;
    margin-top: 0.4rem;
    color: var(--danger);
    font-size: 0.86rem;
    font-weight: 700;
}

.form-note {
    display: inline-flex;
    align-items: center;
    margin-left: 0.75rem;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
}

.form-grid__full,
.form-actions {
    grid-column: 1 / -1;
}

.data-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

.data-table th,
.data-table td {
    padding: 0.95rem 0.8rem;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid #e6eef7;
}

.data-table th {
    font-size: 0.88rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.data-table__status-column {
    max-width: 13rem;
    width: 13rem;
}

.data-table__action-column {
    width: 7rem;
    white-space: nowrap;
}

.data-table__status-column .badge {
    white-space: normal;
}

.data-table td strong {
    display: block;
    margin-bottom: 0.25rem;
}

.student-section + .student-section {
    margin-top: 1.35rem;
}

.student-section__header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.75rem;
}

.student-summary,
.receipt-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem;
    margin-bottom: 1.25rem;
}

.student-summary > div,
.receipt-grid > div {
    padding: 1rem;
    border-radius: var(--radius);
    background: #f9fbfe;
    border: 1px solid var(--border);
}

.receipt-notes {
    margin-top: 1rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #f9fbfe;
}

.text-link {
    font-weight: 700;
    overflow-wrap: anywhere;
}

.empty-state {
    margin: 0;
    padding: 1rem 0;
}

@media (max-width: 980px) {
    .hero-card,
    .stats-grid,
    .panel-grid,
    .panel-grid--wide,
    .landing-card-grid,
    .student-summary,
    .receipt-grid,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .topbar,
    .panel__header,
    .receipt-card__header,
    .summary-item {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar__nav,
    .receipt-actions {
        justify-content: flex-start;
    }

    .summary-item__metrics {
        justify-content: flex-start;
    }
}

@media (max-width: 720px) {
    html {
        font-size: 14px;
    }

    body {
        background: linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
    }

    .app-shell {
        width: min(100% - 1rem, 1180px);
        padding: 1rem 0 2rem;
    }

    .topbar {
        align-items: center;
        flex-direction: row;
        gap: 0.85rem;
        margin-bottom: 1rem;
        position: relative;
    }

    .topbar h1 {
        font-size: 1.35rem;
        text-align: center;
    }

    .topbar > div {
        flex: 1;
        padding-left: 44px;
    }

    .eyebrow {
        font-size: 0.68rem;
    }

    .hero-card h2 {
        font-size: 1.3rem;
    }

    .panel h2,
    .receipt-card h2 {
        font-size: 1.2rem;
    }

    .panel h3 {
        font-size: 1.05rem;
    }

    .muted,
    .panel p,
    .summary-item p,
    .stat-card p,
    .empty-state,
    td span,
    .student-summary span,
    .receipt-grid span,
    .receipt-notes span {
        font-size: 0.9rem;
    }

    .topbar__nav,
    .topbar__nav a,
    .receipt-actions,
    .receipt-actions button,
    .receipt-actions .text-link,
    .tracker-toolbar,
    .tracker-toolbar .button-link,
    .inline-form button,
    .form-actions button {
        width: 100%;
    }

    .topbar__nav {
        display: none;
    }

    .receipt-actions .text-link {
        justify-content: center;
    }

    .menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 auto;
        width: 44px;
        box-shadow: none;
        padding: 0;
    }

    .drawer-backdrop {
        position: fixed;
        inset: 0;
        z-index: 20;
        background: rgba(23, 34, 53, 0.42);
    }

    .drawer-backdrop:not([hidden]) {
        display: block;
    }

    .drawer-menu {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        z-index: 30;
        display: block;
        width: min(20rem, 86vw);
        padding: 1rem;
        border-left: 1px solid var(--border);
        background: var(--surface-strong);
        box-shadow: -18px 0 40px rgba(27, 49, 78, 0.18);
        transform: translateX(100%);
        transition: transform 160ms ease;
    }

    .is-drawer-open {
        overflow: hidden;
    }

    .is-drawer-open .drawer-menu {
        transform: translateX(0);
    }

    .page-content {
        gap: 1rem;
    }

    .hero-card,
    .panel,
    .receipt-card,
    .stat-card {
        padding: 1rem;
    }

    .hero-card {
        gap: 1rem;
    }

    .panel__header,
    .receipt-card__header {
        gap: 0.8rem;
    }

    .panel__header .inline-form {
        width: 100%;
    }

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

    .stat-card strong,
    .student-summary strong,
    .receipt-grid strong {
        font-size: 1.15rem;
        overflow-wrap: anywhere;
    }

    .landing-card strong {
        font-size: 1.1rem;
    }

    input,
    select,
    textarea,
    button,
    .button-link,
    .drawer-menu__nav a {
        font-size: 0.95rem;
    }

    .summary-item {
        padding: 0.85rem;
    }

    .summary-item__metrics,
    .legend {
        width: 100%;
    }

    .tracker-toolbar {
        align-items: stretch;
    }

    .tracker-toolbar .button-link,
    .panel__header .inline-form button {
        width: auto;
        min-height: 32px;
        padding: 0.4rem 0.75rem;
        justify-self: start;
    }

    .landing-card {
        min-height: auto;
    }

    .badge {
        font-size: 0.78rem;
        white-space: normal;
        text-align: center;
    }

    .helper-pill {
        white-space: normal;
    }

    .student-section__header {
        align-items: flex-start;
        flex-direction: column;
        gap: 0.25rem;
    }

    .data-table-wrapper {
        overflow: visible;
    }

    .data-table {
        min-width: 0;
        border-collapse: separate;
        border-spacing: 0;
    }

    .data-table thead {
        display: none;
    }

    .data-table,
    .data-table tbody,
    .data-table tr,
    .data-table td {
        display: block;
        width: 100%;
    }

    .data-table__status-column,
    .data-table__action-column {
        max-width: none;
        width: 100%;
        white-space: normal;
    }

    .data-table tr {
        border: 1px solid var(--border);
        border-radius: var(--radius);
        background: #f9fbfe;
        padding: 0.2rem 0;
        margin-bottom: 1rem;
    }

    .data-table td {
        display: grid;
        grid-template-columns: minmax(7.5rem, 42%) minmax(0, 1fr);
        gap: 0.75rem;
        align-items: start;
        border-bottom: 1px solid #e6eef7;
        padding: 0.75rem 0.85rem;
        overflow-wrap: anywhere;
    }

    .data-table td:last-child {
        border-bottom: 0;
    }

    .data-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 0.68rem;
        font-weight: 700;
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }

    .data-table td.empty-state,
    .data-table td[colspan] {
        display: block;
    }

    .data-table td.empty-state::before,
    .data-table td[colspan]::before {
        content: none;
    }
}

@media (max-width: 420px) {
    .data-table td {
        grid-template-columns: 1fr;
        gap: 0.25rem;
    }
}

@media print {
    body {
        background: #fff;
    }

    .topbar,
    .flash,
    .receipt-actions,
    .topbar__nav {
        display: none !important;
    }

    .app-shell {
        width: 100%;
        padding: 0;
    }

    .receipt-card {
        box-shadow: none;
        border: 1px solid #ccc;
    }
}
