:root {
    --app-bg: #f4f6f8;
    --app-surface: #ffffff;
    --app-surface-alt: #f8fafc;
    --app-border: #d9e1ea;
    --app-text: #5a5162;
    --app-muted: #66788a;
    --app-primary: #b5121b;
    --app-primary-dark: #8d0f17;
    --app-sidebar: #111827;
    --app-sidebar-muted: #9ca3af;
    --app-focus: rgba(181, 18, 27, 0.16);
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--app-text);
    background: var(--app-bg);
    font-family: Arial, Helvetica, sans-serif;
}

a {
    color: var(--app-primary);
}

a:hover {
    color: var(--app-primary-dark);
}

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

.sidenav {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1000;
    width: 248px;
    overflow-y: auto;
    background: var(--app-sidebar);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.sidenav-brand {
    display: flex;
    align-items: center;
    height: 80px;
    padding: 0 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidenav .logo {
    width: 176px;
    height: auto;
    padding: 0;
}

.sidenav ul {
    padding: 18px 10px;
    margin: 0;
    list-style: none;
}

.sidenav a,
.sidenav button {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    color: #e5e7eb;
    border: 0;
    border-radius: 8px;
    background: transparent;
    font-size: 0.95rem;
    line-height: 1.2;
    text-align: left;
    text-decoration: none;
}

.sidenav a:hover,
.sidenav button:hover,
.sidenav a.active {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

.sidenav .nav-icon {
    width: 22px;
    margin-right: 10px;
    color: var(--app-sidebar-muted);
    font-size: 1rem;
}

.sidenav a.nav-subitem {
    min-height: 40px;
    padding-left: 24px;
}

.sidenav a.nav-subitem .nav-icon {
    width: 18px;
    margin-right: 9px;
    font-size: 0.92rem;
}

.nav-section {
    padding: 18px 14px 6px;
    color: var(--app-sidebar-muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.app-main {
    min-height: 100vh;
    margin-left: 248px;
    width: calc(100% - 248px);
    min-width: 0;
}

.content {
    width: 100%;
    max-width: none;
    min-width: 0;
    padding: 32px;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}

.page-title {
    margin: 0;
    color: var(--app-text);
    font-size: 1.85rem;
    font-weight: 700;
    letter-spacing: 0;
}

.page-subtitle {
    margin: 6px 0 0;
    color: var(--app-muted);
    font-size: 0.98rem;
}

.panel {
    margin-bottom: 24px;
    overflow: hidden;
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: 8px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 58px;
    padding: 16px 18px;
    background: var(--app-surface-alt);
    border-bottom: 1px solid var(--app-border);
}

.panel-title {
    margin: 0;
    color: var(--app-text);
    font-size: 1.05rem;
    font-weight: 700;
}

.panel-body {
    padding: 20px;
}

.table {
    margin-bottom: 0;
    color: var(--app-text);
}

.table thead th {
    color: var(--app-text);
    background: #eef3f7;
    border-bottom: 1px solid var(--app-border);
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.table td,
.table th {
    vertical-align: middle;
    border-top: 1px solid var(--app-border);
}

.table tbody tr:hover {
    background: #f8fafc;
}

.table-sort {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0;
    color: inherit;
    border: 0;
    background: transparent;
    font: inherit;
    text-transform: inherit;
}

.table-sort:hover,
.table-sort:focus {
    color: var(--app-primary);
    outline: 0;
}

.table-sort i {
    color: var(--app-muted);
    font-size: 0.82rem;
}

.table-sort.is-sorted-asc i::before {
    content: "\f148";
}

.table-sort.is-sorted-desc i::before {
    content: "\f128";
}

.table-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    white-space: nowrap;
}

.btn {
    border-radius: 7px;
    font-weight: 600;
}

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

.btn-primary:hover,
.btn-primary:focus {
    border-color: var(--app-primary-dark);
    background: var(--app-primary-dark);
}

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

.btn-outline-primary:hover {
    color: #ffffff;
    border-color: var(--app-primary);
    background: var(--app-primary);
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
}

.status-active {
    color: #0f5132;
    background: #d1e7dd;
}

.status-available {
    color: #0f5132;
    background: #d1e7dd;
}

.status-borrowed {
    color: #084298;
    background: #cfe2ff;
}

.status-inactive {
    color: #664d03;
    background: #fff3cd;
}

.status-today {
    color: #6b4e00;
    background: #ffed99;
}

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

.form-control {
    border-color: #cad5df;
    border-radius: 7px;
}

.form-control:focus {
    border-color: var(--app-primary);
    box-shadow: 0 0 0 0.2rem var(--app-focus);
}

.modal-content {
    border: 0;
    border-radius: 8px;
    box-shadow: 0 22px 60px rgba(15, 23, 42, 0.28);
}

.modal-header {
    background: var(--app-surface-alt);
    border-bottom-color: var(--app-border);
}

.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1080;
}

.app-toast {
    display: block;
    min-width: 280px;
}

.login-page {
    min-height: 100vh;
    margin-left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-panel {
    width: 100%;
    max-width: 420px;
    padding: 28px;
}

.profile-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.filter-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.scrum-layout {
    display: flex;
    width: 100%;
    align-items: start;
    gap: 22px;
}

.scrum-main {
    flex: 1 1 auto;
    min-width: 0;
}

.scrum-sidebar {
    flex: 0 0 360px;
    position: sticky;
    top: 18px;
}

.scrum-discussion-panel {
    max-height: calc(100vh - 36px);
    display: flex;
    flex-direction: column;
}

.scrum-discussion-panel .panel-body {
    min-height: 0;
    overflow-y: auto;
}

.scrum-form-grid {
    display: grid;
    grid-template-columns: 160px 210px minmax(260px, 1fr);
    gap: 14px;
}

.scrum-note-field {
    min-width: 0;
}

.scrum-create-footer {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 18px;
}

.scrum-actions-block {
    min-width: 150px;
}

.teacher-checkbox-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.teacher-checkbox-grid-compact {
    min-width: 180px;
    max-width: 280px;
}

.selected-teachers {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
}

.teacher-dropdown-menu {
    width: 280px;
    max-height: 320px;
    overflow-y: auto;
    padding: 10px;
}

.teacher-dropdown-menu .teacher-choice {
    width: 100%;
    margin-bottom: 8px;
}

.teacher-dropdown-menu .teacher-choice:last-child {
    margin-bottom: 0;
}

.teacher-choice {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 30px;
    padding: 5px 9px;
    margin: 0;
    color: var(--app-text);
    background: #f8fafc;
    border: 1px solid var(--app-border);
    border-radius: 7px;
    font-size: 0.85rem;
    font-weight: 600;
}

.teacher-choice input {
    margin: 0;
}

.scrum-table .form-control-sm {
    min-width: 96px;
}

.scrum-table .scrum-note-input {
    min-width: 260px;
}

.scrum-note-textarea {
    min-height: 56px;
    resize: vertical;
}

.scrum-list {
    display: grid;
    gap: 12px;
    padding: 14px;
}

.scrum-list-item {
    display: grid;
    grid-template-columns: 72px 112px 180px minmax(220px, 1fr) minmax(180px, 260px) 112px auto;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: #ffffff;
    border: 1px solid var(--app-border);
    border-radius: 8px;
}

.scrum-list-item-today {
    background: #fffdf3;
    border-left: 4px solid #f2c94c;
}

.scrum-list-item > form,
.discussion-item > form {
    display: none;
}

.scrum-list-label {
    display: block;
    margin-bottom: 5px;
    color: var(--app-text);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.scrum-list-actions {
    justify-content: flex-end;
}

.discussion-create-form {
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--app-border);
}

.discussion-list {
    display: grid;
    gap: 12px;
}

.discussion-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: #f8fafc;
    border: 1px solid var(--app-border);
    border-radius: 8px;
}

.discussion-item .form-control {
    margin-bottom: 0 !important;
}

.discussion-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.discussion-order {
    max-width: 86px;
    margin-right: auto;
}

.avo-form-grid {
    display: grid;
    grid-template-columns: 160px minmax(240px, 1fr) 130px 130px auto;
    align-items: end;
    gap: 14px;
}

.sd-form-grid {
    display: grid;
    grid-template-columns: 160px minmax(260px, 1fr) 150px auto;
    align-items: end;
    gap: 14px;
}

.avo-submit {
    display: flex;
    align-items: end;
}

.avo-row,
.sd-row {
    display: flex;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
    background: #ffffff;
    border: 1px solid var(--app-border);
    border-radius: 8px;
}

.avo-row + .avo-row,
.sd-row + .sd-row {
    margin-top: 12px;
}

.pause-window-form-grid {
    display: grid;
    grid-template-columns: 180px 150px 150px auto;
    align-items: end;
    gap: 14px;
    max-width: 760px;
}

.pause-window-list {
    display: grid;
    gap: 12px;
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--app-border);
}

.pause-window-row {
    display: flex;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
    background: #ffffff;
    border: 1px solid var(--app-border);
    border-radius: 8px;
}

.pause-window-row-form {
    display: grid;
    grid-template-columns: 180px 140px 140px auto;
    align-items: end;
    gap: 12px;
    flex: 1 1 auto;
    min-width: 0;
}

.avo-row-form {
    display: grid;
    grid-template-columns: 120px 120px minmax(220px, 1fr) minmax(180px, 260px) auto;
    align-items: end;
    gap: 12px;
    flex: 1 1 auto;
    min-width: 0;
}

.sd-row-form {
    display: grid;
    grid-template-columns: 150px 150px minmax(240px, 1fr) auto;
    align-items: end;
    gap: 12px;
    flex: 1 1 auto;
    min-width: 0;
}

.avo-row .form-group,
.avo-form-grid .form-group,
.sd-row .form-group,
.sd-form-grid .form-group,
.pause-window-form-grid .form-group,
.pause-window-row .form-group {
    margin-bottom: 0;
}

.avo-teacher {
    min-width: 0;
}

.avo-teacher strong {
    display: block;
    margin: 4px 0 6px;
}

.avo-delete-form {
    display: flex;
    align-items: end;
}

.schedule-row-actions {
    display: flex;
    align-items: end;
    gap: 6px;
    flex: 0 0 auto;
}

.schedule-row-actions form {
    margin: 0;
}

.schedule-period-block {
    display: grid;
    gap: 10px;
    padding: 14px;
    background: #f8fafc;
    border: 1px solid var(--app-border);
    border-radius: 8px;
}

.schedule-period-block + .schedule-period-block {
    margin-top: 14px;
}

.schedule-period-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.schedule-period-heading h3 {
    margin: 0;
    color: var(--app-text);
    font-size: 1rem;
    font-weight: 800;
}

.avo-order-badge {
    align-self: stretch;
    min-height: 64px;
    padding: 9px 10px;
    background: #f8fafc;
    border: 1px solid var(--app-border);
    border-radius: 7px;
}

.avo-order-badge strong {
    display: block;
    margin-top: 4px;
    color: var(--app-primary);
    font-size: 1.18rem;
    line-height: 1;
}

.avo-overlap-warning {
    display: none;
    grid-column: 1 / -1;
    padding: 10px 12px;
    color: #664d03;
    background: #fff3cd;
    border: 1px solid #ffecb5;
    border-radius: 7px;
    font-weight: 600;
}

.avo-overlap-warning.is-visible {
    display: block;
}

.cycle-summary-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
    gap: 22px;
}

.course-cycle-toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    margin: -4px 0 16px;
}

.course-year-panel .panel-header {
    align-items: center;
}

.current-cycle {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.current-cycle > div {
    min-height: 86px;
    padding: 14px;
    background: #f8fafc;
    border: 1px solid var(--app-border);
    border-radius: 8px;
}

.current-cycle strong {
    display: block;
    margin-top: 8px;
    font-size: 1.08rem;
}

.cycle-label {
    display: block;
    color: var(--app-text);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.cycle-periods {
    display: grid;
    gap: 22px;
}

.cycle-period {
    overflow: hidden;
    border: 1px solid var(--app-border);
    border-radius: 8px;
}

.cycle-period-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
    background: #f8fafc;
    border-bottom: 1px solid var(--app-border);
}

.cycle-period-title h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
}

.cycle-period-title span {
    color: var(--app-muted);
    font-size: 0.9rem;
}

.cycle-current-row {
    background: #fffdf3;
}

.course-week-list {
    display: grid;
    gap: 10px;
    padding: 12px;
}

.course-week-row {
    display: grid;
    grid-template-columns: 86px 120px 160px 160px minmax(220px, 1fr) auto;
    align-items: end;
    gap: 12px;
    padding: 12px;
    margin: 0;
    background: #ffffff;
    border: 1px solid var(--app-border);
    border-radius: 8px;
}

.course-week-row label {
    display: block;
    margin-bottom: 5px;
    color: var(--app-text);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.course-week-row.cycle-current-row {
    background: #fffdf3;
    border-left: 4px solid #f2c94c;
}

@media (max-width: 1500px) {
    .scrum-layout {
        flex-direction: column;
    }

    .scrum-main,
    .scrum-sidebar {
        width: 100%;
        flex-basis: auto;
    }

    .scrum-sidebar {
        position: static;
    }

    .scrum-discussion-panel {
        max-height: none;
    }
}

@media (max-width: 1280px) {
    .content {
        padding: 24px;
    }

    .scrum-list-item {
        grid-template-columns: 72px 112px 180px minmax(260px, 1fr) auto;
    }

    .scrum-list-item > div:nth-of-type(5) {
        grid-column: 1 / span 3;
    }

    .scrum-list-item > div:nth-of-type(6) {
        grid-column: 4;
    }

    .scrum-list-actions {
        grid-column: 5;
        grid-row: 1 / span 2;
    }
}

@media (max-width: 900px) {
    .sidenav {
        position: static;
        width: 100%;
        height: auto;
    }

    .sidenav-brand {
        height: 68px;
    }

    .sidenav ul {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px;
    }

    .sidenav li {
        flex: 1 1 180px;
    }

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

    .content {
        max-width: none;
        padding: 20px;
    }

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

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

    .scrum-form-grid {
        grid-template-columns: 1fr;
    }

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

    .discussion-item {
        grid-template-columns: 1fr;
    }

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

    .scrum-list-item {
        grid-template-columns: 1fr;
    }

    .avo-form-grid,
    .sd-form-grid,
    .avo-row-form,
    .sd-row-form,
    .pause-window-form-grid,
    .pause-window-row-form,
    .course-week-row {
        grid-template-columns: 1fr;
    }

    .avo-row,
    .sd-row,
    .pause-window-row {
        flex-direction: column;
    }

    .schedule-row-actions {
        align-items: stretch;
        justify-content: flex-start;
    }

    .avo-submit,
    .avo-delete-form,
    .avo-row .table-actions,
    .sd-row .table-actions,
    .pause-window-row .table-actions {
        align-items: stretch;
    }

    .avo-submit .btn,
    .avo-delete-form .btn,
    .schedule-row-actions .btn,
    .avo-row .table-actions .btn,
    .sd-row .table-actions .btn,
    .pause-window-row .table-actions .btn {
        width: 100%;
    }

    .cycle-summary-grid,
    .current-cycle {
        grid-template-columns: 1fr;
    }

    .scrum-list-item > div:nth-of-type(5),
    .scrum-list-item > div:nth-of-type(6),
    .scrum-list-actions {
        grid-column: auto;
        grid-row: auto;
    }
}

@media (max-width: 720px) {
    .content {
        padding: 16px;
    }

    .page-header,
    .panel-header {
        gap: 12px;
    }

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

    .page-subtitle {
        font-size: 0.92rem;
    }

    .panel {
        margin-bottom: 18px;
    }

    .panel-header {
        min-height: 0;
        padding: 14px;
    }

    .panel-body {
        padding: 16px;
    }

    .panel-header .btn,
    .page-header .btn {
        width: 100%;
    }

    .table {
        min-width: 880px;
    }

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

    .table-responsive {
        border: 0;
    }

    .table-actions {
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        white-space: normal;
    }

    .table-actions form,
    .table-actions .btn {
        width: 100%;
    }

    .table-actions form .btn {
        width: 100%;
    }

    .status-badge {
        white-space: nowrap;
    }

    .toast-container {
        right: 0.75rem;
        left: 0.75rem;
    }

    .toast-container .toast {
        width: 100%;
    }
}

@media (max-width: 560px) {
    .sidenav-brand {
        height: 62px;
        padding: 0 16px;
    }

    .sidenav .logo {
        width: 150px;
    }

    .sidenav ul {
        display: block;
        padding: 8px;
    }

    .sidenav li + li {
        margin-top: 4px;
    }

    .sidenav a,
    .sidenav button {
        min-height: 40px;
        padding: 9px 12px;
    }

    .content {
        padding: 12px;
    }

    .login-page {
        padding: 12px;
    }

    .login-panel {
        padding: 20px;
    }

    .modal-dialog {
        margin: 0.75rem;
    }
}
