:root {
    --app-bg: #f4f7fb;
    --surface: rgba(255, 255, 255, 0.92);
    --surface-border: rgba(24, 48, 85, 0.08);
    --surface-shadow: 0 18px 48px rgba(20, 35, 63, 0.08);
    --text-main: #243042;
    --text-title: #263244;
    --text-heading: #2b384a;
    --text-soft: #697586;
    --text-faint: #8c97a8;
    --brand: #1f6fa8;
    --brand-deep: #123e66;
    --brand-soft: #dbeefb;
    --accent: #df8f34;
    --success: #2f7d4b;
    --success-bg: #ebf7ef;
    --danger: #c94d4d;
    --danger-bg: #fff1f1;
    --table-stripe: rgba(227, 236, 247, 0.45);
    --line-soft: rgba(31, 111, 168, 0.08);
    --line-brand: rgba(31, 111, 168, 0.12);
    --line-brand-strong: rgba(31, 111, 168, 0.18);
    --line-light: rgba(255, 255, 255, 0.55);
    --line-table: rgba(35, 62, 104, 0.08);
    --line-table-soft: rgba(35, 62, 104, 0.06);
    --panel-bg: rgba(255, 255, 255, 0.8);
    --panel-bg-soft: rgba(255, 255, 255, 0.78);
    --panel-bg-strong: rgba(255, 255, 255, 0.88);
    --shadow-soft: 0 12px 30px rgba(20, 35, 63, 0.06);
    --radius-lg: 24px;
    --radius-md: 18px;
    --radius-sm: 12px;
    --radius-pill: 999px;
    --control-radius: 14px;
    --container-max: 1360px;
    --font-ui: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
}

html,
body {
    min-height: 100%;
}

body.app-body {
    position: relative;
    margin: 0;
    color: var(--text-main);
    background:
        radial-gradient(circle at top left, rgba(31, 111, 168, 0.08), transparent 34%),
        radial-gradient(circle at top right, rgba(223, 143, 52, 0.09), transparent 22%),
        linear-gradient(180deg, #f7faff 0%, var(--app-bg) 100%);
    font-family: var(--font-ui);
}

.page-backdrop {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.22), transparent 45%),
        radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.18), transparent 26%);
}

.container {
    max-width: var(--container-max);
}

.topbar-shell {
    position: sticky;
    top: 0;
    z-index: 30;
    padding: 1rem 0 0;
    backdrop-filter: blur(18px);
}

.topbar {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.2rem;
    border: 1px solid var(--line-light);
    border-radius: var(--radius-pill);
    background: var(--panel-bg);
    box-shadow: 0 10px 30px rgba(14, 33, 60, 0.08);
}

.brand-link {
    display: inline-flex;
    align-items: center;
    gap: 0.9rem;
    color: inherit;
    text-decoration: none;
}

.brand-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--brand), var(--brand-deep));
    color: #fff;
    font-weight: 700;
    letter-spacing: 0.08em;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.brand-copy {
    display: flex;
    flex-direction: column;
    gap: 0.08rem;
}

.brand-copy strong {
    font-size: 1rem;
    color: var(--brand-deep);
}

.brand-copy small {
    color: var(--text-soft);
    font-size: 0.82rem;
}

.topbar-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.55rem;
}

.topbar-nav a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.72rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-pill);
    color: var(--text-soft);
    font-weight: 600;
    text-decoration: none;
    transition: 160ms ease;
}

.topbar-nav a:hover,
.topbar-nav a.is-active {
    color: var(--brand-deep);
    background: #fff;
    border-color: var(--line-brand);
    box-shadow: 0 8px 20px rgba(20, 40, 72, 0.08);
}

.topbar-nav .nav-muted {
    color: var(--text-faint);
}

.app-main,
.footer-shell {
    position: relative;
    z-index: 1;
}

.app-main {
    padding: 2rem 0 4rem;
}

.footer-shell {
    padding-bottom: 2rem;
}

.footer-shell p {
    margin: 0;
    color: var(--text-faint);
    font-size: 0.85rem;
    text-align: center;
}

.flash-stack,
.stats-grid,
.toolbar-grid,
.form-grid,
.info-grid,
.dashboard-grid,
.stack-sm {
    display: grid;
}

.flash-stack {
    gap: 0.85rem;
    margin-bottom: 1.4rem;
}

.flash-success,
.flash-error {
    margin: 0;
    padding: 1rem 1.1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    box-shadow: 0 12px 30px rgba(23, 35, 61, 0.05);
}

.flash-success {
    background: var(--success-bg);
    border-color: rgba(47, 125, 75, 0.14);
    color: var(--success);
}

.flash-error {
    background: var(--danger-bg);
    border-color: rgba(201, 77, 77, 0.15);
    color: #a13737;
}

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

.page-heading {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 0.4rem;
    min-height: 9.5rem;
}

.eyebrow,
.filter-pill,
.pill,
.feature-card .feature-tag {
    display: inline-flex;
    align-items: center;
    border-radius: var(--radius-pill);
    font-weight: 700;
    white-space: nowrap;
}

.eyebrow {
    width: fit-content;
    padding: 0.38rem 0.7rem;
    background: var(--brand-soft);
    color: var(--brand-deep);
    font-size: 0.78rem;
    letter-spacing: 0.04em;
}

.page-title {
    margin: 0;
    color: var(--text-title);
    font-size: clamp(2rem, 4vw, 3rem);
    line-height: 1.02;
    letter-spacing: -0.03em;
}

.page-subtitle {
    margin: 0;
    max-width: 52rem;
    min-height: 3rem;
    color: var(--text-soft);
    font-size: 1rem;
}

.page-actions,
.filter-pill-list,
.action-group {
    display: flex;
    flex-wrap: wrap;
}

.page-actions {
    gap: 0.75rem;
    align-self: flex-end;
}

.section-heading,
.table-tools {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.section-heading {
    gap: 1rem;
    margin-bottom: 1rem;
}

.section-heading h3,
.section-heading h4,
.surface-card h3 {
    margin: 0;
    color: var(--text-heading);
}

.section-heading p,
.muted-text,
.table-tools p {
    margin: 0;
    color: var(--text-soft);
}

.surface-card {
    margin: 0 0 1.35rem;
    padding: 1.35rem;
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--surface-shadow);
    backdrop-filter: blur(10px);
}

.filter-pill-list {
    justify-content: flex-end;
    gap: 0.55rem;
}

.filter-pill-list-inline {
    flex-wrap: nowrap;
    align-items: center;
    align-self: flex-start;
    overflow-x: auto;
    scrollbar-width: thin;
}

.filter-pill-list-inline .filter-pill {
    flex: 0 0 auto;
}

.filter-pill {
    padding: 0.38rem 0.72rem;
    border: 1px solid var(--line-brand);
    background: var(--panel-bg-soft);
    color: var(--brand-deep);
    font-size: 0.78rem;
}

.stats-grid,
.toolbar-grid,
.form-grid,
.info-grid,
.dashboard-grid {
    gap: 1rem;
}

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

.current-leave-stats,
.info-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.current-leave-stats > :nth-child(-n + 2) {
    grid-column: span 2;
}

.stat-card,
.meta-card,
.feature-card {
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-md);
}

.stat-card {
    padding: 1rem;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(240, 246, 252, 0.98));
}

.stat-card .stat-label,
.stat-card .stat-value,
.stat-card .stat-note {
    display: block;
}

.stat-card .stat-label {
    margin-bottom: 0.4rem;
    color: var(--text-soft);
    font-size: 0.82rem;
    font-weight: 700;
}

.stat-card .stat-value {
    color: var(--text-main);
    font-size: 1.7rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.stat-card .stat-note {
    margin-top: 0.35rem;
    color: var(--text-faint);
    font-size: 0.84rem;
}

.current-leave-stats .stat-note {
    font-size: 0.8rem;
    white-space: nowrap;
}

.toolbar-grid {
    grid-template-columns: repeat(12, minmax(0, 1fr));
    align-items: end;
}

.filter-shell {
    padding: 1rem;
    border: 1px solid var(--line-soft);
    border-radius: calc(var(--radius-md) + 2px);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(244, 248, 253, 0.9));
}

.student-filter-grid {
    align-items: stretch;
}

.student-filter-grid .filter-block {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    height: 100%;
}

.student-filter-grid .segmented-nav {
    width: 100%;
    align-self: stretch;
}

.toolbar-grid > * {
    margin-bottom: 0;
}

.filter-block {
    padding: 0.85rem;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-sm);
    background: var(--panel-bg);
}

.filter-block-grid {
    gap: 0.75rem;
    align-items: end;
}

.filter-block-grid > * {
    min-width: 0;
}

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

.toolbar-col-3 {
    grid-column: span 3;
}

.toolbar-col-4 {
    grid-column: span 4;
}

.toolbar-col-6 {
    grid-column: span 6;
}

.toolbar-col-8 {
    grid-column: span 8;
}

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

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

.dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
}

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

.meta-card,
.feature-card {
    padding: 1rem 1.1rem;
    background: var(--panel-bg-soft);
}

.meta-card span,
.feature-card p {
    color: var(--text-soft);
}

.meta-card strong,
.feature-card h3 {
    display: block;
    margin-bottom: 0.35rem;
}

.feature-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    height: 100%;
    padding: 1.35rem;
}

.feature-card h3 {
    margin: 0 0 0.45rem;
    color: #273548;
}

.feature-card p {
    margin: 0 0 1rem;
}

.feature-card .feature-tag {
    margin-bottom: 0.8rem;
    padding: 0.34rem 0.65rem;
    background: rgba(31, 111, 168, 0.1);
    color: var(--brand-deep);
    font-size: 0.78rem;
}

.feature-card .btn {
    min-width: 8.5rem;
    margin-top: auto;
    justify-content: center;
}

.table-card {
    padding: 1rem 1rem 0.75rem;
}

.table-shell {
    overflow: hidden;
    border: 1px solid var(--line-table);
    border-radius: 20px;
    background: var(--panel-bg-strong);
}

.history-table .col-rank {
    width: 6rem;
}

.history-table .col-name {
    width: 10rem;
}

.history-table .col-count {
    width: 9rem;
}

.history-table .col-hours,
.history-table .col-student-no,
.routine-table .col-student-no,
.deduction-detail-table .col-datetime,
.deductions-table .col-datetime {
    width: 12rem;
}

.history-table .col-dorm,
.history-table .col-bed,
.students-table .col-dorm,
.students-table .col-bed,
.current-leave-table .col-dorm,
.current-leave-table .col-bed {
    width: 7rem;
}

.students-table .col-class,
.current-leave-table .col-class,
.routine-table .col-class,
.current-leave-table .col-type,
.current-leave-table .col-status,
.deduction-detail-table .col-type,
.deductions-table .col-type {
    width: 8rem;
}

.students-table .col-gender,
.current-leave-table .col-gender,
.routine-table .col-gender {
    width: 5rem;
}

.students-table .col-name,
.routine-table .col-name {
    width: 9rem;
}

.current-leave-table .col-name {
    width: 8rem;
}

.history-table .col-name {
    width: 12rem;
}

.students-table .col-datetime,
.current-leave-table .col-datetime {
    width: 13.5rem;
    min-width: 13.5rem;
}

.students-table .col-actions {
    width: 16rem;
}

.current-leave-table .col-actions {
    width: 10rem;
}

.routine-table .col-actions {
    width: 10rem;
}

.deduction-detail-table .col-detail,
.deductions-table .col-detail,
.current-leave-table .col-reason {
    width: auto;
}

.deduction-detail-table .col-score,
.deductions-table .col-score {
    width: 7rem;
}

.deductions-table .col-actions {
    width: 12rem;
}

figure {
    margin: 0;
    overflow-x: auto;
}

table {
    width: 100%;
    margin: 0;
    border-collapse: collapse;
    background: transparent;
}

thead th {
    padding: 1rem;
    border-bottom: 1px solid rgba(26, 47, 82, 0.08);
    color: var(--text-soft);
    font-size: 0.83rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    background: rgba(247, 250, 254, 0.85);
}

tbody td {
    padding: 1rem;
    border-bottom: 1px solid var(--line-table-soft);
    vertical-align: middle;
}

.datetime-cell,
.datetime-cell .pill,
.datetime-cell .end-time-expired,
.datetime-cell .end-time-normal {
    white-space: nowrap;
}

tbody tr:nth-child(even) td {
    background: var(--table-stripe);
}

tbody tr:last-child td {
    border-bottom: 0;
}

.student-name {
    color: #28364a;
    font-weight: 700;
}

.pill {
    gap: 0.4rem;
    padding: 0.35rem 0.65rem;
    background: rgba(31, 111, 168, 0.1);
    color: var(--brand-deep);
    font-size: 0.8rem;
}

.pill.warn {
    background: rgba(223, 143, 52, 0.16);
    color: #8d5819;
}

.pill.danger {
    background: rgba(186, 61, 61, 0.14);
    color: #a63737;
}

.actions-cell {
    min-width: 12rem;
    white-space: nowrap;
}

.action-group {
    align-items: center;
    gap: 0.45rem;
}

.inline-form {
    display: inline;
    margin: 0;
}

.action-group .btn,
.inline-form .btn {
    margin: 0;
}

.btn-quiet {
    color: var(--brand-deep);
    background: var(--panel-bg-strong);
    border-color: var(--line-brand-strong);
}

.btn-quiet:hover,
.btn-quiet:focus {
    color: #fff;
    background: var(--brand-deep);
    border-color: var(--brand-deep);
}

.btn-strong {
    color: #fff;
    background: linear-gradient(135deg, #4e5f79, #29384d);
    border-color: #29384d;
}

.btn-strong:hover,
.btn-strong:focus {
    color: #fff;
    background: linear-gradient(135deg, #43536d, #223043);
    border-color: #223043;
}

.on-leave-name {
    font-weight: 700;
}

.current-leave-table tr.is-overdue-row td {
    background: rgba(255, 239, 239, 0.72);
}

.end-time-normal,
.end-time-expired {
    font-weight: 700;
}

.end-time-normal {
    color: var(--accent);
}

.end-time-expired {
    color: var(--danger);
}

.reason-cell {
    max-width: 16rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.history-name-cell {
    padding-block: 0.75rem;
}

.history-name-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.history-name-toggle:hover {
    color: var(--brand-deep);
}

.history-name-hint {
    color: var(--text-soft);
    font-size: 0.76rem;
    font-weight: 700;
    white-space: nowrap;
}

.history-detail-row td {
    background: rgba(243, 247, 252, 0.9) !important;
}

.history-summary-row.is-striped td {
    background: var(--table-stripe);
}

.history-detail-cell {
    padding: 0 !important;
}

.history-detail-panel {
    display: grid;
    gap: 0.8rem;
    padding: 1rem;
}

.history-detail-item {
    padding: 0.95rem 1rem;
    border: 1px solid rgba(26, 47, 82, 0.08);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.92);
}

.history-detail-top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
}

.history-detail-range {
    color: var(--text-title);
    font-weight: 700;
}

.history-detail-hours {
    color: var(--brand-deep);
    font-size: 0.86rem;
    font-weight: 700;
}

.history-detail-meta,
.history-detail-reason {
    margin: 0.45rem 0 0;
    color: var(--text-soft);
    font-size: 0.9rem;
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.empty-state {
    margin: 1rem 0 0;
    padding: 1.2rem 1.25rem;
    border: 1px dashed rgba(31, 111, 168, 0.2);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.58);
    color: var(--text-soft);
    text-align: center;
}

.stack-sm {
    gap: 0.5rem;
}

.login-shell {
    max-width: 440px;
    margin: 5rem auto 0;
}

.login-card {
    padding: 1.6rem;
}

.login-card h2 {
    margin-bottom: 0.4rem;
}

.login-card p {
    margin-bottom: 1.25rem;
    color: var(--text-soft);
}

.segmented-nav {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.45rem;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-pill);
    background: rgba(255, 255, 255, 0.7);
}

.segmented-nav a {
    padding: 0.58rem 0.95rem;
    border-radius: var(--radius-pill);
    color: var(--text-soft);
    font-weight: 700;
    text-decoration: none;
}

.segmented-nav a[aria-current="page"] {
    color: #fff;
    background: var(--brand-deep);
}

.form-control,
.form-select {
    border-radius: var(--control-radius) !important;
    background: rgba(255, 255, 255, 0.98);
}

button,
.btn,
input[type="submit"] {
    border-radius: var(--control-radius);
    font-weight: 700;
}

.table-tools {
    flex-wrap: wrap;
    gap: 0.8rem;
    margin-bottom: 0.9rem;
}

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

.rule-callout {
    background: linear-gradient(180deg, rgba(239, 247, 255, 0.98), rgba(249, 251, 255, 0.98));
}

.form-hint {
    margin: 0.45rem 0 0;
    color: var(--text-soft);
    font-size: 0.82rem;
}

.section-heading-compact {
    margin-bottom: 0.9rem;
}

.weekday-template-shell {
    display: grid;
    gap: 1rem;
}

.weekday-template-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.85rem;
}

.weekday-template-card {
    display: grid;
    gap: 0.85rem;
    padding: 0.95rem;
    border: 1px solid rgba(31, 111, 168, 0.12);
    border-radius: var(--radius-md);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(245, 250, 255, 0.98));
}

.weekday-template-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.schedule-toggle-list {
    display: grid;
    gap: 0.65rem;
}

.schedule-toggle {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 2.7rem;
    padding: 0.72rem 0.82rem;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.96);
    color: var(--text-body);
    font-weight: 600;
}

.schedule-toggle input {
    flex: 0 0 auto;
    width: 1rem;
    height: 1rem;
    margin: 0;
    accent-color: var(--brand-deep);
}

.schedule-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 1.8rem;
    padding: 0.28rem 0.7rem;
    border-radius: 999px;
    background: rgba(31, 111, 168, 0.1);
    color: var(--brand-deep);
    font-size: 0.78rem;
    font-weight: 700;
}

.schedule-chip.is-muted {
    background: rgba(146, 160, 179, 0.16);
    color: var(--text-soft);
}

.calendar-weekdays,
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 0.75rem;
}

.calendar-weekdays {
    margin: 1.1rem 0 0.8rem;
}

.calendar-weekdays div {
    padding: 0.7rem 0.9rem;
    color: var(--text-soft);
    font-size: 0.82rem;
    font-weight: 700;
    text-align: center;
}

.calendar-day {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    min-height: 15rem;
    padding: 1rem;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-md);
    background: var(--panel-bg-soft);
    box-shadow: var(--shadow-soft);
}

.calendar-day.is-both {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(243, 249, 255, 0.98));
}

.calendar-day.is-day {
    background: linear-gradient(180deg, rgba(250, 254, 255, 0.96), rgba(239, 248, 255, 0.98));
}

.calendar-day.is-evening {
    background: linear-gradient(180deg, rgba(255, 252, 243, 0.96), rgba(255, 246, 223, 0.98));
}

.calendar-day.is-none {
    background: linear-gradient(180deg, rgba(255, 248, 241, 0.96), rgba(255, 252, 247, 0.98));
}

.calendar-day.is-muted {
    opacity: 0.58;
}

.calendar-day.is-today {
    border-color: rgba(31, 111, 168, 0.35);
    box-shadow: 0 0 0 2px rgba(31, 111, 168, 0.08), var(--shadow-soft);
}

.calendar-day-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}

.calendar-day-head strong {
    color: var(--text-heading);
    font-size: 1.4rem;
    line-height: 1;
}

.calendar-day-head span,
.calendar-day-source {
    color: var(--text-soft);
    font-size: 0.82rem;
}

.calendar-day-flags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.calendar-day-actions {
    display: grid;
    gap: 0.5rem;
    margin-top: auto;
}

.calendar-day-actions .btn {
    width: 100%;
    justify-content: center;
}

.toolbar-actions {
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
}

.toolbar-actions .btn {
    min-width: 7.5rem;
}

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

    .current-leave-stats,
    .info-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .current-leave-stats > :nth-child(-n + 2) {
        grid-column: 1 / -1;
    }

    .toolbar-col-2,
    .toolbar-col-3,
    .toolbar-col-4,
    .toolbar-col-6,
    .toolbar-col-8 {
        grid-column: span 6;
    }

    .toolbar-actions {
        justify-content: flex-start;
    }

    .student-filter-grid {
        gap: 0.85rem;
    }

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

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

@media (max-width: 860px) {
    .topbar {
        padding: 1rem;
        border-radius: 28px;
    }

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

    .page-header,
    .page-heading,
    .page-subtitle {
        min-height: 0;
    }

    .topbar-nav,
    .filter-pill-list {
        justify-content: flex-start;
    }

    .stats-grid,
    .dashboard-grid,
    .form-grid,
    .info-grid {
        grid-template-columns: 1fr;
    }

    .policy-grid {
        grid-template-columns: 1fr;
    }

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

    .current-leave-stats > :nth-child(-n + 2) {
        grid-column: span 1;
    }

    .toolbar-col-2,
    .toolbar-col-3,
    .toolbar-col-4,
    .toolbar-col-6,
    .toolbar-col-8 {
        grid-column: 1 / -1;
    }

    .student-filter-grid .segmented-nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.45rem;
        padding: 0.4rem;
    }

    .student-filter-grid .segmented-nav a {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 2.6rem;
        text-align: center;
        padding-inline: 0.75rem;
    }

    .calendar-weekdays {
        display: none;
    }

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

@media (max-width: 640px) {
    .app-main {
        padding-top: 1.4rem;
    }

    .surface-card {
        padding: 1rem;
        border-radius: 20px;
    }

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

    .student-filter-grid .filter-block {
        padding: 0.75rem;
    }

    .student-filter-grid .segmented-nav {
        gap: 0.4rem;
        padding: 0.35rem;
    }

    .page-title {
        font-size: 2rem;
    }

    .weekday-template-grid {
        grid-template-columns: 1fr;
    }

    thead th,
    tbody td {
        padding: 0.82rem 0.72rem;
    }

    .btn.btn-sm {
        padding: 0.4rem 0.7rem;
    }

    .table-shell {
        overflow: visible;
        border: 0;
        background: transparent;
    }

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

    .responsive-table thead {
        display: none;
    }

    .responsive-table tbody {
        display: grid;
        gap: 0.9rem;
    }

    .responsive-table tr {
        overflow: hidden;
        border: 1px solid var(--line-table);
        border-radius: 18px;
        background: var(--surface);
        box-shadow: var(--shadow-soft);
    }

    .responsive-table tbody tr:nth-child(even) td,
    .responsive-table tbody tr:nth-child(odd) td {
        background: transparent;
    }

    .responsive-table td {
        position: relative;
        min-height: 3.4rem;
        padding: 0.9rem 0.9rem 0.9rem 8rem;
        border-bottom: 1px solid var(--line-table-soft);
        text-align: right;
    }

    .responsive-table td:last-child {
        border-bottom: 0;
    }

    .responsive-table td::before {
        content: attr(data-label);
        position: absolute;
        top: 0.92rem;
        left: 0.9rem;
        color: var(--text-soft);
        font-size: 0.78rem;
        font-weight: 700;
        letter-spacing: 0.03em;
        text-transform: uppercase;
    }

    .actions-cell {
        min-width: 0;
    }

    .responsive-table .actions-cell {
        padding-left: 0.9rem;
        text-align: left;
    }

    .responsive-table .actions-cell::before {
        position: static;
        display: block;
        margin-bottom: 0.6rem;
    }

    .responsive-table .history-name-cell {
        padding-block: 0.9rem;
    }

    .responsive-table .history-name-toggle {
        align-items: flex-start;
        flex-direction: column;
        gap: 0.35rem;
    }

    .responsive-table .history-detail-row {
        border: 0;
        border-radius: 0;
        box-shadow: none;
        background: transparent;
        overflow: visible;
    }

    .responsive-table .history-detail-cell {
        padding: 0 !important;
        border: 0;
        text-align: left;
    }

    .responsive-table .history-detail-cell::before {
        display: none;
        content: none;
    }

    .responsive-table .history-detail-panel {
        padding: 0 0 0.9rem;
    }

    .responsive-table .history-detail-item {
        border-radius: 14px;
    }

    .responsive-table .reason-cell {
        max-width: none;
        padding-left: 0.9rem;
        text-align: left;
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        overflow-wrap: anywhere;
    }

    .responsive-table .reason-cell::before {
        position: static;
        display: block;
        margin-bottom: 0.6rem;
    }

    .responsive-table .action-group {
        gap: 0.5rem;
    }

    .responsive-table .action-group .btn,
    .responsive-table .inline-form .btn {
        flex: 1 1 auto;
    }

    .toolbar-actions .btn {
        width: 100%;
    }

    .calendar-grid {
        grid-template-columns: 1fr;
    }
}
