/* PREM Simulator. No inline style anywhere: the Content-Security-Policy forbids it. */

:root {
    color-scheme: light dark;

    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-2: #eef1f4;
    --line: #dde2e8;
    --text: #17212c;
    --muted: #5a6675;
    --accent: #1f77b4;
    --accent-strong: #185f92;
    --on-accent: #ffffff;
    --focus: rgb(31 119 180 / 0.3);

    --ok: #0f7a56;
    --ok-bg: #e4f5ee;
    --miss: #bd3226;
    --miss-bg: #fcebe9;
    --unknown: #8f5a00;
    --unknown-bg: #fdf2dc;

    /* Same colours as the tasks in the figure (prem_sim.plot.COLORS) */
    --task-0: #1f77b4;
    --task-1: #ff7f0e;
    --task-2: #2ca02c;
    --task-3: #d62728;
    --task-4: #9467bd;
    --task-5: #8c564b;

    --radius: 10px;
    --radius-small: 6px;
    --shadow: 0 1px 2px rgb(16 24 40 / 0.06), 0 1px 3px rgb(16 24 40 / 0.05);
    --header-height: 56px;
    --mono: ui-monospace, 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0e1319;
        --surface: #171e27;
        --surface-2: #212a35;
        --line: #2c3744;
        --text: #e7ecf1;
        --muted: #9aa7b5;
        --accent: #62aee8;
        --accent-strong: #8cc4ef;
        --on-accent: #0b1a26;
        --focus: rgb(98 174 232 / 0.35);

        --ok: #4fd1a5;
        --ok-bg: #12332a;
        --miss: #ff8f83;
        --miss-bg: #3b1c1a;
        --unknown: #f2bd5c;
        --unknown-bg: #36290f;

        --shadow: none;
    }
}

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

[hidden] {
    display: none !important;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.9375rem;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}

h1 { font-size: 1.375rem; line-height: 1.25; }
h2 { font-size: 1.125rem; line-height: 1.3; }
h3 { font-size: 0.875rem; margin-bottom: 0.5rem; }
code { font-family: var(--mono); font-size: 0.9em; }
sup, sub { font-size: 0.7em; line-height: 0; }
.muted { color: var(--muted); }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Header ------------------------------------------------------------------ */
.header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    color: inherit;
    text-decoration: none;
}

.brand-name { font-weight: 700; font-size: 1.0625rem; }
.brand-tag { color: var(--muted); font-size: 0.8125rem; margin-left: 0.375rem; }

/* The logo is a job: Read, Execute, Write */
.mark {
    display: inline-flex;
    gap: 2px;
    height: 20px;
}

.mark i {
    display: block;
    width: 9px;
    border-radius: 2px;
    background-color: var(--accent);
}

.mark .mark-e { width: 8px; }

.mark .mark-r, .mark .mark-w, .hatch, .swatch-hatched {
    background-image: repeating-linear-gradient(135deg, transparent 0 2px, rgb(255 255 255 / 0.55) 2px 4px);
}

.mark-large { height: 34px; margin-bottom: 0.75rem; }
.mark-large i { width: 15px; }
.mark-large .mark-e { width: 13px; }

.main {
    flex: 1;
    width: 100%;
}

.footer {
    padding: 0.75rem;
    text-align: center;
    font-size: 0.75rem;
    color: var(--muted);
}

/* Workspace: settings on the left, result on the right -------------------- */
.workspace {
    display: grid;
    grid-template-columns: 400px minmax(0, 1fr);
    gap: 1.25rem;
    max-width: 1680px;
    margin: 0 auto;
    padding: 1.25rem;
    align-items: start;
}

.panel {
    grid-column: 1;
    grid-row: 1;
    position: sticky;
    top: calc(var(--header-height) + 1.25rem);
    max-height: calc(100vh - var(--header-height) - 2.5rem);
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.results {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

.panel-section {
    padding: 1rem 1.125rem;
    border-bottom: 1px solid var(--line);
}

.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
}

.section-title {
    display: block;
    margin-bottom: 0.625rem;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
}

.panel-actions {
    position: sticky;
    bottom: 0;
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1.125rem;
    background: var(--surface);
    border-top: 1px solid var(--line);
    margin-top: -1px;
}

.panel-actions { flex-wrap: wrap; }
.panel-actions .btn-primary { flex: 1; }

.editing {
    flex-basis: 100%;
    font-size: 0.75rem;
    color: var(--muted);
}

/* Fields ------------------------------------------------------------------ */
.field { margin-top: 0.625rem; min-width: 0; }
.field label {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.8125rem;
    font-weight: 500;
}

.field-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}

.field-row .field { flex: 1; margin-top: 0; }

.end-shortcuts {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--muted);
}

.end-shortcuts .btn { width: auto; }

input[type="text"], input[type="number"], input[type="password"], select, textarea {
    width: 100%;
    padding: 0.4375rem 0.625rem;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-small);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus);
}

textarea {
    display: block;
    resize: vertical;
    font-family: var(--mono);
    font-size: 0.8125rem;
}

.hint {
    margin-top: 0.375rem;
    font-size: 0.75rem;
    color: var(--muted);
}

.hint code { color: var(--text); }

.live {
    margin-top: 0.5rem;
    font-family: var(--mono);
    font-size: 0.75rem;
    color: var(--muted);
    white-space: pre-wrap;
}

.live:empty { display: none; }
#priority-group { margin-top: 0.5rem; }
#priority-group + .option-row { margin-top: 0.5rem; }
.live-warning { color: var(--miss); }

.checks {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    margin-top: 0.75rem;
    font-size: 0.8125rem;
}

.checks label {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    cursor: pointer;
}

input[type="checkbox"] { accent-color: var(--accent); }

/* Segmented control: radio buttons, so it works without JavaScript --------- */
.option-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 0.5rem;
    font-size: 0.875rem;
}

.option-row:first-of-type { margin-top: 0; }

.segmented {
    display: inline-flex;
    flex: none;
    padding: 2px;
    background: var(--surface-2);
    border-radius: var(--radius-small);
}

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

.segmented span {
    display: block;
    min-width: 2.5rem;
    padding: 0.1875rem 0.625rem;
    text-align: center;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--muted);
    border-radius: 4px;
    cursor: pointer;
}

.segmented span:hover { color: var(--text); }

.segmented input:checked + span {
    color: var(--on-accent);
    background: var(--accent);
}

.segmented input:focus-visible + span {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.phase {
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    margin-right: 0.25rem;
    line-height: 1.25rem;
    text-align: center;
    font-size: 0.6875rem;
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 4px;
    background-image: repeating-linear-gradient(135deg, transparent 0 2px, var(--surface-2) 2px 4px);
}

.phase-solid { background: var(--surface-2); }

/* Task editor ------------------------------------------------------------- */
.task-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 3px;
    table-layout: fixed;
}

.task-table th {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--muted);
    text-align: center;
    cursor: help;
}

.task-table th:first-child { width: 2.25rem; }
.task-table th:last-child { width: 1.375rem; }
.task-table td { padding: 0 1px; }

.task-table input[type="text"] {
    padding: 0.25rem 0;
    text-align: center;
    font-family: var(--mono);
    font-size: 0.8125rem;
}

.task-table input[type="text"].is-invalid {
    color: var(--miss);
    border-color: var(--miss);
}

.task-chip {
    display: inline-block;
    min-width: 1.875rem;
    padding: 0 0.25rem;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: #fff;
    border-radius: 4px;
    background: var(--task);
}

.tc-0 { --task: var(--task-0); }
.tc-1 { --task: var(--task-1); }
.tc-2 { --task: var(--task-2); }
.tc-3 { --task: var(--task-3); }
.tc-4 { --task: var(--task-4); }
.tc-5 { --task: var(--task-5); }

.row-remove {
    width: 100%;
    font-size: 1rem;
    line-height: 1;
    color: var(--muted);
    background: none;
    border: none;
    cursor: pointer;
}

.row-remove:hover { color: var(--miss); }

.link-button {
    font: inherit;
    font-size: 0.75rem;
    color: var(--accent);
    background: none;
    border: none;
    cursor: pointer;
}

.link-button:hover { text-decoration: underline; }
#task-add { margin-top: 0.25rem; }

/* Buttons ----------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.4375rem 0.875rem;
    font: inherit;
    font-weight: 500;
    color: var(--text);
    text-decoration: none;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-small);
    cursor: pointer;
}

.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.65; cursor: progress; }

.btn-primary {
    color: var(--on-accent);
    background: var(--accent);
    border-color: var(--accent);
    font-weight: 600;
}

.btn-primary:hover {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
}

.btn-ghost { background: none; }
.btn-small { padding: 0.1875rem 0.625rem; font-size: 0.8125rem; }
.btn-full { width: 100%; margin-top: 0.5rem; }

/* Cards and messages ------------------------------------------------------ */
.card {
    padding: 1rem 1.125rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.alert {
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius-small);
    font-size: 0.875rem;
}

.alert-danger {
    color: var(--miss);
    background: var(--miss-bg);
}

summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
}

details[open] summary { margin-bottom: 0.75rem; }

.alert-info {
    color: var(--muted);
    background: var(--surface-2);
}

/* Tabs: one configuration each, every tab is a link ------------------------ */
.tabs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
}

.tab {
    display: flex;
    align-items: center;
    font-size: 0.875rem;
    background: var(--surface-2);
    border: 1px solid transparent;
    border-radius: var(--radius-small);
}

.tab a {
    padding: 0.25rem 0.625rem;
    color: var(--muted);
    text-decoration: none;
}

.tab a:hover { color: var(--text); }

.tab.is-active {
    background: var(--surface);
    border-color: var(--accent);
}

.tab.is-active a:first-child {
    color: var(--text);
    font-weight: 600;
}

.tab .tab-remove { padding: 0.25rem 0.5rem 0.25rem 0; }
.tab .tab-remove:hover { color: var(--miss); }

.tab-add {
    padding: 0.25rem 0.5rem;
    font-size: 0.8125rem;
    color: var(--accent);
    text-decoration: none;
}

.tab-add:hover { text-decoration: underline; }

.compare-table td a { color: var(--accent); text-decoration: none; }
.compare-title { margin-bottom: 0.375rem; }
.compare-title a { color: inherit; text-decoration: none; }
.compare-title a:hover { color: var(--accent); }
.card > h2 { margin-bottom: 0.25rem; }

/* Verdict ----------------------------------------------------------------- */
.verdict {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0.875rem 1.125rem;
    color: var(--tone);
    background: var(--tone-bg);
    border-radius: var(--radius);
}

.verdict h2 { font-size: 1.25rem; }
.verdict p { color: var(--text); }
.verdict-ok { --tone: var(--ok); --tone-bg: var(--ok-bg); }
.verdict-miss { --tone: var(--miss); --tone-bg: var(--miss-bg); }
.verdict-unknown { --tone: var(--unknown); --tone-bg: var(--unknown-bg); }

.verdict-icon {
    flex: none;
    width: 2.25rem;
    height: 2.25rem;
    line-height: 2.25rem;
    text-align: center;
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--tone-bg);
    background: var(--tone);
    border-radius: 50%;
}

.case-note {
    display: flex;
    flex-wrap: wrap;
    gap: 0 0.625rem;
    font-size: 0.875rem;
}

/* Statistics -------------------------------------------------------------- */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
    gap: 0.5rem;
}

.stat {
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-small);
}

.stat span {
    font-size: 0.75rem;
    color: var(--muted);
}

.stat strong {
    font-family: var(--mono);
    font-size: 1.125rem;
    font-weight: 600;
}

meter {
    width: 100%;
    height: 4px;
    margin-top: 0.25rem;
    appearance: none;
    border: none;
    border-radius: 2px;
    background: var(--surface-2);
}

meter::-webkit-meter-bar { height: 4px; background: var(--surface-2); border: none; border-radius: 2px; }
meter::-webkit-meter-optimum-value { background: var(--accent); }
meter::-webkit-meter-suboptimum-value { background: var(--miss); }
meter::-moz-meter-bar { background: var(--accent); }

/* Figure ------------------------------------------------------------------ */
.figure-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.chips, .figure-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.chip {
    padding: 0.0625rem 0.5rem;
    font-size: 0.75rem;
    color: var(--muted);
    background: var(--surface-2);
    border-radius: 999px;
}

/* The figure has a white background, in dark mode too */
.figure-frame {
    overflow: auto;
    min-height: 120px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius-small);
}

.figure-frame img {
    display: block;
    width: 100%;
    height: auto;
}

.figure-frame a { display: block; cursor: zoom-in; }

.figure-frame.is-loading {
    min-height: 240px;
    background: linear-gradient(100deg, #f1f3f5 30%, #fafbfc 50%, #f1f3f5 70%) 0 0 / 200% 100%;
    animation: shimmer 1.2s linear infinite;
}

@keyframes shimmer {
    to { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .figure-frame.is-loading { animation: none; }
}

/* Viewer: the transform of the image is set by app.js */
.viewer {
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border: none;
    color: var(--text);
    background: var(--surface);
}

.viewer[open] {
    display: flex;
    flex-direction: column;
}

.viewer::backdrop { background: rgb(0 0 0 / 0.6); }

.viewer-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--line);
}

.viewer-level {
    min-width: 3.25rem;
    text-align: center;
    font-family: var(--mono);
    font-size: 0.8125rem;
}

.viewer-hint {
    flex: 1;
    margin-left: 0.5rem;
    font-size: 0.75rem;
    color: var(--muted);
}

#viewer-close { margin-left: auto; }

.viewer-stage {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: #fff;
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.viewer-stage.is-dragging { cursor: grabbing; }

.viewer-stage img {
    position: absolute;
    top: 0;
    left: 0;
    max-width: none;
    transform-origin: 0 0;
    pointer-events: none;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    margin-top: 0.75rem;
    list-style: none;
    font-size: 0.75rem;
    color: var(--muted);
}

.legend li {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.swatch {
    display: block;
    width: 16px;
    height: 12px;
    border-radius: 2px;
}

.swatch-hatched, .swatch-solid { background-color: var(--task-0); }
.swatch-frame { border: 2px solid var(--text); }
.swatch-suspend { width: 4px; background: var(--task-1); }
.swatch-dashed { height: 0; border-top: 2px dashed var(--muted); border-radius: 0; }
.swatch-dotted { height: 0; border-top: 2px dotted var(--task-4); border-radius: 0; }
.swatch-cycle { background: rgb(44 160 44 / 0.2); border-left: 2px solid var(--task-2); border-radius: 0; }

.glyph { font-style: normal; font-weight: 700; }
.glyph-release { color: var(--task-2); }
.glyph-deadline { color: var(--task-3); }

.code-block {
    max-height: 26rem;
    overflow: auto;
    padding: 0.75rem;
    font-family: var(--mono);
    font-size: 0.75rem;
    background: var(--surface-2);
    border-radius: var(--radius-small);
}

#cli { white-space: pre-wrap; word-break: break-word; margin-bottom: 0.5rem; }

.cycle-facts {
    margin-bottom: 0.75rem;
    padding-left: 1.25rem;
    font-size: 0.875rem;
}

.data-table {
    margin-top: 0.75rem;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.data-table th, .data-table td {
    padding: 0.1875rem 0.75rem 0.1875rem 0;
    text-align: left;
    border-bottom: 1px solid var(--line);
}

.data-table th { font-weight: 600; color: var(--muted); }
.slots-table { font-family: var(--mono); font-size: 0.75rem; white-space: nowrap; }
.table-scroll { max-height: 26rem; overflow: auto; }
.differs { color: var(--miss); font-weight: 600; }
.same { color: var(--ok); font-weight: 600; }
.cell-differs { color: var(--miss); background: var(--miss-bg); }
.nested { margin-top: 0.75rem; }

.event-list {
    padding-left: 1.25rem;
    font-size: 0.875rem;
}

/* Empty state ------------------------------------------------------------- */
.empty { padding: 2rem; text-align: center; }
.empty p { max-width: 34rem; margin: 0.25rem auto 0; }

.empty-schedule {
    display: inline-flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 1.25rem;
}

.empty-schedule div { display: flex; gap: 2px; }

.empty-schedule i {
    display: block;
    width: 22px;
    height: 20px;
    border-radius: 2px;
}

.empty-schedule .wide { width: 34px; }
.empty-schedule .blk { background-color: var(--task); }
.empty-schedule .gap { background: var(--surface-2); }

.featured {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.625rem;
    margin-top: 1.25rem;
    text-align: left;
}

.featured-item {
    display: flex;
    flex-direction: column;
    padding: 0.625rem 0.75rem;
    color: inherit;
    text-decoration: none;
    border: 1px solid var(--line);
    border-radius: var(--radius-small);
}

.featured-item:hover { border-color: var(--accent); }
.featured-item strong { font-size: 0.875rem; }

.featured-item span {
    display: -webkit-box;
    overflow: hidden;
    font-size: 0.75rem;
    color: var(--muted);
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
}

/* Reference --------------------------------------------------------------- */
.reference-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem 1.5rem;
    font-size: 0.8125rem;
}

dl {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.125rem 0.625rem;
}

dt { font-weight: 600; }
dd { color: var(--muted); }

/* Login and error pages --------------------------------------------------- */
.center-page {
    display: flex;
    justify-content: center;
    padding: 12vh 1rem 2rem;
}

.center-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    max-width: 360px;
    padding: 2rem;
    text-align: center;
}

.center-card form { width: 100%; margin-top: 0.5rem; text-align: left; gap: 0.5rem; }
.center-card .alert { width: 100%; }

.error-code {
    font-family: var(--mono);
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--muted);
}

/* Narrow screens: the result comes first, then the settings --------------- */
@media (max-width: 1000px) {
    .workspace {
        grid-template-columns: minmax(0, 1fr);
        padding: 0.75rem;
    }

    .panel, .results { grid-column: 1; grid-row: auto; }
    .panel { position: static; max-height: none; }
    .results .empty, .brand-tag, .viewer-hint { display: none; }
    .figure-frame img { width: auto; max-width: none; height: 300px; }
}

@media print {
    .header, .footer, .panel, .figure-actions, .reference { display: none !important; }
    .workspace { display: block; padding: 0; }
    .card { border: none; box-shadow: none; }
}
