/* RCM Timeschedule – one stylesheet, light and dark. */
:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #dde3ea;
    --text: #18212b;
    --muted: #5d6b7a;
    --accent: #1f4e79;
    --accent-hover: #173b5c;
    --accent-soft: #e6eef7;
    --highlight: #f5a524;
    --later: #b42318;
    --later-soft: #fdecea;
    --earlier: #157347;
    --earlier-soft: #e6f4ec;
    --warn: #8a5a00;
    --warn-soft: #fff6e0;
    --custom-row: #eef2f7;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #11161c;
        --surface: #19212a;
        --surface-2: #1f2933;
        --border: #2e3a46;
        --text: #e6ebf0;
        --muted: #9aa8b6;
        --accent: #6aa7e0;
        --accent-hover: #8dbdea;
        --accent-soft: #1d3247;
        --later: #ff8a80;
        --later-soft: #3a1f1f;
        --earlier: #6fd39b;
        --earlier-soft: #173326;
        --warn: #f5c76b;
        --warn-soft: #33290f;
        --custom-row: #22303d;
        --shadow: none;
        color-scheme: dark;
    }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
h1:focus { outline: none; }
h1 { font-size: 1.6rem; margin: 0.2rem 0 0.25rem; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 0 0 0.5rem; }
p { margin: 0.25rem 0 0.75rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Layout */
.container { max-width: 1280px; margin: 0 auto; padding: 0 1.25rem; }
main.container { padding-top: 1.25rem; padding-bottom: 2rem; }
.footer { color: var(--muted); font-size: 0.85rem; padding-bottom: 2rem; }
.footer p { margin: 0.2rem 0; }

.topbar { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .topbar { background: #0c2238; } }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: 0.6rem 1.25rem; display: flex; align-items: center; gap: 1.5rem; }
.brand { display: flex; align-items: center; gap: 0.55rem; color: #fff; text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.brand:hover { color: #fff; }
.topnav { display: flex; gap: 0.25rem; }
.topnav a { color: rgba(255, 255, 255, 0.85); text-decoration: none; padding: 0.35rem 0.75rem; border-radius: 6px; }
.topnav a:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.topnav a.active { background: rgba(255, 255, 255, 0.18); color: #fff; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.head-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.back-link { font-size: 0.9rem; text-decoration: none; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.card-head { margin-bottom: 0.75rem; }
.card-head.row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.card-head p { margin-bottom: 0; }
.actions-row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; margin-top: 0.75rem; }
.empty { color: var(--muted); padding: 1rem 0; }

/* Controls */
button, .button {
    font: inherit;
    font-size: 0.92rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: 36px;
    padding: 0.35rem 0.85rem;
    border-radius: 7px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}
button:hover:not(:disabled), .button:hover { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--accent-hover); color: #fff; }
@media (prefers-color-scheme: dark) { button.primary, .button.primary { color: #0c1620; } button.primary:hover:not(:disabled) { color: #0c1620; } }
button.small, .button.small { min-height: 30px; padding: 0.2rem 0.6rem; font-size: 0.85rem; }
button.danger:hover:not(:disabled) { border-color: var(--later); color: var(--later); }
button.link { border: none; background: none; color: var(--accent); padding: 0.2rem 0.3rem; min-height: 30px; }
button.link.danger { color: var(--later); }
button.icon { min-width: 32px; min-height: 32px; padding: 0; }
.button.secondary { background: var(--surface-2); }

input[type=text], input[type=number], input[type=date], select {
    font: inherit;
    font-size: 0.95rem;
    min-height: 36px;
    padding: 0.3rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--surface);
    color: var(--text);
    max-width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}
input.invalid, .invalid { border-color: var(--later) !important; background: var(--later-soft); }
.time-input { width: 7.2rem; font-variant-numeric: tabular-nums; }
.time-input.short { width: 6rem; }
.name-input { width: 13rem; }
.name-input.wide { width: 18rem; }
.field { display: flex; flex-direction: column; gap: 0.25rem; max-width: 22rem; margin-bottom: 0.75rem; }
.field > span { font-weight: 600; font-size: 0.9rem; }
label.check, label.radio { display: inline-flex; align-items: center; gap: 0.4rem; cursor: pointer; margin-right: 1rem; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.75rem 0.75rem; margin: 0; }
legend { font-weight: 600; font-size: 0.9rem; padding: 0 0.3rem; }
.file-button { position: relative; overflow: hidden; }
.file-button input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.inline-form { display: flex; gap: 0.35rem; align-items: center; flex-wrap: wrap; }

.stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.stepper .step { border: none; border-radius: 0; min-width: 36px; min-height: 36px; font-size: 1.15rem; font-weight: 600; padding: 0; background: var(--surface-2); }
.stepper .step:hover:not(:disabled) { background: var(--accent-soft); }
.stepper input { width: 3.2rem; text-align: center; border: none; border-left: 1px solid var(--border); border-right: 1px solid var(--border); border-radius: 0; min-height: 36px; font-weight: 700; font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Alerts and badges */
.alert { border-radius: 8px; padding: 0.65rem 0.9rem; margin-bottom: 1rem; border: 1px solid transparent; }
.alert ul { margin: 0.35rem 0 0; padding-left: 1.2rem; }
.alert-error { background: var(--later-soft); border-color: var(--later); color: var(--text); }
.alert-warn { background: var(--warn-soft); border-color: var(--warn); }
.alert-ok { background: var(--earlier-soft); border-color: var(--earlier); }
.badge { display: inline-block; font-size: 0.75rem; padding: 0.05rem 0.45rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); margin-left: 0.35rem; white-space: nowrap; }
.badge-error { background: var(--later-soft); color: var(--later); font-weight: 600; }

/* What-if panel */
.whatif { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.section-title { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 0.6rem; }
.class-steppers { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 0.5rem; }
.class-stepper { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.35rem 0.35rem 0.35rem 0.6rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.class-stepper .class-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.5rem; }
.day-card { border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 8px; padding: 0.55rem 0.7rem; background: var(--surface-2); }
.day-card.has-conflict { border-left-color: var(--later); }
.day-card-head { display: flex; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; font-size: 0.9rem; }
.day-name { font-weight: 700; }
.day-times { display: flex; align-items: baseline; gap: 0.35rem; flex-wrap: wrap; margin-top: 0.15rem; font-variant-numeric: tabular-nums; }
.day-end { font-size: 1.35rem; }
.delta { font-weight: 700; font-variant-numeric: tabular-nums; }
.delta.later { color: var(--later); }
.delta.earlier { color: var(--earlier); }
.delta.same { color: var(--muted); }
.conflict-badge { margin-top: 0.3rem; color: var(--later); font-weight: 600; font-size: 0.85rem; }

/* Tabs */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: 0.55rem 0.95rem; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap; font-weight: 600; }
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 0.4rem 0.55rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
tfoot th, tfoot td { font-weight: 600; }

.day-schedule { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.day-schedule-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.day-schedule-head h2 { margin: 0; }
.day-schedule-summary { display: flex; gap: 1.25rem; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.schedule-table { font-size: 0.92rem; }
.schedule-table td { padding-top: 0.32rem; padding-bottom: 0.32rem; }
.col-time { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; width: 6rem; }
.col-marshal { color: var(--muted); font-size: 0.85rem; }
.row-custom td { background: var(--custom-row); font-style: italic; font-weight: 600; }
.row-round-start td { border-top: 2px solid var(--accent); }
.row-conflict td { background: var(--later-soft); }
.row-practice td { background: var(--accent-soft); }
.round-actions { display: flex; align-items: center; gap: 0.25rem; margin-top: 0.3rem; }
.row-pause td { color: var(--muted); font-size: 0.85rem; text-align: center; background: repeating-linear-gradient(45deg, transparent, transparent 6px, var(--surface-2) 6px, var(--surface-2) 12px); }
.row-changed td { background: var(--warn-soft); font-weight: 600; }

.edit-table td, .edit-table th { padding: 0.45rem 0.5rem; }
.edit-table tbody th { font-weight: 600; white-space: nowrap; }
.finals-cell { min-width: 12rem; }
.finals-cell .stepper { margin-top: 0.3rem; }
.list-table td { vertical-align: top; }
.event-link { font-weight: 700; font-size: 1.02rem; }
.day-ends { list-style: none; margin: 0; padding: 0; font-variant-numeric: tabular-nums; }
.day-ends li { display: flex; gap: 0.5rem; justify-content: space-between; max-width: 15rem; }
.row-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; justify-content: flex-end; }

.phase-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0.6rem; margin-bottom: 1rem; }
.phase-box { border: 1px solid var(--border); border-radius: 8px; padding: 0.55rem 0.7rem; background: var(--surface-2); display: flex; flex-direction: column; gap: 0.35rem; align-items: flex-start; }
.phase-name { font-weight: 600; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0.75rem; }

details.overrides summary { cursor: pointer; color: var(--accent); white-space: nowrap; }
.override-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.4rem 0.75rem; margin-top: 0.5rem; }
.override-grid label { display: flex; flex-direction: column; gap: 0.15rem; font-size: 0.85rem; }
.position-editor { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.position-editor select { max-width: 16rem; }

.new-event-form { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; }
.new-event-form .field { margin-bottom: 0; flex: 0 1 22rem; }
.new-event-form .field input { width: 100%; }

.help { max-width: 860px; }
.help ol, .help ul { margin: 0.25rem 0 0.25rem; padding-left: 1.3rem; }
.help li { margin-bottom: 0.45rem; }
.help li::marker { color: var(--accent); font-weight: 700; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 0.3rem; }
.compare-pickers { display: flex; gap: 1rem; flex-wrap: wrap; }
.compare-pickers .field { min-width: 16rem; margin-bottom: 0; }
.compare-table td { font-variant-numeric: tabular-nums; font-size: 1.05rem; }

/* Tablet and phone */
@media (max-width: 960px) {
    .whatif { grid-template-columns: 1fr; }
    body { font-size: 15.5px; }
}
@media (max-width: 600px) {
    .container { padding: 0 0.75rem; }
    .topbar-inner { padding: 0.5rem 0.75rem; gap: 0.75rem; }
    .brand span { display: none; }
    h1 { font-size: 1.35rem; }
    .row-actions { justify-content: flex-start; }
}

/* Print: the schedule tables only */
@media print {
    .topbar, .whatif, .tabs, .head-actions, .alert, .back-link { display: none !important; }
    .footer p:not(.copyright) { display: none; }
    .card { box-shadow: none; break-inside: avoid; }
    body { background: #fff; }
    .day-schedule { box-shadow: none; border: none; break-after: page; }
}

/* Blazor loading and error UI */
.loading { position: relative; min-height: 60vh; }
.loading-progress { position: absolute; display: block; width: 7rem; height: 7rem; inset: 20vh 0 auto 0; margin: 0 auto; }
.loading-progress circle { fill: none; stroke: var(--border); stroke-width: 0.6rem; transform-origin: 50% 50%; transform: rotate(-90deg); }
.loading-progress circle:last-child { stroke: var(--accent); stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%; transition: stroke-dasharray 0.05s ease-in-out; }
.loading-progress-text { position: absolute; text-align: center; font-weight: bold; inset: calc(20vh + 2.9rem) 0 auto 0.2rem; }
.loading-progress-text:after { content: var(--blazor-load-percentage-text, "Loading"); }

#blazor-error-ui { background: var(--warn-soft); color: var(--text); bottom: 0; box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); display: none; left: 0; padding: 0.6rem 1.25rem 0.7rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
.blazor-error-boundary { background: var(--later); padding: 1rem; color: white; border-radius: 8px; }
.blazor-error-boundary::after { content: "An error has occurred."; }
