/* ELUSK / ESA — shared design system.
 * 4px spacing scale, warm neutral surfaces, blue interaction, semantic alerts.
 * Device controls use the same components as the organizational workspace. */
:root {
    color-scheme: dark;
    --page: #171614;
    --sidebar: #1c1b19;
    --surface: #22211f;
    --surface-accent: #2b2926;
    --surface-hover: #34312e;
    --field: #191816;
    --text: #f5f3ef;
    --muted: #b6b1a9;
    --line: #393632;
    --line-strong: #726c64;
    --accent: #9abfff;
    --primary: #2c5eaf;
    --primary-hover: #376dc4;
    --primary-ink: #fff;
    --selection: #202f48;
    --selection-line: #385784;
    --danger: #ffc0af;
    --danger-surface: #492824;
    --danger-line: #8d5348;
    --radius: 12px;
    --control-radius: 7px;
    --space-1: .25rem;
    --space-2: .5rem;
    --space-3: .75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --header-height: 72px;
    --left-width: 208px;
    --right-width: 260px;
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--page);
    color: var(--text);
    accent-color: var(--accent);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; font-size: .9375rem; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.65rem,2.4vw,2.25rem); font-weight: 650; line-height: 1.17; letter-spacing: -.035em; overflow-wrap: anywhere; }
h2 { font-size: 1.0625rem; line-height: 1.35; font-weight: 650; overflow-wrap: anywhere; }
h3 { font-size: .9375rem; line-height: 1.45; font-weight: 650; }
a { color: var(--accent); text-underline-offset: .2em; }
a, button, input, select, textarea, summary { outline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); }
button, select, input, textarea { font: inherit; color: inherit; min-width: 0; max-width: 100%; }
button, select, input:not([type=radio]):not([type=checkbox]), textarea {
    border: 1px solid var(--line-strong);
    border-radius: var(--control-radius);
    background: var(--field);
    min-height: 38px;
    padding: .5rem .75rem;
}
textarea { width: 100%; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
input:not([type=radio]):not([type=checkbox]):focus, select:focus, textarea:focus { border-color: var(--accent); }
button {
    cursor: pointer;
    background: var(--surface-accent);
    font-weight: 570;
    line-height: 1.35;
    overflow-wrap: anywhere;
    transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
button:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--accent); }
button:active:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .48; cursor: default; }
label { display: flex; flex-direction: column; min-width: 0; gap: .375rem; color: var(--muted); font-size: .875rem; }
label > input:not([type=number]):not([type=radio]):not([type=checkbox]), label > select { width: 100%; }
input[type=number] { width: 6rem; font-variant-numeric: tabular-nums; }
input[type=file] { min-width: 0; max-width: 100%; }
input::file-selector-button { font: inherit; color: var(--text); background: var(--surface-accent); border: 1px solid var(--line-strong); border-radius: 4px; padding: .25rem .5rem; margin-right: .5rem; }
small, .muted { color: var(--muted); }
small { font-size: .8125rem; }
.primary { color: var(--primary-ink); background: var(--primary); border-color: transparent; }
.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--accent); }
.quiet { background: transparent; border-color: var(--line); }
.danger { background: var(--danger-surface); color: var(--danger); border-color: var(--danger-line); }
.danger-outline { color: var(--danger); background: transparent; border-color: var(--danger-line); }
.danger:hover:not(:disabled), .danger-outline:hover:not(:disabled) { background: var(--danger-surface); border-color: var(--danger); }

/* Application frame */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 20;
    width: 100%;
    height: var(--header-height);
    padding: .75rem clamp(1rem,2vw,1.75rem);
    gap: 1rem;
    background: var(--sidebar);
    border-bottom: 1px solid var(--line);
}
.brand, .topbar-end { display: flex; align-items: center; min-width: 0; gap: .75rem; }
.brand { flex: 0 0 auto; font-size: 1.375rem; letter-spacing: .075em; font-weight: 700; }
.lab-logo { display:block; width: 42px; height: 42px; padding: 4px; border-radius: 50%; object-fit: contain; background: #f5f3ef; }
.topbar-end { margin-left: auto; justify-content: flex-end; text-align: right; }
.status-tag {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    width: fit-content;
    max-width: 100%;
    padding: .25rem .625rem;
    border-radius: 6px;
    border: 1px solid var(--selection-line);
    background: var(--selection);
    color: var(--accent);
    font-size: .8125rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
    font-variant-numeric: tabular-nums;
}
#status { font-size: .75rem; text-align: right; }
#status::before { content:''; width: 6px; height: 6px; border-radius: 50%; flex: 0 0 6px; background: currentColor; }
.status-tag[data-online="false"] { color: var(--muted); background: var(--surface-accent); border-color: var(--line); }
.top-user { display: grid; min-width: 0; gap: .25rem; line-height: 1.4; overflow-wrap: anywhere; }
.top-user strong { font-size: 1rem; font-weight: 650; }
.shell {
    display: grid;
    grid-template-columns: var(--left-width) minmax(0,1fr) var(--right-width);
    min-height: calc(100dvh - var(--header-height));
    width: 100%;
}
.shell:not(.signed-in) { display: block; }
.sidebar {
    min-width: 0;
    height: calc(100dvh - var(--header-height));
    position: sticky;
    top: var(--header-height);
    align-self: start;
    overflow-y: auto;
    scrollbar-width: thin;
    padding: 1.5rem .875rem 1rem;
    background: var(--sidebar);
}
.sidebar-system { border-right: 1px solid var(--line); }
.sidebar-user { border-left: 1px solid var(--line); display:flex; flex-direction:column; gap: .75rem; }
.sidebar h2 { margin: 0 .625rem .5rem; color: var(--muted); font-size: .75rem; font-weight: 650; letter-spacing: .065em; text-transform: uppercase; }
.sidebar nav { display: grid; min-width: 0; gap: .25rem; }
.sidebar button { width: 100%; min-height: 40px; padding: .625rem .75rem; text-align: left; background: transparent; border-color: transparent; font-size: .875rem; }
.sidebar button:hover:not(:disabled) { background: var(--surface-accent); border-color: var(--line); }
.sidebar button[aria-current="page"] { color: var(--accent); background: var(--selection); border-color: var(--selection-line); box-shadow: inset 3px 0 var(--accent); }
.sidebar .pse-title { border-top: 1px solid var(--line); padding-top: 1.25rem; margin-top: 1.25rem; }
.sidebar .work-navigation { margin: 0; padding: 0; border: 0; }
.work-navigation .work-kind { text-transform: none; letter-spacing: 0; }
.sidebar-user .top-user { background: var(--surface); padding: .875rem; border: 1px solid var(--line); border-radius: var(--radius); }
.sidebar-user #user-title { margin-top: .5rem; margin-bottom: -.25rem; }
.sidebar-footer { margin-top: auto; padding-top: .75rem; border-top: 1px solid var(--line); }
.sidebar-footer button { text-align: right; color: var(--muted); }
main { min-width: 0; width: 100%; padding: 2rem clamp(1rem,2.5vw,2.5rem) 3rem; }
main > section { max-width: 1240px; margin-inline: auto; }
.view-head { margin: 0 0 1.5rem; }
.view-head > div { min-width: 0; }
.view-head p { margin-top: .375rem; }
.split { display: flex; justify-content: space-between; align-items: center; gap: .75rem 1rem; flex-wrap: wrap; }
.view-head.split { align-items: flex-start; }
.login-view { width: min(100%, 430px); margin: clamp(1rem,9vh,6rem) auto; }
.login-view > .card { padding: clamp(1.25rem,3vw,2rem); }
.login-view h1 { margin-bottom: 1.25rem; }
.login-view input { width: 100%; }
#toggle-register { margin-top: .75rem; width: 100%; }

/* Reusable cards, controls and tables */
.card { min-width: 0; padding: var(--space-5); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-wrap: anywhere; }
.card-head { margin-bottom: 1rem; }
.card-head p { margin-top: .375rem; }
.stack, .cards, .console-grid { display:grid; gap:var(--space-4); align-items:start; min-width:0; }
.cards { grid-template-columns: repeat(auto-fit,minmax(min(100%,225px),1fr)); }
.overview-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(min(100%,170px),1fr)); gap: .875rem; }
.metric-card { display:grid; gap: .5rem; }
.metric-card strong { font-size: 1.375rem; font-weight: 650; font-variant-numeric: tabular-nums; }
#overview > .card { margin-top: 1rem; }
.table-wrap { overflow-x:auto; min-width:0; }
table { width:100%; border-collapse:collapse; font-variant-numeric:tabular-nums; }
th, td { padding:.625rem .5rem; text-align:left; border-bottom:1px solid var(--line); vertical-align:middle; }
th:first-child, td:first-child { padding-left:0; }
th:last-child, td:last-child { padding-right:0; }
th { color:var(--muted); font-size:.8125rem; font-weight:600; }
tbody tr:last-child td { border-bottom:0; }
.actions, .inline-form { display:flex; align-items:end; gap:var(--space-2); flex-wrap:wrap; min-width:0; }
.actions > *, .inline-form > * { min-width:0; }
.inline-form label { max-width:100%; }
.tabs { display:flex; flex-wrap:wrap; align-items:end; gap:.25rem; border-bottom:1px solid var(--line); margin-bottom:1.25rem; }
.tabs button { border:1px solid transparent; border-bottom:2px solid transparent; background:transparent; color:var(--muted); border-radius:var(--control-radius) var(--control-radius) 0 0; margin-bottom:-1px; }
.tabs button:hover:not(:disabled) { background:var(--surface); color:var(--text); border-color:transparent; }
.tabs button[aria-selected="true"] { color:var(--accent); background:var(--surface); border-color:var(--line); border-bottom-color:var(--accent); }
.console-grid { grid-template-columns:repeat(auto-fit,minmax(min(100%,420px),1fr)); }
.console-wide { grid-column:1 / -1; }
.file-title { overflow-wrap:anywhere; font-weight:600; }
.progress-row { display:flex; align-items:center; gap:.75rem; margin-top:.625rem; font-variant-numeric:tabular-nums; }
progress { width:100%; height:8px; border:0; border-radius:8px; accent-color:var(--accent); }
progress::-webkit-progress-bar { background:var(--field); border-radius:8px; }
progress::-webkit-progress-value { background:var(--primary-hover); border-radius:8px; }
progress::-moz-progress-bar { background:var(--primary-hover); border-radius:8px; }
#job-time { min-height:1.5em; margin:.375rem 0 .75rem; }
.camera-card img { display:block; width:100%; height:auto; border-radius:var(--control-radius); background:var(--field); }
.feedback { color:var(--muted); margin:.625rem 0; font-size:.875rem; overflow-wrap:anywhere; }
.feedback:empty { display:none; }
.feedback.error { color:var(--danger); }
#fan-form, #aux-fans:not(:empty), #mesh-form { margin-top:1rem; }
.heater-table .inline-form { gap:.375rem; flex-wrap:nowrap; }
.heater-table input[type=number] { width:5.25rem; }
.heater-table th:nth-child(2), .heater-table td:nth-child(2) { white-space:nowrap; }
.jog-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); max-width:230px; gap:.5rem; margin:.875rem 0; }
.tuning-grid, .form-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); align-items:end; gap:1rem; }
.form-grid button { justify-self:start; }
#files .card + .card { margin-top:1rem; }
#filelist p { display:flex; align-items:center; gap:.625rem; padding:.5rem 0; border-top:1px solid var(--line); }
#filelist small { min-width:4rem; text-align:right; }
.file-name { flex:1; text-align:left; min-width:0; overflow-wrap:anywhere; }
.file-name[aria-pressed=true] { border-color:var(--accent); color:var(--accent); background:var(--selection); }
#filetext { width:100%; height:45vh; padding:1rem; overflow:auto; resize:vertical; white-space:pre; font:14px/1.6 ui-monospace,monospace; tab-size:4; background:var(--field); border:1px solid var(--line-strong); border-radius:var(--control-radius); }
#savebar { position:sticky; bottom:0; padding:.75rem 0 .25rem; background:var(--surface); }
#file-filter-label, #model-create { margin-bottom:1rem; }
#gcode-upload { margin-top:1rem; }
summary { cursor:pointer; width:fit-content; color:var(--accent); font-weight:600; }
details[open] > summary { margin-bottom:.75rem; }
details form { margin-top:.75rem; }
.model-card { display:grid; gap:.875rem; }
.model-source, .variant-path { overflow-wrap:anywhere; }
.variant-path { color:var(--muted); font-size:.8125rem; }
.variant-list { display:grid; gap:.5rem; }
.variant { border-top:1px solid var(--line); border-left:2px solid var(--line-strong); padding:.75rem 0 .25rem .75rem; display:flex; flex-wrap:wrap; justify-content:space-between; align-items:start; gap:.625rem; }
.variant[data-approved="true"] { border-left-color:var(--accent); }
.variant[data-archived="true"] { border-left-color:var(--muted); }
.variant-details { flex:1 1 185px; min-width:0; }
.variant-actions { display:flex; flex-wrap:wrap; align-items:start; gap:.5rem; }
.variant-status { color:var(--muted); font-size:.8125rem; }
#journal .card { padding-block:.875rem; }
#journal .card p { overflow-wrap:anywhere; }

/* Equipment and breadcrumbs */
.device-layout { display:block; }
#devices #cards { display:grid; grid-template-columns:minmax(0,1fr); gap:1rem; }
.device-group { display:grid; gap:0; padding-block:1.125rem .375rem; }
.device-group h2 { color:var(--text); margin-bottom:.875rem; }
.device-list-row { display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:.75rem; padding:.875rem 0; border-top:1px solid var(--line); }
.device-list-row > div { display:grid; min-width:0; flex:1; gap:.25rem; overflow-wrap:anywhere; }
.device-list-row strong { font-size:.9375rem; font-weight:600; }
.device-list-row button { flex-shrink:0; min-width:6rem; }
.breadcrumbs { display:flex; flex-wrap:wrap; gap:.5rem; align-items:center; color:var(--muted); margin:0 0 1rem; font-size:.8125rem; }
.breadcrumbs:empty, #device-subnodes:empty { display:none; }
.breadcrumbs button { color:var(--accent); background:transparent; padding:.25rem .375rem; min-height:30px; border-color:transparent; text-align:start; font-size:inherit; }
.breadcrumbs > span:not(:empty)::before, .breadcrumbs button + button::before { content:"/"; color:var(--muted); margin-right:.5rem; }
#topology-edit > label { margin-top:.75rem; }
#topology-edit .inline-form { margin-top:1rem; }
#pid-form + .actions { margin-top:1rem; }
.macro-row { display:flex; align-items:center; justify-content:space-between; gap:.75rem; border-top:1px solid var(--line); padding-top:.75rem; }
.macro-row > div { display:grid; min-width:0; overflow-wrap:anywhere; }
.device-log { max-height:18rem; overflow:auto; margin:0; white-space:pre-wrap; overflow-wrap:anywhere; font-size:.875rem; }
.mesh-grid { width:auto; min-width:min(100%,22rem); margin-top:.625rem; border-collapse:separate; border-spacing:3px; }
.mesh-grid td { background:hsl(var(--mesh-hue) 52% 28%); border:0; border-radius:3px; text-align:center; font-size:.8125rem; padding:.5rem; }

/* Personal workspace */
.mini-calendar { margin:.5rem 0 0; padding:.75rem 0 0; border-top:1px solid var(--line); }
.calendar-controls { display:grid; grid-template-columns:1.75rem minmax(0,1fr) 1.75rem; align-items:center; text-align:center; gap:.25rem; }
.calendar-controls strong { font-size:.8125rem; text-transform:capitalize; }
.calendar-controls button { text-align:center; min-height:28px; padding:0; font-size:1.125rem; }
.month-grid { display:grid; grid-template-columns:repeat(7,minmax(0,1fr)); gap:.125rem; margin-top:.375rem; text-align:center; }
.month-grid small { font-size:.6875rem; }
.month-grid button { min-height:28px; text-align:center; padding:0; font-size:.75rem; position:relative; }
.month-grid button[aria-current="date"] { border-color:var(--selection-line); color:var(--accent); }
.month-grid button[aria-pressed="true"] { background:var(--primary); color:var(--primary-ink); }
.month-grid button[data-event="true"]::after { content:""; position:absolute; inset:auto auto 2px calc(50% - 1.5px); width:3px; height:3px; border-radius:50%; background:currentColor; }
.month-preview { display:grid; gap:.375rem; margin-top:.5rem; }
.month-preview small { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.calendar-form { margin-top:1rem; }
#day-events p { white-space:pre-wrap; overflow-wrap:anywhere; }
.user-card { display:flex; align-items:center; gap:.75rem 1rem; flex-wrap:wrap; justify-content:space-between; overflow-wrap:anywhere; }
#users-more { margin-top:.75rem; }
#personal-task-preview { margin-top:.5rem; gap:.5rem; max-height:45vh; overflow:auto; scrollbar-width:thin; }
#personal-task-preview h2 { position:sticky; top:0; background:var(--sidebar); padding:.375rem .625rem; z-index:1; margin:0; }
#personal-task-preview button { border-color:var(--line); background:var(--surface); display:grid; gap:.375rem; overflow-wrap:anywhere; border-radius:var(--control-radius); }
#personal-task-preview button strong { font-size:.875rem; font-weight:600; line-height:1.4; }
#personal-task-preview button:hover:not(:disabled) { border-color:var(--accent); background:var(--selection); }
#work-content .work-task { display:grid; gap:.75rem; }
.work-description, .work-comment { white-space:pre-wrap; overflow-wrap:anywhere; }
.work-meta { display:flex; flex-wrap:wrap; gap:.375rem .875rem; color:var(--muted); font-size:.8125rem; }
.work-comment { padding:.75rem 0; border-top:1px solid var(--line); }
.work-comment p { margin-top:.375rem; }
.work-members { display:grid; gap:.25rem; }
.work-members .split { border-bottom:1px solid var(--line); padding:.75rem 0; }
.work-members .split:last-child { border-bottom:0; }
.work-members .actions { justify-content:flex-end; }
#work-content textarea { min-height:6rem; }
.work-header-actions { display:flex; flex-wrap:wrap; align-items:flex-start; justify-content:flex-end; gap:.75rem; }
.refresh-control { display:grid; justify-items:end; gap:.25rem; max-width:18rem; }
.refresh-control .feedback { font-size:.75rem; text-align:right; margin:0; max-width:100%; }
.work-tabs { margin-bottom:1.25rem; }
.icon-add { min-width:2.375rem; padding:.25rem .625rem; font-size:1.25rem; line-height:1; }

/* Modal dialogs, without custom fonts or external UI dependencies */
.esa-dialog { width:min(calc(100% - 2rem),560px); max-height:calc(100dvh - 2rem); overflow:auto; color:var(--text); background:var(--surface); border:1px solid var(--line-strong); border-radius:16px; padding:1.5rem; box-shadow:0 20px 60px #0008; }
.esa-dialog::backdrop { background:#0a0908b8; }
.esa-dialog .card { border:0; padding:0; background:transparent; }
.esa-dialog textarea { min-height:6rem; }
.esa-dialog input:not([type=radio]), .esa-dialog select { width:100%; }
.esa-dialog .assignee-picker { margin:0; min-width:0; border:1px solid var(--line); border-radius:var(--control-radius); padding:.5rem; }
.assignee-picker legend { color:var(--muted); font-size:.875rem; padding:0 .375rem; }
.assignee-choices { max-height:12rem; overflow:auto; display:grid; gap:.25rem; }
.assignee-choices label { display:flex; flex-direction:row; align-items:center; gap:.625rem; padding:.5rem; border:1px solid transparent; border-radius:5px; cursor:pointer; color:var(--text); }
.assignee-choices label:has(input:checked) { background:var(--selection); border-color:var(--selection-line); }
.assignee-choices input[type=radio] { min-height:0; accent-color:var(--accent); }
.assignee-picker > small { display:block; padding:.5rem .5rem 0; }
.confirm-dialog { max-width:440px; }
.confirm-dialog .actions { justify-content:flex-end; }

/* Compact workstation and mobile layouts */
@media(max-width:1280px) {
    :root { --left-width: 180px; --right-width: 230px; }
    main { padding-inline:1.25rem; }
}
@media(max-width:980px) {
    :root { --left-width: 152px; --right-width: 194px; }
    .sidebar { padding-inline:.625rem; }
    main { padding-inline:1rem; }
    .card { padding:1rem; }
    .device-group { padding-bottom:.25rem; }
    .sidebar button { padding-inline:.5rem; }
}
@media(max-width:760px) {
    .topbar { position:static; height:auto; min-height:var(--header-height); padding:.75rem 1rem; }
    .topbar-end { max-width:58%; }
    .brand { font-size:1.125rem; gap:.5rem; }
    .lab-logo { width:36px; height:36px; }
    #status { font-size:.6875rem; }
    .shell { grid-template-columns:minmax(0,1fr) minmax(0,1fr); }
    .sidebar { position:static; height:auto; align-self:stretch; overflow:visible; padding:.875rem .75rem; border-bottom:1px solid var(--line); }
    .sidebar-system { grid-column:1; grid-row:1; }
    .sidebar-user { grid-column:2; grid-row:1; }
    main { grid-column:1 / -1; grid-row:2; padding:1.5rem 1rem 2rem; }
    .sidebar .pse-title { margin-top:.75rem; padding-top:.75rem; }
    .sidebar button { min-height:36px; }
    .mini-calendar button { min-height:26px; padding:0; }
    #personal-task-preview { max-height:11rem; }
    .sidebar-user .top-user { padding:.625rem; }
    .view-head { margin-bottom:1.25rem; }
    .work-header-actions { justify-content:flex-start; }
    .refresh-control { justify-items:start; }
    .refresh-control .feedback { text-align:left; }
}
@media(max-width:480px) {
    .topbar { gap:.5rem; }
    #status { max-width:100%; padding:.25rem .375rem; }
    .form-grid, .tuning-grid { grid-template-columns:minmax(0,1fr); }
    .card { padding:.875rem; }
    .device-group { padding-bottom:.25rem; }
    #filelist p, .macro-row { flex-wrap:wrap; }
    .heater-table .inline-form { flex-wrap:wrap; }
    .heater-table input[type=number] { width:4.75rem; }
    .esa-dialog { padding:1rem; }
}
@media(prefers-reduced-motion:reduce) {
    *, *::before, *::after { scroll-behavior:auto !important; transition:none !important; }
}
