/* Shared responsive safeguards for the CRM and student cabinet. */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    overflow-x: hidden;
}

body {
    min-width: 320px;
}

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

button,
a,
input,
select,
textarea {
    -webkit-tap-highlight-color: transparent;
}

input,
select,
textarea {
    min-width: 0;
    max-width: 100%;
}

button,
[role="button"] {
    touch-action: manipulation;
}

:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.28);
    outline-offset: 2px;
}

.app-shell {
    height: 100vh;
    height: 100dvh;
}

.app-main,
.app-scroll,
.app-content,
.app-content > *,
.student-content,
.student-content > * {
    min-width: 0;
}

.app-scroll {
    overscroll-behavior-y: contain;
    scrollbar-gutter: stable;
}

.app-content,
.student-content {
    overflow-wrap: anywhere;
}

.app-content .overflow-x-auto {
    max-width: 100%;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
}

.app-content .overflow-x-auto > table {
    min-width: 720px;
}

.app-content table th,
.app-content table td {
    vertical-align: middle;
}

.app-content textarea {
    resize: vertical;
}

/* Dashboard stat cards keep their content readable at every container width. */
.dashboard-stat-card > .flex:first-of-type {
    gap: 0.75rem;
}

.dashboard-stat-card > .flex:first-of-type > div:first-child {
    min-width: 0;
}

.dashboard-stat-card > .flex:first-of-type > div:last-child {
    flex-shrink: 0;
}

.dashboard-stat-card > .mt-4.flex {
    column-gap: 0.5rem;
    flex-wrap: wrap;
    row-gap: 0.35rem;
}

.dashboard-stat-card p,
.dashboard-stat-card span {
    overflow-wrap: anywhere;
}

.sidebar-scroll {
    overscroll-behavior: contain;
}

.sidebar-link {
    gap: 0.75rem;
}

.sidebar-icon {
    flex: 0 0 1.5rem;
    line-height: 1;
    margin: 0 !important;
    overflow: hidden;
    text-align: center;
    width: 1.5rem;
}

.sidebar-label {
    min-width: 0;
}

@media (max-width: 1279px) {
    .app-sidebar {
        width: min(18rem, calc(100vw - 2rem));
    }
}

@media (max-width: 767px) {
    .app-content {
        padding: 1rem !important;
    }

    .app-header {
        min-height: 4rem;
        height: auto !important;
        padding-top: calc(0.65rem + env(safe-area-inset-top));
        padding-bottom: 0.65rem;
    }

    .app-content .p-8 {
        padding: 1.25rem !important;
    }

    .app-content .px-8 {
        padding-left: 1.25rem !important;
        padding-right: 1.25rem !important;
    }

    .app-content .p-6 {
        padding: 1.1rem !important;
    }

    .app-content .px-6 {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    .app-content .py-6 {
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }

    .app-content .mt-12 {
        margin-top: 1.5rem !important;
    }

    .app-content .text-4xl {
        font-size: 1.875rem !important;
        line-height: 2.25rem !important;
    }

    .app-content .text-3xl {
        font-size: 1.5rem !important;
        line-height: 2rem !important;
    }

    .app-content .rounded-3xl {
        border-radius: 1rem !important;
    }

    .app-content .flex.justify-between {
        flex-wrap: wrap;
        row-gap: 0.75rem;
    }

    .app-content .flex.space-x-4,
    .app-content .flex.space-x-3,
    .app-content .flex.space-x-2 {
        column-gap: 0.75rem;
        row-gap: 0.75rem;
    }

    .app-content .flex.space-x-4 > *,
    .app-content .flex.space-x-3 > *,
    .app-content .flex.space-x-2 > * {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .app-content button,
    .app-content a[class*="px-"] {
        min-height: 42px;
    }

    .app-content .overflow-x-auto {
        background-image: linear-gradient(to right, white, white),
            linear-gradient(to right, white, white),
            linear-gradient(to right, rgba(15, 23, 42, 0.12), transparent),
            linear-gradient(to left, rgba(15, 23, 42, 0.12), transparent);
        background-position: left center, right center, left center, right center;
        background-repeat: no-repeat;
        background-size: 20px 100%, 20px 100%, 10px 100%, 10px 100%;
        background-attachment: local, local, scroll, scroll;
    }
}

@media (max-width: 639px) {
    input,
    select,
    textarea {
        font-size: 16px !important;
    }

    .app-content .grid.grid-cols-2,
    .app-content .grid.grid-cols-3,
    .app-content .grid.grid-cols-4,
    .app-content .grid.grid-cols-5 {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .app-content .col-span-2,
    .app-content .col-span-3,
    .app-content .col-span-4,
    .app-content .col-span-5 {
        grid-column: auto !important;
    }

    .mobile-action-row {
        align-items: stretch !important;
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) !important;
        width: 100%;
    }

    .mobile-action-row > * {
        justify-content: center;
        margin: 0 !important;
        text-align: center;
        width: 100%;
    }

    .student-header-inner {
        align-items: stretch !important;
        flex-direction: column;
    }

    .student-nav {
        display: grid !important;
        gap: 0.5rem !important;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        width: 100%;
    }

    .student-nav a {
        align-items: center;
        display: inline-flex;
        justify-content: center;
        min-height: 42px;
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
        text-align: center;
    }

    .student-main {
        padding-bottom: calc(1.25rem + env(safe-area-inset-bottom)) !important;
        padding-top: 1.25rem !important;
    }

    .student-content .text-3xl {
        font-size: 1.5rem !important;
        line-height: 2rem !important;
    }

    .student-content .p-6,
    .student-content .p-8 {
        padding: 1.25rem !important;
    }

    .student-content .rounded-\[2rem\] {
        border-radius: 1.25rem !important;
    }

    .auth-card {
        padding: 1.5rem !important;
        border-radius: 1.25rem !important;
    }
}

@media (max-width: 479px) {
    .app-content form.flex.flex-wrap > * {
        width: 100%;
    }

    .app-content form.flex.flex-wrap button,
    .app-content form.flex.flex-wrap a {
        justify-content: center;
    }

    .student-content .grid.grid-cols-3 {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .student-profile {
        align-items: flex-start !important;
        flex-direction: column;
    }

    .student-content .tracking-\[0\.25em\],
    .student-content .tracking-\[0\.2em\] {
        letter-spacing: 0.12em !important;
    }
}

@media (hover: none) {
    .app-content tr .opacity-0 {
        opacity: 1 !important;
    }

    .app-content .group-card-actions,
    .app-content .photo-upload-action {
        opacity: 1 !important;
    }

    .app-content .photo-upload-action {
        background: #2563eb !important;
        bottom: -0.25rem !important;
        height: 2.25rem !important;
        inset: auto -0.25rem -0.25rem auto !important;
        width: 2.25rem !important;
    }

    .app-content .photo-upload-action .material-icons {
        font-size: 1.125rem !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
