:root {
    --tm-purple: #6657ff;
    --tm-teal: #11c5b4;
    --tm-green: #34c759;
    --tm-orange: #f5a85c;
    --tm-blue: #4f63ff;
    --tm-bg: #f4f7fb;
    --tm-white: #ffffff;
    --tm-text: #111827;
    --tm-muted: #6b7280;
    --tm-border: #e5eaf2;
    --tm-soft-blue: #eef0ff;
    --tm-shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
    --tm-radius: 8px;
}

* { box-sizing: border-box; }

html {
    height: 100%;
}

body {
    margin: 0;
    background: var(--tm-bg);
    color: var(--tm-text);
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
}

a { text-decoration: none; }

.app-shell {
    min-height: 100vh;
    padding-top: 76px;
    padding-left: 260px;
}

.topbar {
    background: var(--tm-white);
    border-bottom: 1px solid var(--tm-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 34px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 76px;
    z-index: 20;
}

.topbar-brand, .topbar-user, .brand-link {
    display: flex;
    align-items: center;
}

.brand-link {
    gap: 12px;
    color: var(--tm-purple);
    font-weight: 700;
    font-size: 22px;
}

.brand-link img {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.brand-icon {
    font-size: 22px;
}

.icon-btn {
    border: 0;
    background: transparent;
    color: var(--tm-muted);
    width: 38px;
    height: 38px;
    border-radius: var(--tm-radius);
    margin-right: 10px;
}

.topbar-user {
    gap: 12px;
}

.user-copy {
    text-align: right;
    display: flex;
    flex-direction: column;
}

.user-copy strong {
    font-size: 13px;
    color: #0f172a;
    font-weight: 700;
}

.user-copy span {
    font-size: 13px;
    color: var(--tm-muted);
}

.user-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #f2f4ff;
    border: 1px solid var(--tm-border);
    display: grid;
    place-items: center;
    color: var(--tm-purple);
}

.logout-link {
    color: var(--tm-muted);
    padding: 8px;
}

.sidebar {
    background: var(--tm-white);
    border-right: 1px solid var(--tm-border);
    padding: 16px;
    position: fixed;
    top: 76px;
    left: 0;
    bottom: 0;
    width: 260px;
    overflow-x: hidden;
    overflow-y: auto;
    z-index: 15;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow: visible;
}

.nav-link {
    height: 50px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 16px;
    border-radius: 6px;
    color: #5f6b7a;
    font-size: 15px;
    font-weight: 500;
}

.nav-link span:first-of-type {
    flex: 1 1 auto;
    min-width: 0;
}

.nav-link i {
    width: 18px;
    color: #74808e;
}

.nav-badge {
    min-width: 24px;
    height: 24px;
    padding: 0 7px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(102, 87, 255, .12);
    color: var(--tm-purple);
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
}

.nav-link.active {
    background: var(--tm-soft-blue);
    color: var(--tm-purple);
    font-weight: 700;
}

.nav-link.active i {
    color: var(--tm-purple);
}

.nav-section {
    margin: 26px 8px 10px;
    color: #3f4652;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.content {
    position: relative;
    padding: 24px;
    min-width: 0;
    min-height: calc(100vh - 76px);
    overflow: visible;
}

.pending-approval-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.pending-approval-banner strong {
    display: block;
    margin-bottom: 4px;
    color: #172033;
    font-size: 15px;
}

.page-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 16px;
}

.page-title h1 {
    font-size: 25px;
    font-weight: 700;
    margin: 0;
    color: #111827;
}

.page-title p {
    margin: 3px 0 0;
    color: var(--tm-muted);
    font-size: 13px;
}

.btn {
    border-radius: 7px;
    font-size: 13px;
    font-weight: 700;
    padding: 9px 14px;
}

.btn-primary {
    background: var(--tm-purple);
    border-color: var(--tm-purple);
}

.btn-light-action {
    background: #f4f6ff;
    border: 1px solid #dfe4ff;
    color: var(--tm-purple);
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.kpi-card {
    min-height: 140px;
    color: #fff;
    border-radius: 12px;
    padding: 20px 18px;
    box-shadow: var(--tm-shadow);
    position: relative;
    overflow: hidden;
}

.kpi-card.purple { background: linear-gradient(135deg, #6b5cff, #5142d9); }
.kpi-card.teal { background: linear-gradient(135deg, #10c7b4, #04aa9f); }
.kpi-card.green { background: linear-gradient(135deg, #34c759, #18a84b); }
.kpi-card.orange { background: linear-gradient(135deg, #f9b765, #ef8654); }

.kpi-card:after {
    content: "";
    position: absolute;
    right: -22px;
    bottom: -28px;
    width: 110px;
    height: 110px;
    border: 8px solid rgba(255,255,255,.16);
    border-radius: 22px;
    transform: rotate(-16deg);
}

.kpi-card label {
    display: block;
    color: rgba(255,255,255,.68);
    text-transform: uppercase;
    font-size: 12px;
    font-weight: 800;
    margin-bottom: 6px;
}

.kpi-card strong {
    display: block;
    font-size: 30px;
    font-weight: 800;
}

.kpi-card span {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 9px;
    border-radius: 6px;
    background: rgba(255,255,255,.22);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
}

.panel {
    background: var(--tm-white);
    border: 1px solid var(--tm-border);
    border-radius: 12px;
    box-shadow: var(--tm-shadow);
}

.panel-header {
    padding: 18px 18px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.panel-title {
    font-size: 17px;
    font-weight: 700;
    margin: 0;
}

.panel-body {
    padding: 18px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.chart-box {
    min-height: 315px;
}

.table {
    margin-bottom: 0;
    color: #111827;
}

.table thead th {
    color: #6b7280;
    font-size: 12px;
    text-transform: uppercase;
    font-weight: 800;
    background: #fbfcfe;
    border-bottom: 1px solid var(--tm-border);
    padding: 14px 16px;
}

.table tbody td {
    padding: 15px 16px;
    vertical-align: middle;
    border-bottom: 1px solid var(--tm-border);
    font-size: 14px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    min-width: 66px;
    justify-content: center;
    border-radius: 999px;
    padding: 5px 9px;
    font-size: 11px;
    font-weight: 700;
}

.status-paid { background: #dcfce7; color: #15803d; }
.status-partial { background: #fef3c7; color: #b45309; }
.status-pending { background: #e0f2fe; color: #0369a1; }
.status-active { background: #eef2ff; color: var(--tm-purple); }

.student-photo-col {
    width: 72px;
    min-width: 72px;
    max-width: 72px;
    text-align: center;
}

.student-avatar-thumb {
    width: 42px !important;
    height: 42px !important;
    min-width: 42px !important;
    max-width: 42px !important;
    min-height: 42px !important;
    max-height: 42px !important;
    display: inline-block !important;
    object-fit: cover !important;
    border-radius: 50% !important;
    border: 1px solid #dfe4ff;
    background: #f7f8ff;
    box-shadow: 0 4px 10px rgba(79, 99, 255, .12);
}

.student-avatar-box {
    width: 42px !important;
    height: 42px !important;
    display: inline-grid !important;
    place-items: center !important;
    overflow: hidden !important;
    border-radius: 50% !important;
}

.student-avatar-box img {
    width: 42px !important;
    height: 42px !important;
    object-fit: cover !important;
    border-radius: 50% !important;
}

.student-avatar-fallback {
    width: 42px !important;
    height: 42px !important;
    display: inline-grid !important;
    place-items: center !important;
    border-radius: 50% !important;
    color: #ffffff !important;
    background: linear-gradient(135deg, #6657ff 0%, #11c5b4 100%) !important;
    border: 2px solid #ffffff !important;
    box-shadow: 0 0 0 1px #dfe4ff, 0 6px 14px rgba(102, 87, 255, .22) !important;
    font-size: 16px !important;
}

.student-avatar-preview,
.student-profile-photo img {
    object-fit: cover;
    border: 1px solid #dfe4ff;
    background: #f7f8ff;
}

.student-avatar-empty {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: inline-grid;
    place-items: center;
    color: #ffffff;
    background: linear-gradient(135deg, #6b5cff, #11c5b4);
    border: 3px solid #ffffff;
    box-shadow: 0 6px 14px rgba(102, 87, 255, .22), 0 0 0 1px #dfe4ff;
    font-size: 15px;
}

.student-avatar-empty.large,
.student-avatar-preview {
    width: 82px;
    height: 82px;
    border-radius: 12px;
}

.student-profile-photo {
    display: flex;
    justify-content: center;
}

.student-profile-photo img,
.student-profile-photo span {
    width: 120px;
    height: 120px;
    border-radius: 16px;
}

.student-profile-photo span {
    display: grid;
    place-items: center;
    color: var(--tm-purple);
    background: #eef0ff;
    border: 1px solid #dfe4ff;
    font-size: 42px;
}

.action-icons {
    display: flex;
    gap: 7px;
}

.action-icons a, .action-icons button {
    width: 34px;
    height: 32px;
    border-radius: 7px;
    border: 1px solid #dfe4ff;
    background: #fff;
    color: var(--tm-purple);
    display: grid;
    place-items: center;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin-bottom: 14px;
}

.toolbar form {
    flex: 1;
    max-width: 420px;
}

.form-control, .form-select {
    border-color: #dbe2ee;
    border-radius: 7px;
    font-size: 14px;
    min-height: 40px;
}

.form-label {
    font-size: 13px;
    color: #4b5563;
    font-weight: 700;
}

.quick-actions {
    display: grid;
    gap: 10px;
}

.quick-actions a {
    background: #f7f8ff;
    color: #4f46e5;
    border: 1px solid #e1e6ff;
    border-radius: 8px;
    padding: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: #f4f7fb;
}

.login-shell {
    width: min(420px, calc(100% - 32px));
}

.login-panel {
    background: #fff;
    border-radius: 14px;
    padding: 32px;
    box-shadow: var(--tm-shadow);
    border: 1px solid var(--tm-border);
}

.brand-mark {
    width: 54px;
    height: 54px;
    border-radius: 14px;
    background: #eef0ff;
    color: var(--tm-purple);
    display: grid;
    place-items: center;
    font-size: 24px;
    margin-bottom: 16px;
}

.login-panel h1 {
    font-size: 25px;
    font-weight: 800;
    margin: 0;
}

.login-panel p, .login-hint {
    color: var(--tm-muted);
    font-size: 13px;
}

.login-hint {
    margin-top: 16px;
    text-align: center;
}

.flash-message {
    position: fixed;
    top: 88px;
    right: 24px;
    z-index: 50;
    box-shadow: var(--tm-shadow);
}

.pagination .page-link {
    color: var(--tm-purple);
    border-color: #dfe4ff;
    font-size: 13px;
}

.pagination .active .page-link {
    background: var(--tm-purple);
    border-color: var(--tm-purple);
}

.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding-top: 16px;
}

.student-pagination-footer {
    border-top: 1px solid #eef2f7;
    margin-top: 4px;
    padding: 18px 0 2px;
}

.table-count {
    color: var(--tm-muted);
    font-size: 13px;
    font-weight: 600;
}

.student-count-pill {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 14px;
    border-radius: 999px;
    background: #ffffff;
    border: 1px solid #e5eaf2;
    color: #596579;
    box-shadow: 0 6px 16px rgba(15, 23, 42, .05);
}

.student-count-pill i,
.student-count-pill strong {
    color: var(--tm-purple);
}

.smart-pagination {
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 7px;
    padding: 8px;
    border: 1px solid #e5eaf2;
    border-radius: 14px;
    background: #ffffff;
    box-shadow: 0 8px 20px rgba(15, 23, 42, .06);
}

.smart-pagination .page-link {
    min-width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    padding: 0 10px;
    border: 0;
    background: #f8faff;
    color: var(--tm-purple);
    font-weight: 700;
    font-size: 13px;
    transition: background .16s ease, color .16s ease, box-shadow .16s ease;
}

.smart-pagination .page-link:hover {
    background: #eef0ff;
    box-shadow: 0 5px 12px rgba(79, 99, 255, .13);
}

.smart-pagination .page-link.page-text {
    min-width: 64px;
    padding: 0 14px;
}

.smart-pagination .page-item.disabled .page-link {
    color: #a3acba;
    background: #f4f6fb;
    cursor: not-allowed;
}

.smart-pagination .page-item.active .page-link {
    background: var(--tm-purple);
    color: #fff;
    box-shadow: 0 8px 16px rgba(102, 87, 255, .28);
}

@media (max-width: 1100px) {
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    body {
        overflow-x: hidden;
        overflow-y: auto;
    }
    .app-shell {
        min-height: 100vh;
        padding-top: 68px;
        padding-left: 0;
    }
    .topbar {
        height: 68px;
        padding: 0 16px;
    }
    .brand-link { font-size: 18px; }
    .sidebar {
        display: none;
        position: static;
        top: auto;
        left: auto;
        bottom: auto;
        width: auto;
        height: auto;
        overflow: visible;
    }
    .sidebar.open { display: block; }
    .content {
        position: static;
        top: auto;
        right: auto;
        bottom: auto;
        left: auto;
        padding: 16px;
        min-height: calc(100vh - 68px);
        overflow: visible;
    }
    .kpi-grid { grid-template-columns: 1fr; }
    .page-title-row, .toolbar { flex-direction: column; align-items: stretch; }
    .table-footer { flex-direction: column; align-items: flex-start; }
    .smart-pagination { justify-content: flex-start; }
    .pending-approval-banner { flex-direction: column; align-items: flex-start; }
    .user-copy { display: none; }
}
