:root {
    color-scheme: dark;
    --bg: #0b0b0b;
    --panel: #141414;
    --panel-2: #1a1a1a;
    --line: #2a2a2a;
    --text: #f3f3f3;
    --muted: #9f9f9f;
    --good: #52d273;
    --warn: #f1bb4d;
    --bad: #ef6b6b;
    --accent: #ffffff;
    --accent-text: #111111;
    --radius: 18px;
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
}
* {
    box-sizing: border-box;
}
.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
}
.brand-logo {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    flex: 0 0 auto;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.3);
}
.boot-screen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 12px;
    padding: 28px;
    text-align: center;
    background: var(--bg);
    transition:
        opacity 0.22s ease,
        visibility 0.22s ease;
}
body:not(.booting) .boot-screen {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.boot-logo {
    width: 104px;
    height: 104px;
    border-radius: 28px;
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
}
.boot-screen h1 {
    font-size: 34px;
}
.boot-screen > p {
    color: var(--muted);
    margin: 0;
}
.boot-spinner {
    width: 34px;
    height: 34px;
    border: 4px solid #252525;
    border-top-color: #2aa8ff;
    border-radius: 50%;
    animation: classfund-spin 0.85s linear infinite;
}
.boot-slow {
    max-width: 420px;
    border: 1px solid var(--line);
    background: var(--panel);
    border-radius: 16px;
    padding: 14px;
    margin-top: 8px;
}
.boot-slow p {
    color: var(--muted);
    font-size: 13px;
    margin: 0 0 10px;
}
@keyframes classfund-spin {
    to {
        transform: rotate(360deg);
    }
}

html,
body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
}
body {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button,
input,
select {
    font: inherit;
}
button {
    -webkit-tap-highlight-color: transparent;
}
.topbar {
    max-width: 1100px;
    margin: 0 auto;
    padding: 22px 18px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
h1 {
    margin: 0;
    font-size: clamp(24px, 5vw, 34px);
    letter-spacing: -0.04em;
}
h2 {
    margin: 0;
    font-size: 22px;
}
.muted {
    color: var(--muted);
    margin: 4px 0 0;
    font-size: 13px;
}
.app-shell {
    max-width: 1100px;
    margin: 0 auto;
    padding: 10px 18px 48px;
}
.panel {
    border: 1px solid var(--line);
    background: var(--panel);
    border-radius: var(--radius);
}
.toolbar,
.controls,
.actions {
    display: flex;
    gap: 10px;
    align-items: end;
    padding: 12px;
    flex-wrap: wrap;
}
.field {
    display: grid;
    gap: 6px;
    min-width: 160px;
}
.field.grow {
    flex: 1 1 280px;
}
label {
    font-size: 12px;
    color: var(--muted);
    font-weight: 700;
}
input,
select {
    width: 100%;
    border: 1px solid var(--line);
    background: #0f0f0f;
    color: var(--text);
    border-radius: 12px;
    padding: 12px 13px;
    outline: none;
}
input:focus,
select:focus {
    border-color: #575757;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.05);
}
.btn {
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    border-radius: 12px;
    padding: 11px 14px;
    font-weight: 800;
    cursor: pointer;
    min-height: 44px;
}
.btn:hover {
    border-color: #484848;
}
.btn:active {
    transform: translateY(1px);
}
.btn.primary {
    background: var(--accent);
    color: var(--accent-text);
    border-color: var(--accent);
}
.btn.danger-soft {
    color: #ff9a9a;
}
.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin: 10px 0;
}
.summary-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 15px;
    display: grid;
    gap: 6px;
}
.summary-card span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}
.summary-card strong {
    font-size: clamp(19px, 4vw, 28px);
    letter-spacing: -0.03em;
}
.segmented {
    display: flex;
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    background: #0f0f0f;
}
.segmented button {
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 11px 12px;
    font-weight: 800;
    cursor: pointer;
}
.segmented button.active {
    background: #292929;
    color: var(--text);
}
.collection-meta {
    color: var(--muted);
    font-size: 13px;
    padding: 12px 4px 4px;
}
.student-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin: 10px 0;
}
.student-card {
    border: 1px solid var(--line);
    background: var(--panel);
    border-radius: 18px;
    padding: 14px;
    min-height: 138px;
    display: grid;
    gap: 10px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.student-card:hover {
    border-color: #454545;
}
.student-card.paid {
    border-color: rgba(82, 210, 115, 0.45);
}
.student-card.partial {
    border-color: rgba(241, 187, 77, 0.5);
}
.student-card .name {
    font-weight: 900;
    line-height: 1.2;
    font-size: 16px;
    padding-right: 78px;
}
.status-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 5px 8px;
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 0.05em;
}
.status-badge.paid {
    color: var(--good);
}
.status-badge.partial {
    color: var(--warn);
}
.status-badge.unpaid {
    color: var(--muted);
}
.money-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    color: var(--muted);
    font-size: 12px;
}
.money-row strong {
    color: var(--text);
    font-size: 14px;
}
.progress {
    height: 7px;
    border-radius: 999px;
    background: #242424;
    overflow: hidden;
}
.progress > span {
    display: block;
    height: 100%;
    background: #7f7f7f;
    border-radius: inherit;
}
.student-card.paid .progress > span {
    background: var(--good);
}
.student-card.partial .progress > span {
    background: var(--warn);
}
.card-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.hint {
    color: var(--muted);
    font-size: 11px;
}
.mini-btn {
    border: 1px solid var(--line);
    background: #202020;
    color: var(--text);
    border-radius: 10px;
    padding: 7px 9px;
    font-weight: 800;
    font-size: 11px;
    cursor: pointer;
}
.actions {
    margin-top: 12px;
}
.sync-pill {
    display: inline-flex;
    gap: 7px;
    align-items: center;
    border: 1px solid var(--line);
    background: var(--panel);
    border-radius: 999px;
    padding: 8px 10px;
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}
.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #6f6f6f;
}
.dot.online {
    background: var(--good);
}
.dot.syncing {
    background: var(--warn);
}
dialog {
    border: none;
    padding: 0;
    border-radius: 20px;
    background: transparent;
    color: var(--text);
    width: min(94vw, 600px);
}
dialog::backdrop {
    background: rgba(0, 0, 0, 0.76);
    backdrop-filter: blur(4px);
}
.dialog-card {
    background: #121212;
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 18px;
    display: grid;
    gap: 14px;
}
.dialog-card.wide {
    width: min(94vw, 720px);
    max-height: 84vh;
    overflow: auto;
}
.dialog-head {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 12px;
}
.icon-btn {
    border: 0;
    background: #242424;
    color: var(--text);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
}
.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.check-row {
    display: flex;
    gap: 9px;
    align-items: center;
    color: var(--text);
    font-size: 14px;
}
.check-row input {
    width: auto;
}
.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}
.dialog-actions.between {
    justify-content: space-between;
}
.inline-form {
    display: flex;
    gap: 8px;
}
.inline-form input {
    flex: 1;
}
.manager-list {
    display: grid;
    gap: 8px;
}
.manager-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border: 1px solid var(--line);
    background: #171717;
    border-radius: 13px;
    padding: 10px 12px;
}
.manager-row span {
    font-weight: 800;
}
.manager-row .row-actions {
    display: flex;
    gap: 6px;
}
.empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 38px 16px;
    border: 1px dashed var(--line);
    border-radius: var(--radius);
    color: var(--muted);
}
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(18px + env(safe-area-inset-bottom));
    transform: translateX(-50%) translateY(20px);
    background: #f0f0f0;
    color: #111;
    border-radius: 999px;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 800;
    opacity: 0;
    pointer-events: none;
    transition: 0.2s ease;
    z-index: 50;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
    max-width: min(90vw, 560px);
    text-align: center;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.print-report {
    display: none;
}
@media (max-width: 850px) {
    .summary-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .student-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
@media (max-width: 560px) {
    .topbar {
        padding-top: 16px;
    }
    .sync-pill span:last-child {
        display: none;
    }
    .toolbar,
    .controls,
    .actions {
        align-items: stretch;
    }
    .toolbar .btn,
    .actions .btn {
        flex: 1 1 calc(50% - 6px);
    }
    .student-grid {
        grid-template-columns: 1fr;
    }
    .student-card {
        min-height: 124px;
    }
    .segmented {
        width: 100%;
    }
    .segmented button {
        flex: 1;
        padding-inline: 7px;
    }
    .two-col {
        grid-template-columns: 1fr;
    }
    .dialog-actions.between {
        display: grid;
    }
    .inline-form {
        flex-direction: column;
    }
    .manager-row {
        padding: 8px;
        gap: 7px;
    }
    .manager-row .row-actions {
        gap: 4px;
    }
    .manager-row .mini-btn {
        padding: 7px;
    }
}

/* Swipeable student bubbles */
.student-swipe-wrap {
    position: relative;
    overflow: hidden;
    border-radius: 18px;
    min-width: 0;
    animation: card-in 0.28s cubic-bezier(0.2, 0.8, 0.2, 1) both;
    animation-delay: var(--card-delay, 0ms);
}
.student-swipe-wrap.no-enter-anim {
    animation: none;
}
.student-swipe-wrap .student-card {
    height: 100%;
    z-index: 2;
    touch-action: pan-y;
    will-change: transform;
    transition:
        transform 0.22s cubic-bezier(0.2, 0.85, 0.25, 1),
        border-color 0.18s ease,
        box-shadow 0.18s ease;
}
.student-card.swiping {
    transition: none;
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
}
.student-card.snap-back {
    transition: transform 0.24s cubic-bezier(0.2, 0.9, 0.25, 1);
}
.swipe-action {
    position: absolute;
    inset-block: 0;
    display: flex;
    align-items: center;
    gap: 7px;
    width: 118px;
    padding: 0 18px;
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.02em;
    opacity: var(--swipe-progress, 0);
    transform: scale(0.98);
    transition:
        opacity 0.12s ease,
        transform 0.12s ease;
}
.swipe-action span {
    font-size: 22px;
    line-height: 1;
}
.swipe-partial {
    left: 0;
    justify-content: flex-start;
    color: #ffe19b;
    background: linear-gradient(90deg, rgba(241, 187, 77, 0.22), rgba(241, 187, 77, 0.02));
}
.swipe-remove {
    right: 0;
    justify-content: flex-end;
    color: #ffaaaa;
    background: linear-gradient(270deg, rgba(239, 107, 107, 0.23), rgba(239, 107, 107, 0.02));
}
@keyframes card-in {
    from {
        opacity: 0;
        transform: translateY(7px) scale(0.985);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Drag-and-drop class ordering */
.manager-row {
    transition:
        transform 0.16s ease,
        border-color 0.16s ease,
        background 0.16s ease,
        opacity 0.16s ease;
}
.manager-row.dragging {
    border-color: #5b5b5b;
    background: #202020;
    opacity: 0.82;
    transform: scale(0.99);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.24);
}
.manager-list.is-reordering .manager-row:not(.dragging) {
    transition: transform 0.16s ease;
}
.drag-handle {
    flex: 0 0 34px;
    width: 34px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #101010;
    color: #8d8d8d;
    font-weight: 900;
    letter-spacing: -3px;
    cursor: grab;
    touch-action: none;
    user-select: none;
}
.drag-handle:active {
    cursor: grabbing;
    color: #fff;
}
.manager-name {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 9px;
}
.manager-name small {
    display: inline-grid;
    place-items: center;
    width: 24px;
    height: 24px;
    flex: 0 0 24px;
    border-radius: 50%;
    background: #242424;
    color: var(--muted);
    font-size: 10px;
}

@media (prefers-reduced-motion: reduce) {
    .student-swipe-wrap,
    .student-card,
    .manager-row,
    .toast {
        animation: none !important;
        transition-duration: 0.01ms !important;
    }
}

@media print {
    @page {
        size: A4 portrait;
        margin: 12mm;
    }
    body {
        background: #fff;
        color: #111;
        padding: 0;
        font-family: Arial, sans-serif;
    }
    .no-print,
    dialog,
    .toast {
        display: none !important;
    }
    .print-report {
        display: block !important;
        color: #111;
    }
    .print-report h1 {
        font-size: 22pt;
        margin: 0 0 2mm;
    }
    .print-report .sub {
        font-size: 10pt;
        color: #444;
        margin-bottom: 4mm;
    }
    .print-summary {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        border: 1px solid #555;
        margin: 3mm 0 5mm;
    }
    .print-summary div {
        padding: 2.5mm;
        border-right: 1px solid #777;
    }
    .print-summary div:last-child {
        border-right: 0;
    }
    .print-summary span {
        display: block;
        font-size: 7.5pt;
        text-transform: uppercase;
        color: #555;
    }
    .print-summary strong {
        font-size: 11pt;
    }
    .print-table {
        width: 100%;
        border-collapse: collapse;
        font-size: 8.5pt;
    }
    .print-table th,
    .print-table td {
        border: 1px solid #666;
        padding: 1.8mm 2mm;
        text-align: left;
    }
    .print-table th {
        background: #efefef;
    }
    .print-table td.num,
    .print-table th.num {
        text-align: right;
    }
    .print-table tr {
        break-inside: avoid;
    }
    .print-footer {
        margin-top: 4mm;
        display: flex;
        justify-content: space-between;
        color: #555;
        font-size: 7.5pt;
    }

    .receipt-shell {
        width: 72mm;
        margin: 0 auto;
        color: #111;
        font-family: "Courier New", Courier, monospace;
        font-size: 9pt;
        line-height: 1.35;
    }
    .receipt-brand {
        text-align: center;
        font-weight: 700;
        font-size: 13pt;
        letter-spacing: 0.08em;
    }
    .receipt-sub {
        text-align: center;
        font-size: 10pt;
        margin-top: 1.5mm;
    }
    .receipt-meta {
        text-align: center;
        color: #333;
        font-size: 8pt;
    }
    .receipt-cut {
        border-top: 1px dashed #666;
        margin: 2.5mm 0;
    }
    .receipt-table {
        width: 100%;
        border-collapse: collapse;
    }
    .receipt-table td {
        padding: 1.1mm 0;
    }
    .receipt-table td:last-child {
        text-align: right;
        font-weight: 700;
    }
    .receipt-shell h3 {
        font-size: 9.2pt;
        margin: 2mm 0 1mm;
        letter-spacing: 0.06em;
    }
    .receipt-list {
        list-style: none;
        margin: 0;
        padding: 0;
    }
    .receipt-list li {
        display: flex;
        justify-content: space-between;
        gap: 6px;
        border-bottom: 1px dotted #bbb;
        padding: 1.1mm 0;
    }
    .receipt-list li strong {
        text-align: right;
    }
    .receipt-footer {
        text-align: center;
        margin-top: 2.5mm;
        font-size: 8pt;
        color: #444;
    }
}
.card-foot {
    justify-content: flex-end;
}
input[type="range"] {
    padding: 0;
    accent-color: var(--accent);
}

.install-btn {
    border-color: rgba(82, 210, 115, 0.4);
}
.install-btn.ready {
    background: rgba(82, 210, 115, 0.1);
    color: #a9f5bc;
    border-color: rgba(82, 210, 115, 0.55);
}
.install-instructions {
    border: 1px solid var(--line);
    background: #0f0f0f;
    border-radius: 14px;
    padding: 13px 14px;
    color: var(--muted);
    line-height: 1.55;
    font-size: 13px;
}
.install-instructions strong {
    color: var(--text);
}
.install-instructions p {
    margin: 6px 0 0;
}
.install-instructions ol {
    margin: 8px 0 0;
    padding-left: 21px;
}
.offline-ready-row {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--muted);
    font-size: 13px;
}
.offline-ready-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--warn);
    box-shadow: 0 0 0 4px rgba(241, 187, 77, 0.08);
}
.offline-ready-dot.ready {
    background: var(--good);
    box-shadow: 0 0 0 4px rgba(82, 210, 115, 0.08);
}
@media (display-mode: standalone) {
    .install-btn {
        display: none !important;
    }
}

/* Collection completion + history */
.done-btn {
    border-color: rgba(82, 210, 115, 0.5);
    background: rgba(82, 210, 115, 0.1);
    color: #b7f8c6;
}
.done-btn:hover {
    background: rgba(82, 210, 115, 0.16);
}
.history-list {
    display: grid;
    gap: 10px;
    max-height: min(62vh, 620px);
    overflow: auto;
    padding-right: 2px;
}
.history-item {
    display: flex;
    gap: 14px;
    align-items: center;
    justify-content: space-between;
    border: 1px solid var(--line);
    background: #111;
    border-radius: 15px;
    padding: 14px;
}
.history-main {
    min-width: 0;
    flex: 1;
}
.history-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
}
.history-badge {
    display: inline-flex;
    align-items: center;
    border: 1px solid rgba(82, 210, 115, 0.35);
    background: rgba(82, 210, 115, 0.1);
    color: #aef1bd;
    border-radius: 999px;
    padding: 2px 7px;
    font-size: 9px;
    font-weight: 900;
    letter-spacing: 0.08em;
}
.history-period {
    color: var(--muted);
    font-size: 12px;
    margin-top: 5px;
}
.history-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 7px 12px;
    color: #c7c7c7;
    font-size: 11px;
    margin-top: 8px;
}
.history-actions {
    display: flex;
    gap: 7px;
    flex: 0 0 auto;
}
.archived-note {
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
}
@media (max-width: 560px) {
    .history-item {
        align-items: stretch;
        flex-direction: column;
    }
    .history-actions .btn {
        flex: 1;
    }
}
