:root {
    --bg: #0f172a;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --text: #0f172a;
    --text-soft: #475569;
    --border: #cbd5e1;
    --accent: #0f766e;
    --accent-dark: #115e59;
    --secondary: #0f172a;
    --receipt-accent: #0f766e;
    --shadow: 0 18px 50px rgba(15, 23, 42, 0.12);
    --radius: 18px;
}

*, *::before, *::after { box-sizing: border-box; }
html {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}
body {
    margin: 0;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
    color: var(--text);
    overflow-wrap: break-word;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
textarea { font: inherit; resize: vertical; }
img, svg, canvas, video, iframe {
    max-width: 100%;
    height: auto;
}
button, .button-primary, .button-secondary {
    border: 0;
    border-radius: 12px;
    cursor: pointer;
}
input, select, textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    color: var(--text);
}
label span {
    display: block;
    font-size: 0.92rem;
    color: var(--text-soft);
    margin-bottom: 8px;
}
.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: radial-gradient(circle at top left, rgba(15,118,110,.2), transparent 35%), var(--bg);
}
.auth-shell {
    width: min(1120px, 100%);
    display: grid;
    grid-template-columns: 1.05fr 0.95fr;
    background: rgba(255,255,255,.96);
    border-radius: 28px;
    overflow: hidden;
    box-shadow: var(--shadow);
}
.auth-shell-wide { grid-template-columns: 0.85fr 1.15fr; }
.brand-panel {
    padding: 48px;
    background: linear-gradient(160deg, var(--secondary), var(--accent));
    color: #f8fafc;
}
.brand-panel h1 { font-size: 2.4rem; margin: 16px 0; line-height: 1.1; }
.brand-panel p { line-height: 1.7; color: rgba(226,232,240,.86); }
.brand-points { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 28px; }
.brand-points span, .badge, .step {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(255,255,255,.12);
    font-size: 0.85rem;
}
.auth-panel { padding: 36px; background: var(--surface); }
.panel-head h2, .card-head h2, .topbar h1 { margin: 0 0 8px; }
.panel-head p, .card-head p, .topbar p { margin: 0; color: var(--text-soft); line-height: 1.6; }
.brand-kicker {
    font-size: 0.8rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #99f6e4;
}
.brand-lockup {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    min-width: 0;
}
.brand-logo {
    width: 52px;
    height: 52px;
    object-fit: contain;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.96);
    padding: 8px;
}
.brand-logo-fallback {
    display: grid;
    place-items: center;
    font-weight: 700;
    color: var(--secondary);
}
.stack-form { display: grid; gap: 18px; min-width: 0; max-width: 100%; }
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    min-width: 0;
    max-width: 100%;
}
.span-2 { grid-column: span 2; }
.button-primary, .button-secondary, .inline-form button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 18px;
    transition: 0.2s ease;
    max-width: 100%;
    white-space: normal;
    text-align: center;
}
.button-primary { background: var(--accent); color: #fff; }
.button-primary:hover { background: var(--accent-dark); }
.button-secondary { background: #e2e8f0; color: var(--text); }
.button-secondary:hover { background: #cbd5e1; }
.alert {
    border-radius: 14px;
    padding: 14px 16px;
    margin-bottom: 16px;
    border: 1px solid transparent;
}
.alert-success { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.alert-danger { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border-color: #fcd34d; }
.alert-info { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.stepper { display: flex; flex-wrap: wrap; gap: 10px; margin: 24px 0; }
.step { background: #e2e8f0; color: #334155; }
.step.active { background: rgba(15,118,110,.12); color: var(--accent-dark); }
.check-list, .summary-grid { display: grid; gap: 14px; }
.check-item, .summary-grid div {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    padding: 14px 16px;
    border-radius: 14px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
}
.check-item.ok { border-color: #86efac; }
.check-item.fail { border-color: #fca5a5; }
.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 280px 1fr;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}
.sidebar {
    background: #0f172a;
    color: #e2e8f0;
    padding: 28px 22px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    min-width: 0;
    max-width: 100%;
    overflow-x: hidden;
}
.sidebar-brand,
.sidebar-nav,
.sidebar-foot,
.sidebar-nav a,
.sidebar-brand strong,
.sidebar-brand small {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
}
.sidebar-brand strong { display: block; margin-top: 8px; }
.sidebar-brand small { display: block; margin-top: 6px; color: #94a3b8; }
.sidebar-nav { display: grid; gap: 10px; }
.sidebar-nav a {
    padding: 12px 14px;
    border-radius: 12px;
    color: #cbd5e1;
}
.sidebar-nav a:hover, .sidebar-nav a.active {
    background: rgba(148,163,184,.18);
    color: #fff;
}
.sidebar-foot {
    margin-top: auto;
    display: grid;
    gap: 8px;
    font-size: 0.92rem;
    color: #94a3b8;
}
.main-shell {
    display: grid;
    grid-template-rows: auto 1fr;
    min-width: 0;
    max-width: 100%;
}
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 24px 28px;
    border-bottom: 1px solid var(--border);
    background: rgba(255,255,255,.9);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 10;
    min-width: 0;
    max-width: 100%;
}
.topbar > * {
    min-width: 0;
    max-width: 100%;
}
.topbar h1,
.topbar p {
    overflow-wrap: anywhere;
}
.topbar-user {
    display: grid;
    justify-items: end;
    gap: 8px;
    min-width: 0;
}
.content-shell {
    padding: 28px;
    display: grid;
    gap: 24px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}
.content-shell > * {
    min-width: 0;
    max-width: 100%;
}
.grid-cards, .page-grid { display: grid; gap: 18px; }
.grid-cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.page-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.metric-card, .card {
    background: rgba(255,255,255,.94);
    border: 1px solid rgba(203,213,225,.8);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 100%;
    min-width: 0;
}
.metric-card { padding: 22px; display: grid; gap: 8px; }
.metric-card strong { font-size: clamp(1.35rem, 5vw, 2rem); }
.metric-card span { color: var(--text-soft); }
.metric-card small { color: var(--text-soft); line-height: 1.5; }
.card { padding: 22px; }
.card-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    margin-bottom: 18px;
    min-width: 0;
    max-width: 100%;
}
.card-head > * {
    min-width: 0;
    max-width: 100%;
}
.card-head h2,
.card-head p {
    overflow-wrap: anywhere;
}
.table-wrap {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}
table {
    width: 100%;
    max-width: 100%;
    min-width: 640px;
    border-collapse: collapse;
}
th, td {
    text-align: left;
    padding: 14px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
    vertical-align: top;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.feature-list {
    margin: 0;
    padding-left: 18px;
    display: grid;
    gap: 10px;
    color: var(--text-soft);
}
.button-row, .inline-form, .role-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    min-width: 0;
    max-width: 100%;
}
.inline-form input[type="text"] {
    width: min(260px, 100%);
}
.filters-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 20px;
    min-width: 0;
    max-width: 100%;
}
.compact-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}
.filters-actions {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
    min-width: 0;
    max-width: 100%;
}
.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    min-width: 0;
    max-width: 100%;
}
.muted-text {
    color: var(--text-soft);
    font-size: 0.92rem;
    overflow-wrap: anywhere;
}
.table-identity {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.avatar-image,
.avatar-fallback {
    border-radius: 18px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    object-fit: cover;
}
.avatar-sm {
    width: 52px;
    height: 52px;
}
.avatar-xl {
    width: 132px;
    height: 132px;
}
.avatar-fallback {
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 2rem;
    color: var(--accent-dark);
}
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-radius: 999px;
    background: var(--surface-muted);
    color: var(--text);
    border: 1px solid var(--border);
    font-size: 0.84rem;
}
.status-active {
    background: #ecfdf5;
    color: #166534;
    border-color: #86efac;
}
.status-inactive {
    background: #f8fafc;
    color: #475569;
    border-color: #cbd5e1;
}
.status-graduated {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #93c5fd;
}
.status-transferred {
    background: #fff7ed;
    color: #c2410c;
    border-color: #fdba74;
}
.status-primary {
    background: #f5f3ff;
    color: #6d28d9;
    border-color: #c4b5fd;
}
.status-unpaid {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #93c5fd;
}
.status-partial {
    background: #fffbeb;
    color: #92400e;
    border-color: #fcd34d;
}
.status-paid {
    background: #ecfdf5;
    color: #166534;
    border-color: #86efac;
}
.status-overdue {
    background: #fef2f2;
    color: #991b1b;
    border-color: #fca5a5;
}
.status-cancelled {
    background: #f8fafc;
    color: #475569;
    border-color: #cbd5e1;
}
.profile-layout {
    display: grid;
    gap: 20px;
    min-width: 0;
    max-width: 100%;
}
.profile-hero {
    display: flex;
    align-items: center;
    gap: 22px;
    margin-bottom: 22px;
    min-width: 0;
    max-width: 100%;
}
.profile-hero-form,
.profile-hero-guardian {
    align-items: flex-start;
}
.profile-meta {
    display: grid;
    gap: 10px;
    min-width: 0;
}
.profile-meta h2,
.profile-meta h3 {
    margin: 0;
    overflow-wrap: anywhere;
}
.profile-meta p {
    margin: 0;
    color: var(--text-soft);
}
.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    min-width: 0;
    max-width: 100%;
}
.detail-item {
    display: grid;
    gap: 8px;
    padding: 16px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: var(--surface-muted);
    min-width: 0;
    max-width: 100%;
}
.detail-item span {
    color: var(--text-soft);
    font-size: 0.9rem;
}
.detail-item strong {
    line-height: 1.6;
}
.detail-item-wide {
    grid-column: span 2;
}
.linked-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    min-width: 0;
    max-width: 100%;
}
.linked-card,
.inline-create-card,
.form-section {
    padding: 18px;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: var(--surface-muted);
    min-width: 0;
    max-width: 100%;
}
.linked-card-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 14px;
    min-width: 0;
    max-width: 100%;
}
.linked-card-head h3 {
    margin: 0 0 6px;
}
.linked-card-head p,
.linked-card-body {
    margin: 0;
    color: var(--text-soft);
    line-height: 1.7;
}
.linked-card-body {
    display: grid;
    gap: 6px;
    margin-bottom: 14px;
}
.badge-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.selection-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    min-width: 0;
    max-width: 100%;
}
.selection-list {
    display: grid;
    gap: 14px;
    min-width: 0;
    max-width: 100%;
}
.selection-item {
    display: grid;
    gap: 14px;
    padding: 16px;
    border-radius: 16px;
    background: #fff;
    border: 1px solid var(--border);
    min-width: 0;
    max-width: 100%;
}
.selection-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-width: 0;
}
.selection-head input[type="checkbox"] {
    margin-top: 5px;
    flex: 0 0 auto;
}
.selection-grid,
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    min-width: 0;
    max-width: 100%;
}
.checkline {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #fff;
    min-width: 0;
    max-width: 100%;
}
.checkline input {
    width: auto;
    margin: 0;
}
.form-section {
    display: grid;
    gap: 18px;
}
.upload-field {
    display: grid;
    gap: 8px;
    width: min(420px, 100%);
    max-width: 100%;
}
.section-spacer {
    margin-bottom: 24px;
}
.summary-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    min-width: 0;
    max-width: 100%;
}
.summary-chip {
    display: grid;
    gap: 8px;
    padding: 16px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: var(--surface-muted);
    min-width: 0;
    max-width: 100%;
}
.summary-chip span,
.summary-chip small {
    color: var(--text-soft);
}
.summary-chip strong {
    font-size: 1.1rem;
}
.empty-state {
    padding: 22px;
    border-radius: 16px;
    background: #f8fafc;
    border: 1px dashed var(--border);
    width: 100%;
    max-width: 100%;
}
.page-footer {
    color: var(--text-soft);
    text-align: center;
    font-size: 0.92rem;
    padding-top: 8px;
}
.logo-preview-card {
    display: grid;
    gap: 10px;
    padding: 18px;
    border-radius: 16px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    width: min(320px, 100%);
    max-width: 100%;
}
.preview-label {
    color: var(--text-soft);
    font-size: 0.9rem;
}
.logo-preview {
    max-width: 220px;
    max-height: 90px;
    object-fit: contain;
}
.sidebar-toggle {
    display: none;
    padding: 10px 14px;
    background: #e2e8f0;
}

.theme-dark {
    --surface: #111827;
    --surface-muted: #1f2937;
    --text: #f8fafc;
    --text-soft: #cbd5e1;
    --border: #334155;
    --shadow: 0 18px 50px rgba(2, 6, 23, 0.45);
}
.theme-dark body,
.theme-dark.app-body,
.theme-dark.auth-body {
    background: linear-gradient(180deg, #020617 0%, #0f172a 100%);
}
.theme-dark input,
.theme-dark select,
.theme-dark textarea {
    background: #0f172a;
    color: var(--text);
}
.theme-dark .auth-shell,
.theme-dark .metric-card,
.theme-dark .card,
.theme-dark .topbar {
    background: rgba(17, 24, 39, 0.94);
}
.theme-dark .button-secondary {
    background: #334155;
    color: #f8fafc;
}
.theme-dark .selection-item,
.theme-dark .checkline {
    background: #0f172a;
}
.theme-dark .status-inactive {
    background: #111827;
    color: #cbd5e1;
}
.theme-dark .status-cancelled {
    background: #111827;
    color: #cbd5e1;
}
.theme-dark .sidebar-toggle {
    background: #334155;
    color: #f8fafc;
}
.sidebar-soft .sidebar {
    background: linear-gradient(180deg, #1e293b, #0f172a);
}
.sidebar-compact .sidebar {
    padding: 22px 16px;
}
.dashboard-compact .content-shell {
    gap: 16px;
}
.dashboard-compact .metric-card,
.dashboard-compact .card {
    padding: 18px;
}

@media (max-width: 1024px) {
    .auth-shell, .auth-shell-wide, .app-shell, .grid-cards, .page-grid, .form-grid, .filters-grid, .compact-grid, .detail-grid, .linked-grid, .selection-grid, .checkbox-grid, .summary-strip {
        grid-template-columns: 1fr;
    }
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: 260px;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        z-index: 20;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: inline-flex; }
}

@media (max-width: 768px) {
    .topbar,
    .card-head,
    .profile-hero,
    .linked-card-head,
    .selection-toolbar,
    .topbar-user,
    .table-identity {
        flex-direction: column;
        align-items: flex-start;
    }
    .topbar-user {
        justify-items: start;
    }
    .button-row,
    .filters-actions,
    .table-actions,
    .inline-form {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }
    .button-row > *,
    .filters-actions > *,
    .table-actions > *,
    .inline-form > *,
    .summary-chip .button-secondary {
        width: 100%;
        max-width: 100%;
    }
    .button-primary,
    .button-secondary,
    .inline-form button {
        min-height: 44px;
    }
}

@media (max-width: 640px) {
    .auth-body, .content-shell, .auth-panel, .brand-panel { padding: 18px; }
    .topbar { padding: 18px; align-items: flex-start; }
    .card, .metric-card { padding: 18px; }
    .span-2 { grid-column: span 1; }
    .detail-item-wide {
        grid-column: span 1;
    }
    table {
        min-width: 560px;
    }
}

@media (max-width: 480px) {
    .auth-body,
    .content-shell,
    .auth-panel,
    .brand-panel,
    .topbar {
        padding: 14px;
    }
    .card,
    .metric-card,
    .summary-chip,
    .detail-item,
    .linked-card,
    .inline-create-card,
    .form-section,
    .selection-item,
    .empty-state,
    .logo-preview-card {
        padding: 14px;
    }
    .grid-cards,
    .page-grid,
    .form-grid,
    .filters-grid,
    .compact-grid,
    .detail-grid,
    .linked-grid,
    .selection-grid,
    .checkbox-grid,
    .summary-strip,
    .stack-form,
    .selection-list {
        gap: 12px;
    }
    .card-head,
    .button-row,
    .filters-actions,
    .table-actions,
    .role-badges {
        gap: 10px;
    }
    .brand-panel h1,
    .topbar h1 {
        font-size: clamp(1.15rem, 6vw, 1.5rem);
        line-height: 1.25;
    }
    .avatar-xl {
        width: 96px;
        height: 96px;
    }
    table {
        min-width: 520px;
    }
}
