:root {
    --ink: #172033;
    --muted: #637083;
    --line: #e1e7ef;
    --panel: #ffffff;
    --page: #f7f9fc;
    --blue: #1767c8;
    --blue-dark: #0e4d9b;
    --teal: #0f8f8c;
    --coral: #e15b3f;
    --soft-blue: #eaf3ff;
    --soft-teal: #e7f7f5;
    --shadow: 0 10px 28px rgba(23, 32, 51, 0.07);
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    padding: 24px;
    background: var(--page);
    color: var(--ink);
    font-family: "Open Sans", Helvetica, Arial, sans-serif;
}

#heights-wrapper {
    width: min(1180px, 100%);
    margin: 0 auto;
}

.heights-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    padding: 18px 0 20px;
    border-bottom: 1px solid var(--line);
}

.logo-container {
    display: flex;
    align-items: center;
    min-height: 72px;
}

.logo-container img {
    width: auto;
    max-width: 220px;
    max-height: 86px;
}

.logo-fallback {
    display: none;
    padding: 0;
    color: var(--blue-dark);
    font-size: 24px;
    font-weight: 900;
}

.logo-container.is-missing img {
    display: none;
}

.logo-container.is-missing .logo-fallback {
    display: inline-flex;
}

.header-text {
    max-width: 560px;
    text-align: right;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--coral);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.heights-header h1 {
    margin: 0;
    color: var(--blue-dark);
    font-size: 34px;
    line-height: 1.1;
}

.term-title {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 20px;
    font-weight: 800;
}

.filter-panel {
    display: grid;
    gap: 14px;
    margin: 20px 0;
    padding: 16px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.filter-toggle {
    display: none;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 42px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--blue-dark);
    font: inherit;
    font-weight: 900;
    text-align: left;
    cursor: pointer;
}

.filter-toggle::after {
    content: "";
    width: 10px;
    height: 10px;
    flex: 0 0 10px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform 160ms ease;
}

.filter-toggle[aria-expanded="false"]::after {
    transform: rotate(-45deg);
}

.filter-summary {
    min-width: 0;
    margin-left: auto;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-align: right;
}

.filter-content {
    display: grid;
    gap: 14px;
}

.filter-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.filter-title {
    flex: 0 0 86px;
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.filter-option {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 8px 13px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    color: var(--ink);
    font-weight: 800;
    font-size: 14px;
    line-height: 1.2;
    cursor: pointer;
    transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.filter-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.filter-option:has(input:focus-visible) {
    outline: 3px solid rgba(23, 103, 200, 0.25);
    outline-offset: 2px;
}

.filter-option:hover {
    border-color: rgba(23, 103, 200, 0.45);
}

.filter-option:has(input:checked) {
    background: var(--blue);
    border-color: var(--blue);
    color: #ffffff;
    box-shadow: none;
}

.filter-group-days .filter-option:has(input:checked) {
    background: var(--teal);
    border-color: var(--teal);
    box-shadow: none;
}

.status-message {
    display: none;
    margin-bottom: 16px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--muted);
}

.status-message.is-visible {
    display: block;
}

.timetable-shell {
    overflow: hidden;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

#timetable {
    min-height: 120px;
}

.cm-table-custom,
.timetable-table {
    width: 100% !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    background: #ffffff;
}

.cm-th-custom,
.timetable-heading-row th,
.timetable-table th {
    padding: 14px 18px !important;
    background: #f1f6fc !important;
    border-bottom: 1px solid var(--line) !important;
    color: var(--blue-dark) !important;
    font-size: 12px;
    font-weight: 800;
    text-align: left;
    text-transform: uppercase;
}

.day-header-row td,
.timetable-day-row td {
    padding: 11px 18px !important;
    background: #f7fbfb !important;
    border-top: 1px solid #d8eeeb !important;
    border-bottom: 1px solid #d8eeeb !important;
    color: #08706e !important;
    font-size: 13px !important;
    font-weight: 900;
    text-transform: uppercase;
}

.cm-td-custom,
.timetable-table td {
    padding: 14px 18px !important;
    border-bottom: 1px solid #eff3f8 !important;
    color: var(--ink);
    font-size: 15px;
    line-height: 1.35;
    vertical-align: middle;
}

.cm-table-custom.has-location-column th:nth-child(2),
.cm-table-custom.has-location-column td:nth-child(2),
.location-column {
    display: none !important;
}

.cm-tr-custom[data-row-type="class"]:hover td,
.timetable-row[data-row-type="class"]:hover td {
    background: #fbfdff;
}

.cm-td-custom:first-child,
.timetable-table td:first-child {
    width: 132px;
    color: var(--blue-dark);
    font-weight: 900;
}

.class-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.discipline-badge,
.squad-badge {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 3px 8px;
    border-radius: 999px;
    background: var(--soft-blue);
    color: var(--blue-dark);
    font-size: 12px;
    font-weight: 900;
}

.discipline-badge {
    background: #f1f0fb;
    color: #454985;
}

.squad-badge {
    background: #fff0eb;
    color: #a73520;
}

.coach-box {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 160px;
}

.coach-img {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border: 1px solid #d9e7f7;
    border-radius: 50%;
    background: #ffffff;
    object-fit: cover;
}

.empty-message {
    margin: 18px 18px 26px;
    padding: 16px;
    border: 1px solid #f6c7bd;
    border-radius: 8px;
    background: #fff5f2;
    color: #8b2d1d;
    font-weight: 800;
}

.site-footer {
    padding: 22px 0 6px;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
}

.builder-panel {
    margin: 20px 0;
    padding: 18px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

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

.builder-field {
    display: grid;
    gap: 7px;
}

.builder-field-wide {
    grid-column: 1 / -1;
}

.builder-field span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 900;
}

.builder-field input,
.builder-field select {
    width: 100%;
    min-height: 46px;
    padding: 10px 12px;
    border: 1px solid #d7e2ef;
    border-radius: 8px;
    background: #ffffff;
    color: var(--ink);
    font: inherit;
    font-weight: 700;
}

.builder-output {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 14px;
    align-items: end;
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.builder-actions {
    display: flex;
    gap: 10px;
}

.builder-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    padding: 10px 16px;
    border: 1px solid #d7e2ef;
    border-radius: 8px;
    background: #ffffff;
    color: var(--blue-dark);
    font: inherit;
    font-weight: 900;
    text-decoration: none;
    cursor: pointer;
}

.builder-button-primary {
    border-color: var(--blue);
    background: var(--blue);
    color: #ffffff;
}

.builder-preview {
    width: calc(100vw - 48px);
    margin: 20px 0 20px 50%;
    transform: translateX(-50%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.builder-preview-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    background: #f1f6fc;
}

.builder-preview-header h2 {
    margin: 0;
    color: var(--blue-dark);
    font-size: 16px;
    font-weight: 900;
}

.builder-preview iframe {
    display: block;
    width: 100%;
    height: 100vh;
    min-height: 900px;
    border: 0;
    background: #ffffff;
}

.url-builder-page #heights-wrapper {
    width: min(1500px, 100%);
}

.iframe-mode,
.iframe-filter-mode,
.iframe-header-mode,
.iframe-day-filter-mode {
    overflow: hidden;
}

.iframe-mode body,
.iframe-header-mode body,
.iframe-day-filter-mode body,
.iframe-filter-mode body {
    min-height: 0;
    padding: 0;
    background: transparent;
    overflow: hidden;
}

.iframe-mode #heights-wrapper,
.iframe-header-mode #heights-wrapper,
.iframe-day-filter-mode #heights-wrapper,
.iframe-filter-mode #heights-wrapper {
    width: 100%;
}

.iframe-mode .heights-header,
.iframe-mode .filter-panel,
.iframe-mode .site-footer {
    display: none;
}

.iframe-filter-mode .heights-header,
.iframe-filter-mode .site-footer {
    display: none;
}

.iframe-header-mode .filter-panel {
    display: none;
}

.iframe-day-filter-mode .filter-group-class {
    display: none;
}

.iframe-day-filter-mode .filter-panel {
    margin: 0 0 14px;
}

.iframe-filter-mode .filter-panel {
    margin: 0 0 14px;
}

.iframe-mode .status-message,
.iframe-header-mode .status-message,
.iframe-day-filter-mode .status-message,
.iframe-filter-mode .status-message {
    margin: 0 0 10px;
}

.iframe-mode .timetable-shell,
.iframe-header-mode .timetable-shell,
.iframe-day-filter-mode .timetable-shell,
.iframe-filter-mode .timetable-shell {
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

@media (max-width: 820px) {
    body {
        padding: 16px;
    }

    .heights-header {
        align-items: flex-start;
        padding-top: 12px;
    }

    .heights-header h1 {
        font-size: 32px;
    }

    .filter-title {
        flex-basis: 100%;
    }

    .builder-grid,
    .builder-output {
        grid-template-columns: 1fr;
    }

    .builder-actions {
        justify-content: stretch;
    }

    .builder-button {
        flex: 1;
    }
}

@media (max-width: 680px) {
    body {
        padding: 12px;
    }

    .heights-header {
        flex-direction: column;
        gap: 14px;
    }

    .header-text {
        text-align: left;
    }

    .heights-header h1 {
        font-size: 31px;
    }

    .term-title {
        font-size: 15px;
    }

    .filter-panel {
        margin: 16px 0;
        padding: 12px;
        gap: 10px;
    }

    .filter-toggle {
        display: flex;
    }

    .filter-content {
        gap: 16px;
    }

    .filter-panel.is-collapsed .filter-content {
        display: none;
    }

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

    .filter-title {
        grid-column: 1 / -1;
        font-size: 13px;
    }

    .filter-option {
        width: 100%;
        min-height: 38px;
        padding: 9px 10px;
        font-size: 14px;
        text-align: center;
    }

    .cm-table-custom,
    .timetable-table,
    .cm-table-custom tbody,
    .timetable-table tbody {
        display: block;
        width: 100% !important;
    }

    .cm-table-custom thead,
    .timetable-table thead,
    .timetable-heading-row {
        display: none;
    }

    .cm-tr-custom,
    .timetable-row {
        display: block;
    }

    .day-header-row,
    .timetable-day-row {
        position: sticky;
        top: 0;
        z-index: 1;
    }

    .day-header-row td,
    .timetable-day-row td {
        display: block;
        padding: 11px 14px !important;
        font-size: 13px !important;
    }

    .cm-tr-custom[data-row-type="class"],
    .timetable-row[data-row-type="class"] {
        margin: 10px;
        border: 1px solid var(--line);
        border-radius: 8px;
        background: #ffffff;
        box-shadow: none;
    }

    .cm-tr-custom[data-row-type="class"] .cm-td-custom,
    .timetable-row[data-row-type="class"] td {
        display: grid;
        grid-template-columns: 74px minmax(0, 1fr);
        gap: 12px;
        width: 100% !important;
        padding: 12px 14px !important;
        border-bottom: 1px solid #edf1f6 !important;
        font-size: 14px;
        white-space: normal;
    }

    .cm-tr-custom[data-row-type="class"] .cm-td-custom::before,
    .timetable-row[data-row-type="class"] td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 12px;
        font-weight: 900;
        text-transform: uppercase;
    }

    .cm-tr-custom[data-row-type="class"] td:last-child,
    .timetable-row[data-row-type="class"] td:last-child {
        border-bottom: 0 !important;
    }

    .coach-box {
        min-width: 0;
    }

    .coach-img {
        width: 38px;
        height: 38px;
        flex-basis: 38px;
    }
}

@media (max-width: 420px) {
    .filter-group {
        grid-template-columns: 1fr;
    }

    .cm-tr-custom[data-row-type="class"] .cm-td-custom,
    .timetable-row[data-row-type="class"] td {
        grid-template-columns: 1fr;
        gap: 5px;
    }
}
