* {
    box-sizing: border-box;
}

:root {
    --brand: #C8102E;
    --brand-dark: #9c0c24;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #1f2937;
    background: #f3f4f6;
}

body {
    margin: 0;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    padding: 18px 24px;
    background: #fff;
    border-bottom: 1px solid #d1d5db;
    border-top: 4px solid var(--brand);
}

header h1 {
    margin: 0;
    font-size: 1.45rem;
    color: var(--brand);
}

header p {
    margin: 4px 0 0;
    color: #64748b;
}

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

button {
    font: inherit;
    padding: 9px 13px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    background: #fff;
    cursor: pointer;
}

button:hover {
    background: #f8fafc;
}

button.primary {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}

button.primary:hover {
    background: var(--brand-dark);
    border-color: var(--brand-dark);
}

main {
    display: grid;
    grid-template-columns: minmax(360px, 1.15fr) minmax(280px, .82fr) minmax(360px, 1fr);
    gap: 14px;
    padding: 14px;
    height: calc(100vh - 126px);
}

section {
    min-width: 0;
}

main > section {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 9px;
}

.panel-heading {
    min-height: 48px;
    padding: 11px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #e5e7eb;
}

.panel-heading h2 {
    margin: 0;
    font-size: 1rem;
}

#statusText {
    color: #64748b;
    font-size: .82rem;
}

textarea {
    width: 100%;
    height: 100%;
    min-height: 0;
    padding: 16px;
    border: 0;
    outline: 0;
    resize: none;
    font: 14px/1.55 Consolas, "SFMono-Regular", "Liberation Mono", monospace;
    tab-size: 4;
    caret-color: var(--brand);
    selection-color: #111827;
    selection-background-color: #bfdbfe;
}

#messages {
    flex: 0 0 auto;
    max-height: 220px;
    overflow: auto;
    padding: 0 12px;
}

#outline,
#preview {
    min-height: 0;
    overflow: auto;
    padding: 12px;
}

.message {
    padding: 9px;
    border-radius: 6px;
    margin-top: 9px;
    font-size: .87rem;
}

.message.error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.message.warning {
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
}

.outline-group {
    margin-bottom: 10px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.outline-children {
    border-top: 1px solid #e5e7eb;
}

.outline-row {
    width: 100%;
    display: grid;
    grid-template-columns: 1.55rem minmax(0, 1fr) auto;
    gap: 7px;
    align-items: center;
    padding: 8px 10px;
    border: 0;
    border-radius: 0;
    text-align: left;
}

.outline-row + .outline-row {
    border-top: 1px solid #f1f5f9;
}

.module-row {
    font-weight: 700;
    background: #f8fafc;
}

.item-row {
    padding-left: 14px;
}

.criterion-row {
    padding-left: 18px;
}

.rating-row {
    padding-left: 34px;
    font-size: .9rem;
}

.outline-row.active {
    background: #fdecee;
    box-shadow: inset 4px 0 0 var(--brand);
}

.outline-icon {
    text-align: center;
}

.outline-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rubric-section-title {
    margin: 16px 2px 8px;
    color: #475569;
    font-size: .78rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.tag {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 999px;
    background: #eef2ff;
    font-size: .72rem;
    font-weight: 500;
    white-space: nowrap;
}

.preview {
    line-height: 1.62;
}

.preview h1 {
    margin-top: 4px;
}

.preview-type {
    color: #64748b;
    font-size: .75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .05em;
}

.preview-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 18px;
}

.rendered-content blockquote {
    margin-left: 0;
    padding-left: 14px;
    border-left: 4px solid #cbd5e1;
    color: #475569;
}

.rendered-content code {
    padding: 2px 5px;
    border-radius: 4px;
    background: #f1f5f9;
}

.rubric {
    width: 100%;
    border-collapse: collapse;
}

.rubric th,
.rubric td {
    padding: 8px;
    border: 1px solid #d1d5db;
    text-align: left;
}

.rubric th {
    background: #f8fafc;
}

.criterion-preview {
    margin: 18px 0;
    padding-top: 4px;
}

.criterion-preview + .criterion-preview {
    border-top: 1px solid #e5e7eb;
}

.rating-points {
    font-size: 1.4rem;
    font-weight: 700;
}

.muted {
    color: #64748b;
}

.button-link {
    display: inline-block;
    padding: 9px 13px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    background: #fff;
    color: #1f2937;
    text-decoration: none;
}

.button-link:hover {
    background: #f8fafc;
}

body.modal-open {
    overflow: hidden;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(15, 23, 42, .55);
}

.modal[hidden] {
    display: none;
}

.modal-dialog {
    display: flex;
    flex-direction: column;
    width: min(1150px, 100%);
    max-height: 88vh;
    overflow: hidden;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, .3);
}

.modal-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid #e5e7eb;
}

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

.modal-tools {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.legend {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #475569;
    font-size: .8rem;
}

.legend-swatch {
    width: 22px;
    height: 10px;
    border-radius: 5px;
}

.swatch-available {
    background: #1a7a4c;
}

.swatch-due {
    background: var(--brand);
}

.swatch-until {
    background: #b45309;
}

.legend-marker {
    color: var(--brand);
    font-size: .85rem;
}

.gantt-body {
    overflow: auto;
    padding: 16px 18px 22px;
}

.gantt-empty {
    margin: 8px 2px;
}

.gantt-chart {
    min-width: 720px;
}

.gantt-row {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
}

.gantt-rows {
    position: relative;
}

.gantt-module-row {
    margin: 14px 2px 6px;
    color: #475569;
    font-size: .78rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.gantt-label {
    display: grid;
    grid-template-columns: 1.4rem minmax(0, 1fr);
    gap: 6px;
    align-items: center;
    padding: 6px 8px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    text-align: left;
    font-size: .88rem;
}

button.gantt-label:hover {
    background: #eff6ff;
}

.gantt-label-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gantt-track {
    position: relative;
    height: 26px;
    border-radius: 6px;
    background:
        repeating-linear-gradient(
            to right,
            transparent,
            transparent calc(10% - 1px),
            #f1f5f9 calc(10% - 1px),
            #f1f5f9 10%
        ),
        #f8fafc;
}

.gantt-span {
    position: absolute;
    top: 9px;
    height: 8px;
    border-radius: 4px;
    background: #cbd5e1;
}

.gantt-marker {
    position: absolute;
    top: 50%;
    width: 14px;
    height: 14px;
    transform: translate(-50%, -50%) rotate(45deg);
    border-radius: 3px;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, .15);
}

.marker-available {
    background: #1a7a4c;
}

.marker-due {
    background: var(--brand);
    width: 16px;
    height: 16px;
}

.marker-until {
    background: #b45309;
}

.gantt-skipped-note {
    margin: 4px 2px 0;
    font-size: .82rem;
}

.gantt-axis-row {
    position: sticky;
    top: 0;
    z-index: 2;
    padding-bottom: 26px;
    background: #fff;
}

.gantt-axis-label {
    color: #64748b;
    font-size: .78rem;
}

.gantt-axis {
    height: 10px;
    background: transparent;
    border-bottom: 1px solid #e5e7eb;
    border-radius: 0;
}

.gantt-tick {
    position: absolute;
    top: 0;
    bottom: -6px;
    border-left: 1px solid #cbd5e1;
}

.gantt-tick span {
    position: absolute;
    top: 12px;
    left: 3px;
    color: #64748b;
    font-size: .7rem;
    white-space: nowrap;
}

.gantt-overlay-row {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.gantt-overlay {
    position: relative;
    height: 100%;
    background: transparent;
    border-radius: 0;
}

.gantt-today {
    position: absolute;
    top: 0;
    bottom: 0;
    border-left: 2px dashed #334155;
}

.gantt-today span {
    position: absolute;
    top: -2px;
    left: 4px;
    padding: 1px 6px;
    border-radius: 999px;
    background: #e2e8f0;
    color: #334155;
    font-size: .68rem;
    font-weight: 700;
}

footer {
    text-align: center;
    padding: 12px;
    color: #64748b;
    font-size: .86rem;
}

footer a {
    color: var(--brand);
}

@media (max-width: 1050px) {
    main {
        grid-template-columns: 1fr 1fr;
        height: auto;
    }

    .editor-panel {
        grid-column: 1 / -1;
        height: 560px;
    }

    .outline-panel,
    .preview-panel {
        height: 650px;
    }
}

@media (max-width: 720px) {
    header {
        align-items: flex-start;
        flex-direction: column;
    }

    main {
        grid-template-columns: 1fr;
    }

    .editor-panel,
    .outline-panel,
    .preview-panel {
        height: 540px;
    }
}

.gantt-print-only {
    display: none;
}

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #f3f4f6;
}

.login-card {
    width: min(380px, 92vw);
    padding: 28px 26px;
    background: #fff;
    border: 1px solid #d1d5db;
    border-top: 4px solid var(--brand);
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(15, 23, 42, .08);
}

.login-card h1 {
    margin: 0 0 6px;
    font-size: 1.3rem;
    color: var(--brand);
}

.login-card .muted {
    margin: 0 0 18px;
}

.login-card form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.login-card input[type="password"] {
    font: inherit;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
}

.login-card button {
    padding: 10px 13px;
}

@media print {
    body.printing-gantt > header,
    body.printing-gantt > main,
    body.printing-gantt > footer,
    body.printing-gantt #ganttModal .modal-heading #ganttPrint,
    body.printing-gantt #ganttModal .modal-heading #ganttClose,
    body.printing-gantt #ganttModal .modal-heading .legend {
        display: none !important;
    }

    body.printing-gantt {
        background: #fff;
    }

    body.printing-gantt #ganttModal {
        position: static;
        inset: auto;
        padding: 0;
        background: none;
        display: block;
    }

    body.printing-gantt #ganttModal .modal-dialog {
        width: 100%;
        max-height: none;
        box-shadow: none;
        border-radius: 0;
    }

    body.printing-gantt .gantt-body {
        overflow: visible;
    }

    body.printing-gantt .gantt-print-only {
        display: block;
        margin-top: 18px;
        page-break-inside: avoid;
    }

    body.printing-gantt .gantt-print-legend {
        display: flex;
        gap: 18px;
        margin-bottom: 12px;
        font-size: .85rem;
    }

    body.printing-gantt .gantt-print-legend span {
        display: inline-flex;
        align-items: center;
        gap: 6px;
    }

    body.printing-gantt .gantt-print-table {
        width: 100%;
        border-collapse: collapse;
        font-size: .82rem;
    }

    body.printing-gantt .gantt-print-table th,
    body.printing-gantt .gantt-print-table td {
        padding: 6px 8px;
        border: 1px solid #94a3b8;
        text-align: left;
    }

    body.printing-gantt .gantt-print-table th {
        background: #f1f5f9;
    }

    body.printing-gantt,
    body.printing-gantt * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    @page {
        size: landscape;
        margin: 14mm;
    }
}
