:root {
    --accent: #b4232a;
    --accent-strong: #8f1d23;
    --accent-soft: #fff1f1;
    --ink: #23201f;
    --muted: #6f6863;
    --subtle: #8c837c;
    --line: #e4ddd5;
    --line-strong: #d4c9bf;
    --paper: #fffdf9;
    --panel: #ffffff;
    --canvas: #faf7f1;
    --success: #1f7a5c;
    --success-soft: #ecf7f2;
    --warning: #9b6818;
    --warning-soft: #fff6df;
    --error: #b4232a;
    --error-soft: #fff1f1;
    --shadow-soft: 0 18px 40px rgba(57, 45, 35, 0.08);
    --shadow-tight: 0 8px 20px rgba(57, 45, 35, 0.07);
    --radius: 8px;
    --radius-sm: 6px;
    --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    overflow-y: scroll;
    background: var(--canvas);
}

body {
    min-width: 320px;
    margin: 0;
    font-family: var(--font);
    color: var(--ink);
    background:
        linear-gradient(180deg, rgba(255, 253, 249, 0.95) 0%, rgba(250, 247, 241, 1) 380px),
        var(--canvas);
}

button,
input {
    font: inherit;
}

button {
    border: 0;
}

button:focus-visible,
input:focus-visible,
label:has(input:focus-visible) {
    outline: 3px solid rgba(180, 35, 42, 0.22);
    outline-offset: 2px;
}

.app-shell {
    width: min(1480px, 100%);
    margin: 0 auto;
    padding: 28px;
}

.app-header {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: flex-end;
    padding: 8px 0 26px;
}

.brand-block {
    max-width: 760px;
}

.eyebrow,
.section-kicker,
.state-label {
    margin: 0 0 7px;
    color: var(--accent);
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 8px;
    color: var(--ink);
    font-size: clamp(2.05rem, 5vw, 4.15rem);
    line-height: 0.96;
    letter-spacing: 0;
}

.header-copy {
    max-width: 660px;
    margin-bottom: 0;
    color: var(--muted);
    font-size: 1rem;
    line-height: 1.55;
}

.term-badge {
    min-width: 176px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.72);
    box-shadow: var(--shadow-tight);
    text-align: left;
}

.term-badge span,
.summary-strip span,
.list-header span,
.helper-text {
    color: var(--subtle);
    font-size: 0.78rem;
}

.term-badge strong {
    display: block;
    margin-top: 3px;
    color: var(--ink);
    font-size: 1.08rem;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(360px, 430px) minmax(0, 1fr);
    gap: 22px;
    align-items: start;
}

.workflow-panel {
    position: sticky;
    top: 18px;
}

#main-controls {
    display: grid;
    gap: 16px;
}

.panel-section,
.results-area,
.state-card,
.schedule-display {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow-soft);
}

.panel-section {
    padding: 18px;
}

.section-heading {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: flex-start;
    margin-bottom: 16px;
}

.section-heading h2,
.results-toolbar h2,
.state-card h2 {
    margin-bottom: 0;
    color: var(--ink);
    font-size: 1.18rem;
    line-height: 1.2;
}

.metric-pill {
    flex: 0 0 auto;
    padding: 6px 9px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--paper);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
}

.field-label {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
}

.search-wrap {
    position: relative;
}

#course-search-input {
    width: 100%;
    height: 44px;
    padding: 0 13px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--paper);
    color: var(--ink);
    transition: border-color 0.16s, box-shadow 0.16s, background-color 0.16s;
}

#course-search-input::placeholder {
    color: #9b938c;
}

#course-search-input:focus {
    border-color: var(--accent);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(180, 35, 42, 0.09);
    outline: none;
}

.helper-text {
    margin: 8px 0 0;
    min-height: 18px;
}

.course-lists-container {
    display: grid;
    gap: 15px;
    margin-top: 16px;
}

.course-list-wrapper {
    min-width: 0;
}

.list-header {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
    margin-bottom: 8px;
}

.list-header h3,
.pref-group h3 {
    margin-bottom: 0;
    color: var(--ink);
    font-size: 0.92rem;
    line-height: 1.2;
}

.course-list {
    height: 236px;
    margin: 0;
    padding: 6px;
    overflow-y: auto;
    list-style: none;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fbf8f3;
}

.selected-list {
    height: 166px;
}

.course-list::-webkit-scrollbar {
    width: 10px;
}

.course-list::-webkit-scrollbar-thumb {
    border: 3px solid #fbf8f3;
    border-radius: 999px;
    background: #cfc4b9;
}

.course-list li {
    min-height: 54px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 34px;
    gap: 10px;
    align-items: center;
    padding: 9px 9px 9px 11px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color 0.14s, border-color 0.14s, transform 0.14s;
}

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

.course-list li:not(.info-item):hover {
    border-color: #eadfd4;
    background: #fff;
}

.course-list li:not(.info-item):active {
    transform: scale(0.995);
}

.course-list li div {
    min-width: 0;
}

.course-code,
.course-name {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.course-code {
    color: var(--ink);
    font-size: 0.92rem;
    font-weight: 850;
}

.course-name {
    margin-top: 2px;
    color: var(--muted);
    font-size: 0.8rem;
    line-height: 1.3;
}

.course-action-btn {
    width: 32px;
    height: 32px;
    display: inline-grid;
    place-items: center;
    border: 1px solid transparent;
    border-radius: 999px;
    background: var(--success-soft);
    color: var(--success);
    cursor: pointer;
    font-size: 1.2rem;
    font-weight: 900;
    line-height: 1;
}

.selected-list .course-action-btn {
    background: var(--accent-soft);
    color: var(--accent);
}

.course-action-btn:hover {
    border-color: currentColor;
}

.info-item {
    grid-template-columns: 1fr !important;
    min-height: 72px !important;
    color: var(--subtle);
    cursor: default !important;
    text-align: center;
}

.pref-group {
    padding-top: 17px;
    margin-top: 17px;
    border-top: 1px solid var(--line);
}

.pref-group:first-of-type {
    padding-top: 0;
    margin-top: 0;
    border-top: 0;
}

.pref-description {
    margin: 6px 0 12px;
    color: var(--muted);
    font-size: 0.84rem;
    line-height: 1.45;
}

.priority-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.priority-option {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--paper);
    color: var(--muted);
    cursor: pointer;
    font-size: 0.83rem;
    font-weight: 750;
    line-height: 1.25;
    transition: border-color 0.14s, background-color 0.14s, color 0.14s;
}

.priority-option:hover,
.priority-option:has(input:checked) {
    border-color: rgba(180, 35, 42, 0.42);
    background: var(--accent-soft);
    color: var(--ink);
}

.priority-option input {
    width: 16px;
    height: 16px;
    margin: 0;
    flex: 0 0 auto;
    accent-color: var(--accent);
}

.preference-row {
    min-height: 42px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding: 8px 0;
}

.check-label {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 9px;
    color: var(--ink);
    font-size: 0.91rem;
    font-weight: 650;
}

.check-label input {
    width: 18px;
    height: 18px;
    margin: 0;
    flex: 0 0 auto;
    accent-color: var(--accent);
}

.check-label label {
    cursor: pointer;
}

input[type="time"] {
    width: 128px;
    height: 38px;
    padding: 0 9px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--ink);
}

input[type="time"]:disabled {
    border-color: var(--line);
    background: #f1ede8;
    color: #aaa29a;
    cursor: not-allowed;
}

.action-bar {
    display: block;
}

.primary-action,
.secondary-btn,
.icon-button {
    min-height: 42px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 850;
    transition: transform 0.14s, background-color 0.14s, border-color 0.14s, color 0.14s;
}

.primary-action {
    width: 100%;
    padding: 0 16px;
    background: var(--accent);
    color: #fff;
    box-shadow: 0 12px 24px rgba(180, 35, 42, 0.22);
}

.primary-action:hover:not(:disabled) {
    background: var(--accent-strong);
    transform: translateY(-1px);
}

.primary-action:disabled,
.secondary-btn:disabled,
.icon-button:disabled {
    cursor: not-allowed;
    opacity: 0.52;
    transform: none;
}

.results-area {
    min-height: 700px;
    padding: 0;
    overflow: hidden;
}

.state-card {
    min-height: 700px;
    display: grid;
    place-items: center;
    padding: 46px;
    border: 0;
    box-shadow: none;
    text-align: center;
}

.state-card > * {
    max-width: 500px;
}

.state-card p:last-child {
    margin-bottom: 0;
    color: var(--muted);
    line-height: 1.55;
}

.state-card h2 {
    margin-bottom: 8px;
    font-size: clamp(1.35rem, 3vw, 2rem);
}

.state-info {
    background: linear-gradient(180deg, #fff 0%, #fcf8f1 100%);
}

.state-loading {
    background: linear-gradient(180deg, #fff 0%, #f8f2ec 100%);
}

.state-warn {
    background: var(--warning-soft);
}

.state-error {
    background: var(--error-soft);
}

.state-success {
    display: none;
}

.hidden {
    display: none !important;
}

.schedule-display {
    min-height: 700px;
    padding: 20px;
    border: 0;
    box-shadow: none;
}

.results-toolbar {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    margin-bottom: 16px;
}

.schedule-nav {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.icon-button {
    width: 42px;
    padding: 0;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    font-size: 1.05rem;
}

.icon-button:hover:not(:disabled),
.secondary-btn:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}

.secondary-btn {
    padding: 0 14px;
    border: 1px solid var(--line);
    background: var(--paper);
    color: var(--ink);
}

.summary-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 15px;
}

.summary-strip div {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--paper);
}

.summary-strip strong {
    display: block;
    margin-top: 3px;
    color: var(--ink);
    font-size: 1.28rem;
    line-height: 1;
}

.section-summary {
    margin: 0 0 14px;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.45;
}

.seat-warning-strip {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px;
    align-items: center;
    margin: 0 0 14px;
    padding: 11px 12px;
    border: 1px solid #e4b85f;
    border-radius: var(--radius-sm);
    background: var(--warning-soft);
    color: var(--warning);
}

.seat-warning-strip strong {
    color: var(--warning);
    font-size: 0.86rem;
}

.seat-warning-strip span {
    font-size: 0.86rem;
    line-height: 1.4;
}

.canvas-frame {
    width: 100%;
    min-height: 500px;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}

#schedule-canvas {
    display: block;
    width: 100%;
    min-width: 720px;
    height: 620px;
}

.mobile-schedule-details {
    display: grid;
    gap: 9px;
    margin-top: 14px;
}

.detail-card {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--paper);
}

.detail-card strong {
    display: block;
    margin-bottom: 4px;
    color: var(--ink);
}

.detail-card span {
    display: block;
    color: var(--muted);
    font-size: 0.86rem;
    line-height: 1.45;
}

.detail-card .seat-note {
    margin-top: 6px;
    color: var(--success);
    font-weight: 800;
}

.detail-card .seat-note-warn {
    color: var(--warning);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(35, 32, 31, 0.44);
}

.modal-panel {
    width: min(520px, 100%);
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: 0 24px 60px rgba(35, 32, 31, 0.22);
}

.modal-heading {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
}

.modal-heading h2 {
    margin-bottom: 0;
    font-size: 1.25rem;
}

.modal-copy {
    margin: 12px 0 16px;
    color: var(--muted);
    line-height: 1.5;
}

.date-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.date-field span {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
}

.date-field input {
    width: 100%;
    height: 42px;
    padding: 0 10px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--paper);
    color: var(--ink);
}

.modal-error {
    min-height: 20px;
    margin: 10px 0 0;
    color: var(--error);
    font-size: 0.86rem;
    font-weight: 750;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

.modal-actions .secondary-btn,
.modal-primary {
    width: auto;
}

@media (max-width: 1120px) {
    .workspace {
        grid-template-columns: 1fr;
    }

    .workflow-panel {
        position: static;
    }

    .course-lists-container {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 760px) {
    .app-shell {
        padding: 18px;
    }

    .app-header,
    .results-toolbar {
        display: grid;
    }

    .term-badge {
        width: 100%;
    }

    .course-lists-container,
    .priority-group,
    .summary-strip {
        grid-template-columns: 1fr;
    }

    .seat-warning-strip {
        grid-template-columns: 1fr;
    }

    .date-grid,
    .modal-actions {
        grid-template-columns: 1fr;
    }

    .date-grid {
        display: grid;
    }

    .modal-actions {
        display: grid;
    }

    .modal-actions .secondary-btn,
    .modal-primary {
        width: 100%;
    }

    .panel-section,
    .schedule-display {
        padding: 15px;
    }

    .course-list {
        height: 220px;
    }

    .selected-list {
        height: 150px;
    }

    .preference-row {
        align-items: flex-start;
        flex-direction: column;
    }

    input[type="time"] {
        width: 100%;
    }

    .schedule-nav {
        justify-content: stretch;
    }

    .schedule-nav .secondary-btn {
        flex: 1 1 100%;
    }

    .icon-button {
        flex: 1 1 0;
    }

    .results-area,
    .state-card,
    .schedule-display {
        min-height: 520px;
    }

    .state-card {
        padding: 32px 18px;
    }

    .canvas-frame {
        min-height: 390px;
    }

    #schedule-canvas {
        min-width: 680px;
        height: 480px;
    }
}

@media (max-width: 420px) {
    .app-shell {
        padding: 14px;
    }

    .section-heading {
        display: grid;
    }

    .metric-pill {
        width: max-content;
    }
}
