:root {
	--side: #15181d;
	--side-2: #1b1f25;
	--ink: #e8ebef;
	--muted: #98a2ad;
	--faint: #667079;
	--line: #2a3037;
	--line-2: #333b44;
	--accent: #52b9cb;
	--accent-ink: #06171b;
	--accent-dim: #1a3a41;
	--sel: #2f3a40;
	--sidebar-w: 250px;
	--strip-w: 60px;
	--sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	--mono: "Cascadia Code", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

html, body { overscroll-behavior: none; }
html { touch-action: manipulation; }

body {
	background-color: black;
	overflow: hidden;
	height: 100vh;
	width: 100%;
	padding: 0;
	margin: 0;
	font-family: var(--sans);
	color: var(--ink);
}

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

/* content pane (holds the canvas) */
.content {
	font-family: "Lucida Console", "Courier New", monospace;
	position: relative;
	background-color: #202429;	/* matches the canvas backdrop (--pane) */
	flex: 1 1 auto;
	min-width: 0;
	border: none;
	display: flex;
	flex-direction: column;
}
.canvas-host { position: relative; flex: 1 1 auto; min-height: 0; }

/* ---------------- Tab bar (compact, square, flush to the top) ---------------- */
.tabbar { flex: 0 0 auto; display: flex; align-items: stretch; height: 28px; padding: 0; background: var(--side); border-bottom: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.tabbar::-webkit-scrollbar { height: 4px; }
.tabbar::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 3px; }
.tab { display: flex; align-items: center; gap: 7px; max-width: 220px; min-width: 90px; padding: 0 7px 0 12px; background: var(--side); border-right: 1px solid var(--line); color: var(--muted); font-family: var(--sans); font-size: 12px; cursor: pointer; white-space: nowrap; flex: 0 0 auto; }
.tab:hover { color: var(--ink); background: var(--side-2); }
.tab.active { background: #202429; color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }
.tab .t-lbl { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; }
.tab .t-x { flex: 0 0 auto; display: grid; place-items: center; width: 15px; height: 15px; border-radius: 4px; color: var(--faint); font-size: 13px; line-height: 1; }
.tab .t-x:hover { background: var(--line-2); color: var(--ink); }
.tab.drop { box-shadow: inset 2px 0 0 var(--accent); }
.tab-add { flex: 0 0 auto; display: grid; place-items: center; width: 30px; border: 0; border-right: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 16px; cursor: pointer; }
.tab-add:hover { background: var(--side-2); color: var(--ink); }
.tab-overflow { position: absolute; top: 0; right: 0; width: 30px; height: 28px; border: 0; border-left: 1px solid var(--line); background: var(--side); color: var(--muted); font-size: 16px; cursor: pointer; z-index: 5; }
.tab-overflow:hover { background: var(--side-2); color: var(--ink); }
.ctx-sep { height: 1px; margin: 4px 6px; background: var(--line); }

/* Right-click tab context menu (holds Back / New / Close). */
.tab-ctx { position: fixed; z-index: 200; min-width: 150px; padding: 4px; background: #1b1f25; border: 1px solid var(--line-2); border-radius: 8px; box-shadow: 0 6px 22px rgba(0,0,0,.5); }
.tab-ctx button { display: flex; align-items: center; width: 100%; padding: 7px 10px; border: 0; background: transparent; color: var(--ink); font-family: var(--sans); font-size: 12.5px; text-align: left; cursor: pointer; border-radius: 6px; }
.tab-ctx button:hover { background: var(--side-2); }
.tab-ctx button.disabled { color: var(--faint); cursor: default; }
.tab-ctx button.disabled:hover { background: transparent; }

/* Canvas row context menu (right-click a grid/worksheet row). SQUARE to match the canvas layout, and it
   OWNS the blue highlight: the .active item (set by keyboard nav OR mouse hover) takes the selection teal. */
#canvas-ctx.canvas-ctx { border-radius: 0; padding: 3px; }
#canvas-ctx.canvas-ctx button { border-radius: 0; }
#canvas-ctx.canvas-ctx button.active,
#canvas-ctx.canvas-ctx button.active:hover { background: #2c6f7c; color: #fff; }
/* Plain hover no longer paints on its own — the shared .active highlighter (mouseenter) drives the blue. */
#canvas-ctx.canvas-ctx button:hover { background: transparent; }

/* ---------------- Sidebar ---------------- */
.sidebar {
	width: var(--sidebar-w);
	flex: 0 0 var(--sidebar-w);
	background: var(--side);
	border-right: 1px solid var(--line);
	display: flex;
	flex-direction: column;
	min-height: 0;
	transition: width .18s ease, flex-basis .18s ease;
	user-select: none;
}
.app.collapsed .sidebar { width: var(--strip-w); flex-basis: var(--strip-w); }
.sidebar.guest .nav, .sidebar.guest .grp { display: none; }

.side-head { display: flex; align-items: center; gap: 10px; padding: 14px; height: 56px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; overflow: hidden; }
.brand .name { font-weight: 640; font-size: 16px; letter-spacing: -0.01em; white-space: nowrap; }
.brand .name small { display: block; font-weight: 500; font-size: 11px; letter-spacing: .02em; text-transform: none; color: var(--faint); }
.collapse-btn { margin-left: auto; width: 30px; height: 30px; flex: 0 0 30px; border: 0; background: transparent; color: var(--muted); border-radius: 7px; display: grid; place-items: center; cursor: pointer; }
.collapse-btn:hover { background: var(--side-2); color: var(--ink); }
.app.collapsed .brand .name { display: none; }
.app.collapsed .side-head { justify-content: center; padding: 14px 0; }
.app.collapsed .collapse-btn { margin-left: 0; }
.app.collapsed .collapse-btn svg { transform: scaleX(-1); }

/* The clock reserves its full height from first paint.
 *
 * #trading-clock ships EMPTY in html/index.php and is only filled by tradingClockTick(),
 * which cannot run until the /trading_now fetch resolves. Until then the element is zero
 * height, so when it fills it pops open to two lines and shoves the whole nav down the
 * page. min-height holds the space it is going to need.
 *
 * The value is content-box (there is no box-sizing rule in this stylesheet, so padding
 * sits outside it): two 12px lines at line-height 1.3 = 31.2px, plus the 1px flex gap.
 * If the font-size or line-height above changes, this needs to change with it.
 *
 * justify-content keeps the text vertically centred in that reserved box, so the empty
 * and filled states occupy the same space and nothing moves when it populates. */
.trading-clock { display: flex; flex-direction: column; justify-content: center; gap: 1px; min-height: 32.2px; padding: 8px 14px; border-bottom: 1px solid var(--line); font-family: var(--sans); line-height: 1.3; }
/* tabular-nums on the DATE as well as the time. Without it the day and year digits are
 * proportionally spaced, so the line visibly re-flows every time the date rolls over —
 * which at the current 4320x sim speed is roughly every 20 real seconds. */
.trading-clock .tc-date { font-size: 12px; font-weight: 560; color: var(--ink); white-space: nowrap; font-variant-numeric: tabular-nums; }
.trading-clock .tc-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.trading-clock .tc-speed { margin-left: 6px; font-size: 10px; font-weight: 700; color: #3a8f9e; letter-spacing: .02em; }
.app.collapsed .trading-clock { display: none; }

.nav { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; padding: 10px 8px; }
.nav::-webkit-scrollbar { width: 8px; }
.nav::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; }

.grp { margin-bottom: 2px; }
.grp-head { display: flex; align-items: center; gap: 11px; width: 100%; padding: 9px 10px; border: 0; background: transparent; color: var(--ink); font-family: var(--sans); font-size: 13.5px; font-weight: 560; cursor: pointer; border-radius: 8px; text-align: left; }
.grp-head:hover { background: var(--side-2); }
.grp-head .ico { flex: 0 0 18px; width: 18px; height: 18px; color: var(--muted); }
.grp-head .lbl { flex: 1 1 auto; white-space: nowrap; }
.grp-head .chev { flex: 0 0 14px; width: 14px; height: 14px; color: var(--faint); transition: transform .15s; }
.grp.open .grp-head .chev { transform: rotate(90deg); }

.kids { overflow: hidden; max-height: 0; transition: max-height .2s ease; }
.grp.open .kids { max-height: 600px; }
.subhead { display: flex; align-items: center; gap: 6px; width: 100%; padding: 8px 10px 4px 26px; margin-top: 2px; border: 0; background: transparent; cursor: pointer; font-family: var(--mono); font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); text-align: left; }
.subhead:hover { color: var(--muted); }
.subhead .lbl { flex: 1 1 auto; }
.subhead .chev { flex: 0 0 auto; display: grid; place-items: center; color: var(--faint); transition: transform .18s ease; }
.subhead.open .chev { transform: rotate(90deg); }
.subkids { overflow: hidden; max-height: 0; transition: max-height .2s ease; }
.subkids.open { max-height: 300px; }

.item { display: flex; align-items: center; gap: 11px; width: 100%; padding: 8px 10px 8px 12px; margin: 1px 0; border: 0; background: transparent; color: var(--muted); font-family: var(--sans); font-size: 13px; cursor: pointer; border-radius: 8px; text-align: left; position: relative; }
.item .dot { flex: 0 0 18px; width: 18px; display: grid; place-items: center; }
.item .dot::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--line-2); }
.item .lbl { flex: 1 1 auto; white-space: nowrap; }
.item:hover { background: var(--side-2); color: var(--ink); }
.item:hover .dot::before { background: var(--muted); }
.item.active { background: var(--accent-dim); color: var(--ink); }
.item.active .dot::before { background: var(--accent); }
.item.active::before { content: ""; position: absolute; left: -8px; top: 6px; bottom: 6px; width: 3px; border-radius: 3px; background: var(--accent); }
.item.off { opacity: .4; cursor: default; }
.item.off:hover { background: transparent; color: var(--muted); }
.item.off .soon { margin-left: auto; font-family: var(--mono); font-size: 9px; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }

.app.collapsed .grp-head { justify-content: center; padding: 10px 0; }
.app.collapsed .grp-head .lbl, .app.collapsed .grp-head .chev,
.app.collapsed .item .lbl, .app.collapsed .item .soon, .app.collapsed .subhead { display: none; }
.app.collapsed .kids { max-height: 0 !important; }
.app.collapsed .item { justify-content: center; padding: 8px 0; }

/* Account footer */
.account { border-top: 1px solid var(--line); padding: 10px; position: relative; }
.acct-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border: 0; background: transparent; color: var(--ink); cursor: pointer; border-radius: 9px; text-align: left; }
.acct-btn:hover { background: var(--side-2); }
.avatar { width: 30px; height: 30px; flex: 0 0 30px; border-radius: 8px; display: grid; place-items: center; background: var(--sel); color: var(--ink); font-weight: 640; font-size: 12px; font-family: var(--mono); }
.acct-meta { flex: 1 1 auto; overflow: hidden; }
.acct-meta .who { font-size: 12.5px; font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct-meta .role { font-size: 11px; color: var(--faint); white-space: nowrap; }
.acct-btn .more { flex: 0 0 16px; color: var(--faint); }
.app.collapsed .acct-meta, .app.collapsed .acct-btn .more { display: none; }
.app.collapsed .acct-btn { justify-content: center; padding: 8px 0; }

.popover { position: absolute; bottom: 62px; left: 10px; right: 10px; background: var(--side-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 6px; box-shadow: 0 12px 34px rgba(0,0,0,.45); display: none; z-index: 20; }
.popover.show { display: block; }
.popover button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: transparent; color: var(--ink); font-family: var(--sans); font-size: 13px; border-radius: 7px; cursor: pointer; text-align: left; }
.popover button:hover { background: var(--sel); }
.popover button svg { color: var(--muted); width: 16px; height: 16px; }
.popover .sep { height: 1px; background: var(--line); margin: 5px 6px; }

svg { display: block; }

/* ---------------- Document chrome (right Details rail) ---------------- */
/* A right sidebar symmetric to the left: a thin strip while a worksheet is open, expanding
   inward to the full inspector. Only present when a worksheet is the active canvas screen. */
.doc-rail {
	flex: 0 0 0px; width: 0; overflow: hidden;
	background: var(--side); border-left: 1px solid var(--line);
	display: flex; flex-direction: column; min-height: 0;
	transition: width .18s ease, flex-basis .18s ease;
}
.app.has-doc .doc-rail { flex-basis: 52px; width: 52px; }
.app.has-doc.doc-open .doc-rail { flex-basis: 380px; width: 380px; max-width: 88vw; }

.doc-rail-toggle {
	display: none;
	flex-direction: column; align-items: center; gap: 12px;
	width: 52px; flex: 0 0 auto; padding: 16px 0; border: 0; background: transparent;
	color: var(--accent); cursor: pointer;
}
.app.has-doc:not(.doc-open) .doc-rail-toggle { display: flex; }
.doc-rail-toggle svg { width: 20px; height: 20px; }
.doc-rail-toggle span {
	writing-mode: vertical-rl; text-orientation: mixed;
	font-family: var(--sans); font-size: 11px; font-weight: 640; letter-spacing: .1em;
	text-transform: uppercase; color: var(--muted);
}
.doc-rail-toggle:hover span { color: var(--ink); }

.doc-inspector {
	display: none; flex-direction: column; flex: 1 1 auto; min-height: 0;
	width: 380px; max-width: 88vw;
	font-family: var(--sans); color: var(--ink);
}
.app.doc-open .doc-inspector { display: flex; }

.insp-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.insp-head b { font-size: 14px; }
.insp-head .sub { color: var(--faint); font-size: 12px; text-transform: capitalize; }
.insp-head .x { margin-left: auto; border: 0; background: transparent; color: var(--muted); font-size: 15px; cursor: pointer; width: 28px; height: 28px; border-radius: 7px; }
.insp-head .x:hover { background: var(--side-2); color: var(--ink); }

.insp-body { flex: 1 1 auto; overflow-y: auto; padding: 4px 16px 20px; }
.insp-body::-webkit-scrollbar { width: 8px; }
.insp-body::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; }

.insp-sec { padding: 14px 0; border-bottom: 1px solid var(--line); }
.insp-sec:last-child { border-bottom: 0; }
.insp-sec > h4 { margin: 0 0 10px; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); font-weight: 600; }
.insp-body .muted { color: var(--faint); font-size: 12.5px; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; font-size: 13px; }
.kv span { color: var(--faint); }
.kv b { font-weight: 560; text-align: right; }

.addr-static { font-size: 12.5px; color: var(--muted); line-height: 1.5; white-space: pre-line; }

.addr {
	display: flex; align-items: flex-start; gap: 10px; width: 100%; text-align: left;
	border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; margin-bottom: 8px;
	background: #202429; color: var(--ink); cursor: pointer; font-family: var(--sans);
	transition: border-color .12s, background .12s;
}
.addr:hover { border-color: var(--accent); }
.addr:disabled { cursor: default; opacity: .8; }
.addr:disabled:hover { border-color: var(--line); }
.addr .radio { width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--line-2); margin-top: 2px; flex: 0 0 15px; }
.addr.on { border-color: var(--accent); background: var(--accent-dim); }
.addr.on .radio { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 2.5px var(--side); }
.addr .a-body { flex: 1 1 auto; min-width: 0; }
.addr .a-label { display: block; font-size: 12.5px; font-weight: 600; }
.addr .a-lines { display: block; color: var(--muted); font-size: 12px; line-height: 1.4; margin-top: 3px; }
.addr .badge { font-size: 9px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); border: 1px solid var(--accent); border-radius: 5px; padding: 0 5px; }

.link-btn {
	border: 0; background: transparent; color: var(--accent); cursor: pointer;
	font-family: var(--sans); font-size: 11px; font-weight: 600; padding: 0 0 0 4px; text-transform: lowercase;
}
.link-btn:hover { text-decoration: underline; }

.picker { margin: 2px 0 8px; }
.picker input {
	width: 100%; border: 1px solid var(--line-2); border-radius: 8px;
	background: #202429; color: var(--ink); font-family: var(--sans); font-size: 12.5px; padding: 7px 9px;
}
.picker input:focus { outline: none; border-color: var(--accent); }
.picker-results { margin-top: 6px; display: flex; flex-direction: column; gap: 3px; }
.picker-item {
	display: flex; align-items: baseline; justify-content: space-between; gap: 8px; width: 100%; text-align: left;
	border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px; cursor: pointer;
	background: #202429; color: var(--ink); font-family: var(--sans); font-size: 12.5px;
}
.picker-item:hover { border-color: var(--accent); background: var(--accent-dim); }
.picker-item .picker-id { color: var(--faint); font-family: var(--mono); font-size: 10.5px; }

.ref-edit { display: flex; gap: 8px; margin: 2px 0 4px; }
.ref-edit input {
	flex: 1 1 auto; min-width: 0; border: 1px solid var(--line-2); border-radius: 8px;
	background: #202429; color: var(--ink); font-family: var(--sans); font-size: 12.5px; padding: 7px 9px;
}
.ref-edit input:focus { outline: none; border-color: var(--accent); }
.ref-edit button {
	flex: 0 0 auto; border: 0; border-radius: 8px; padding: 8px 14px;
	background: var(--accent); color: var(--accent-ink); font-family: var(--sans); font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.ref-edit button:hover { filter: brightness(1.08); }

.cur-edit { display: flex; gap: 8px; margin: 2px 0 4px; align-items: center; }
.cur-edit select {
	flex: 1 1 auto; min-width: 0; border: 1px solid var(--line-2); border-radius: 8px;
	background: #202429; color: var(--ink); font-family: var(--sans); font-size: 12.5px; padding: 7px 9px;
}
.cur-edit input {
	flex: 0 0 84px; min-width: 0; border: 1px solid var(--line-2); border-radius: 8px;
	background: #202429; color: var(--ink); font-family: var(--sans); font-size: 12.5px; padding: 7px 9px;
}
.cur-edit select:focus, .cur-edit input:focus { outline: none; border-color: var(--accent); }
.cur-edit button {
	flex: 0 0 auto; border: 0; border-radius: 8px; padding: 8px 14px;
	background: var(--accent); color: var(--accent-ink); font-family: var(--sans); font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.cur-edit button:hover { filter: brightness(1.08); }

.note-add { display: flex; gap: 8px; margin-bottom: 12px; }
.note-add textarea {
	flex: 1 1 auto; resize: vertical; min-height: 38px; border: 1px solid var(--line-2); border-radius: 8px;
	background: #202429; color: var(--ink); font-family: var(--sans); font-size: 12.5px; padding: 7px 9px;
}
.note-add textarea:focus { outline: none; border-color: var(--accent); }
.note-add button {
	flex: 0 0 auto; align-self: flex-start; border: 0; border-radius: 8px; padding: 8px 14px;
	background: var(--accent); color: var(--accent-ink); font-family: var(--sans); font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.note-add button:hover { filter: brightness(1.08); }

.note { border-left: 2px solid var(--line-2); padding: 1px 0 8px 12px; margin-bottom: 10px; }
.note .meta { font-size: 10.5px; color: var(--faint); font-family: var(--mono); margin-bottom: 3px; }
.note .body { font-size: 12.5px; color: var(--ink); white-space: pre-line; }

.hist { display: flex; gap: 10px; padding: 5px 0; font-size: 12px; align-items: baseline; }
.hist .hist-t { flex: 0 0 auto; font-family: var(--mono); font-size: 10.5px; color: var(--faint); white-space: nowrap; }
.hist .hist-b { flex: 1 1 auto; color: var(--ink); }
.hist .hist-by { color: var(--faint); }

@media (prefers-reduced-motion: reduce) { .sidebar, .kids, .chev, .doc-rail { transition: none !important; } }
