:root {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --ink: #172033;
    --muted: #667085;
    --line: #e6eaf0;
    --primary: #0f766e;
    --primary-dark: #115e59;
    --accent: #2563eb;
    --danger: #dc2626;
    --warning: #d97706;
    --success: #16a34a;
    --shadow: 0 16px 40px rgba(23, 32, 51, .08);
}

* { box-sizing: border-box; }
html { overflow-x: hidden; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
.app-shell { min-height: 100vh; display: flex; }
.sidebar {
    width: 270px;
    background: #111827;
    color: #f9fafb;
    padding: 22px;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 28px; }
.brand-mark {
    width: 46px; height: 46px; border-radius: 8px;
    background: var(--primary); display: grid; place-items: center;
    font-weight: 800;
}
.brand strong { display: block; line-height: 1.2; }
.brand span, .sidebar-footer span { display: block; color: #cbd5e1; font-size: 12px; margin-top: 4px; }
.nav { display: grid; gap: 8px; }
.nav a {
    padding: 12px 14px;
    border-radius: 8px;
    color: #d1d5db;
    transition: .2s;
}
.nav a:hover, .nav a.active { background: rgba(255,255,255,.11); color: #fff; }
.sidebar-footer { margin-top: auto; border-top: 1px solid rgba(255,255,255,.12); padding-top: 16px; }
.sidebar-footer a { display: inline-block; margin-top: 10px; color: #fff; font-weight: 700; }
.main { flex: 1; margin-left: 270px; min-width: 0; width: calc(100% - 270px); }
.topbar {
    background: rgba(255,255,255,.88);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
    padding: 18px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar h1 { margin: 0; font-size: 22px; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.content { padding: 28px; max-width: 100%; }
.menu-btn { display: none; }
.admin-chip, .badge {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 999px;
    padding: 8px 12px;
    color: var(--muted);
    white-space: nowrap;
}
.avatar {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid var(--line);
    background: #f8fafc;
    display: inline-grid;
    place-items: center;
    color: var(--muted);
    font-size: 11px;
}
.avatar-empty {
    line-height: 42px;
    text-align: center;
}
.grid { display: grid; gap: 18px; }
.cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card, .panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}
.card { padding: 20px; }
.card span { color: var(--muted); font-size: 13px; }
.card strong { display: block; margin-top: 8px; font-size: 25px; }
.panel { padding: 22px; margin-bottom: 22px; }
.panel-header { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 16px; }
.panel-header h2 { margin: 0; font-size: 18px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.btn, button {
    border: 0;
    border-radius: 8px;
    padding: 10px 14px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    line-height: 1.2;
    white-space: nowrap;
}
.btn:hover, button:hover { background: var(--primary-dark); }
.btn.secondary { background: #eef2f7; color: var(--ink); }
.btn.danger { background: var(--danger); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.form-group { display: grid; gap: 7px; align-content: start; }
label { font-weight: 700; font-size: 13px; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px 12px;
    background: #fff;
    color: var(--ink);
    outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
.photo-preview {
    width: 120px;
    height: 120px;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    display: grid;
    place-items: center;
    overflow: hidden;
    background: #f8fafc;
    color: var(--muted);
    font-size: 12px;
    text-align: center;
    padding: 8px;
}
.photo-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.balance-preview {
    border: 1px solid var(--line);
    background: #f8fafc;
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--primary);
    font-weight: 700;
}
.table-wrap { width: 100%; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
table { width: 100%; border-collapse: separate; border-spacing: 0; background: #fff; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .04em; background: #f8fafc; }
tr:last-child td { border-bottom: 0; }
.muted { color: var(--muted); }
.students-toolbar .panel-header { margin-bottom: 12px; }
.students-panel { padding: 16px; }
.students-table { table-layout: fixed; min-width: 0; font-size: 12px; }
.students-table th:first-child,
.students-table td:first-child { width: 6%; }
.students-table th:nth-child(2),
.students-table td:nth-child(2) { width: 8%; }
.students-table th:nth-child(3),
.students-table td:nth-child(3) { width: 14%; }
.students-table th:nth-child(4),
.students-table td:nth-child(4) { width: 16%; }
.students-table th:nth-child(5),
.students-table td:nth-child(5) { width: 13%; }
.students-table th:nth-child(6),
.students-table td:nth-child(6) { width: 6%; }
.students-table th:nth-child(7),
.students-table td:nth-child(7) { width: 11%; }
.students-table th:nth-child(8),
.students-table td:nth-child(8) { width: 9%; }
.students-table th:nth-child(9),
.students-table td:nth-child(9) { width: 14%; }
.students-table th:last-child,
.students-table td:last-child {
    padding-right: 16px;
}
.students-table td {
    overflow-wrap: break-word;
    word-break: normal;
    height: 68px;
}
.students-table td strong { font-size: 12px; }
.students-table small { font-size: 10px; }
.students-table tbody tr:hover { background: #f8fafc; }
.student-photo { width: 74px; }
.student-photo .avatar,
table img.avatar {
    width: 40px !important;
    height: 40px !important;
    max-width: 40px !important;
    max-height: 40px !important;
    min-width: 40px;
    object-fit: cover;
    border-radius: 8px;
    display: inline-block;
}
.students-table .actions {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-start;
    gap: 5px;
}
.students-table .btn {
    min-height: 28px;
    width: auto;
    min-width: 48px;
    padding: 5px 7px;
    font-size: 10px;
    border-radius: 7px;
}
.students-table .btn.danger { min-width: 56px; }
.inline-form { margin: 0; display: inline-flex; }
.status-active { color: var(--success); background: #dcfce7; border: 0; }
.status-inactive { color: var(--danger); background: #fee2e2; border: 0; }
.alert { padding: 13px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; }
.alert-success { color: #166534; background: #dcfce7; border-color: #bbf7d0; }
.alert-error { color: #991b1b; background: #fee2e2; border-color: #fecaca; }
.alert-info { color: #1e40af; background: #dbeafe; border-color: #bfdbfe; }
.empty {
    padding: 34px;
    text-align: center;
    color: var(--muted);
    background: #fff;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
}
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: linear-gradient(135deg, #e0f2fe, #f8fafc 45%, #ccfbf1);
}
.login-card { width: min(440px, 100%); padding: 28px; }
.login-card h1 { margin: 0 0 8px; }
.login-card p { margin: 0 0 22px; color: var(--muted); }
.summary-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.summary-row:last-child { border-bottom: 0; }
.receipt {
    width: 148mm;
    min-height: 105mm;
    background: #fff;
    color: #111827;
    margin: 0 auto;
    padding: 14mm;
    border: 1px solid #d1d5db;
}
.receipt-head { text-align: center; border-bottom: 2px solid #111827; padding-bottom: 8px; margin-bottom: 12px; }
.receipt-head h1 { margin: 0; font-size: 24px; }
.receipt-head p { margin: 4px 0 0; }
.signature { margin-top: 34px; text-align: right; }
.signature span { border-top: 1px solid #111827; padding: 8px 28px 0; display: inline-block; }
@media (max-width: 980px) {
    .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .sidebar {
        width: 300px;
        max-width: 86vw;
        transform: translateX(-100%);
        transition: .2s;
        box-shadow: 18px 0 40px rgba(15, 23, 42, .28);
    }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; width: 100%; }
    .menu-btn { display: inline-flex; background: #111827; }
    .topbar { padding: 16px 20px; }
    .content { padding: 20px; }
    .panel, .card { box-shadow: 0 10px 24px rgba(23, 32, 51, .06); }
    .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
    body { font-size: 13px; }
    .content, .topbar { padding: 14px; }
    .cards, .form-grid { grid-template-columns: 1fr; }
    .topbar {
        align-items: flex-start;
        justify-content: flex-start;
        gap: 10px;
    }
    .topbar h1 { font-size: 20px; }
    .topbar p { font-size: 12px; }
    .admin-chip { display: none; }
    .panel {
        padding: 14px;
        margin-bottom: 14px;
        border-radius: 8px;
    }
    .panel-header {
        align-items: stretch;
        flex-direction: column;
        gap: 12px;
    }
    .panel-header h2 { font-size: 17px; }
    .panel-header .btn,
    .students-toolbar .panel-header .btn {
        width: 100%;
    }
    .actions {
        width: 100%;
        align-items: stretch;
        gap: 8px;
    }
    .actions input,
    .actions select,
    .actions .btn,
    .actions button {
        width: 100% !important;
        max-width: none !important;
    }
    .btn, button {
        width: 100%;
        min-height: 42px;
        padding: 10px 12px;
    }
    input, select, textarea {
        min-height: 42px;
        font-size: 16px;
    }
    .card { padding: 14px; }
    .card strong { font-size: 20px; }
    .brand strong { font-size: 15px; }
    .nav a { padding: 11px 12px; }
    .receipt {
        width: 100%;
        min-height: auto;
        padding: 18px;
    }
}
@media (max-width: 760px) {
    .students-panel { padding: 12px; }
    .table-wrap {
        border: 0;
        background: transparent;
        overflow: visible;
    }
    .students-table,
    .students-table thead,
    .students-table tbody,
    .students-table th,
    .students-table td,
    .students-table tr {
        display: block;
        width: 100% !important;
    }
    .students-table {
        border-collapse: separate;
        border-spacing: 0;
        background: transparent;
        font-size: 13px;
    }
    .students-table thead { display: none; }
    .students-table tbody tr {
        background: #fff;
        border: 1px solid var(--line);
        border-radius: 8px;
        margin-bottom: 12px;
        padding: 12px;
        box-shadow: 0 8px 22px rgba(23, 32, 51, .06);
    }
    .students-table td {
        height: auto;
        border: 0;
        padding: 7px 0;
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        gap: 14px;
        text-align: right;
    }
    .students-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 11px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: .04em;
        text-align: left;
    }
    .students-table td.student-photo {
        justify-content: center;
        padding-bottom: 12px;
    }
    .students-table td.student-photo::before { display: none; }
    .student-photo .avatar,
    table img.avatar {
        width: 64px !important;
        height: 64px !important;
        max-width: 64px !important;
        max-height: 64px !important;
    }
    .students-table .actions {
        flex-direction: row;
        justify-content: stretch;
        gap: 8px;
        padding-top: 10px;
    }
    .students-table .actions::before { display: none; }
    .students-table .actions .btn,
    .students-table .actions button,
    .students-table .inline-form {
        flex: 1;
        width: 100%;
    }
    .students-table .btn {
        min-width: 0;
        min-height: 38px;
        font-size: 12px;
    }
}
@media (max-width: 420px) {
    .content, .topbar { padding: 12px; }
    .sidebar { width: 280px; }
    .topbar h1 { font-size: 18px; }
    .panel { padding: 12px; }
    .login-card { padding: 20px; }
    .students-table tbody tr { padding: 10px; }
    .students-table td {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
        text-align: left;
    }
    .students-table td.student-photo { align-items: center; }
    .students-table .actions {
        flex-direction: column;
    }
}
@media print {
    body { background: #fff; }
    .sidebar, .topbar, .no-print, .content > .alert { display: none !important; }
    .main { margin: 0; }
    .content { padding: 0; }
    .receipt { border: 0; box-shadow: none; margin: 0; width: 148mm; min-height: 105mm; }
    @page { size: A4 portrait; margin: 8mm; }
}
