:root {
    --bg: #1e1e1e;
    --panel: #252526;
    --surface: #2d2d2d;
    --border: #3c3c3c;
    --text: #d4d4d4;
    --muted: #9a9a9a;
    --accent: #4263eb;
    --region: #00e5ff;
    --select: #ffd400;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: sans-serif;
    font-size: 13px;
    overflow: hidden;
}

#app {
    display: flex;
    height: 100vh;
}

aside {
    width: 340px;
    flex: 0 0 auto;
    padding: 12px;
    overflow-y: auto;
    background: var(--panel);
}

#left {
    border-right: 1px solid var(--border);
}

#right {
    width: 360px;
    border-left: 1px solid var(--border);
}

h3,
h4 {
    margin: 0 0 8px;
}

hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 12px 0;
}

label {
    display: block;
    margin-bottom: 4px;
}

label.inline {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin: 0;
    white-space: nowrap;
    color: var(--muted);
}

.row {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
    align-items: center;
}

.grow,
.wide {
    flex: 1;
}

.wide {
    width: 100%;
    display: block;
    margin-bottom: 6px;
}

.hidden {
    display: none !important;
}

.muted {
    color: var(--muted);
    font-size: 12px;
}

.hint {
    color: var(--muted);
    font-size: 12px;
    margin: 6px 0;
}

button,
select,
input[type="text"] {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 5px 8px;
    font-size: 13px;
    font-family: inherit;
}

button {
    cursor: pointer;
}

button:hover {
    background: #383838;
}

button:disabled {
    opacity: 0.4;
    cursor: default;
    background: var(--surface);
}

button.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

button.danger {
    background: #e03131;
    border: none;
    color: #fff;
}

select,
input[type="text"] {
    width: 100%;
}

#show-opts label {
    display: block;
    margin-bottom: 3px;
}

#show-opts input {
    margin-right: 6px;
}

.panel {
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px;
    margin-top: 6px;
}

.notice {
    border: 1px solid #7a5c00;
    background: rgba(184, 134, 11, 0.14);
    border-radius: 4px;
    padding: 8px;
    font-size: 12px;
    line-height: 1.45;
}

pre {
    white-space: pre-wrap;
    word-break: break-all;
    margin: 6px 0 0;
    font-family: inherit;
}

#status {
    color: var(--text);
    min-height: 2em;
}

#centre {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

#centre-bar {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 6px;
    border-bottom: 1px solid var(--border);
}

.badge {
    background: #b8860b;
    color: #fff;
    border-radius: 3px;
    padding: 2px 8px;
    font-size: 12px;
}

#view-stack {
    flex: 1 1 auto;
    position: relative;
    min-height: 0;
}

#view3d {
    position: absolute;
    inset: 0;
}

#slice-wrap {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
}

#slice-bar {
    flex: 0 0 auto;
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
}

#slice-bar select {
    width: 220px;
}

#slice-canvas {
    flex: 1 1 auto;
    min-height: 0;
    display: block;
    width: 100%;
    cursor: crosshair;
}

#slice-note {
    flex: 0 0 auto;
    padding: 4px 8px;
    color: var(--muted);
    font-size: 12px;
}

.slider {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
}

.slider input {
    flex: 1;
}

#ctx-menu {
    position: fixed;
    z-index: 1000;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

#ctx-menu button {
    display: block;
    width: 100%;
    text-align: left;
    margin-bottom: 2px;
}

#busy {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 2000;
}

.spinner {
    width: 22px;
    height: 22px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* --- tissue palette ------------------------------------------------------ */
.chip {
    /* Filled with the tissue's own colour; app.js picks black or white text for
       it so dark tissue colours stay readable. */
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1px 8px;
    margin-left: 6px;
    font-weight: 600;
    font-size: 14px;
    color: var(--muted);
}

.tissue-list {
    max-height: 260px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 3px;
    margin-bottom: 4px;
}

.tis {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 1px 2px;
}

.tis-vis {
    flex: 0 0 auto;
    margin: 0;
}

.tis-swatch {
    flex: 0 0 auto;
    width: 12px;
    height: 12px;
    border-radius: 2px;
    border: 1px solid rgba(0, 0, 0, 0.5);
}

.tis-name {
    flex: 1;
    text-align: left;
    background: none;
    border: none;
    padding: 2px 4px;
    color: var(--text);
    font-size: 12px;
    border-radius: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tis-name:hover {
    background: #383838;
}

.tis.active .tis-name {
    background: var(--accent);
    color: #fff;
}

.tis-count {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 11px;
    padding-right: 3px;
}

.tis-empty {
    color: var(--muted);
    font-size: 12px;
    padding: 6px 4px;
}

/* =========================================================================
   Accounts, admin panel and file manager — taken from TraceBV's stylesheet
   (Web/TraceBV/assets/style.css), minus its revision log, XP and audit rules.
   Trace's own .chip above is kept: it sizes the active-tissue chip.
   ========================================================================= */

/* --- session gate ------------------------------------------------------- */
/* The sign-in page is the only thing on its own screen, so unlike the editor it
   scrolls rather than clipping: a short laptop window in landscape has less
   height than the card. */
.login-body {
    overflow: auto;
}

.gate {
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    /* Two soft washes in the vessel colours, over the editor's own background,
       so the page reads as part of the same tool rather than a bare form. */
    background:
        radial-gradient(58% 50% at 15% 8%, rgba(216, 27, 27, 0.10), transparent 70%),
        radial-gradient(55% 48% at 88% 92%, rgba(26, 115, 232, 0.13), transparent 70%),
        var(--bg);
}

.gate-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
    padding: 26px 28px 22px;
    width: 370px;
    max-width: 100%;
}

.gate-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 22px;
}

.gate-mark {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
}

.gate-card h2 {
    margin: 0;
    font-size: 21px;
    letter-spacing: 0.3px;
}

.gate-sub {
    color: var(--muted);
    margin: 2px 0 0;
    font-size: 12px;
}

.gate-field {
    display: block;
    margin-bottom: 14px;
}

.gate-field > span {
    display: block;
    margin-bottom: 5px;
    font-size: 11px;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: var(--muted);
}

/* The base rule only reaches input[type="text"], so the password box would
   otherwise render as a white browser default next to a dark account box. */
.gate-card input {
    width: 100%;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 14px;
    padding: 9px 10px;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

/* Chromium paints its own near-white background over an autofilled field, which
   on a dark form looks like a rendering bug. There is no property that turns it
   off; an inset shadow the size of the box is the standard way to cover it. */
.gate-card input:-webkit-autofill,
.gate-card input:-webkit-autofill:hover,
.gate-card input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px var(--surface) inset;
    -webkit-text-fill-color: var(--text);
    caret-color: var(--text);
}

.gate-card input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(66, 99, 235, 0.28);
}

.gate-card button.save {
    margin-top: 4px;
    padding: 10px;
    font-size: 14px;
    transition: background 0.12s ease;
}

.gate-card button.save:hover:not(:disabled) {
    background: #0ca678;
}

.gate-error {
    color: #ff8787;
    margin-top: 14px;
    padding: 9px 11px;
    border-radius: 4px;
    border-left: 3px solid #e03131;
    background: rgba(224, 49, 49, 0.12);
    line-height: 1.4;
}

.gate-error.hidden {
    display: none;
}

.gate-foot {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.5;
    margin: 20px 0 0;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

/* --- revision log ------------------------------------------------------- */

button.save {
    background: #12b886;
    border: none;
    color: #fff;
    padding: 8px;
}

/* --- account bar (editor) ----------------------------------------------- */
#account-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 10px;
}

#account-bar h3 {
    margin: 0;
    flex: 1;
}

#account-bar #who-chip {
    margin-left: 0;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#admin-link {
    color: var(--muted);
    text-decoration: none;
    font-size: 15px;
    padding: 2px 4px;
}

#admin-link:hover {
    color: var(--text);
}

#admin-link.hidden {
    display: none;
}

#folder-name {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 5px 8px;
    font-size: 13px;
    word-break: break-all;
}

#folder-name.unassigned {
    color: var(--muted);
    font-style: italic;
}

/* --- admin panel --------------------------------------------------------- */
.admin-body {
    overflow: auto;
}

#admin {
    max-width: 1180px;
    margin: 0 auto;
    padding: 18px 22px 40px;
}

#admin-head {
    display: flex;
    align-items: baseline;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
    margin-bottom: 16px;
}

#admin-head h2 {
    margin: 0;
}

#admin-head .spacer {
    flex: 1;
}

.btn-link {
    color: var(--muted);
    text-decoration: none;
}

.btn-link:hover {
    color: var(--text);
}

#admin-cols {
    display: grid;
    grid-template-columns: minmax(320px, 1fr) minmax(340px, 1fr);
    gap: 26px;
    align-items: start;
}

@media (max-width: 860px) {
    #admin-cols {
        grid-template-columns: 1fr;
    }
}

.user-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-bottom: 5px;
    background: var(--panel);
}

.user-row.active {
    border-color: #4263eb;
}

.user-name {
    flex: 1;
    text-align: left;
    background: none;
    border: none;
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    padding: 2px 0;
}

.user-name:hover {
    text-decoration: underline;
}

.user-tag {
    font-size: 11px;
    white-space: nowrap;
}

.picker {
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--panel);
    max-height: 260px;
    overflow: auto;
    padding: 4px 6px;
    margin-bottom: 12px;
}

.check {
    display: block;
    font-size: 12px;
    padding: 2px 0;
    cursor: pointer;
    word-break: break-all;
}

.pad {
    padding: 6px 2px;
}


#admin-status.bad {
    color: #ff6b6b;
}

/* -- admin: worked time & XP ---------------------------------------------- */
#admin-time {
    margin-top: 26px;
}

table.time-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
}

table.time-table th,
table.time-table td {
    padding: 5px 8px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

table.time-table th {
    color: var(--muted);
    font-weight: 600;
}

table.time-table td.num,
table.time-table th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

table.time-table tr.idle td {
    color: var(--muted);
}

/* One bar per day of the window. Bars are laid out from the baseline so a short
   day reads as a short bar rather than a floating block. */
.spark {
    display: flex;
    align-items: flex-end;
    gap: 1px;
    height: 20px;
    min-width: 90px;
}

.spark i {
    flex: 1;
    min-width: 2px;
    border-radius: 1px;
    background: var(--accent);
}


#admin-files {
    margin-top: 26px;
    border-top: 1px solid var(--border);
    padding-top: 14px;
}

.fm-bar .spacer,
.fm-tools .spacer {
    flex: 1;
}

.fm-tools {
    flex-wrap: wrap;
}

.fm-crumb {
    background: none;
    border: 1px solid transparent;
    color: var(--text);
    padding: 2px 5px;
    cursor: pointer;
}

.fm-crumb:hover {
    text-decoration: underline;
}

.fm-list {
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--panel);
    max-height: 460px;
    overflow: auto;
    min-height: 80px;
}

table.fm-table td:first-child,
table.fm-table th:first-child {
    width: 28px;
}

table.fm-table tr.sel td {
    background: rgba(66, 99, 235, 0.14);
}

table.fm-table tr[draggable="true"] {
    cursor: grab;
}

.fm-name {
    background: none;
    border: none;
    padding: 0;
    color: var(--text);
    font-size: inherit;
    text-align: left;
    cursor: pointer;
    text-decoration: none;
    white-space: normal;
    word-break: break-all;
}

.fm-name:hover {
    text-decoration: underline;
}

tr.fm-dir .fm-name {
    font-weight: 600;
}

/* Where a drag will land: a folder row, a path segment, or the whole list. */
.drop-over,
table.fm-table tr.drop-over td {
    outline: 1px dashed var(--accent);
    background: rgba(66, 99, 235, 0.22);
}

.fm-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    font-size: 12px;
}

.fm-progress span {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fm-bar-track {
    flex: 0 0 240px;
    height: 8px;
    border-radius: 4px;
    background: var(--surface);
    overflow: hidden;
}

.fm-bar-track i {
    display: block;
    height: 100%;
    width: 0;
    background: var(--accent);
}

#fm-status.bad {
    color: #ff6b6b;
}
