:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-strong: #eef4ff;
    --text: #162033;
    --muted: #68758b;
    --line: #dce4f0;
    --grid-line: #9aa8bd;
    --accent: #1769e0;
    --accent-dark: #0e54bb;
    --danger: #c93333;
    --success: #167948;
    --warning: #946200;
    --shadow: 0 18px 48px rgba(30, 49, 83, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(135deg, rgba(23, 105, 224, 0.08), transparent 34%),
        var(--bg);
    color: var(--text);
    font-family: "Segoe UI", Arial, sans-serif;
    letter-spacing: 0;
}

button,
input,
select {
    font: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

.login-body {
    display: grid;
    place-items: center;
}

.login-shell {
    width: min(100%, 1120px);
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px;
}

.login-panel {
    width: min(100%, 440px);
    padding: 36px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow);
}

.brand-mark {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    margin-bottom: 22px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 800;
    font-size: 26px;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--accent);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0;
}

h1 {
    font-size: 34px;
    line-height: 1.12;
}

h2 {
    font-size: 19px;
}

.auth-form,
.stack-form {
    display: grid;
    gap: 16px;
    margin-top: 28px;
}

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
}

input,
select {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
}

input:focus,
select:focus {
    outline: 3px solid rgba(23, 105, 224, 0.16);
    border-color: var(--accent);
}

.primary-button,
.ghost-button,
.icon-button {
    border: 0;
    cursor: pointer;
}

.primary-button {
    min-height: 44px;
    display: inline-grid;
    place-items: center;
    padding: 0 18px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
}

.primary-button:hover {
    background: var(--accent-dark);
}

.compact-button {
    width: 100%;
    min-height: 40px;
}

.ghost-button {
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font-weight: 700;
}

.icon-button {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--surface-strong);
    color: var(--text);
    font-size: 18px;
    font-weight: 800;
}

.icon-button:hover {
    filter: brightness(0.96);
}

.danger {
    color: var(--danger);
}

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

.breadcrumbs {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    color: var(--muted);
    font-weight: 700;
}

.breadcrumbs a {
    color: var(--accent);
}

.page-shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 36px 0 56px;
}

.wide-page {
    width: min(1500px, calc(100% - 28px));
}

.page-heading {
    margin-bottom: 30px;
}

.page-heading.compact {
    margin-bottom: 22px;
}

.action-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 18px;
}

.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 18px;
}

.folder-tile {
    position: relative;
    min-height: 230px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 12px 34px rgba(31, 55, 89, 0.08);
    transition: transform 160ms ease, box-shadow 160ms ease;
}

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

.folder-link {
    min-height: 230px;
    display: grid;
    grid-template-rows: 122px auto auto;
    align-content: start;
    gap: 8px;
    padding: 72px 24px 22px;
}

.folder-link strong {
    min-width: 0;
    font-size: 24px;
    line-height: 1.14;
    overflow-wrap: anywhere;
}

.folder-link small,
.competency-row small {
    color: var(--muted);
}

.folder-icon {
    position: absolute;
    top: 26px;
    left: 24px;
    width: 96px;
    height: 68px;
    border-radius: 8px;
    background: #f1b84d;
}

.sortable-folder .folder-icon {
    position: relative;
    top: auto;
    left: auto;
    grid-row: 1;
}

.sortable-folder .folder-link small {
    grid-row: 3;
    margin-top: 0;
}

.sortable-folder .folder-link strong {
    grid-row: 2;
}

.folder-icon::before {
    content: "";
    position: absolute;
    top: -12px;
    left: 0;
    width: 42px;
    height: 18px;
    border-radius: 8px 8px 0 0;
    background: #d99721;
}

.folder-tile-bar {
    position: absolute;
    top: 14px;
    left: 14px;
    right: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    z-index: 2;
}

.drag-instruction {
    display: none;
    flex: 1;
    min-height: 32px;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    border: 1px dashed rgba(23, 105, 224, 0.32);
    border-radius: 8px;
    background: #eef5ff;
    color: var(--accent);
    cursor: grab;
    user-select: none;
    touch-action: none;
    font-size: 13px;
    font-weight: 800;
    text-align: center;
}

.move-mode .drag-instruction {
    display: flex;
}

.sortable-folder.is-dragging {
    opacity: 0.58;
    transform: scale(0.98);
    box-shadow: 0 8px 26px rgba(31, 55, 89, 0.12);
}

.edit-folder-button {
    color: var(--accent);
}

.folder-edit-menu {
    position: absolute;
    top: -48px;
    left: 14px;
    z-index: 5;
    display: flex;
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 14px 34px rgba(31, 55, 89, 0.14);
}

.folder-edit-menu[hidden] {
    display: none;
}

.menu-button {
    min-height: 34px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    font-weight: 700;
}

.menu-button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.tile-grid.move-mode .sortable-folder {
    cursor: grab;
}

.tile-grid.is-pointer-dragging {
    user-select: none;
}

.folder-wiggle {
    animation: folder-wiggle 520ms ease-in-out infinite alternate;
}

.sortable-folder.drop-before::before,
.sortable-folder.drop-after::after {
    content: "";
    position: absolute;
    top: 12px;
    bottom: 12px;
    z-index: 6;
    width: 8px;
    border-radius: 999px;
    background: rgba(23, 105, 224, 0.5);
    box-shadow: 0 0 0 7px rgba(23, 105, 224, 0.12);
}

.sortable-folder.drop-before::before {
    left: -13px;
}

.sortable-folder.drop-after::after {
    right: -13px;
}

@keyframes folder-wiggle {
    from {
        transform: rotate(-0.45deg) translateY(-1px);
    }
    to {
        transform: rotate(0.45deg) translateY(1px);
    }
}

.add-folder-tile {
    min-height: 230px;
    border-style: dashed;
    background: #fbfdff;
}

.add-folder-tile form {
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 14px;
    height: 100%;
    padding: 20px;
}

.add-folder-head {
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    height: 72px;
}

.small-folder {
    position: relative;
    top: auto;
    left: 0;
    width: 88px;
    height: 56px;
    opacity: 0.9;
    background: #f6c462;
    box-shadow: inset 0 -10px 0 rgba(217, 151, 33, 0.16);
}

.small-folder::before {
    width: 46px;
    background: #dda33a;
}

.add-folder-tile input {
    min-height: 38px;
}

.workspace-layout {
    display: grid;
    grid-template-columns: minmax(260px, 320px) 1fr;
    gap: 22px;
    align-items: start;
}

.side-panel,
.list-panel,
.excel-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 12px 34px rgba(31, 55, 89, 0.08);
}

.side-panel {
    padding: 22px;
}

.list-panel {
    overflow: hidden;
}

.competency-list {
    display: grid;
}

.competency-row,
.student-row,
.table-header {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 16px;
    align-items: center;
    padding: 16px 18px;
    border-bottom: 1px solid var(--line);
}

.competency-row:last-child,
.student-row:last-child {
    border-bottom: 0;
}

.competency-row > a {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.competency-row strong,
.student-row strong {
    overflow-wrap: anywhere;
}

.row-actions {
    display: flex;
    gap: 8px;
}

.empty-state {
    padding: 44px 28px;
    color: var(--muted);
    text-align: center;
}

.empty-state h2 {
    margin-bottom: 8px;
    color: var(--text);
}

.report-head {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 22px;
}

.report-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.download-button {
    min-width: 140px;
}

.save-state {
    min-width: 132px;
    color: var(--success);
    font-size: 14px;
    font-weight: 700;
    text-align: right;
}

.save-state[data-mode="dirty"],
.save-state[data-mode="saving"] {
    color: var(--warning);
}

.save-state[data-mode="error"] {
    color: var(--danger);
}

.excel-panel {
    overflow: hidden;
}

.excel-scroll {
    overflow: auto;
    max-height: calc(100vh - 190px);
}

.excel-table {
    width: 100%;
    min-width: 2240px;
    border-collapse: collapse;
    table-layout: fixed;
    background: #fff;
}

.excel-table th,
.excel-table td {
    border: 1px solid var(--grid-line);
    padding: 0;
    text-align: center;
    vertical-align: middle;
}

.excel-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    height: 58px;
    padding: 6px 5px;
    background: #f8fbff;
    color: #071321;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.1;
}

.excel-table td.track-row,
.excel-table td.track-column {
    background: rgba(23, 105, 224, 0.08);
}

.excel-table th.track-column {
    background: #dceaff;
    box-shadow: inset 0 -2px 0 var(--accent);
}

.excel-table td.axis-active {
    background: rgba(23, 105, 224, 0.16);
    box-shadow: inset 0 0 0 2px rgba(23, 105, 224, 0.42);
}

.excel-table th.axis-active {
    background: #cfe2ff;
}

.excel-table th:first-child,
.excel-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 3;
    background: #fff;
}

.excel-table th:first-child {
    z-index: 4;
    background: #f8fbff;
}

.excel-table td:first-child.track-row,
.excel-table td:first-child.axis-active {
    background: #dceaff;
}

.excel-table input {
    min-height: 28px;
    height: 28px;
    padding: 2px 5px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #000;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 14px;
    text-align: center;
}

.excel-table input:focus {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.excel-table input[readonly] {
    font-weight: 500;
}

.excel-table .total-row input {
    font-weight: 700;
}

.excel-table .manual-total {
    background: #fff6d9;
}

.messages {
    display: grid;
    gap: 10px;
    margin: 18px 0;
}

.message {
    padding: 12px 14px;
    border-radius: 8px;
    background: #eef4ff;
    color: var(--accent-dark);
    font-weight: 700;
}

.message.error {
    background: #fff0f0;
    color: var(--danger);
}

.message.success {
    background: #edf9f2;
    color: var(--success);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(16, 31, 54, 0.34);
    backdrop-filter: blur(8px);
}

.modal-backdrop[hidden] {
    display: none;
}

.modal-panel {
    position: relative;
    width: min(420px, 100%);
    display: grid;
    gap: 18px;
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
}

.modal-panel h2 {
    margin-bottom: 2px;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 8px;
    background: var(--surface-strong);
    color: var(--danger);
    cursor: pointer;
    font-size: 22px;
    font-weight: 800;
}

@media (max-width: 760px) {
    .topbar {
        align-items: flex-start;
        padding: 14px 16px;
    }

    .page-shell,
    .wide-page {
        width: min(100% - 24px, 1180px);
        padding-top: 24px;
    }

    h1 {
        font-size: 28px;
    }

    .workspace-layout {
        grid-template-columns: 1fr;
    }

    .report-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .action-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .report-actions {
        width: 100%;
        justify-content: space-between;
    }
}
