/* Shell and components. Square corners, flat fills, 1px outlines. */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--ground); color: var(--text);
  font-family: var(--font); font-size: var(--size); line-height: var(--line-height);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-weight: 300; line-height: 1.1; margin: 0; }
h1 { font-size: var(--h1); } h2 { font-size: var(--h2); } h3 { font-size: var(--h3); }
p { margin: 0 0 var(--gap-2); }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--text-2); }
.boot { padding: var(--gap-4); color: var(--text-2); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: square; }

/* ---- shell ---------------------------------------------------------------- */
.shell { display: grid; grid-template-columns: var(--menu-width) minmax(0, 1fr); grid-template-rows: var(--bar-height) minmax(0, 1fr); height: 100vh; height: 100dvh; }
.shell.mini { --menu-width: 56px; }
.menu { grid-row: 1 / 3; background: var(--ground-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.menu-head { height: var(--bar-height); display: flex; align-items: center; gap: var(--gap-2); padding: 0 var(--gap-3); border-bottom: 1px solid var(--line); flex: none; }
.brand { font-size: 16px; font-weight: 700; letter-spacing: .01em; white-space: nowrap; overflow: hidden; }
.brand small { display: block; font-weight: 400; font-size: 11px; color: var(--text-2); }
.menu nav { overflow-y: auto; flex: 1; padding: var(--gap-2) 0; }
.menu-section { padding: var(--gap-3) var(--gap-3) var(--gap-1); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.menu-item { display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 var(--gap-3); color: var(--text); border-left: 3px solid transparent; white-space: nowrap; }
.menu-item:hover { background: var(--action-hover); color: var(--on-action); text-decoration: none; }
.menu-item[aria-current="page"] { background: var(--action); color: var(--on-action); border-left-color: var(--future-blue-50); }
.menu-foot { border-top: 1px solid var(--line); padding: var(--gap-2); flex: none; }
.shell.mini .brand, .shell.mini .menu-section { display: none; }
/* collapsed menu: the words leave the eye but stay the name of the link and of the button (never display: none) */
.shell.mini .menu-item span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.shell.mini .menu-foot .btn { font-size: 0; gap: 0; }
.shell.mini .menu-item, .shell.mini .menu-head { padding: 0; justify-content: center; }

.bar { display: flex; align-items: center; gap: var(--gap-2); padding: 0 var(--gap-3); border-bottom: 1px solid var(--line); background: var(--ground); min-width: 0; }
.bar-title { font-size: 16px; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.bar-tools { display: flex; align-items: center; gap: var(--gap-2); flex: none; }
.bar .burger { display: none; }
.identity { display: flex; align-items: center; gap: var(--gap-2); height: var(--control); padding: 0 10px 0 0; border: 1px solid var(--line); background: var(--panel); white-space: nowrap; }
.identity .initials { width: var(--control); height: calc(var(--control) - 2px); display: grid; place-items: center; background: var(--action); color: var(--on-action); font-weight: 700; font-size: 12px; }
.identity .who { display: flex; flex-direction: column; line-height: 1.15; }
.identity .who small { color: var(--text-2); font-size: 11px; }
.viewing-banner { display: flex; align-items: center; gap: var(--gap-3); padding: var(--gap-2) var(--gap-3); background: var(--panel-2); border-bottom: 1px solid var(--warn); }
.viewing-banner strong { font-weight: 700; }

.content { min-width: 0; min-height: 0; overflow: auto; display: flex; flex-direction: column; }
.page-head { padding: var(--gap-3) var(--gap-4) 0; display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--gap-3); }
.page-head .titles { flex: 1; min-width: 200px; }
.page-head p { color: var(--text-2); margin: 6px 0 0; }
.page-body { padding: var(--gap-3) var(--gap-4) var(--gap-4); flex: 1; min-height: 0; display: flex; flex-direction: column; gap: var(--gap-3); }
.tabs { display: flex; gap: 0; padding: var(--gap-3) var(--gap-4) 0; border-bottom: 1px solid var(--line); overflow-x: auto; flex: none; }
.tab { padding: 10px var(--gap-3); color: var(--text-2); border-bottom: 3px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--text); text-decoration: none; background: var(--panel); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--action); font-weight: 700; }

/* ---- panels, toolbars -------------------------------------------------------- */
.panel { background: var(--panel); border: 1px solid var(--line); padding: var(--gap-3); min-width: 0; }
.panel > h2, .panel > h3 { margin-bottom: var(--gap-3); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap-2); }
.toolbar .grow { flex: 1; }
.placeholder { border: 1px dashed var(--line); padding: var(--gap-4); color: var(--text-2); max-width: 720px; }
.placeholder h2 { color: var(--text); margin-bottom: var(--gap-2); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px var(--gap-3); margin: 0; }
.kv dt { color: var(--text-2); } .kv dd { margin: 0; }

/* ---- buttons ------------------------------------------------------------------ */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--gap-2); height: var(--control); padding: 0 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text); font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--link); }
.btn.primary { background: var(--action); border-color: var(--action); color: var(--on-action); }
.btn.primary:hover { background: var(--action-hover); border-color: var(--action-hover); }
.btn.danger { border-color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #FFFFFF; }
.btn.small { height: 30px; padding: 0 10px; }
.btn.icon-only { width: var(--control); padding: 0; }
.btn.block { width: 100%; }
.btn:disabled { background: var(--disabled); border-color: var(--disabled); color: var(--disabled-text); font-style: italic; cursor: not-allowed; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--link); cursor: pointer; }
.linkbtn:hover { text-decoration: underline; }

/* ---- chips (state always carries a text label) --------------------------------- */
.chip { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px; border: 1px solid var(--line); background: transparent; color: var(--text); font-size: 12px; white-space: nowrap; border-radius: var(--radius); }
.chip::before { content: ""; width: 8px; height: 8px; background: var(--no-data); flex: none; }
.chip.ok { border-color: var(--ok); } .chip.ok::before { background: var(--ok); }
.chip.warn { border-color: var(--warn); } .chip.warn::before { background: var(--warn); }
.chip.alert { border-color: var(--alert); } .chip.alert::before { background: var(--alert); }
.chip.danger { border-color: var(--danger); } .chip.danger::before { background: var(--danger); }
.chip.info { border-color: var(--info); } .chip.info::before { background: var(--info); }
.chip.plain::before { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }

/* ---- forms --------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: var(--gap-3); }
.field label, .field .label { font-size: 13px; color: var(--text-2); }
.field .help { font-size: 12px; color: var(--muted); }
/* E-26: date and time pickers follow the theme too (they were white boxes in the dark theme) */
:root { color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"], input[type="date"],
input[type="time"], input[type="datetime-local"], input[type="month"], input[type="url"], input[type="tel"], select, textarea {
  height: var(--control); padding: 0 10px; width: 100%; background: var(--field); color: var(--text);
  border: 1px solid var(--field-line); border-radius: var(--radius); font: inherit;
}
textarea { height: auto; padding: 8px 10px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--link); box-shadow: inset 0 0 0 1px var(--link); }
input.code { font-size: 22px; letter-spacing: .4em; text-align: center; height: 48px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px var(--gap-3); }
.check { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--action); margin: 0; }
.form-error { border: 1px solid var(--danger); border-left-width: 4px; padding: var(--gap-2) 12px; margin-bottom: var(--gap-3); color: var(--danger-text); background: transparent; }
.form-note { border: 1px solid var(--info); border-left-width: 4px; padding: var(--gap-2) 12px; margin-bottom: var(--gap-3); }

/* ---- tables -------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); background: var(--panel); }
/* E-24: a table straight in the page body keeps its height (as a scroll box it would shrink to a sliver) */
.page-body > .table-wrap { flex-shrink: 0; }
table.data { width: 100%; border-collapse: collapse; }
table.data caption { text-align: left; padding: var(--gap-2) 12px; color: var(--text-2); caption-side: top; }
table.data th, table.data td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); height: 40px; vertical-align: middle; }
table.data th { font-weight: 700; color: var(--text-2); white-space: nowrap; background: var(--panel); position: sticky; top: 0; }
table.data th button { all: unset; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
table.data th button:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
table.data th[aria-sort="ascending"] button::after { content: "\25B2"; font-size: 9px; }
table.data th[aria-sort="descending"] button::after { content: "\25BC"; font-size: 9px; }
table.data tbody tr:nth-child(even) { background: var(--stripe); }
table.data tbody tr:hover { background: var(--row-hover); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.num, table.data th.num { text-align: right; }
table.data td.num { white-space: nowrap; }  /* E-31: "1.85 s" stays on one line; the table scrolls instead */
table.data td.actions { text-align: right; white-space: nowrap; }
table.data td.actions .btn + .btn { margin-left: 6px; }
table.data td.empty { color: var(--text-2); text-align: center; padding: var(--gap-4); }
table.matrix th.role, table.matrix td.role { text-align: center; width: 1%; white-space: nowrap; }

/* ---- panes (no gaps; the separator is the 1px line) ----------------------------- */
.panes { display: flex; flex: 1; min-height: 0; min-width: 0; border: 1px solid var(--line); background: var(--panel); }
.panes.column { flex-direction: column; }
.pane { min-width: 0; min-height: 0; overflow: auto; padding: var(--gap-3); flex: 0 0 auto; }
.pane:last-child { flex: 1 1 0; }
.pane-sep { flex: 0 0 1px; background: var(--line); position: relative; cursor: col-resize; touch-action: none; }
.panes.column > .pane-sep { cursor: row-resize; }
.pane-sep::after { content: ""; position: absolute; inset: 0 -4px; }
.panes.column > .pane-sep::after { inset: -4px 0; }
.pane-sep:hover, .pane-sep:focus-visible, .pane-sep.dragging { background: var(--link); outline: 1px solid var(--link); }

/* ---- dialog, toast ------------------------------------------------------------- */
dialog.dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text); padding: 0; width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); }
dialog.dialog.wide { width: min(760px, calc(100vw - 32px)); }
dialog.dialog::backdrop { background: rgba(4, 9, 20, .72); }
.dialog-head { padding: var(--gap-3); border-bottom: 1px solid var(--line); }
.dialog-body { padding: var(--gap-3); overflow: auto; }
.dialog-foot { padding: var(--gap-3); border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: var(--gap-2); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); min-width: 280px; max-width: min(560px, calc(100vw - 32px)); padding: 12px var(--gap-3); background: var(--toast); color: #FFFFFF; border: 1px solid var(--line); z-index: 50; white-space: normal; overflow-wrap: anywhere; }  /* E-27: the whole message, on more lines if needed */
.toast.success { background: #068941; border-color: #068941; }
.secret { display: flex; gap: var(--gap-2); align-items: stretch; }
.secret code { flex: 1; padding: 8px 10px; background: var(--ground); border: 1px solid var(--line); overflow-wrap: anywhere; }

/* ---- sign-in ------------------------------------------------------------------- */
.signin { min-height: 100dvh; display: grid; place-items: center; padding: var(--gap-3); background: var(--smart-navy); }
:root[data-theme="light"] .signin { background: var(--ground); }
.signin-card { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line); padding: var(--gap-4); }
.signin-card h1 { margin-bottom: 6px; }
.signin-card .lead { color: var(--text-2); margin-bottom: var(--gap-3); }
.signin-links { display: flex; justify-content: space-between; gap: var(--gap-3); margin-top: var(--gap-3); flex-wrap: wrap; }
.signin-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--gap-4); }

/* ---- narrow screens ------------------------------------------------------------ */
@media (max-width: 768px) {
  .shell, .shell.mini { grid-template-columns: minmax(0, 1fr); --menu-width: 260px; }
  .menu { position: fixed; top: 0; right: 0; bottom: 0; width: var(--menu-width); z-index: 40; border-right: 0; border-left: 1px solid var(--line); transform: translateX(100%); visibility: hidden; }
  .shell.drawer-open .menu { transform: none; visibility: visible; }
  .shell.drawer-open::after { content: ""; position: fixed; inset: 0; background: rgba(4, 9, 20, .72); z-index: 30; }
  .shell.mini .brand, .shell.mini .menu-section { display: revert; }
  .shell.mini .menu-item span { position: static; width: auto; height: auto; overflow: visible; clip-path: none; }
  .shell.mini .menu-item, .shell.mini .menu-head { padding: 0 var(--gap-3); justify-content: flex-start; }
  .bar .burger { display: inline-flex; }
  .menu-foot { display: none; }
  .identity .who, .bar .hide-narrow { display: none; }
  .identity { padding: 0; }
  .page-head, .page-body, .tabs { padding-left: var(--gap-3); padding-right: var(--gap-3); }
  .panes, .panes.column { flex-direction: column; }
  .panes > .pane { flex: 0 0 auto !important; width: auto !important; height: auto !important; }
  .panes > .pane-sep { flex-basis: 1px; cursor: default; pointer-events: none; }
  :root { --h1: 26px; }
  .dialog-foot { flex-direction: column-reverse; } .dialog-foot .btn { width: 100%; }
}

/* ---- small additions ----------------------------------------------------------- */
fieldset.field { border: 0; padding: 0; margin: 0 0 var(--gap-3); min-width: 0; }
fieldset.field legend { padding: 0; margin-bottom: 4px; }
.bar select { width: auto; max-width: 180px; }
.stack { display: flex; flex-direction: column; gap: var(--gap-3); min-width: 0; }
.row { display: flex; flex-wrap: wrap; gap: var(--gap-2); align-items: center; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap-2); padding: 8px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li .grow { flex: 1 1 16ch; min-width: 0; }
/* E-5, E-6: in a row that wraps, the growing text keeps a readable width; what does not fit goes to the next line */
.row > .grow { flex: 1 1 16ch; }
.list li.alert-row { align-items: flex-start; }
.list li.alert-row > .grow { overflow-wrap: anywhere; }
.meta-line { font-size: 12px; margin-top: 2px; }
.live { font-size: 12px; color: var(--text-2); }
.content-col { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.content-col > .content { flex: 1; }
/* M-017: panel height grip */
.panel { position: relative; }
.height-grip { height: 6px; margin: 8px -12px -12px; cursor: row-resize; border-top: 1px solid var(--line); }
.height-grip:hover, .height-grip:focus-visible { background: var(--line); outline: none; }
/* T16: every table exports what it shows */
.table-export { float: right; margin: 6px; }
