/*
 * GE BrightSpeed / LightSpeed console emulation.
 *
 * The original is an X11/Motif application on a fixed 1280x1024 CRT. Everything is drawn inside a
 * fixed-size surface that is scaled to the browser window, rather than reflowing, because the
 * layout is positional and reflowing it would stop looking like the console.
 *
 * Colours are sampled from photographs of a running console and corrected for the camera cast.
 * See docs/research/research_ui.md.
 */

:root {
    --console-w: 1280px;
    --console-h: 1024px;

    --bg-window: #6e7c99;
    --bg-panel: #b8bcc6;
    --bg-panel-dark: #96a0b2;
    --bg-top-panel: #e6ded0;
    --bg-figure: #aeb4c0;
    --border-figure: #f2edc0;

    --bg-grid-header: #8797b0;
    --bg-grid-cell: #f1efe3;
    --bg-grid-body: #4e5e78;
    --bg-tabband: #141c38;

    --bg-desktop: #25314c;
    --desktop-divider: #e7dcc6;
    --bg-icon-tile: #e6cfa0;

    --bg-list-row: #efece0;
    --bg-list-row-selected: #e8dca0;
    --bg-tab-selected: #e4dcc8;
    --bg-tab: #96a0b0;

    --accent-yellow: #f0e7a6;
    --accent-red: #d9685c;

    --text: #10131a;
    --text-light: #e8e8ea;
    --text-disabled: #6a7080;

    --bevel-light: rgba(255, 255, 255, 0.75);
    --bevel-dark: rgba(0, 0, 0, 0.45);

    --font-chrome: "Helvetica Neue", Helvetica, Arial, sans-serif;
    --font-data: "DejaVu Sans Mono", "Liberation Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: #0b0d12;
    font-family: var(--font-chrome);
    color: var(--text);
    height: 100%;
    overflow: hidden;
}

/* The console surface: fixed pixel geometry, scaled to fit whatever window it is viewed in. */
.console-viewport {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
}

.console-screen {
    position: relative;
    width: var(--console-w);
    height: var(--console-h);
    background: linear-gradient(100deg, #64718c 0%, var(--bg-window) 55%, #74829e 100%);
    transform-origin: center center;
    flex: 0 0 auto;
    overflow: hidden;
    -webkit-font-smoothing: none;
    font-smooth: never;
}

/* ---------- Motif primitives ---------- */

.mo-raised {
    border-top: 2px solid var(--bevel-light);
    border-left: 2px solid var(--bevel-light);
    border-right: 2px solid var(--bevel-dark);
    border-bottom: 2px solid var(--bevel-dark);
    border-radius: 0;
}

.mo-sunken {
    border-top: 2px solid var(--bevel-dark);
    border-left: 2px solid var(--bevel-dark);
    border-right: 2px solid var(--bevel-light);
    border-bottom: 2px solid var(--bevel-light);
    border-radius: 0;
}

.mo-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: var(--bg-panel-dark);
    color: var(--text);
    font-family: var(--font-chrome);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.15;
    padding: 3px 8px;
    cursor: pointer;
    text-decoration: none;
    user-select: none;

    border-top: 2px solid var(--bevel-light);
    border-left: 2px solid var(--bevel-light);
    border-right: 2px solid var(--bevel-dark);
    border-bottom: 2px solid var(--bevel-dark);
}

.mo-btn:active:not(.is-disabled) {
    border-top-color: var(--bevel-dark);
    border-left-color: var(--bevel-dark);
    border-right-color: var(--bevel-light);
    border-bottom-color: var(--bevel-light);
}

/* Motif keeps the full bevel on an insensitive widget and greys only the label. */
.mo-btn.is-disabled {
    color: var(--text-disabled);
    text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.5);
    cursor: default;
    pointer-events: none;
}

.mo-btn.is-yellow { background: var(--accent-yellow); }
.mo-btn.is-red { background: var(--accent-red); }
.mo-btn.is-active { background: var(--bg-tab-selected); }

/* ---------- Desktop chrome ---------- */

.status-bar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 104px;
    height: 22px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 10px;
    background: var(--bg-panel);
    border-top: 2px solid var(--bevel-dark);
    border-bottom: 2px solid var(--bevel-light);
    font-size: 12px;
}

.status-bar .clock { font-family: var(--font-data); font-weight: 700; }
.status-bar .message { flex: 1; }

.desktop-bar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 104px;
    background: var(--bg-desktop);
    border-top: 10px solid var(--desktop-divider);
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 4px 20px 0;
}

.desktop-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-decoration: none;
    cursor: pointer;
}

.desktop-icon .tile {
    width: 64px;
    height: 46px;
    background: var(--bg-icon-tile);
    border: 1px solid #7a6a45;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.desktop-icon .tile svg { width: 100%; height: 100%; }

.desktop-icon .caption {
    font-size: 10px;
    color: #b9c0cf;
    letter-spacing: 0.2px;
}

.desktop-icon.is-current .caption { color: #fff; font-weight: 700; }
.desktop-icon.is-current .tile { box-shadow: 0 0 0 2px #f0e7a6; }

/* ---------- Protocol Management ---------- */

.pm-heading {
    position: absolute;
    font-size: 15px;
    font-weight: 700;
    color: #161a22;
}

.source-tabs {
    position: absolute;
    display: flex;
    gap: 2px;
}

.source-tab {
    background: var(--bg-tab);
    padding: 2px 12px;
    font-size: 11px;
    font-weight: 700;
    color: #1a1d24;
    border-top: 2px solid var(--bevel-light);
    border-left: 2px solid var(--bevel-light);
    border-right: 2px solid var(--bevel-dark);
    border-bottom: none;
    cursor: default;
}

.source-tab.is-selected { background: var(--bg-tab-selected); }

.figure-panel {
    position: absolute;
    background: var(--bg-figure);
    border: 3px solid var(--border-figure);
}

.figure-panel svg { width: 100%; height: 100%; display: block; }

.region-hit {
    fill: transparent;
    cursor: pointer;
    stroke: transparent;
    stroke-width: 1;
}

.region-hit:hover { fill: rgba(255, 255, 200, 0.35); stroke: #2b2f3a; }

.leader-line { stroke: #1d2029; stroke-width: 1; }

.default-buttons {
    position: absolute;
    display: flex;
    flex-direction: column;
}

.default-button {
    height: 26px;
    background: var(--bg-panel-dark);
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    padding: 0 6px;
    white-space: nowrap;
    overflow: hidden;      /* the console hard-clips these labels, with no ellipsis */
    text-overflow: clip;
    text-decoration: none;
    cursor: pointer;

    border-top: 2px solid var(--bevel-light);
    border-left: 2px solid var(--bevel-light);
    border-right: 2px solid var(--bevel-dark);
    border-bottom: 2px solid var(--bevel-dark);
}

.pediatric-button {
    position: absolute;
    width: 42px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-panel-dark);
    font-size: 12px;
    font-weight: 700;
    line-height: 15px;
    letter-spacing: 0;
    text-decoration: none;
    color: var(--text);
    cursor: pointer;

    border-top: 2px solid var(--bevel-light);
    border-left: 2px solid var(--bevel-light);
    border-right: 2px solid var(--bevel-dark);
    border-bottom: 2px solid var(--bevel-dark);
}

/* ---------- Protocol list panel ---------- */

.list-panel {
    position: absolute;
    background: var(--bg-panel);
    padding: 10px 14px 14px;
    z-index: 20;

    border-top: 2px solid var(--bevel-light);
    border-left: 2px solid var(--bevel-light);
    border-right: 2px solid var(--bevel-dark);
    border-bottom: 2px solid var(--bevel-dark);
}

.list-panel .panel-title {
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 6px;
}

.list-panel .panel-subtitle { font-size: 11px; font-weight: 700; margin-bottom: 3px; }

.protocol-list {
    background: var(--bg-list-row);
    border-top: 2px solid var(--bevel-dark);
    border-left: 2px solid var(--bevel-dark);
    border-right: 2px solid var(--bevel-light);
    border-bottom: 2px solid var(--bevel-light);
}

.protocol-row {
    display: flex;
    align-items: stretch;
    height: 22px;
    text-decoration: none;
    color: var(--text);
}

.protocol-row .slot {
    width: 58px;
    flex: 0 0 58px;
    text-align: right;
    padding-right: 8px;
    font-family: var(--font-data);
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    color: #23262e;
}

.protocol-row .name {
    flex: 1;
    background: var(--bg-list-row);
    border-bottom: 1px solid #b6b2a4;
    font-family: var(--font-data);
    font-size: 13px;
    display: flex;
    align-items: center;
    padding: 0 6px;
    white-space: nowrap;
    overflow: hidden;
}

.protocol-row:not(.is-empty) .name:hover { background: #f7f4e6; }
.protocol-row.is-selected .name { background: var(--bg-list-row-selected); }
.protocol-row.is-default .slot::after { content: " *"; }

.panel-buttons { display: flex; gap: 8px; margin-top: 12px; }
.panel-buttons .mo-btn { min-width: 78px; }

.pager { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.pager .triangle { font-size: 17px; line-height: 15px; color: #1b1e26; }
.pager .triangle.is-disabled { color: #98a0b0; }
.pager .caption { font-size: 11px; font-weight: 700; }

/* ---------- Pediatric colour bands ---------- */

.color-bands { display: grid; grid-template-columns: repeat(3, 150px); gap: 8px; margin-top: 8px; }

.color-band {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    background: var(--bg-panel-dark);
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
    color: var(--text);

    border-top: 2px solid var(--bevel-light);
    border-left: 2px solid var(--bevel-light);
    border-right: 2px solid var(--bevel-dark);
    border-bottom: 2px solid var(--bevel-dark);
}

.color-band .swatch { width: 18px; height: 18px; border: 1px solid #333; flex: 0 0 18px; }
.color-band.is-empty { color: var(--text-disabled); }

/* ---------- ViewEdit ---------- */

.ve-header {
    position: absolute;
    top: 6px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 60px;
    font-size: 14px;
    font-weight: 700;
}

.ve-top {
    position: absolute;
    top: 26px;
    left: 0;
    right: 0;
    height: 220px;
    background: var(--bg-top-panel);
    display: flex;
    padding: 8px 10px;
    gap: 14px;
}

.patient-graphic {
    width: 250px;
    height: 130px;
    flex: 0 0 250px;
    background: #cfd3d8;
    border: 1px solid #9aa0aa;
}

.patient-graphic svg { width: 100%; height: 100%; }

.ve-fields { display: flex; gap: 24px; flex: 1; font-size: 12px; }
.ve-field-label { font-weight: 700; }
.ve-field-value { font-family: var(--font-data); }

.dose-panel {
    width: 400px;
    flex: 0 0 400px;
    font-size: 11px;
}

.dose-panel .dose-title { text-align: center; font-weight: 700; font-size: 13px; }
.dose-panel table { width: 100%; border-collapse: collapse; }
.dose-panel th { font-weight: 700; font-size: 10px; text-align: center; padding: 1px 2px; }
.dose-panel td { font-family: var(--font-data); font-size: 11px; text-align: center; padding: 1px 2px; }
.dose-summary { margin-top: 4px; }
.dose-summary div { display: flex; justify-content: flex-end; gap: 8px; }
.dose-summary .value { font-family: var(--font-data); min-width: 74px; text-align: right; }

.tab-band {
    position: absolute;
    top: 246px;
    left: 0;
    right: 0;
    height: 62px;
    background: var(--bg-tabband);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
}

.tab-band .spacer { flex: 1; }

.icon-tab {
    width: 74px;
    height: 58px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-panel-dark);
    border-top: 2px solid var(--bevel-light);
    border-left: 2px solid var(--bevel-light);
    border-right: 2px solid var(--bevel-dark);
    border-bottom: none;
    cursor: pointer;
}

.icon-tab.is-selected { background: var(--bg-grid-header); box-shadow: 0 3px 0 var(--bg-grid-header); }
.icon-tab svg { width: 56px; height: 44px; }

.grid-area {
    position: absolute;
    top: 308px;
    left: 0;
    right: 0;
    bottom: 214px;
    background: var(--bg-grid-body);
    overflow: auto;
}

table.param-grid { border-collapse: collapse; }

table.param-grid th {
    background: var(--bg-grid-header);
    color: var(--text);
    font-size: 10px;
    font-weight: 700;
    line-height: 11px;
    padding: 3px 2px;
    text-align: center;
    vertical-align: middle;
    min-width: 46px;

    border-top: 2px solid var(--bevel-light);
    border-left: 2px solid var(--bevel-light);
    border-right: 2px solid var(--bevel-dark);
    border-bottom: 2px solid var(--bevel-dark);
}

table.param-grid td {
    background: var(--bg-grid-cell);
    font-family: var(--font-data);
    font-size: 11px;
    line-height: 12px;
    text-align: center;
    padding: 3px 3px;
    vertical-align: middle;
    white-space: pre-line;

    border-top: 2px solid var(--bevel-dark);
    border-left: 2px solid var(--bevel-dark);
    border-right: 2px solid var(--bevel-light);
    border-bottom: 2px solid var(--bevel-light);
}

table.param-grid td.is-disabled {
    background: var(--bg-panel-dark);
    color: var(--text-disabled);
    text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.45);
}

table.param-grid td.row-label { background: var(--accent-yellow); font-weight: 700; }

.ve-buttons {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 126px;
    height: 88px;
    padding: 6px 10px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    background: transparent;
}

.ve-buttons .mo-btn { width: 78px; height: 44px; }

/* ---------- Login and admin ---------- */

.login-panel {
    position: absolute;
    top: 300px;
    left: 50%;
    transform: translateX(-50%);
    width: 420px;
    background: var(--bg-panel);
    padding: 18px 22px 22px;

    border-top: 2px solid var(--bevel-light);
    border-left: 2px solid var(--bevel-light);
    border-right: 2px solid var(--bevel-dark);
    border-bottom: 2px solid var(--bevel-dark);
}

.login-panel h1 { font-size: 16px; margin: 0 0 4px; }
.login-panel .subtitle { font-size: 12px; margin-bottom: 14px; color: #2b2f38; }
.login-panel label { display: block; font-size: 12px; font-weight: 700; margin: 10px 0 3px; }

.login-panel input[type="text"],
.login-panel input[type="password"] {
    width: 100%;
    font-family: var(--font-data);
    font-size: 14px;
    padding: 4px 6px;
    background: var(--bg-list-row);
    border-top: 2px solid var(--bevel-dark);
    border-left: 2px solid var(--bevel-dark);
    border-right: 2px solid var(--bevel-light);
    border-bottom: 2px solid var(--bevel-light);
}

.form-error { background: var(--accent-red); color: #1a0f0f; font-size: 12px; padding: 5px 8px; margin-top: 10px; }
.form-note { font-size: 12px; margin-top: 10px; }

/* Admin pages step out of the emulation deliberately: they are ours, not GE's. */
.admin-page {
    position: absolute;
    inset: 0 0 126px 0;
    overflow: auto;
    background: #eef0f4;
    padding: 22px 28px;
    font-family: var(--font-chrome);
}

.admin-page h1 { font-size: 20px; margin: 0 0 4px; }
.admin-page .lede { color: #444b58; font-size: 13px; margin-bottom: 18px; }
.admin-page table { border-collapse: collapse; width: 100%; background: #fff; font-size: 13px; }
.admin-page th, .admin-page td { border: 1px solid #c8ccd4; padding: 6px 9px; text-align: left; }
.admin-page th { background: #dfe3ea; }
.admin-page .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.admin-page input, .admin-page select {
    font-size: 13px; padding: 4px 6px; border: 1px solid #aab0bb; background: #fff;
}
.admin-page .field { margin-bottom: 12px; max-width: 420px; }
.admin-page .field label { display: block; font-weight: 700; font-size: 12px; margin-bottom: 3px; }
.admin-page .flash { background: #d8ecd8; border: 1px solid #6f9f6f; padding: 8px 10px; margin-bottom: 14px; }
.admin-page .flash.is-error { background: #f5d9d6; border-color: #b06a60; }

/* ---------- Worksheet (print view) ---------- */

.worksheet {
    position: absolute;
    inset: 0 0 126px 0;
    overflow: auto;
    background: #fff;
    color: #111;
    padding: 26px 32px;
    font-family: var(--font-chrome);
    font-size: 12px;
}

.worksheet h1 { font-size: 19px; margin: 0 0 2px; }
.worksheet h2 { font-size: 14px; margin: 18px 0 6px; border-bottom: 1px solid #999; padding-bottom: 2px; }
.worksheet h3 { font-size: 12.5px; margin: 12px 0 4px; }
.worksheet table { border-collapse: collapse; width: 100%; margin-bottom: 8px; }
.worksheet th, .worksheet td { border: 1px solid #999; padding: 3px 5px; text-align: left; }
.worksheet th { background: #eceff3; font-size: 11px; }
.worksheet td { font-family: var(--font-data); font-size: 11px; }
.worksheet .meta { color: #444; margin-bottom: 10px; }
.worksheet .no-print { margin-bottom: 16px; }

@media print {
    html, body { overflow: visible; background: #fff; height: auto; }
    .console-viewport { position: static; display: block; overflow: visible; }
    .console-screen { width: auto; height: auto; transform: none !important; background: #fff; }
    .worksheet { position: static; inset: auto; padding: 0; overflow: visible; }
    .status-bar, .desktop-bar, .no-print { display: none !important; }
    .worksheet h2 { break-after: avoid; }
    .worksheet table { break-inside: auto; }
    .worksheet tr { break-inside: avoid; }
}

/* One-time sign-in code, shown once after creating a user or resetting a password. */
.admin-page .claim-code {
    background: #fff8dc;
    border: 2px solid #b9962f;
    padding: 14px 18px;
    margin-bottom: 18px;
    max-width: 620px;
}

.admin-page .claim-code h2 { font-size: 15px; margin: 0 0 6px; }
.admin-page .claim-code p { margin: 0 0 8px; font-size: 13px; }

.admin-page .claim-code .code {
    font-family: var(--font-data);
    font-size: 30px;
    font-weight: 700;
    letter-spacing: 3px;
    background: #fff;
    border: 1px solid #b9962f;
    padding: 10px 14px;
    text-align: center;
    user-select: all;
}

.admin-page .claim-code .expiry { margin-top: 8px; font-size: 12px; color: #5a4a12; }

/* Live match feedback on the set-password screen, where both boxes are shown as plain text. */
.login-panel .password-match {
    font-size: 12px;
    font-weight: 700;
    margin-top: 8px;
    min-height: 16px;
}

.login-panel .password-match.is-match { color: #17600f; }
.login-panel .password-match.is-mismatch { color: #8c1d12; }
