:root {
    --bg: #f8f9ff;
    --surface: #ffffff;
    --surface-soft: #eef4ff;
    --line: #d7e1f3;
    --text: #0d1c2e;
    --muted: #5b6474;
    --primary: #00288e;
    --primary-soft: #dce9ff;
    --success-soft: #dff8e7;
    --danger-soft: #ffe4e1;
    --warning-soft: #fff2d6;
    --shadow: 0 20px 40px rgba(0, 40, 142, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Sarabun", "Plus Jakarta Sans", sans-serif;
    background: radial-gradient(circle at top right, #dfeaff 0, #f8f9ff 40%, #f8f9ff 100%);
    color: var(--text);
}

a {
    text-decoration: none;
}

.row {
    display: flex;
    flex-wrap: wrap;
    margin-right: -0.75rem;
    margin-left: -0.75rem;
}

.row > * {
    padding-right: 0.75rem;
    padding-left: 0.75rem;
}

.col-12,
.col-lg-4,
.col-lg-8,
.col-md-6,
.col-xl-3,
.col-xl-4,
.col-xl-5,
.col-xl-7,
.col-xl-8 {
    width: 100%;
}

.g-4 {
    row-gap: 1.5rem;
}

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-auto { margin-top: auto; }
.me-2 { margin-right: 0.5rem; }
.p-3 { padding: 1rem; }
.p-4 { padding: 1.5rem; }
.px-3 { padding-left: 1rem; padding-right: 1rem; }
.px-4 { padding-left: 1.5rem; padding-right: 1.5rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.d-flex { display: flex; }
.d-grid { display: grid; }
.align-items-center { align-items: center; }
.align-items-end { align-items: flex-end; }
.align-items-start { align-items: flex-start; }
.justify-content-between { justify-content: space-between; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 1rem; }
.flex-wrap { flex-wrap: wrap; }
.h-100 { height: 100%; }
.w-100 { width: 100%; }
.small { font-size: 0.875rem; }
.text-muted { color: var(--muted); }
.text-center { text-align: center; }
.fw-bold,
.fw-semibold,
strong { font-weight: 700; }
.fs-3 { font-size: 1.75rem; }

.app-shell {
    min-height: 100vh;
    display: flex;
}

.app-sidebar {
    width: 280px;
    min-height: 100vh;
    background: linear-gradient(180deg, #00288e 0%, #173bab 100%);
    color: #fff;
    padding: 1.5rem;
    position: fixed;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.brand-block {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.brand-icon {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.1);
    display: grid;
    place-items: center;
    overflow: hidden;
    flex: 0 0 auto;
}

.brand-logo-frame {
    padding: 0.35rem;
}

.brand-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.brand-block h1 {
    font-size: 1.2rem;
    font-weight: 700;
    margin: 0;
}

.brand-block p,
.admin-mini small {
    margin: 0;
    color: rgba(255, 255, 255, 0.72);
}

.nav {
    display: flex;
    flex-direction: column;
}

.app-sidebar .nav-link {
    color: rgba(255, 255, 255, 0.8);
    border-radius: 16px;
    padding: 0.9rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    font-weight: 500;
}

.app-sidebar .nav-link.active,
.app-sidebar .nav-link:hover {
    color: #05361c;
    background: #6dfe9c;
}

.sidebar-cta,
.sidebar-footer {
    margin-top: auto;
}

.admin-mini {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.avatar-circle {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    display: grid;
    place-items: center;
    font-weight: 700;
}

.app-main {
    width: calc(100% - 280px);
    margin-left: 280px;
}

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(248, 249, 255, 0.92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
}

.search-pill {
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 999px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.35rem 1rem;
    min-width: min(480px, 100%);
}

.search-pill .form-control {
    background: transparent;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.icon-btn {
    width: 42px;
    height: 42px;
    border-radius: 999px;
    border: 0;
    background: var(--surface);
    box-shadow: 0 8px 18px rgba(13, 28, 46, 0.06);
    cursor: pointer;
}

.app-content {
    padding: 2rem;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-header h2 {
    color: var(--primary);
    font-size: clamp(1.75rem, 2vw, 2.35rem);
    font-weight: 700;
    margin: 0;
}

.page-header p {
    margin: 0.35rem 0 0;
    color: var(--muted);
}

.glass-card,
.data-card {
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.65);
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
    border-radius: 1.5rem;
}

.border {
    border: 1px solid var(--line);
}

.rounded-3 {
    border-radius: 1rem;
}

.rounded-4 {
    border-radius: 1.25rem;
}

.rounded-pill {
    border-radius: 999px;
}

.bg-white {
    background: #fff;
}

.metric-card {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.metric-icon {
    width: 54px;
    height: 54px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    font-size: 1.4rem;
}

.metric-card h3,
.metric-card p {
    margin: 0;
}

.metric-card p {
    color: var(--muted);
    font-size: 0.9rem;
}

.metric-card h3 {
    font-size: 1.9rem;
    font-weight: 700;
    color: var(--primary);
}

.card-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem 1.5rem 0;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table thead th {
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    color: var(--muted);
    background: #f6f9ff;
    border-bottom-width: 1px;
}

.table th,
.table td {
    padding: 0.9rem 1rem;
    border-bottom: 1px solid #e7edf7;
    text-align: left;
}

.table tbody td {
    vertical-align: middle;
}

.table-responsive {
    overflow-x: auto;
}

.form-control,
.form-select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 1rem;
    padding: 0.75rem 1rem;
    background: #fff;
    color: var(--text);
    min-height: 44px;
}

.form-control-sm {
    min-height: 36px;
    padding: 0.45rem 0.7rem;
}

.form-label {
    display: inline-block;
    margin-bottom: 0.4rem;
    font-weight: 500;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    border: 1px solid transparent;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    font-weight: 500;
    cursor: pointer;
    background: #fff;
    color: var(--text);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

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

.btn-light {
    background: #fff;
    color: var(--primary);
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.4rem 0.7rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
}

.text-bg-primary,
.text-bg-primary-subtle {
    background: #dce9ff;
    color: var(--primary);
}

.text-bg-success,
.text-bg-success-subtle {
    background: #dff8e7;
    color: #0d6b34;
}

.text-bg-info,
.text-bg-info-subtle {
    background: #e0f1ff;
    color: #0a5d9d;
}

.text-bg-danger,
.text-bg-danger-subtle {
    background: #ffe4e1;
    color: #a4281d;
}

.text-bg-warning-subtle {
    background: #fff2d6;
    color: #8b5a00;
}

.text-primary,
.text-primary-emphasis {
    color: var(--primary);
}

.text-success,
.text-success-emphasis {
    color: #0d6b34;
}

.text-info,
.text-info-emphasis {
    color: #0a5d9d;
}

.text-danger,
.text-danger-emphasis {
    color: #a4281d;
}

.report-tile {
    padding: 1.5rem;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.report-tile .tile-icon {
    width: 56px;
    height: 56px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 1.5rem;
}

.progress {
    background: #e6eef9;
    border-radius: 999px;
    overflow: hidden;
}

.progress-thin {
    height: 8px;
    border-radius: 999px;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #00288e, #1e40af);
    border-radius: inherit;
}

.spreadsheet th:first-child,
.spreadsheet td:first-child {
    position: sticky;
    left: 0;
    background: #fff;
}

.attendance-table th:nth-child(3),
.attendance-table td:nth-child(3) {
    min-width: 340px;
}

.attendance-status-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
}

.attendance-status-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.attendance-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 36px;
    padding: 0.6rem 1rem;
    border-radius: 999px;
    border: 1.5px solid currentColor;
    background: #fff;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.attendance-status-pill:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 18px rgba(13, 28, 46, 0.08);
}

.attendance-status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: currentColor;
    flex: 0 0 auto;
}

.attendance-status-pill.present {
    color: #138a52;
}

.attendance-status-pill.late {
    color: #e4a000;
}

.attendance-status-pill.absent {
    color: #eb445a;
}

.attendance-status-pill.leave {
    color: #00b4ff;
}

.attendance-status-input:checked + .attendance-status-pill.present {
    background: #1b8f58;
    border-color: #1b8f58;
    color: #ffffff;
    box-shadow: 0 10px 22px rgba(27, 143, 88, 0.22);
}

.attendance-status-input:checked + .attendance-status-pill.late {
    background: #e4a000;
    border-color: #e4a000;
    color: #ffffff;
    box-shadow: 0 10px 22px rgba(228, 160, 0, 0.22);
}

.attendance-status-input:checked + .attendance-status-pill.absent {
    background: #eb445a;
    border-color: #eb445a;
    color: #ffffff;
    box-shadow: 0 10px 22px rgba(235, 68, 90, 0.22);
}

.attendance-status-input:checked + .attendance-status-pill.leave {
    background: #00b4ff;
    border-color: #00b4ff;
    color: #ffffff;
    box-shadow: 0 10px 22px rgba(0, 180, 255, 0.22);
}

@media (max-width: 991.98px) {
    .app-sidebar {
        position: static;
        width: 100%;
        min-height: auto;
    }

    .app-shell {
        flex-direction: column;
    }

    .app-main {
        width: 100%;
        margin-left: 0;
    }

    .app-topbar,
    .page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .search-pill {
        min-width: 0;
        width: 100%;
    }

    .attendance-table th:nth-child(3),
    .attendance-table td:nth-child(3) {
        min-width: 300px;
    }
}

@media (min-width: 768px) {
    .col-md-6 {
        width: 50%;
    }
}

@media (min-width: 992px) {
    .col-lg-4 {
        width: 33.333333%;
    }

    .col-lg-8 {
        width: 66.666667%;
    }
}

@media (min-width: 1200px) {
    .col-xl-3 {
        width: 25%;
    }

    .col-xl-4 {
        width: 33.333333%;
    }

    .col-xl-5 {
        width: 41.666667%;
    }

    .col-xl-7 {
        width: 58.333333%;
    }

    .col-xl-8 {
        width: 66.666667%;
    }
}

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

.subject-editor-dialog {
    max-width: 980px;
}

.subject-editor-modal {
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 1.75rem;
    overflow: hidden;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, #f8fbff 100%);
    box-shadow: 0 32px 70px rgba(0, 40, 142, 0.18);
}

.subject-editor-header {
    padding: 1.5rem 1.5rem 1rem;
    border-bottom: 1px solid #e7edf7;
    background: linear-gradient(180deg, #ffffff 0%, #f4f8ff 100%);
}

.subject-editor-header .modal-title {
    color: var(--text);
    font-size: 1.65rem;
}

.subject-editor-modal .modal-body {
    padding: 1.5rem;
}

.subject-editor-modal .border {
    border-color: #dfe7f5;
}

.subject-editor-modal .table thead th {
    background: #f7faff;
}

.subject-editor-modal .btn-primary {
    min-height: 48px;
}

@media (max-width: 767.98px) {
    .subject-editor-dialog {
        margin: 0.75rem;
    }

    .subject-editor-header,
    .subject-editor-modal .modal-body {
        padding: 1rem;
    }

    .subject-editor-header {
        align-items: start;
    }
}

input.score-input[type="number"]::-webkit-outer-spin-button,
input.score-input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input.score-input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
}

input.score-input[type="number"],
.total-score-field,
.grade-field {
    padding-left: 0.7rem;
    padding-right: 0.7rem;
    text-align: center;
}

input.score-input[type="number"] {
    min-width: 4rem;
    width: 4rem;
    font-weight: 500;
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
}

.total-score-field,
.grade-field {
    min-width: 4.5rem;
    width: 4.5rem;
    font-weight: 500;
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
}




.spreadsheet tbody td:nth-child(2) strong {
    font-size: 1rem;
    font-weight: 400;
}


.dashboard-hero {
    display: grid;
    grid-template-columns: minmax(0, 1.9fr) minmax(280px, 0.9fr);
    gap: 1.5rem;
    padding: 1.75rem;
    border-radius: 1.75rem;
    background:
        radial-gradient(circle at top left, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.82) 40%, rgba(227, 238, 255, 0.9) 100%),
        linear-gradient(135deg, #f8fbff 0%, #dde9ff 100%);
    border: 1px solid rgba(255, 255, 255, 0.72);
    box-shadow: var(--shadow);
}

.dashboard-hero__content h2 {
    margin: 0;
    color: var(--primary);
    font-size: clamp(2rem, 2.3vw, 2.8rem);
    font-weight: 800;
    line-height: 1.1;
}

.dashboard-hero__content p {
    margin: 1rem 0 0;
    max-width: 52rem;
    color: #52627f;
    font-size: 1rem;
}

.dashboard-hero__eyebrow {
    display: inline-flex;
    align-items: center;
    padding: 0.45rem 0.8rem;
    border-radius: 999px;
    background: rgba(0, 40, 142, 0.08);
    color: var(--primary);
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

.dashboard-hero__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.dashboard-hero__meta span {
    display: inline-flex;
    align-items: center;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    background: rgba(255, 255, 255, 0.88);
    color: #1e3159;
    border: 1px solid rgba(205, 220, 245, 0.95);
    font-weight: 600;
}

.dashboard-hero__panel {
    padding: 1.5rem;
    border-radius: 1.5rem;
    background: linear-gradient(160deg, #0b3199 0%, #1d4ac0 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 100%;
}

.dashboard-hero__panel-label {
    color: rgba(255, 255, 255, 0.78);
    font-size: 0.9rem;
    font-weight: 600;
}

.dashboard-hero__panel-value {
    margin-top: 0.6rem;
    font-size: clamp(2.4rem, 3vw, 3.5rem);
    font-weight: 800;
    line-height: 1;
}

.dashboard-hero__panel p {
    margin: 0.9rem 0 1.25rem;
    color: rgba(255, 255, 255, 0.84);
}

.dashboard-summary-card {
    border: 1px solid rgba(217, 226, 244, 0.9);
}

.dashboard-module-card {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    border: 1px solid rgba(217, 226, 244, 0.9);
}

.dashboard-module-card__icon {
    width: 60px;
    height: 60px;
    border-radius: 1.25rem;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #dfe9ff 0%, #f4f7ff 100%);
    color: var(--primary);
    font-size: 1.55rem;
}

.dashboard-module-card h5,
.dashboard-module-card p {
    margin: 0;
}

.dashboard-module-card p {
    color: var(--muted);
}

.dashboard-side-panel {
    border: 1px solid rgba(217, 226, 244, 0.9);
}

.dashboard-list-card {
    border-color: rgba(217, 226, 244, 0.9) !important;
}

.dashboard-list-card__meta {
    margin-top: 0.65rem;
    color: #64748b;
    font-size: 0.84rem;
}

@media (max-width: 991.98px) {
    .dashboard-hero {
        grid-template-columns: 1fr;
    }
}

/* Responsive system layout */
html {
    min-width: 0;
}

img,
svg,
video,
canvas {
    max-width: 100%;
}

.table-responsive {
    width: 100%;
    -webkit-overflow-scrolling: touch;
}

.table-responsive .table {
    min-width: 720px;
}

.spreadsheet .table {
    min-width: 980px;
}

.page-header > div,
.card-toolbar > div,
.dashboard-hero__content,
.dashboard-hero__panel {
    min-width: 0;
}

.page-header form,
.page-header .d-flex,
.card-toolbar .d-flex {
    min-width: 0;
}

.form-select,
.form-control,
.btn {
    max-width: 100%;
}

@media (max-width: 1199.98px) {
    .app-sidebar {
        width: 240px;
        padding: 1.15rem;
    }

    .app-main {
        width: calc(100% - 240px);
        margin-left: 240px;
    }

    .brand-icon {
        width: 54px;
        height: 54px;
        border-radius: 16px;
    }

    .brand-block h1 {
        font-size: 1.05rem;
    }

    .app-content {
        padding: 1.5rem;
    }
}

@media (max-width: 991.98px) {
    body {
        background: #f8f9ff;
    }

    .app-sidebar {
        position: sticky;
        top: 0;
        z-index: 40;
        width: 100%;
        min-height: auto;
        padding: 0.85rem 1rem;
        gap: 0.85rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.18);
    }

    .brand-block {
        gap: 0.75rem;
    }

    .brand-icon {
        width: 46px;
        height: 46px;
        border-radius: 14px;
    }

    .brand-block h1 {
        font-size: 1rem;
    }

    .brand-block p {
        font-size: 0.8rem;
    }

    .app-sidebar .nav {
        flex-direction: row;
        gap: 0.5rem;
        overflow-x: auto;
        padding-bottom: 0.25rem;
        scrollbar-width: thin;
    }

    .app-sidebar .nav-link {
        flex: 0 0 auto;
        border-radius: 999px;
        padding: 0.65rem 0.85rem;
        white-space: nowrap;
    }

    .sidebar-cta {
        display: none;
    }

    .sidebar-footer {
        margin-top: 0;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
    }

    .admin-mini {
        min-width: 0;
        flex: 1;
        padding-top: 0.75rem;
    }

    .admin-mini > div:last-child {
        min-width: 0;
    }

    .admin-mini strong,
    .admin-mini small {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .sidebar-footer .btn {
        width: auto !important;
        min-height: 40px;
        padding: 0.55rem 0.85rem;
        white-space: nowrap;
    }

    .app-main {
        width: 100%;
        margin-left: 0;
    }

    .app-topbar {
        position: static;
        padding: 1rem;
        gap: 0.75rem;
    }

    .topbar-actions {
        justify-content: flex-end;
    }

    .app-content {
        padding: 1rem;
    }

    .page-header {
        align-items: stretch;
    }

    .page-header h2 {
        font-size: 1.75rem;
        line-height: 1.2;
    }

    .page-header form,
    .page-header > .d-flex {
        width: 100%;
    }

    .page-header form > *,
    .page-header > .d-flex > * {
        flex: 1 1 220px;
    }

    .card-toolbar {
        flex-direction: column;
        align-items: stretch;
        padding: 1rem 1rem 0;
    }

    .data-card,
    .glass-card {
        border-radius: 1rem;
    }

    .dashboard-hero {
        padding: 1.25rem;
        border-radius: 1.25rem;
    }

    .dashboard-hero__content h2 {
        font-size: 1.9rem;
    }
}

@media (max-width: 767.98px) {
    .row {
        margin-right: -0.5rem;
        margin-left: -0.5rem;
    }

    .row > * {
        padding-right: 0.5rem;
        padding-left: 0.5rem;
    }

    .g-4 {
        row-gap: 1rem;
    }

    .app-sidebar {
        padding: 0.75rem;
    }

    .app-sidebar .nav-link span {
        font-size: 0.9rem;
    }

    .app-topbar {
        display: grid;
        grid-template-columns: 1fr auto;
        align-items: center;
    }

    .search-pill {
        min-width: 0;
        padding: 0.35rem 0.75rem;
    }

    .search-pill input {
        font-size: 0.9rem;
    }

    .topbar-actions {
        gap: 0.45rem;
    }

    .icon-btn {
        width: 38px;
        height: 38px;
    }

    .app-content {
        padding: 0.85rem;
    }

    .page-header {
        margin-bottom: 1rem;
    }

    .page-header h2 {
        font-size: 1.55rem;
    }

    .page-header p {
        font-size: 0.92rem;
    }

    .page-header form,
    .page-header > .d-flex,
    .card-toolbar,
    .card-toolbar .d-flex,
    .modal-body .row {
        gap: 0.75rem;
    }

    .page-header form > *,
    .page-header > .d-flex > * {
        flex-basis: 100%;
    }

    .btn,
    .form-control,
    .form-select {
        min-height: 46px;
    }

    .p-3,
    .p-4 {
        padding: 0.85rem !important;
    }

    .px-3,
    .px-4 {
        padding-left: 0.85rem !important;
        padding-right: 0.85rem !important;
    }

    .metric-card,
    .dashboard-module-card,
    .dashboard-hero__panel {
        padding: 1rem;
    }

    .metric-icon,
    .dashboard-module-card__icon {
        width: 48px;
        height: 48px;
        border-radius: 14px;
        font-size: 1.25rem;
    }

    .dashboard-hero {
        padding: 1rem;
        gap: 1rem;
    }

    .dashboard-hero__content h2 {
        font-size: 1.55rem;
    }

    .dashboard-hero__meta span {
        width: 100%;
        padding: 0.65rem 0.8rem;
    }

    .table th,
    .table td {
        padding: 0.75rem 0.8rem;
    }

    .subject-check-row {
        align-items: flex-start !important;
    }
}

@media (max-width: 575.98px) {
    .brand-block {
        align-items: flex-start;
    }

    .brand-block h1,
    .brand-block p {
        line-height: 1.25;
    }

    .app-sidebar .nav-link {
        padding: 0.58rem 0.75rem;
    }

    .sidebar-footer {
        align-items: stretch;
        flex-direction: column;
    }

    .sidebar-footer .btn {
        width: 100% !important;
    }

    .app-topbar {
        grid-template-columns: 1fr;
    }

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

    .page-header h2 {
        font-size: 1.4rem;
    }

    .card-toolbar h5 {
        font-size: 1rem;
    }

    .badge {
        white-space: normal;
        text-align: left;
    }

    .modal-dialog {
        margin: 0.5rem;
    }

    .modal-content,
    .subject-editor-modal {
        border-radius: 1rem;
    }

    .subject-editor-header .modal-title {
        font-size: 1.25rem;
    }

    input.score-input[type="number"],
    .total-score-field,
    .grade-field {
        min-width: 3.8rem;
        width: 3.8rem;
        font-size: 0.95rem;
    }
}

/* Overflow safety */
.app-shell,
.app-main,
.app-content,
.data-card,
.glass-card,
.modal-content {
    min-width: 0;
}

h1,
h2,
h3,
h4,
h5,
p,
strong,
small,
.btn,
.badge,
.nav-link,
.table th,
.table td {
    overflow-wrap: anywhere;
}

/* Page-specific responsive sizing */
@media (min-width: 768px) {
    .col-md-4 { width: 33.333333%; }
    .col-md-8 { width: 66.666667%; }
}

@media (min-width: 1200px) {
    .col-xl-6 { width: 50%; }
}

.attendance-table {
    min-width: 920px !important;
}

.subject-editor-modal .table {
    min-width: 720px;
}

.data-card .table th,
.data-card .table td {
    white-space: normal;
}

.data-card .table th:nth-child(n+2),
.data-card .table td:nth-child(n+2) {
    min-width: 92px;
}

.data-card .table th:first-child,
.data-card .table td:first-child {
    min-width: 160px;
}

/* Keep the student list compact enough to show every column on desktop. */
.student-table-wrap {
    padding: 0.75rem 1rem 1rem;
}

.student-table {
    table-layout: auto;
    width: 100%;
}

.student-table th,
.student-table td {
    min-width: 0 !important;
    padding: 0.65rem 0.55rem !important;
    font-size: 0.9rem;
}

.student-table th:first-child,
.student-table td:first-child {
    width: 34%;
    min-width: 180px !important;
}

.student-table th:nth-child(2),
.student-table td:nth-child(2),
.student-table th:nth-child(3),
.student-table td:nth-child(3),
.student-table th:nth-child(4),
.student-table td:nth-child(4),
.student-table th:nth-child(5),
.student-table td:nth-child(5),
.student-table th:last-child,
.student-table td:last-child {
    white-space: nowrap;
}

.student-table td.text-end .btn.btn-sm {
    width: 34px;
    height: 34px;
    padding: 0;
    display: inline-grid;
    place-items: center;
}

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

.curriculum-table th:first-child,
.curriculum-table td:first-child {
    width: 1%;
    min-width: 88px !important;
    white-space: nowrap;
}

.curriculum-table th:nth-child(2),
.curriculum-table td:nth-child(2) {
    min-width: 180px !important;
}

.curriculum-filter-card {
    padding: 1.25rem;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(239, 246, 255, 0.92));
    border: 1px solid #d7e5fb;
    box-shadow: 0 14px 34px rgba(17, 55, 122, 0.08);
}

.curriculum-filter-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.curriculum-filter-heading {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.curriculum-filter-heading h5 {
    color: var(--primary);
    font-weight: 800;
}

.curriculum-filter-heading-icon {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    color: #fff;
    background: linear-gradient(135deg, #0b3aa9, #2563eb);
    box-shadow: 0 8px 18px rgba(11, 58, 169, 0.2);
}

.curriculum-result-count {
    padding: 0.45rem 0.8rem;
    border-radius: 999px;
    color: #16448f;
    background: #e2edff;
    font-size: 0.82rem;
    font-weight: 800;
    white-space: nowrap;
}

.curriculum-filter-grid {
    display: grid;
    grid-template-columns: minmax(200px, 1.7fr) repeat(3, minmax(118px, 1fr)) auto;
    gap: 0.65rem;
    align-items: end;
}

.student-filter-grid {
    grid-template-columns: minmax(260px, 2fr) repeat(2, minmax(160px, 1fr)) auto;
}

.curriculum-filter-field .form-label {
    margin: 0 0 0.4rem 0.2rem;
    color: #40516d;
    font-size: 0.82rem;
    font-weight: 700;
}

.curriculum-filter-control {
    position: relative;
}

.curriculum-filter-control > i {
    position: absolute;
    z-index: 2;
    left: 0.9rem;
    top: 50%;
    transform: translateY(-50%);
    color: #6b82aa;
    pointer-events: none;
}

.curriculum-filter-control .form-control,
.curriculum-filter-control .form-select {
    min-height: 46px;
    padding-left: 2.55rem;
    border: 1px solid #ccdbf2;
    border-radius: 14px;
    background-color: rgba(255, 255, 255, 0.96);
    box-shadow: 0 3px 10px rgba(15, 43, 91, 0.03);
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

.curriculum-filter-control .form-control:focus,
.curriculum-filter-control .form-select:focus {
    border-color: #6797ec;
    background-color: #fff;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.curriculum-filter-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    white-space: nowrap;
}

.curriculum-filter-submit,
.curriculum-filter-reset {
    min-height: 46px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.curriculum-filter-submit {
    padding-inline: 1.15rem;
    box-shadow: 0 8px 16px rgba(11, 58, 169, 0.18);
}

.curriculum-filter-reset {
    gap: 0.4rem;
}

.curriculum-active-filters {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.45rem;
    padding-top: 0.9rem;
    margin-top: 1rem;
    border-top: 1px dashed #cad9f0;
}

.curriculum-active-filters-label {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
}

.curriculum-filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.65rem;
    border-radius: 999px;
    color: #15458e;
    background: #fff;
    border: 1px solid #cddcf4;
    font-size: 0.8rem;
    font-weight: 700;
}

.dashboard-list-card,
.report-tile,
.subject-check-row {
    min-width: 0;
}

.report-tile {
    height: 100%;
    min-height: 220px;
}

@media (max-width: 991.98px) {
    .data-card .table-responsive,
    .glass-card .table-responsive {
        border-radius: 0.85rem;
    }

    .subject-editor-dialog.modal-xl,
    .subject-editor-dialog.modal-lg,
    .subject-editor-dialog {
        max-width: calc(100vw - 1.5rem);
    }
}

@media (max-width: 767.98px) {
    .curriculum-filter-card {
        padding: 1rem;
    }

    .curriculum-filter-header {
        align-items: flex-start;
    }

    .curriculum-filter-heading-icon {
        width: 38px;
        height: 38px;
        flex-basis: 38px;
    }

    .curriculum-filter-grid {
        grid-template-columns: 1fr;
    }

    .curriculum-filter-actions {
        grid-column: auto;
        display: grid;
    }

    .student-summary-grid {
        grid-template-columns: 1fr;
    }

    .page-header form.d-flex,
    .page-header .d-flex.flex-wrap,
    .card-toolbar .d-flex.flex-wrap {
        display: grid !important;
        grid-template-columns: 1fr;
    }

    .page-header form.d-flex > *,
    .page-header .d-flex.flex-wrap > *,
    .card-toolbar .d-flex.flex-wrap > * {
        width: 100%;
    }

    .text-end {
        text-align: left;
    }

    .text-end .btn,
    .modal-body .btn-primary,
    .card-toolbar > .btn,
    .page-header .btn {
        width: 100%;
    }

    .attendance-status-group {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.45rem;
    }

    .attendance-status-pill {
        justify-content: center;
        min-width: 0;
        width: 100%;
    }

    .report-tile {
        min-height: auto;
    }
}

@media (max-width: 575.98px) {
    .data-card .table-responsive,
    .glass-card .table-responsive,
    .spreadsheet {
        margin-left: -0.35rem;
        margin-right: -0.35rem;
        padding-left: 0.35rem !important;
        padding-right: 0.35rem !important;
    }

    .table-responsive::after {
        content: "เลื่อนตารางซ้าย-ขวาเพื่อดูข้อมูลทั้งหมด";
        display: block;
        margin-top: 0.5rem;
        color: var(--muted);
        font-size: 0.78rem;
    }

    .subject-editor-modal .row > *,
    .modal-body .row > * {
        width: 100% !important;
    }

    .attendance-status-group {
        grid-template-columns: 1fr;
    }

    .dashboard-module-card,
    .metric-card {
        gap: 0.75rem;
    }
}


/* Mobile app-style bottom navigation */
@media (max-width: 767.98px) {
    .app-shell {
        padding-bottom: calc(76px + env(safe-area-inset-bottom));
    }

    .app-sidebar {
        position: fixed;
        inset: auto 0 0 0;
        z-index: 1000;
        width: 100%;
        min-height: auto;
        padding: 0.45rem 0.55rem calc(0.45rem + env(safe-area-inset-bottom));
        background: rgba(255, 255, 255, 0.96);
        color: var(--text);
        border-top: 1px solid rgba(215, 225, 243, 0.95);
        border-bottom: 0;
        box-shadow: 0 -10px 30px rgba(15, 42, 96, 0.12);
        backdrop-filter: blur(14px);
    }

    .app-sidebar .brand-block,
    .app-sidebar .sidebar-cta,
    .app-sidebar .sidebar-footer {
        display: none;
    }

    .app-sidebar .nav {
        display: grid;
        grid-auto-flow: column;
        grid-auto-columns: minmax(64px, 1fr);
        gap: 0.25rem;
        overflow-x: auto;
        padding: 0;
        scrollbar-width: none;
    }

    .app-sidebar .nav::-webkit-scrollbar {
        display: none;
    }

    .app-sidebar .nav-link {
        min-width: 64px;
        min-height: 58px;
        padding: 0.45rem 0.35rem;
        border-radius: 16px;
        color: #52627f;
        background: transparent;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.18rem;
        white-space: nowrap;
        font-size: 0.72rem;
        line-height: 1.15;
        text-align: center;
    }

    .app-sidebar .nav-link i {
        margin: 0;
        font-size: 1.2rem;
        line-height: 1;
    }

    .app-sidebar .nav-link span {
        display: block;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 0.72rem;
    }

    .app-sidebar .nav-link.active,
    .app-sidebar .nav-link:hover {
        color: var(--primary);
        background: #e7efff;
    }

    .app-main {
        padding-bottom: 0;
    }
}

@media (max-width: 380px) {
    .app-sidebar .nav {
        grid-auto-columns: minmax(58px, 1fr);
    }

    .app-sidebar .nav-link {
        min-width: 58px;
        font-size: 0.68rem;
    }

    .app-sidebar .nav-link span {
        font-size: 0.68rem;
    }
}

/* Score entry workspace */
.score-entry-card {
    border: 1px solid #e2eaf6;
    background: #ffffff;
}

.score-entry-card .card-toolbar {
    align-items: flex-start;
    padding: 1.35rem 1.35rem 1rem;
    border-bottom: 1px solid #e8eef8;
    background: linear-gradient(180deg, #ffffff 0%, #f9fbff 100%);
}

.score-summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(140px, 1fr));
    gap: 0.65rem;
    min-width: min(100%, 560px);
}

.score-pill {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    min-height: 42px;
    padding: 0.6rem 0.85rem;
    border-radius: 0.85rem;
    border: 1px solid transparent;
    font-size: 0.86rem;
    line-height: 1.2;
}

.score-pill span {
    color: #344054;
    font-weight: 600;
}

.score-pill strong {
    color: #0d1c2e;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.score-pill-primary {
    background: #e7efff;
    border-color: #cddcff;
}

.score-pill-info {
    background: #e5f7fb;
    border-color: #c8edf4;
}

.score-pill-success {
    background: #e8f8ee;
    border-color: #cef0db;
}

.score-sheet {
    max-height: calc(100vh - 250px);
    padding: 0 1rem;
    overflow: auto;
    scrollbar-gutter: stable;
    background: #ffffff;
}

.score-sheet .score-table {
    min-width: 1120px;
    border-collapse: separate;
    border-spacing: 0;
}

.score-sheet .score-table thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    height: 58px;
    padding: 0.75rem 0.7rem;
    background: #f3f7fd;
    color: #455163;
    border-bottom: 1px solid #dbe5f2;
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.78rem;
    font-weight: 700;
    text-align: center;
    vertical-align: middle;
}

.score-sheet .score-table tbody td {
    height: 72px;
    padding: 0.65rem 0.7rem;
    background: #ffffff;
    border-bottom: 1px solid #e8eef7;
    vertical-align: middle;
}

.score-sheet .score-table tbody tr:nth-child(even) td {
    background: #fbfdff;
}

.score-sheet .score-table tbody tr:hover td {
    background: #f4f8ff;
}

.score-sheet .student-code-col,
.score-sheet .student-code-cell {
    position: sticky;
    left: 0;
    z-index: 6;
    width: 142px;
    min-width: 142px !important;
    text-align: left !important;
}

.score-sheet .student-name-col,
.score-sheet .student-name-cell {
    position: sticky;
    left: 142px;
    z-index: 6;
    width: 240px;
    min-width: 240px !important;
    text-align: left !important;
    box-shadow: 8px 0 14px rgba(15, 23, 42, 0.04);
}

.score-sheet thead .student-code-col,
.score-sheet thead .student-name-col {
    z-index: 8;
}

.score-sheet .student-code-cell span {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 0.25rem 0.55rem;
    border-radius: 999px;
    background: #eef4ff;
    color: #102a56;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.score-sheet .student-name-cell strong {
    display: block;
    color: #111827;
    font-size: 0.98rem;
    font-weight: 700;
    line-height: 1.35;
    overflow-wrap: normal;
}

.score-sheet .student-name-cell .small {
    margin-top: 0.2rem;
}

.score-sheet .score-col,
.score-sheet .score-cell,
.score-sheet .final-score-cell,
.score-sheet .result-cell,
.score-sheet .grade-cell {
    width: 88px;
    min-width: 88px !important;
    text-align: center !important;
}

.score-sheet .final-score-col,
.score-sheet .final-score-cell {
    border-left: 1px solid #dbe5f2;
}

.score-sheet .result-col,
.score-sheet .result-cell,
.score-sheet .grade-col,
.score-sheet .grade-cell {
    width: 92px;
    min-width: 92px !important;
}

.score-sheet .remark-col,
.score-sheet .remark-cell {
    width: 170px;
    min-width: 170px !important;
}

.score-sheet input.score-input[type="number"],
.score-sheet .total-score-field,
.score-sheet .grade-field {
    width: 64px;
    min-width: 64px;
    height: 44px;
    margin: 0 auto;
    padding: 0.45rem 0.35rem;
    border-radius: 0.75rem !important;
    border-color: #c9d7ed;
    background: #ffffff;
    font-size: 1rem;
    font-weight: 700;
    text-align: center;
    font-variant-numeric: tabular-nums;
    box-shadow: inset 0 1px 0 rgba(15, 23, 42, 0.02);
}

.score-sheet input.score-input[type="number"]:focus {
    border-color: #0b57d0;
    box-shadow: 0 0 0 0.2rem rgba(11, 87, 208, 0.12);
}

.score-sheet input.score-input[type="number"]:out-of-range {
    border-color: #dc3545;
    background: #fff5f5;
}

.score-sheet .total-score-field,
.score-sheet .grade-field {
    border-color: #d6e0ee;
    background: #f6f9fd;
    color: #102a56;
}

.score-sheet .remark-input {
    min-width: 150px;
    height: 44px;
    border-radius: 0.75rem !important;
}

.score-save-bar {
    position: sticky;
    bottom: 0;
    z-index: 9;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 0.25rem 1rem;
    border-top: 1px solid #e2eaf6;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.92) 0%, #ffffff 42%);
}

.score-save-bar .btn {
    min-width: 180px;
    min-height: 46px;
    font-weight: 700;
}

@media (max-width: 1199.98px) {
    .score-entry-card .card-toolbar,
    .score-summary,
    .score-save-bar {
        align-items: stretch;
    }

    .score-summary {
        grid-template-columns: 1fr;
        min-width: 220px;
    }

    .score-sheet {
        max-height: calc(100vh - 230px);
    }
}

@media (max-width: 767.98px) {
    .score-entry-card .card-toolbar {
        padding: 1rem;
    }

    .score-sheet {
        padding: 0 0.5rem;
    }

    .score-sheet .student-code-col,
    .score-sheet .student-code-cell {
        width: 122px;
        min-width: 122px !important;
    }

    .score-sheet .student-name-col,
    .score-sheet .student-name-cell {
        left: 122px;
        width: 190px;
        min-width: 190px !important;
    }

    .score-save-bar {
        display: grid;
        grid-template-columns: 1fr;
    }

    .score-save-bar .btn {
        width: 100%;
    }
}

.subject-edit-icon {
    display: inline-grid !important;
    place-items: center;
    width: 36px !important;
    min-width: 36px;
    height: 36px;
    padding: 0 !important;
    border: 0;
    color: var(--primary);
    background: transparent;
    line-height: 1;
    cursor: pointer;
    transition: color 150ms ease, transform 150ms ease;
}

.subject-edit-icon .bi {
    margin: 0;
    font-size: 1.1rem;
}

.subject-edit-icon:hover,
.subject-edit-icon:focus-visible {
    color: #315dc6;
    transform: scale(1.12);
}

.subject-edit-icon:focus-visible {
    outline: 2px solid rgba(0, 40, 142, 0.35);
    outline-offset: 2px;
}

.subject-status-icon {
    display: inline-grid;
    place-items: center;
    width: 36px;
    min-width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    background: transparent;
    line-height: 1;
    cursor: pointer;
    transition: color 150ms ease, transform 150ms ease;
}

.subject-status-icon .bi {
    font-size: 1.1rem;
}

.subject-status-icon.is-deactivate { color: #6c757d; }
.subject-status-icon.is-activate { color: #198754; }

.subject-status-icon:hover,
.subject-status-icon:focus-visible {
    transform: scale(1.12);
}

.subject-status-icon.is-deactivate:hover { color: #dc3545; }
.subject-status-icon.is-activate:hover { color: #157347; }

.subject-status-icon:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}
