:root {
    /* School Logo Color Palette (Doon International School) */
    --primary: #003399;
    /* Navy Blue */
    --primary-dark: #002266;
    --primary-light: #4c7ecf;
    --secondary: #001a4d;
    /* Darker Navy */
    --accent: #ff4500;
    /* School Sun Orange-Red */
    --success: #228b22;
    /* School Leaf Green */

    /* Neutrals */
    --background: #f8fafc;
    /* Slate 50 */
    --surface: #ffffff;
    /* White */
    --surface-hover: #f1f5f9;
    /* Slate 100 */

    /* Text */
    --text: #1e293b;
    /* Slate 800 */
    --text-secondary: #64748b;
    /* Slate 500 */
    --text-inverse: #ffffff;
    /* White */

    /* Borders & Dividers */
    --border: #e2e8f0;
    /* Slate 200 */
    --border-light: #f1f5f9;
    /* Slate 100 */

    /* Status Colors */
    --success: #10b981;
    /* Emerald 500 */
    --success-bg: #d1fae5;
    /* Emerald 100 */
    --warning: #f59e0b;
    /* Amber 500 */
    --warning-bg: #fef3c7;
    /* Amber 100 */
    --danger: #ef4444;
    /* Red 500 */
    --danger-bg: #fee2e2;
    /* Red 100 */
    --info: #3b82f6;
    /* Blue 500 */
    --info-bg: #dbeafe;
    /* Blue 100 */

    /* Spacing & Layout */
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --header-height: 70px;
    --sidebar-width: 260px;

    /* Effects */
    --shadow-sm: 0 1px 3px rgba(0, 51, 153, 0.05);
    --shadow: 0 4px 6px -1px rgba(0, 51, 153, 0.1), 0 2px 4px -1px rgba(0, 51, 153, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 51, 153, 0.1), 0 4px 6px -2px rgba(0, 51, 153, 0.05);
    --glass: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.5);
    --backdrop-blur: 10px;

    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset & Base */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--background);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--secondary);
    font-weight: 700;
    line-height: 1.25;
}

h1 {
    font-size: 2rem;
    letter-spacing: -0.025em;
}

h2 {
    font-size: 1.5rem;
    letter-spacing: -0.025em;
}

h3 {
    font-size: 1.25rem;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    color: var(--primary-dark);
}

/* Utilities */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.text-muted {
    color: var(--text-secondary);
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.d-flex {
    display: flex;
}

.align-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-2 {
    gap: 0.5rem;
}

.gap-4 {
    gap: 1rem;
}

.mt-4 {
    margin-top: 1rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

/* Components: Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    font-weight: 600;
    font-size: 0.95rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--transition);
    gap: 0.5rem;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(0, 51, 153, 0.3);
}

.btn-primary:hover {
    background-color: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(0, 51, 153, 0.4);
}

.btn-secondary {
    background-color: white;
    border-color: var(--border);
    color: var(--text);
}

.btn-secondary:hover {
    background-color: var(--surface-hover);
    border-color: var(--text-secondary);
}

.btn-danger {
    background-color: var(--danger);
    color: white;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background-color: #dc2626;
    /* Red 600 */
}

.btn-outline {
    background-color: transparent;
    border-color: var(--primary);
    color: var(--primary);
}

.btn-outline:hover {
    background-color: var(--primary);
    color: white;
}

/* Components: Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

/* Components: Inputs */
input,
select,
textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background-color: var(--surface);
    font-size: 1rem;
    /* Prevent iOS zoom */
    transition: var(--transition);
    color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(0, 51, 153, 0.1);
    transform: translateY(-1px);
}

label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text);
    font-size: 0.9rem;
}

/* Tables */
.table-responsive {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    white-space: nowrap;
}

.table th,
.table td {
    padding: 1rem 1.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}

.table th {
    background-color: #f8fafc;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.table tr:last-child td {
    border-bottom: none;
}

.table tbody tr:hover {
    background-color: var(--surface-hover);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
}

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

.badge-warning {
    background: var(--warning-bg);
    color: var(--warning);
}

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

.badge-info {
    background: var(--info-bg);
    color: var(--info);
}

.badge-secondary {
    background: var(--border-light);
    color: var(--text-secondary);
}

/* Flex Utilities */
.flex-column {
    flex-direction: column;
}

.flex-row {
    flex-direction: row;
}

@media (min-width: 640px) {
    .sm-flex-row {
        flex-direction: row;
    }

    .sm-flex-column {
        flex-direction: column;
    }
}

.w-full {
    width: 100%;
}

.py-4 {
    padding-top: 1rem;
    padding-bottom: 1rem;
}

.mr-1 {
    margin-right: 0.25rem;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.alert-success {
    background: var(--success-bg);
    color: #064e3b;
    border: 1px solid var(--success);
}

.alert-danger {
    background: var(--danger-bg);
    color: #7f1d1d;
    border: 1px solid var(--danger);
}

/* Layout Structure */
.header {
    background: white;
    height: var(--header-height);
    position: sticky;
    top: 0;
    z-index: 50;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.header .container {
    height: 100%;
}

.layout {
    display: flex;
    min-height: calc(100vh - var(--header-height));
}

.sidebar {
    width: var(--sidebar-width);
    background: white;
    border-right: 1px solid var(--border);
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    overflow-y: auto;
    transition: transform 0.3s ease;
}

.sidebar-content {
    padding: 1.5rem 1rem;
}

.sidebar h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin: 1.5rem 0.5rem 0.5rem;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.sidebar h3:first-child {
    margin-top: 0;
}

.sidebar ul {
    list-style: none;
}

.sidebar a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.sidebar a:hover {
    background-color: var(--surface-hover);
    color: var(--primary);
}

.sidebar a.active {
    background-color: var(--info-bg);
    color: var(--primary);
    font-weight: 600;
}

.sidebar a i {
    width: 1.25rem;
    text-align: center;
}

.main {
    flex: 1;
    padding: 2rem;
    background-color: var(--background);
    overflow-x: hidden;
}

/* Mobile Sidebar Toggle */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text);
    padding: 0.5rem;
}

/* Auth Pages */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--background);
    padding: 1rem;
}

.auth-card {
    background: white;
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-header h1 {
    font-size: 1.75rem;
    color: var(--secondary);
    margin-bottom: 0.5rem;
}

.auth-header p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .layout {
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: var(--header-height);
        height: calc(100vh - var(--header-height));
        z-index: 40;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .menu-toggle {
        display: block;
    }

    .main {
        padding: 1rem;
    }

    .header h1 {
        font-size: 1.25rem;
    }

    /* Sidebar Overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 35;
        backdrop-filter: blur(2px);
    }

    .sidebar-overlay.open {
        display: block;
    }
}

/* Grid System */
.grid {
    display: grid;
    gap: 1.5rem;
}

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

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

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

@media (min-width: 640px) {
    .sm-grid-cols-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1024px) {
    .lg-grid-cols-3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* Stats Card */
.stats-card {
    background: white;
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    transition: var(--transition);
}

.stats-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
    border-color: var(--primary-light);
}

.stats-card .label {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stats-card .value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--secondary);
    line-height: 1;
}

.stats-card .icon {
    font-size: 1.5rem;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

/* Legacy Grid Support (for compatibility) */
.row {
    display: flex;
    flex-wrap: wrap;
    margin: -10px;
}

.col {
    flex: 1;
    padding: 10px;
    min-width: 250px;
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .header h1 {
        font-size: 0.9rem !important;
        /* Even smaller font on mobile */
        display: flex;
        align-items: center;
    }

    .header h1 img {
        height: 25px !important;
        /* Smaller logo */
        margin-right: 5px !important;
    }

    .header h1 small {
        display: none;
        /* Hide subtitle on very small screens to save space */
    }
}

/* KPI & Grid Extensions */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.kpi-card {
    background: white;
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: relative;
    overflow: hidden;
    transition: var(--transition);
}

.kpi-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.kpi-card::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    background: var(--primary);
}

.kpi-card.kpi-success::after {
    background: var(--success);
}

.kpi-card.kpi-danger::after {
    background: var(--danger);
}

.kpi-card.kpi-warning::after {
    background: var(--warning);
}

.kpi-card .label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.kpi-card .value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.02em;
}

/* Modern Table Styles */
.table {
    border-collapse: separate;
    border-spacing: 0;
}

.table th {
    background-color: #f1f5f9;
    color: var(--text-secondary);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    padding: 1rem 1.5rem;
    border-bottom: 2px solid var(--border);
}

.table td {
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
    transition: background-color 0.2s;
}

.table tbody tr {
    transition: transform 0.1s, box-shadow 0.1s;
}

.table tbody tr:hover td {
    background-color: var(--surface-hover);
}

/* Status Badges refinement */
.badge {
    padding: 0.35em 0.8em;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    border-radius: 6px;
}

/* Compact Form Helper */
.form-compact {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
}

.form-compact .form-group {
    flex: 1;
    min-width: 150px;
}

.form-compact .form-group.action {
    flex: 0 0 auto;
}

@media (max-width: 640px) {
    .form-compact {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .form-compact .form-group {
        width: 100%;
        min-width: 100%;
        max-width: 100% !important;
        /* Override inline styles */
    }

    .form-compact .form-group.action {
        width: 100%;
    }

    .form-compact .form-group.action button {
        width: 100%;
    }
}

/* Action Bar Floating */
#bulk_actions_bar {
    position: sticky;
    top: 10px;
    z-index: 1000;
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius);
    padding: 0.75rem 1.25rem;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Tables & Actions Responsive */
@media (max-width: 768px) {
    .table-responsive {
        border: none;
        box-shadow: none;
    }

    .table thead {
        display: none;
    }

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

    .table tr {
        margin-bottom: 1rem;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        background: white;
        padding: 0;
        box-shadow: var(--shadow-sm);
        overflow: hidden;
    }

    .table td {
        border-bottom: 1px solid var(--border-light);
        padding: 0.75rem 1rem !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center;
        text-align: right;
    }

    /* specific styling for Student Name to look like header */
    .table td[data-label="Student"] {
        background-color: var(--surface-hover);
        flex-direction: column !important;
        align-items: flex-start !important;
        text-align: left !important;
        border-bottom: 1px solid var(--border);
    }

    .table td[data-label="Student"]::before {
        display: none;
    }

    .table td:last-child {
        border-bottom: none;
        justify-content: flex-end !important;
        padding: 1rem !important;
        background: #fcfcfc;
    }

    .table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        text-align: left;
    }

    .btn-group {
        display: flex;
        gap: 0.25rem;
        width: 100%;
        justify-content: flex-end;
    }
}

/* Responsive Grid Columns */
.cols-1 {
    grid-template-columns: 1fr;
}

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

.cols-3 {
    grid-template-columns: repeat(3, 1fr);
}

.cols-4 {
    grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 640px) {
    .sm-cols-1 {
        grid-template-columns: 1fr !important;
    }
}

/* Grid Utilities */
.grid {
    display: grid;
    width: 100%;
}

.gap-2 {
    gap: 0.5rem;
}

.gap-4 {
    gap: 1rem;
}

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

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

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

.col-span-1 {
    grid-column: span 1 / span 1;
}

.col-span-2 {
    grid-column: span 2 / span 2;
}

.col-span-full {
    grid-column: 1 / -1;
}

@media (min-width: 640px) {
    .sm-grid-cols-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .sm-grid-cols-3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (min-width: 1024px) {
    .lg-grid-cols-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .lg-grid-cols-3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .lg-col-span-2 {
        grid-column: span 2 / span 2;
    }
}

.h-full {
    height: 100%;
}

/* ============================================================
   MOBILE RESPONSIVENESS ENHANCEMENTS
   ============================================================ */

/* --- lg-grid-cols-4 utility (missing) --- */
@media (min-width: 1024px) {
    .lg-grid-cols-4 {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

/* ============================================================
   Small screens (≤ 768px)
   ============================================================ */
@media (max-width: 768px) {

    /* --- Cards: reduce padding & disable hover lift --- */
    .card {
        padding: 1rem;
    }

    .card:hover {
        transform: none;
    }

    /* --- KPI Grid: 2 per row, smaller values --- */
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
        margin-bottom: 1rem;
    }

    .kpi-card {
        padding: 1rem;
    }

    .kpi-card .value {
        font-size: 1.35rem;
    }

    .kpi-card .label {
        font-size: 0.72rem;
    }

    /* --- Stats Cards: smaller values --- */
    .stats-card {
        padding: 1rem;
    }

    .stats-card .value {
        font-size: 1.35rem !important;
    }

    .stats-card .label {
        font-size: 0.75rem;
    }

    /* --- Header: compact user info --- */
    .header .user-info span[style*="font-weight"] {
        display: none;
    }

    /* --- Bulk Actions Bar: stack vertically --- */
    #bulk_actions_bar .row {
        flex-direction: column;
        gap: 0.5rem;
        align-items: stretch !important;
    }

    #bulk_actions_bar .col {
        min-width: 100%;
        text-align: center;
    }

    #bulk_actions_bar .text-right,
    #bulk_actions_bar .col.text-right {
        text-align: center !important;
    }

    #bulk_actions_bar .btn {
        font-size: 0.8rem;
        padding: 0.4rem 0.6rem;
    }

    /* --- Select All + Tab Buttons row: stack --- */
    .card>.row {
        flex-direction: column;
        gap: 0.5rem;
    }

    .card>.row>.col {
        min-width: 100%;
    }

    .card>.row>.col[style*="text-align:right"],
    .card>.row>.col[style*="text-align: right"] {
        text-align: left !important;
    }

    /* --- Tab buttons (btn-group): full width --- */
    .btn-group {
        flex-wrap: wrap;
    }

    .btn-group .btn {
        font-size: 0.8rem;
        padding: 0.4rem 0.75rem;
    }

    /* --- Table mobile: checkbox column cleanup --- */
    .table td[data-label="Select"] {
        justify-content: flex-start !important;
        padding: 0.5rem 1rem !important;
        background: var(--surface-hover);
        border-bottom: 1px solid var(--border);
    }

    .table td[data-label="Select"]::before {
        display: none;
    }

    /* --- Fee filter card: reduce inner padding --- */
    .card .form-compact {
        gap: 0.5rem;
    }

    /* --- Student history: stack info header buttons --- */
    .d-flex.justify-between.align-center.flex-wrap {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }

    .d-flex.justify-between.align-center.flex-wrap>.d-flex.gap-2 {
        width: 100%;
    }

    .d-flex.justify-between.align-center.flex-wrap>.d-flex.gap-2 .btn {
        flex: 1;
    }

    /* --- Student history filter form: wrap on mobile --- */
    .card form.d-flex.align-center.gap-4.flex-wrap {
        flex-direction: column;
        align-items: stretch !important;
        gap: 0.5rem;
    }

    .card form.d-flex.align-center.gap-4.flex-wrap select {
        width: 100% !important;
    }

    /* --- Student fee page: header flex column --- */
    .d-flex.justify-between.align-center.mb-4.flex-column.sm-flex-row {
        flex-direction: column;
        align-items: stretch !important;
    }

    .d-flex.justify-between.align-center.mb-4.flex-column.sm-flex-row>.card {
        max-width: 100% !important;
    }

    /* --- Annual Fee Modal: full width on mobile --- */
    #annualFeeModal .card {
        width: 95% !important;
    }

    /* --- Typography: slightly smaller headings --- */
    h2 {
        font-size: 1.25rem;
    }

    h3 {
        font-size: 1.1rem;
    }
}

/* ============================================================
   Extra-small screens (≤ 480px)
   ============================================================ */
@media (max-width: 480px) {

    /* --- Main content: tighter padding --- */
    .main {
        padding: 0.75rem;
    }

    /* --- KPI Grid: single column on very small --- */
    .kpi-grid {
        grid-template-columns: 1fr;
    }

    /* --- Cards: even tighter --- */
    .card {
        padding: 0.75rem;
        border-radius: var(--radius-sm);
    }

    /* --- Buttons: compact --- */
    .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }

    .btn-sm {
        padding: 0.3rem 0.5rem;
        font-size: 0.75rem;
    }

    /* --- Table mobile cards: tighter --- */
    .table td {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.85rem;
    }

    /* --- Add Student form: bottom action bar stacking --- */
    .d-flex.justify-between.align-center.mt-4.pt-4 {
        flex-direction: column;
        gap: 0.75rem;
    }

    .d-flex.justify-between.align-center.mt-4.pt-4 .btn {
        width: 100%;
        justify-content: center;
    }

    /* --- Badges: slightly smaller --- */
    .badge {
        font-size: 0.65rem;
        padding: 0.25em 0.6em;
    }
}

/* ============================================================
   Grid column span collapse on small screens  
   ============================================================ */
@media (max-width: 640px) {
    .col-span-2 {
        grid-column: span 1 / span 1 !important;
    }

    /* Ensure grids with gap work well */
    .grid {
        gap: 0.75rem;
    }

    /* Form sections nested cards */
    .card .card {
        padding: 0.75rem;
    }

    .d-block {
        display: block;
    }
}

/* ============================================================
   Student Fee History Page — Mobile
   ============================================================ */
@media (max-width: 768px) {

    /* --- Student info header: stack avatar + info --- */
    .card>.d-flex.justify-between.align-center.flex-wrap>.d-flex.align-center.gap-4 {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }

    /* --- Avatar: smaller on mobile --- */
    .avatar-placeholder {
        width: 40px !important;
        height: 40px !important;
        font-size: 1.2rem !important;
    }

    /* --- Student name: smaller --- */
    .card>.d-flex.justify-between.align-center.flex-wrap h2 {
        font-size: 1.15rem !important;
    }

    /* --- Info line with dots: wrap to lines --- */
    .card>.d-flex.justify-between.align-center.flex-wrap .text-muted {
        display: flex;
        flex-wrap: wrap;
        gap: 0.25rem 0.5rem;
        align-items: center;
        font-size: 0.8rem !important;
    }

    /* Hide dot separators on mobile — they look bad when wrapped */
    .card>.d-flex.justify-between.align-center.flex-wrap .text-muted>span[style*="margin: 0 8px"] {
        display: none;
    }

    /* --- Action buttons: full width --- */
    .card>.d-flex.justify-between.align-center.flex-wrap>.d-flex.gap-2 {
        width: 100%;
        flex-direction: row;
    }

    .card>.d-flex.justify-between.align-center.flex-wrap>.d-flex.gap-2 .btn {
        flex: 1;
        justify-content: center;
        font-size: 0.85rem;
    }

    /* --- Fee breakdown panel: tighter padding --- */
    .card .d-flex.justify-between.mb-3 {
        font-size: 0.9rem;
    }

    .card div[style*="padding: 1.25rem"] {
        padding: 0.75rem !important;
    }

    /* --- lg-col-span-2: collapse on mobile --- */
    .lg-col-span-2 {
        grid-column: span 1 / span 1 !important;
    }

    /* --- Fee history filter form: make Apply btn full width --- */
    .card form.d-flex.align-center.gap-4.flex-wrap button {
        width: 100%;
    }

    /* --- Payment history table: last col (Receipt) smaller --- */
    .table td:last-child .btn-sm {
        padding: 0.35rem 0.6rem;
    }
}

@media (max-width: 480px) {

    /* --- Student header buttons: stack vertically on very small --- */
    .card>.d-flex.justify-between.align-center.flex-wrap>.d-flex.gap-2 {
        flex-direction: column;
    }

    .card>.d-flex.justify-between.align-center.flex-wrap>.d-flex.gap-2 .btn {
        width: 100%;
    }

    /* --- Fee breakdown: even tighter --- */
    .card .d-flex.justify-between.mb-3 {
        font-size: 0.8rem;
    }

    /* --- KPI cards: icon hide on very small --- */
    .kpi-card .icon {
        display: none;
    }
}

/* ============================================================
   Billing Pages — Mobile
   ============================================================ */
@media (max-width: 768px) {

    /* --- Create Bill: card max-width off --- */
    #billingForm {
        font-size: 0.9rem;
    }

    /* --- Quick-add buttons: smaller on mobile --- */
    #billingForm .btn-sm {
        font-size: 0.75rem;
        padding: 0.3rem 0.5rem;
    }

    /* --- Items table: allow horizontal scroll --- */
    #itemsTable th,
    #itemsTable td {
        font-size: 0.8rem;
        padding: 0.4rem 0.3rem;
        white-space: nowrap;
    }

    #itemsTable input.form-control {
        min-width: 60px;
        font-size: 0.8rem;
        padding: 0.3rem 0.4rem;
    }

    /* --- Submit buttons: stack full width --- */
    #billingForm .justify-end {
        flex-direction: column;
    }

    #billingForm .justify-end .btn {
        width: 100%;
        text-align: center;
    }

    /* --- Student search dropdown: full width --- */
    #studentDropdown {
        font-size: 0.85rem;
    }

    /* --- Receipt: stack header info vertically --- */
    #receiptCard {
        max-width: 100% !important;
        padding: 1rem;
    }

    #receiptCard .d-flex.justify-between {
        flex-direction: column;
        gap: 0.5rem;
    }

    #receiptCard .d-flex.justify-between>div {
        text-align: left !important;
    }

    #receiptCard table th,
    #receiptCard table td {
        font-size: 0.8rem;
        padding: 0.4rem 0.3rem;
    }

    /* --- Billing index: filter/actions --- */
    .form-compact .form-group.action {
        min-width: unset;
    }
}

@media (max-width: 480px) {

    /* --- Quick-add: 2 per row grid --- */
    #billingForm .d-flex.flex-wrap.gap-2 {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 0.4rem;
    }

    #billingForm .d-flex.flex-wrap.gap-2 .btn-sm {
        width: 100%;
        justify-content: center;
    }

    /* --- Items table inputs even smaller --- */
    #itemsTable input.form-control {
        min-width: 50px;
        font-size: 0.75rem;
    }

    /* --- Receipt signatures stack --- */
    #receiptCard .d-flex.justify-between {
        align-items: stretch;
    }

    #receiptCard .d-flex.justify-between>div {
        min-width: unset !important;
        width: 100%;
    }
}