/* ==========================================================================
   SMUI.HTML
   A statistics workbench laid out as JMP lays one out: a menu bar, the
   table's Columns and Rows panels on the left, and a work area with the
   data grid and one tab per report. Reports are outline boxes with a
   disclosure triangle and a red-triangle menu. Colours are kvot.css's
   tokens, so the theme toggle works. Class prefix: sm-.
   ========================================================================== */

/* The page's own tokens live on :root, because dialogs, menus and toasts
   are appended to <body>, outside .sm. */
:root {
  --sm-cont: #2f6ec7;
  --sm-ord: #2f8a3e;
  --sm-nom: #c0392b;
  --sm-sel-bg: color-mix(in oklab, var(--color-kvot-bright) 34%, var(--bg-primary));
  --sm-sel-strong: color-mix(in oklab, var(--color-kvot-accent) 30%, var(--bg-primary));
  --sm-head-bg: var(--bg-secondary);
}
:root[data-theme="dark"] { --sm-cont: #6aa7ff; --sm-ord: #6cc27a; --sm-nom: #ff7a6b; }
.sm {
  --sm-side-w: 250px;
  --sm-row-h: 22px;
  display: grid;
  grid-template-rows: 30px minmax(0, 1fr);
  height: 100%;
  overflow: hidden;
  font-family: verdana, sans-serif;
  font-size: 12.5px;
  color: var(--text-primary);
  background: var(--bg-primary);
}

.sm [hidden], .sm-dialog [hidden] { display: none !important; }
.sm-type { display: inline-block; flex: none; vertical-align: -1px; }
.sm-type-continuous { color: var(--sm-cont); }
.sm-type-ordinal { color: var(--sm-ord); }
.sm-type-nominal { color: var(--sm-nom); }

/* ---- the menu bar -------------------------------------------------------- */
.sm-menubar {
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0 6px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-surface);
  user-select: none;
  min-width: 0;
}
.sm-menubar > button {
  padding: 0 10px;
  border: 0;
  background: none;
  font: inherit;
  color: var(--text-primary);
  cursor: pointer;
}
.sm-menubar > button:hover, .sm-menubar > button.is-open { background: var(--sm-sel-bg); }
.sm-menubar .sm-spacer { flex: 1 1 auto; }
.sm-engine {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 4px 0;
  padding: 0 10px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--bg-primary);
  font-size: 11px;
  color: var(--text-secondary);
  cursor: pointer;
  max-width: 46vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sm-engine::before { content: ''; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.sm-engine[data-state="loading"]::before, .sm-engine[data-busy="1"]::before { background: var(--color-kvot-bright); animation: sm-pulse 1s ease-in-out infinite; }
.sm-engine[data-state="ready"]::before { background: #3a9a4a; }
.sm-engine[data-state="error"]::before { background: #c0392b; }
@keyframes sm-pulse { 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .sm-engine::before { animation: none !important; } }

/* ---- drop-down menus (menu bar, red triangles, right clicks) ------------- */
.sm-menu {
  position: fixed;
  z-index: 60;
  min-width: 190px;
  max-width: 360px;
  max-height: calc(100vh - 20px);
  overflow-y: auto;
  padding: 4px 0;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-surface);
  box-shadow: 0 8px 24px var(--shadow-color);
  font-size: 12.5px;
}
.sm-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 4px 14px 4px 8px;
  border: 0;
  background: none;
  font: inherit;
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}
.sm-menu button:hover, .sm-menu button:focus-visible, .sm-menu button.is-open { background: var(--sm-sel-bg); outline: none; }
.sm-menu button[disabled] { color: var(--text-muted); cursor: default; background: none; }
.sm-menu .sm-mark { flex: none; width: 14px; text-align: center; color: var(--color-kvot-accent); }
.sm-menu .sm-label { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; }
.sm-menu .sm-key { flex: none; color: var(--text-muted); font-size: 11px; }
.sm-menu .sm-sub::after { content: '▸'; flex: none; color: var(--text-muted); }
.sm-menu hr { margin: 4px 0; border: 0; border-top: 1px solid var(--border-color); }
.sm-menu .sm-menu-head { padding: 4px 14px 2px 30px; font-size: 10.5px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted); }

/* ---- the body: side panels, handle, work area ----------------------------- */
/* Two columns: the side panels and the work area, which meet at the side's
   border. The resize handle lies over that border instead of taking a
   column of its own, so the tab bar reaches all the way to the panels. */
.sm-body { position: relative; display: grid; grid-template-columns: var(--sm-side-w) minmax(0, 1fr); min-height: 0; }
.sm-side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--border-color);
  background: var(--bg-surface);
}
.sm-handle { cursor: col-resize; position: absolute; top: 0; bottom: 0; left: calc(var(--sm-side-w) - 4px); width: 7px; z-index: 6; }
.sm-handle::after { content: ''; position: absolute; inset: 0 2px; border-radius: 2px; transition: background 0.15s; }
.sm-handle:hover::after, .sm-handle.active::after { background: var(--color-kvot-accent); }
.sm-panel { display: flex; flex-direction: column; min-height: 0; border-bottom: 1px solid var(--border-color); }
.sm-panel > h3 {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 6px 10px 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.sm-panel > h3 .sm-count { font-weight: 400; letter-spacing: 0; text-transform: none; color: var(--text-muted); }
.sm-panel > h3 .sm-grow { flex: 1 1 auto; }
.sm-panel-table { flex: none; padding-bottom: 8px; }
.sm-panel-cols { flex: 1 1 auto; }
.sm-panel-rows { flex: none; }
.sm-tablebox { padding: 0 10px; }
.sm-tablebox select, .sm-tablebox input { width: 100%; box-sizing: border-box; font: inherit; }
.sm-tablebox .sm-tablename { margin: 0 0 3px; padding: 3px 6px; border: 1px solid var(--border-color); border-radius: 3px; background: var(--input-bg); color: var(--text-primary); font-weight: 600; }
.sm-tablebox .sm-tablemeta { font-size: 11px; color: var(--text-muted); line-height: 1.4; overflow-wrap: anywhere; }
.sm-colfilter { margin: 0 10px 4px; padding: 3px 6px; border: 1px solid var(--border-color); border-radius: 3px; background: var(--input-bg); color: var(--text-primary); font: inherit; font-size: 12px; }
.sm-collist { flex: 1 1 auto; min-height: 0; overflow-y: auto; margin: 0; padding: 0 0 6px; list-style: none; }
.sm-collist li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  cursor: default;
  white-space: nowrap;
}
.sm-collist li:hover { background: color-mix(in oklab, var(--sm-sel-bg) 50%, transparent); }
.sm-collist li.is-selected { background: var(--sm-sel-bg); }
.sm-collist li .sm-colname { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; }
.sm-collist li .sm-colflag { flex: none; font-size: 10px; color: var(--text-muted); }
.sm-collist li button.sm-typebtn { display: inline-flex; padding: 1px; border: 0; background: none; cursor: pointer; border-radius: 2px; }
.sm-collist li button.sm-typebtn:hover { background: var(--bg-primary); }
.sm-rowcounts { margin: 0 10px 8px; border-collapse: collapse; font-size: 12px; }
.sm-rowcounts td { padding: 1px 0; }
.sm-rowcounts td:last-child { padding-left: 14px; text-align: right; font-variant-numeric: tabular-nums; }
.sm-rowcounts tr.is-zero { color: var(--text-muted); }

/* ---- the work area: tabs and views ---------------------------------------- */
/* Placed by column, so that the work area keeps the second column when the
   side panels are hidden (at phone width a hidden item leaves its track). */
.sm-main { grid-column: 2; display: grid; grid-template-rows: auto minmax(0, 1fr); min-width: 0; min-height: 0; }
.sm-side { grid-column: 1; }
.sm-tabs {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  padding: 5px 8px 0;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
  overflow-x: auto;
  scrollbar-width: thin;
}
.sm-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 260px;
  padding: 5px 8px 5px 11px;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 4px 4px 0 0;
  background: none;
  font: inherit;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
}
.sm-tab:hover { color: var(--text-primary); background: color-mix(in oklab, var(--bg-primary) 60%, transparent); }
.sm-tab.is-active { background: var(--bg-primary); border-color: var(--border-color); color: var(--text-primary); font-weight: 600; margin-bottom: -1px; padding-bottom: 6px; }
.sm-tab .sm-tabtitle { overflow: hidden; text-overflow: ellipsis; }
.sm-tab .sm-tabclose { display: inline-flex; width: 16px; height: 16px; align-items: center; justify-content: center; border-radius: 3px; color: var(--text-muted); font-size: 13px; line-height: 1; }
.sm-tab .sm-tabclose:hover { background: var(--sm-sel-bg); color: var(--text-primary); }
.sm-view { min-height: 0; overflow: hidden; }
.sm-view[hidden] { display: none; }

/* ---- the data grid ---------------------------------------------------------- */
.sm-gridwrap { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100%; }
.sm-gridbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-bottom: 1px solid var(--border-color);
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 0;
}
.sm-gridbar .sm-spacer { flex: 1 1 auto; }
.sm-gridbar .sm-cellref { font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sm-grid { position: relative; overflow: auto; outline: none; background: var(--bg-primary); }
.sm-grid-inner { position: relative; }
.sm-grid-head {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  background: var(--sm-head-bg);
  border-bottom: 1px solid var(--border-color);
}
.sm-grid-corner {
  position: sticky;
  left: 0;
  z-index: 4;
  flex: none;
  box-sizing: border-box;
  border-right: 1px solid var(--border-color);
  background: var(--sm-head-bg);
}
.sm-hcell {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  gap: 5px;
  box-sizing: border-box;
  height: 26px;
  padding: 0 8px 0 6px;
  border-right: 1px solid var(--border-color);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
}
.sm-hcell .sm-hname { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; }
.sm-hcell .sm-hflag { flex: none; font-weight: 400; font-size: 10px; color: var(--text-muted); }
.sm-hcell.is-selected { background: var(--sm-sel-strong); }
.sm-hcell .sm-resizer { position: absolute; right: -3px; top: 0; bottom: 0; width: 7px; cursor: col-resize; z-index: 2; }
.sm-grid-rows { position: absolute; left: 0; top: 26px; }
.sm-grow {
  position: absolute;
  left: 0;
  display: flex;
  height: var(--sm-row-h);
  box-sizing: border-box;
  border-bottom: 1px solid color-mix(in oklab, var(--border-color) 70%, transparent);
}
.sm-rhead {
  position: sticky;
  left: 0;
  z-index: 2;
  flex: none;
  display: flex;
  align-items: center;
  gap: 3px;
  box-sizing: border-box;
  padding: 0 6px 0 4px;
  border-right: 1px solid var(--border-color);
  background: var(--sm-head-bg);
  color: var(--text-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  user-select: none;
}
.sm-rhead .sm-rnum { flex: 1 1 auto; text-align: right; }
.sm-rhead .sm-rstate { flex: none; width: 34px; display: flex; gap: 2px; align-items: center; font-size: 10px; }
.sm-rhead .sm-rdot { width: 8px; height: 8px; border-radius: 50%; }
.sm-cell {
  flex: none;
  box-sizing: border-box;
  padding: 0 7px;
  border-right: 1px solid color-mix(in oklab, var(--border-color) 70%, transparent);
  line-height: calc(var(--sm-row-h) - 1px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.sm-cell.num { text-align: right; }
.sm-cell.miss { color: var(--text-muted); }
.sm-cell.is-cursor { outline: 2px solid var(--color-kvot-accent); outline-offset: -2px; }
.sm-cell.is-colsel { background: color-mix(in oklab, var(--sm-sel-bg) 55%, transparent); }
.sm-grow.is-selected .sm-cell, .sm-grow.is-selected .sm-rhead { background: var(--sm-sel-bg); }
.sm-grow.is-excluded .sm-cell { color: var(--text-muted); font-style: italic; }
.sm-grow.is-hidden .sm-rnum { text-decoration: line-through; }
.sm-cell-edit { position: absolute; z-index: 5; box-sizing: border-box; padding: 0 6px; border: 2px solid var(--color-kvot-accent); background: var(--input-bg); color: var(--text-primary); font: inherit; outline: none; }
.sm-grid-empty { padding: 40px 24px; color: var(--text-secondary); max-width: 640px; line-height: 1.6; }
.sm-grid-empty h2 { margin: 0 0 8px; font-size: 18px; color: var(--text-primary); font-weight: 600; }
.sm-grid-empty .sm-examples { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; }

/* ---- buttons ------------------------------------------------------------------ */
.sm-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-surface);
  color: var(--text-primary);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.sm-btn:hover { border-color: var(--color-kvot-accent); }
.sm-btn.primary { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; font-weight: 600; }
.sm-btn.primary:hover { filter: brightness(1.08); }
.sm-btn[disabled] { opacity: 0.55; cursor: default; }
.sm-btn.small { padding: 2px 8px; font-size: 11.5px; }

/* ---- reports ---------------------------------------------------------------------- */
.sm-report { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100%; }
.sm-reportbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-bottom: 1px solid var(--border-color);
  min-width: 0;
  flex-wrap: wrap;
}
.sm-reportbar .sm-spacer { flex: 1 1 auto; }
.sm-reportbar .sm-reportnote { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sm-reportbody { overflow: auto; padding: 10px 14px 40px; }
.sm-reportbody.is-running { opacity: 0.6; }

.sm-ob { margin: 0 0 6px; min-width: 0; }
.sm-ob-head { display: flex; align-items: center; gap: 4px; min-height: 22px; }
.sm-ob-head h2, .sm-ob-head h3, .sm-ob-head h4 { margin: 0; font-size: 13px; font-weight: 600; line-height: 1.3; }
.sm-ob.level-0 > .sm-ob-head h2 { font-size: 14px; }
.sm-ob-toggle, .sm-ob-menu {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: none;
  cursor: pointer;
  color: var(--text-secondary);
}
.sm-ob-toggle:hover, .sm-ob-menu:hover { background: var(--sm-sel-bg); }
.sm-ob-toggle svg { transition: transform 0.12s; }
.sm-ob.is-closed > .sm-ob-head .sm-ob-toggle svg { transform: rotate(-90deg); }
.sm-ob-menu { color: #c8322b; }
:root[data-theme="dark"] .sm-ob-menu { color: #ff6b5c; }
.sm-ob-body { padding: 4px 0 6px 21px; min-width: 0; }
.sm-ob.is-closed > .sm-ob-body { display: none; }
.sm-ob-row { display: flex; flex-wrap: wrap; gap: 16px 22px; align-items: flex-start; }
.sm-ob-row > * { min-width: 0; }
.sm-ob-note { margin: 2px 0 6px; font-size: 11.5px; color: var(--text-secondary); max-width: 760px; line-height: 1.45; }
.sm-ob-warn { margin: 2px 0 6px; padding: 5px 9px; border-left: 3px solid var(--color-kvot-bright); background: color-mix(in oklab, var(--color-kvot-bright) 12%, transparent); font-size: 11.5px; color: var(--text-primary); max-width: 760px; }
.sm-ob-error { margin: 2px 0 6px; padding: 6px 10px; border-left: 3px solid #c0392b; background: color-mix(in oklab, #c0392b 10%, transparent); font-size: 12px; max-width: 760px; white-space: pre-wrap; }

.sm-rt { border-collapse: collapse; font-size: 12px; margin: 2px 0 8px; }
.sm-rt caption { caption-side: top; text-align: left; padding: 0 0 3px; font-size: 11.5px; font-weight: 600; color: var(--text-secondary); }
.sm-rt th, .sm-rt td { padding: 2px 9px; border-bottom: 1px solid color-mix(in oklab, var(--border-color) 75%, transparent); white-space: nowrap; }
.sm-rt thead th { background: var(--sm-head-bg); border-bottom: 1px solid var(--border-color); font-weight: 600; text-align: right; color: var(--text-primary); position: relative; }
.sm-rt thead th.sm-l, .sm-rt td.sm-l { text-align: left; }
.sm-rt td { text-align: right; font-variant-numeric: tabular-nums; }
.sm-rt td.sm-l { font-variant-numeric: normal; }
.sm-rt td.p-sig { color: #c8322b; font-weight: 600; }
:root[data-theme="dark"] .sm-rt td.p-sig { color: #ff8a7a; }
.sm-rt tbody tr:hover td { background: color-mix(in oklab, var(--sm-sel-bg) 40%, transparent); }
.sm-rt.sortable thead th { cursor: pointer; }
.sm-rt tfoot td { font-size: 11px; color: var(--text-muted); text-align: left; border-bottom: 0; }
.sm-kv { border-collapse: collapse; font-size: 12px; margin: 2px 0 8px; }
.sm-kv td { padding: 1.5px 0; border-bottom: 1px solid color-mix(in oklab, var(--border-color) 55%, transparent); }
.sm-kv td:first-child { padding-right: 18px; color: var(--text-primary); white-space: nowrap; }
.sm-kv td:last-child { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sm-plot { position: relative; min-width: 260px; }
.sm-plot .js-plotly-plot .modebar { opacity: 0.25; }
.sm-plot:hover .js-plotly-plot .modebar { opacity: 1; }
.sm-code { margin: 4px 0 8px; }
.sm-code summary { cursor: pointer; font-size: 11.5px; color: var(--link-color); }
.sm-code pre { margin: 4px 0 0; padding: 8px 10px; max-width: 820px; overflow-x: auto; border: 1px solid var(--border-color); border-radius: 4px; background: var(--code-bg); font-size: 11.5px; line-height: 1.45; }
.sm-slider { display: flex; align-items: center; gap: 8px; font-size: 12px; margin: 2px 0; }
.sm-slider input[type="range"] { width: 160px; }

/* ---- the Local Data Filter ------------------------------------------------------------ */
.sm-reportbody.has-filter { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 16px; align-items: start; }
.sm-filter { position: sticky; top: 0; z-index: 2; box-sizing: border-box; max-height: calc(100vh - 200px); overflow-y: auto; padding: 8px 10px; border: 1px solid var(--border-color); border-radius: 5px; background: var(--bg-surface); font-size: 12px; }
.sm-filter-head { display: flex; align-items: center; gap: 6px; }
.sm-filter-head .sm-spacer, .sm-filter-colhead .sm-spacer { flex: 1 1 auto; }
.sm-filter-count { margin: 4px 0 6px; color: var(--text-secondary); }
.sm-filter-actions { display: flex; gap: 6px; margin-bottom: 8px; }
.sm-filter-col { border-top: 1px solid var(--border-color); padding: 6px 0; }
.sm-filter-colhead { display: flex; align-items: center; gap: 6px; font-weight: 600; margin-bottom: 4px; min-width: 0; }
.sm-filter-colhead .sm-colname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sm-filter-levels { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 3px; }
.sm-filter-level { display: inline-flex; gap: 6px; padding: 2px 7px; border: 1px solid var(--border-color); border-radius: 3px; background: var(--bg-primary); color: var(--text-primary); font: inherit; font-size: 11.5px; cursor: pointer; }
.sm-filter-level .sm-count { color: var(--text-muted); }
.sm-filter-level.is-on { background: var(--sm-sel-bg); border-color: var(--color-kvot-accent); }
.sm-filter-range { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 6px; margin-bottom: 3px; }
.sm-filter-range input { width: 100%; box-sizing: border-box; padding: 2px 5px; border: 1px solid var(--border-color); border-radius: 3px; background: var(--input-bg); color: var(--text-primary); font: inherit; }
.sm-switcher { margin: 0 0 10px; padding: 6px 10px 8px; border: 1px solid var(--border-color); border-radius: 5px; background: var(--bg-surface); font-size: 12px; }
.sm-switch-list { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.sm-switch-list .sm-filter-level { align-items: center; }
.sm-reportcol { min-width: 0; }
.sm-panel-filter { flex: 0 1 auto; max-height: 48%; overflow-y: auto; padding: 6px 10px 8px; font-size: 12px; }
.sm-filter-modes { display: flex; gap: 12px; margin: 0 0 6px; }
.sm-filter-modes label { display: inline-flex; align-items: center; gap: 4px; }
@media (max-width: 760px) { .sm-reportbody.has-filter { grid-template-columns: minmax(0, 1fr); } .sm-filter { position: static; max-height: none; } }

/* ---- dialogs ---------------------------------------------------------------------- */
/* The (i) panel opened from a dialog lies above the dialog's dimmed backdrop
   (kvot-info.css puts it at 45, the backdrop is at 50) and below menus; on
   a wide window the dialog moves left, clear of the panel. */
.info-panel { z-index: 55; }
@media (min-width: 1100px) {
  :root.kvot-info-open .sm-modal-back { padding-right: calc(min(400px, 100vw - 24px) + 12px); }
}
.sm-modal-back, .sm-menu, .sm-toast { font-family: verdana, sans-serif; }
.sm-modal-back { font-size: 12.5px; color: var(--text-primary); }
.sm-modal-back input, .sm-modal-back select, .sm-modal-back textarea, .sm-modal-back button { font-family: inherit; }
.sm-modal-back { position: fixed; inset: 0; z-index: 50; background: rgba(20, 14, 10, 0.34); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 12px 12px; overflow-y: auto; }
.sm-dialog {
  display: flex;
  flex-direction: column;
  width: min(900px, 100%);
  max-height: 88vh;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-surface);
  box-shadow: 0 18px 50px var(--shadow-color);
  position: relative;
}
.sm-dialog.narrow { width: min(460px, 100%); }
.sm-dialog-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border-color); }
.sm-dialog-head h2 { flex: 1 1 auto; margin: 0; font-size: 14px; font-weight: 600; }
.sm-dialog-head .sm-dialog-x { border: 0; background: none; font-size: 18px; color: var(--text-secondary); cursor: pointer; width: 26px; height: 26px; }
.sm-dialog-body { padding: 12px 14px; overflow-y: auto; min-height: 0; }
.sm-dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border-color); }
.sm-dialog-lead { margin: 0 0 10px; font-size: 12px; color: var(--text-secondary); line-height: 1.5; }

.sm-launch { display: grid; grid-template-columns: minmax(170px, 0.9fr) minmax(0, 1.5fr) 118px; gap: 14px; min-height: 320px; }
.sm-launch h4 { margin: 0 0 5px; font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }
.sm-launch h4 .sm-grow { flex: 1 1 auto; }
.sm-pick { display: flex; flex-direction: column; min-height: 0; }
.sm-pick input { margin: 0 0 4px; padding: 3px 6px; border: 1px solid var(--border-color); border-radius: 3px; background: var(--input-bg); color: var(--text-primary); font: inherit; }
.sm-pick-list { flex: 1 1 auto; min-height: 220px; max-height: 50vh; overflow-y: auto; margin: 0; padding: 2px 0; list-style: none; border: 1px solid var(--border-color); border-radius: 3px; background: var(--bg-primary); }
.sm-pick-list li, .sm-role-list li { display: flex; align-items: center; gap: 6px; padding: 2px 7px; cursor: default; user-select: none; white-space: nowrap; }
.sm-pick-list li .sm-colname, .sm-role-list li .sm-colname { overflow: hidden; text-overflow: ellipsis; }
.sm-pick-list li.is-selected, .sm-role-list li.is-selected { background: var(--sm-sel-bg); }
.sm-pick-list li.is-disabled { color: var(--text-muted); }
.sm-roles { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.sm-role { display: grid; grid-template-columns: var(--sm-role-w, 104px) minmax(0, 1fr) 17px; gap: 7px; align-items: start; }
.sm-role .sm-btn { justify-content: center; width: var(--sm-role-w, 104px); white-space: normal; text-align: center; }
.sm-role .sm-btn.required::after { content: ''; }
.sm-role-list { min-height: 24px; max-height: 128px; overflow-y: auto; margin: 0; padding: 2px 0; list-style: none; border: 1px solid var(--border-color); border-radius: 3px; background: var(--bg-primary); }
.sm-role-list.is-empty::before { content: attr(data-hint); display: block; padding: 3px 7px; color: var(--text-muted); font-size: 11.5px; font-style: italic; }
.sm-role-list.drop { outline: 2px dashed var(--color-kvot-accent); outline-offset: -2px; }
.sm-role.is-missing .sm-role-list { border-color: #c0392b; }
.sm-actions { display: flex; flex-direction: column; gap: 6px; }
.sm-actions .sm-btn { justify-content: center; }
.sm-launch-opts { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border-color); display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; font-size: 12px; }
.sm-launch-opts label { display: inline-flex; align-items: center; gap: 6px; }
.sm-launch-opts input[type="text"], .sm-launch-opts input[type="number"], .sm-launch-opts select { padding: 2px 5px; border: 1px solid var(--border-color); border-radius: 3px; background: var(--input-bg); color: var(--text-primary); font: inherit; }
.sm-launch-msg { min-height: 18px; margin-top: 8px; font-size: 12px; color: #c0392b; }
.sm-launch-msg.is-info { color: var(--text-secondary); }
.sm-form { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 7px 12px; align-items: center; font-size: 12.5px; }
.sm-form input[type="text"], .sm-form input[type="number"], .sm-form select, .sm-form textarea { padding: 3px 6px; border: 1px solid var(--border-color); border-radius: 3px; background: var(--input-bg); color: var(--text-primary); font: inherit; min-width: 0; }
.sm-form textarea { min-height: 70px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.sm-form .full { grid-column: 1 / -1; }
.sm-toast { position: fixed; z-index: 70; left: 50%; bottom: calc(var(--footer-height, 31px) + 14px); transform: translateX(-50%); max-width: min(620px, 92vw); padding: 8px 14px; border-radius: 5px; background: var(--text-primary); color: var(--bg-primary); font-size: 12.5px; box-shadow: 0 6px 20px var(--shadow-color); }
.sm-toast.error { background: #a8322a; color: #fff; }

/* ---- the frame: side toggle, views, drop target ---------------------------------------- */
.sm-sidetoggle { display: none; }
.sm-views { position: relative; min-height: 0; min-width: 0; }
.sm-views > .sm-view { position: absolute; inset: 0; }
.sm-tableview { height: 100%; }
.sm.is-dropping .sm-views { outline: 3px dashed var(--color-kvot-accent); outline-offset: -6px; }
.sm-tab .sm-tabicon { flex: none; color: var(--text-muted); }
.sm-tab.is-active .sm-tabicon { color: var(--color-kvot-accent); }
.sm-collist li.drop-above { box-shadow: inset 0 2px 0 var(--color-kvot-accent); }
.sm-menu .sm-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: -1px; }

/* ---- home ------------------------------------------------------------------------------ */
.sm-home { height: 100%; overflow-y: auto; }
.sm-home-inner { max-width: 900px; padding: 18px 26px 60px; line-height: 1.55; font-size: 13px; }
.sm-home-inner h2 { margin: 4px 0 8px; font-size: 18px; font-weight: 600; }
.sm-home-inner h3 { margin: 22px 0 8px; font-size: 13.5px; }
.sm-home-inner p { margin: 0 0 10px; max-width: 760px; }
.sm-homebtns { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 10px; }
.sm-examples, .sm-dslist { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; }
.sm-exitem, .sm-dsitem {
  display: flex; flex-direction: column; gap: 3px; align-items: flex-start; text-align: left;
  padding: 8px 10px; border: 1px solid var(--border-color); border-radius: 5px; background: var(--bg-surface);
  color: var(--text-primary); font: inherit; font-size: 12px; cursor: pointer; line-height: 1.4;
}
.sm-exitem:hover, .sm-dsitem:hover { border-color: var(--color-kvot-accent); }
/* In a dialog, which is itself --bg-surface, the cards take the page's own
   background (white in the light theme), as the launch dialog's lists do. */
.sm-dsitem { background: var(--bg-primary); }
.sm-dsitem[disabled] { opacity: 0.6; cursor: progress; }
.sm-exitem span, .sm-dsitem span { color: var(--text-secondary); }
.sm-dsitem em { color: var(--text-muted); font-size: 11px; }
.sm-dslist { max-height: 60vh; overflow-y: auto; }
.sm-homelist { margin: 0; padding-left: 4px; list-style: none; }
.sm-homelist > li { margin: 3px 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.sm-homelist ul { flex-basis: 100%; margin: 0 0 0 22px; padding: 0; list-style: none; }
.sm-linkbtn { border: 0; background: none; padding: 0; font: inherit; color: var(--link-color); cursor: pointer; text-align: left; }
.sm-linkbtn:hover { text-decoration: underline; }
.sm-home-inner .sm-home-engine { margin-top: 26px; }

/* ---- dialogs: odds and ends --------------------------------------------------------------- */
.sm-inline { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sm-orderbox { display: flex; gap: 8px; align-items: flex-start; }
.sm-orderlist { flex: 1 1 auto; min-width: 140px; max-height: 170px; }
.sm-orderbtns { display: flex; flex-direction: column; gap: 4px; }
.sm-log { max-height: 240px; overflow: auto; }
.sm-launch-dialog .sm-dialog-body { overflow-y: auto; }

/* ---- Distribution --------------------------------------------------------------------------- */
.sm-dist-wrap { display: flex; flex-wrap: wrap; gap: 6px 30px; align-items: flex-start; }
.sm-dist-wrap > .sm-ob { flex: 0 1 auto; }
.sm-dist-wrap.is-stacked { flex-direction: column; }
.sm-dist-wrap[style*="--per-row"] > .sm-ob { flex-basis: calc(100% / var(--per-row) - 30px); }
.sm-dist-tables { display: flex; flex-direction: column; gap: 2px; }
.sm-stem { margin: 2px 0 6px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11.5px; line-height: 1.35; }
.sm-platforms td { font-size: 12px; }
.sm-platforms td code { font-size: 11px; }

/* ---- help --------------------------------------------------------------------------- */
.sm-help { overflow-y: auto; height: 100%; }
.sm-help-inner { max-width: 880px; padding: 16px 24px 60px; line-height: 1.6; font-size: 13px; }
.sm-help-inner h2 { margin: 26px 0 8px; font-size: 16px; }
.sm-help-inner h2:first-child { margin-top: 4px; }
.sm-help-inner h3 { margin: 18px 0 6px; font-size: 13.5px; }
.sm-help-inner p { margin: 0 0 10px; }
.sm-help-inner ul { margin: 0 0 10px; padding-left: 20px; }
.sm-help-inner code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; background: var(--code-bg); padding: 0 3px; border-radius: 3px; }
.sm-help-inner table { border-collapse: collapse; font-size: 12px; margin: 4px 0 12px; }
.sm-help-inner th, .sm-help-inner td { border-bottom: 1px solid var(--border-color); padding: 3px 10px 3px 0; text-align: left; vertical-align: top; }
.sm-help-inner .sm-build { margin-top: 30px; font-size: 11px; color: var(--text-muted); }

@media (max-width: 760px) {
  .sm { --sm-side-w: 0px; }
  .sm-sidetoggle { display: inline-flex; align-items: center; padding: 0 10px; border: 0; background: none; font-size: 16px; color: var(--text-primary); cursor: pointer; }
  .sm-body { grid-template-columns: 0 minmax(0, 1fr); }
  .sm-side, .sm-handle { display: none; }
  .sm.side-open .sm-body { grid-template-columns: min(80vw, 280px) minmax(0, 1fr); }
  .sm.side-open .sm-side { display: flex; }
  .sm-menubar { overflow-x: auto; }
  .sm-launch { grid-template-columns: 1fr; }
  .sm-actions { flex-direction: row; flex-wrap: wrap; }
}
@media print {
  .sm-menubar, .sm-side, .sm-handle, .sm-tabs, .sm-reportbar, .sm-ob-menu { display: none !important; }
  .sm-body { display: block; }
  .sm-reportbody { overflow: visible; }
}
