*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    background:
        radial-gradient(circle at top left, rgba(79, 70, 229, 0.12), transparent 30%),
        linear-gradient(180deg, #f6f9ff 0%, #eef4ff 100%);
    color: #152238;
    min-height: 100vh;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

body::-webkit-scrollbar {
    display: none;
}

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

.app-main {
    max-height: calc(100vh - 9.5rem);
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.app-main::-webkit-scrollbar {
    display: none;
}

.app-header {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(16px);
}

.app-title {
    font-size: 1.35rem;
    font-weight: 700;
}

.app-version {
    color: #64748b;
    font-size: 0.72rem;
    font-weight: 600;
    margin-left: 0.35rem;
    vertical-align: middle;
}

.app-subtitle,
.info-line {
    font-size: 0.9rem;
}

.eyebrow {
    color: #4f46e5;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.hero-card,
.panel-card {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 1.5rem;
    box-shadow: 0 20px 45px rgba(15, 23, 42, 0.08);
}

.board-form-title {
    font-size: 1.1rem;
    font-weight: 700;
}

.board-form {
    scroll-margin-top: 1rem;
}

.board-hint-line {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: space-between;
}

.board-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
}

.board-legend-item {
    border: 1px solid #dbe5f4;
    border-radius: 999px;
    color: #334155;
    padding: 0.18rem 0.65rem;
}

.class-row {
    display: grid;
    gap: 0.75rem;
    padding-bottom: 0.5rem;
    align-items: stretch;
    width: 100%;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.class-card {
    display: block;
    min-width: 0;
    width: 100%;
}

.class-card.is-collapsed {
    width: 2.5rem;
}

.class-card-body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 0.75rem;
    background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
    border: 1px solid #d8e3f5;
    border-radius: 1.15rem;
    padding: 0.9rem;
    box-shadow: 0 10px 30px rgba(79, 70, 229, 0.08);
}

.class-card-header {
    align-items: center;
    display: flex;
    gap: 0.75rem;
    justify-content: space-between;
}

.class-card-actions {
    display: flex;
    gap: 0.5rem;
}

.class-card-title {
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-radius: 999px;
    color: #312e81;
    font-weight: 700;
    padding: 0.5rem 0.9rem;
}

.class-card-title.highlight-target {
    background: #fef3c7;
    border-color: #f59e0b;
    color: #92400e;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18);
    position: relative;
    z-index: 3;
}

.student-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 220px;
    max-height: 25rem;
    overflow-y: auto;
    padding-right: 0.15rem;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.student-list::-webkit-scrollbar {
    display: none;
}

.student-pill {
    background: #ffffff;
    border: 1px solid #dbe5f4;
    border-radius: 0.95rem;
    flex: 0 0 auto;
    font-size: 0.92rem;
    line-height: 1.35;
    padding: 0.6rem 0.75rem;
    text-align: left;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
    white-space: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.student-pill::-webkit-scrollbar {
    display: none;
}

.student-pill:hover:not(.readonly):not(:disabled) {
    border-color: #6366f1;
    box-shadow: 0 12px 24px rgba(99, 102, 241, 0.12);
    transform: translateY(-1px);
}

.student-kind {
    color: #1e293b;
}

.student-kind-linked {
    background: #e0f2fe;
    border-color: #bae6fd;
}

.student-kind-separated {
    background: #fef3c7;
    border-color: #fde68a;
}

.student-kind-fixed {
    background: #dcfce7;
    border-color: #bbf7d0;
}

.student-kind-broken {
    background: #fca5a5;
    border-color: #ef4444;
}

.student-pill.selected {
    background: #e0f2fe;
    border-color: #0284c7;
    color: #075985;
}

.student-pill.readonly {
    opacity: 1;
}

.stats-box {
    background: #475569;
    color: #ffffff;
    display: grid;
    font-size: 0.8rem;
    gap: 0.25rem;
    margin: 0 -0.9rem -0.9rem;
    padding: 0.55rem 0.9rem;
}

.class-card-collapsed {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 0.9rem;
    color: #334155;
    min-height: 100%;
    padding: 0.75rem 0.4rem;
    writing-mode: vertical-rl;
}

.selection-mode-active .board-form-title,
.selection-mode-active .stats-box,
.selection-mode-active .hide-class-button,
.selection-mode-active .view-all-button {
    opacity: 0.18;
}

.selection-mode-active .student-pill:not(.selected),
.selection-mode-active .class-card-title,
.selection-mode-active .class-card-collapsed {
    opacity: 1;
}

.selection-mode-active .student-pill:not(.selected) {
    opacity: 0.18;
}

.selection-mode-active .student-pill.selected {
    opacity: 1;
}

.data-modal-dialog {
    max-width: 90vw;
}

.class-view-all-dialog {
    max-width: 96vw;
}

.data-modal-content {
    min-height: 90vh;
}

.class-view-all {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.class-view-all-title {
    color: #312e81;
    font-size: 1.1rem;
    font-weight: 700;
}

.class-view-all-grid {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
}

.class-view-all-item {
    background: #f8fbff;
    border: 1px solid #dbe5f4;
    border-radius: 0.95rem;
    font-size: 0.92rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
    padding: 0.65rem 0.8rem;
    white-space: normal;
}

.student-label {
    border: 1px solid #dbe5f4;
    border-radius: 0.8rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
    padding: 0.55rem 0.7rem;
    white-space: normal;
}

.student-label.student-kind-linked,
.class-view-all-item.student-kind-linked {
    background: #e0f2fe;
    border-color: #bae6fd;
}

.student-label.student-kind-separated,
.class-view-all-item.student-kind-separated {
    background: #fef3c7;
    border-color: #fde68a;
}

.student-label.student-kind-fixed,
.class-view-all-item.student-kind-fixed {
    background: #dcfce7;
    border-color: #bbf7d0;
}

.student-label.student-kind-broken,
.class-view-all-item.student-kind-broken {
    background: #fca5a5;
    border-color: #ef4444;
}

.data-table {
    width: 100%;
}

.data-table td,
.data-table th {
    padding: 0.75rem;
    vertical-align: top;
}

.data-table th:nth-child(2),
.data-table td:nth-child(2) {
    text-align: center;
    white-space: nowrap;
}

.empty-state {
    background: #ffffff;
    border: 1px dashed #cbd5e1;
    border-radius: 1.25rem;
    padding: 2rem;
    text-align: center;
}

.import-status-grid {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    margin-top: 1rem;
}

.import-status-item {
    background: #f8fafc;
    border: 1px solid #dbe5f4;
    border-radius: 0.85rem;
    padding: 0.8rem;
}

.import-status-label {
    color: #64748b;
    display: block;
    font-size: 0.82rem;
}

.import-status-value {
    color: #1e293b;
    display: block;
    font-size: 1.2rem;
    font-weight: 700;
    margin-top: 0.15rem;
}

@media (min-width: 1800px) and (min-height: 1000px) {
    .app-title {
        font-size: 1.1rem;
    }

    .app-main {
        padding-top: 0.45rem;
        padding-bottom: 0.45rem;
    }

    .board-panel {
        padding: 0.45rem 0.65rem;
    }

    #boardHints .text-muted {
        font-size: 0.66rem;
        margin-bottom: 0.15rem;
    }

    #boardHints .mb-3 {
        margin-bottom: 0.3rem;
    }

    .board-form {
        margin-bottom: 0.45rem;
    }

    .board-form-title {
        font-size: 0.82rem;
    }

    .board-legend-item {
        font-size: 0.62rem;
        padding: 0.08rem 0.35rem;
    }

    .class-row {
        gap: 0.35rem;
    }

    .class-card-body {
        gap: 0.2rem;
        padding: 0.32rem;
    }

    .class-card-title {
        font-size: 0.68rem;
        padding: 0.18rem 0.4rem;
    }

    .class-card-actions .btn-sm {
        font-size: 0.6rem;
        padding: 0.08rem 0.3rem;
    }

    .student-list {
        gap: 0.1rem;
    }

    .student-pill {
        font-size: 0.56rem;
        line-height: 1.05;
        padding: 0.1rem 0.28rem;
        border-radius: 0.4rem;
    }

    .stats-box {
        font-size: 0.54rem;
        margin: 0 -0.32rem -0.32rem;
        padding: 0.18rem 0.32rem;
    }

    .class-view-all-dialog .modal-title {
        font-size: 0.82rem;
    }

    .class-view-all {
        gap: 0.35rem;
    }

    .class-view-all-title {
        font-size: 0.72rem;
    }

    .class-view-all-grid {
        gap: 0.22rem;
        grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
    }

    .class-view-all-item {
        font-size: 0.56rem;
        line-height: 1.05;
        padding: 0.14rem 0.28rem;
        border-radius: 0.4rem;
    }
}

/* Desktop with mouse: compact board + viewport height (excludes touch tablets) */
@media (min-width: 1280px) and (max-height: 1100px) and (hover: hover) and (pointer: fine) {
    body {
        overflow: hidden;
    }

    .app-shell {
        display: flex;
        flex-direction: column;
        height: 100vh;
        min-height: 100vh;
        overflow: hidden;
    }

    .app-header {
        flex-shrink: 0;
    }

    .app-main {
        display: flex;
        flex: 1;
        flex-direction: column;
        max-height: none;
        min-height: 0;
        overflow: hidden;
        padding-top: 0.35rem;
        padding-bottom: 0.35rem;
    }

    .board-panel {
        display: flex;
        flex: 1;
        flex-direction: column;
        min-height: 0;
        overflow: hidden;
        padding: 0.35rem 0.5rem;
    }

    #boardHints {
        flex-shrink: 0;
    }

    #boardContainer {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    #boardContainer::-webkit-scrollbar {
        display: none;
    }

    .board-form {
        display: flex;
        flex-direction: column;
        min-height: 0;
        margin-bottom: 0.35rem;
    }

    .class-row {
        align-items: stretch;
        gap: 0.28rem;
        height: calc(100vh - var(--board-chrome-height, 14rem));
        min-height: 0;
    }

    .class-card {
        height: 100%;
        min-height: 0;
    }

    .class-card-body {
        display: flex;
        flex-direction: column;
        gap: 0.15rem;
        height: 100%;
        min-height: 0;
        padding: 0.25rem;
        border-radius: 0.65rem;
    }

    .student-list {
        flex: 1;
        gap: 0.06rem;
        max-height: none;
        min-height: 0;
        overflow-y: auto;
    }

    .app-title {
        font-size: 0.95rem;
    }

    .app-subtitle {
        display: none;
    }

    .info-line {
        font-size: 0.72rem;
    }

    #boardHints .board-hint-line p {
        margin-bottom: 0.1rem;
    }

    #boardHints .text-muted {
        font-size: 0.6rem;
        line-height: 1.15;
        margin-bottom: 0.1rem;
    }

    #boardHints .mb-3 {
        margin-bottom: 0.2rem;
    }

    .board-form-title {
        font-size: 0.74rem;
    }

    .board-legend-item {
        font-size: 0.56rem;
        padding: 0.06rem 0.28rem;
    }

    .class-card-title {
        font-size: 0.6rem;
        padding: 0.14rem 0.32rem;
    }

    .class-card-actions .btn-sm {
        font-size: 0.54rem;
        padding: 0.06rem 0.22rem;
    }

    .student-pill {
        font-size: 0.5rem;
        line-height: 1;
        padding: 0.06rem 0.2rem;
        border-radius: 0.32rem;
    }

    .stats-box {
        flex-shrink: 0;
        font-size: 0.48rem;
        margin-top: auto;
        margin-right: -0.25rem;
        margin-bottom: -0.25rem;
        margin-left: -0.25rem;
        padding: 0.14rem 0.25rem;
    }

    .class-view-all-dialog .data-modal-content {
        min-height: auto;
    }

    .class-view-all-dialog .modal-title {
        font-size: 0.74rem;
    }

    .class-view-all {
        gap: 0.25rem;
    }

    .class-view-all-title {
        font-size: 0.64rem;
    }

    .class-view-all-grid {
        gap: 0.15rem;
        grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr));
    }

    .class-view-all-item {
        font-size: 0.5rem;
        line-height: 1;
        padding: 0.08rem 0.18rem;
        border-radius: 0.32rem;
    }
}

@media (max-width: 991px) {
    .app-main {
        max-height: calc(100vh - 8.5rem);
    }

    .board-hint-line {
        align-items: flex-start;
        flex-direction: column;
    }

    .board-legend {
        justify-content: flex-start;
    }

    .class-card {
        min-width: 0;
    }

    .app-subtitle {
        display: none;
    }
}
