/* Shell and panel layout.
 *
 * The shell is a grid of chart panels with draggable dividers between them. A panel is a whole
 * chart in its own document, so this file only has to place them and get out of the way.
 */

/* ------------------------------------------------------------------ shell */

/* Same reasoning as the panel: the grid it takes is whatever is left. */
body.shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}
body.shell > .sh-grid { flex: 1 1 auto; min-height: 0; }
body.shell > .menubar,
body.shell > .statusbar { flex: 0 0 auto; }

:root { --split: 4px; }

.sh-grid {
  display: grid;
  min-height: 0;
  background: var(--line);
  overflow: hidden;
}

.sh-row {
  display: grid;
  min-height: 0;
  min-width: 0;
  background: var(--line);
}

.sh-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
  /* An inset outline rather than a border: a border would change the cell's size and shift the
     chart by a pixel every time focus moved, which reads as the layout twitching. */
  outline: 1px solid transparent;
  outline-offset: -1px;
}
.sh-cell.focused { outline-color: #33333a; }

.sh-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--bg);
}

/* While a divider is dragged the frames must not receive the pointer, or the iframe swallows it
   the moment the cursor crosses one and the divider sticks where it was. */
.sh-grid.dragging .sh-frame { pointer-events: none; }

/* Panel name strip. It only appears when there is more than one panel, because a label saying
   "chart" above a single chart is noise. */
.sh-tag {
  position: absolute;
  right: 0;
  bottom: 0;
  display: none;
  align-items: center;
  gap: 6px;
  height: 18px;
  padding: 0 2px 0 8px;
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  border-top-left-radius: var(--r);
  color: var(--ink-faint);
  font-size: var(--t-xs);
  pointer-events: auto;
}
.sh-grid.multi .sh-tag { display: flex; }
.sh-cell.focused .sh-tag { color: var(--ink-dim); }

.sh-name { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sh-x {
  width: 18px;
  height: 16px;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--ink-faint);
  font: var(--t-sm) var(--mono);
  cursor: pointer;
}
.sh-x:hover { background: var(--sell); color: #fff; }

/* dividers */
.sh-div-row,
.sh-div-col {
  background: var(--line);
  position: relative;
}
.sh-div-row { cursor: row-resize; }
.sh-div-col { cursor: col-resize; }
/* A 4px divider is too thin to grab reliably, so the hit area is widened without moving anything
   visually - the same trick a native splitter uses. */
.sh-div-row::after,
.sh-div-col::after {
  content: '';
  position: absolute;
  inset: -3px 0;
}
.sh-div-col::after { inset: 0 -3px; }
.sh-div-row:hover,
.sh-div-col:hover { background: var(--line-2); }

/* ------------------------------------------------------------------ panel */

/* FLEX, not a fixed grid template.
 *
 * This was `grid-template-rows: auto auto auto 1fr`, which assumes exactly four visible children
 * forever. Hiding the tab strip leaves three - so the stage lands in an auto row, the 1fr row
 * stays empty, and a band of background shows below the lowest indicator. Any future element that
 * can be hidden would do the same.
 *
 * A column flex has no such assumption: the stage takes whatever is left, however many siblings
 * are visible. min-height:0 is what lets it SHRINK too, without which a tall canvas pushes the
 * layout past the viewport instead of fitting inside it. */
body.panel {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}
body.panel > .stage { flex: 1 1 auto; min-height: 0; }
body.panel > .tabstrip,
body.panel > .bar,
body.panel > .info { flex: 0 0 auto; }

/* A panel has no menu bar or status bar of its own - the shell owns those - so its chrome starts
   at the tab strip. */
body.panel .menubar,
body.panel .statusbar { display: none; }

@media (max-width: 640px) {
  /* On a phone one chart fills the screen. Splitting a 390px viewport into panels produces two
     charts too small to read, so the grid collapses to whichever panel has focus. */
  .sh-grid { display: block; }
  .sh-row { display: block; height: 100%; }
  .sh-cell { display: none; height: 100%; }
  .sh-cell.focused { display: block; }
  .sh-div-row, .sh-div-col { display: none; }
}

/* ------------------------------------------------------------ period picker */

/* ------------------------------------------------------------- new tab page */

/* Covers the stage while a tab has no instrument. The page IS the empty state - it never sits
   over a chart, because a fresh tab has nothing to show yet. */
.newtab {
  position: fixed;
  inset: var(--newtab-top, 96px) 0 0 0;
  z-index: 30;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 28px 32px;
}
.newtab-view {
  display: flex;
  align-items: center;
  gap: 10px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: 4px;
  padding: 10px 14px;
  cursor: pointer;
}
.newtab-view:hover { background: var(--panel-2); }
.newtab-view.off { color: var(--ink-faint); cursor: default; }
.newtab-view.off:hover { background: transparent; }
.newtab-why { font-size: var(--t-xs); color: var(--ink-faint); }
.newtab-hint { color: var(--ink-dim); font-size: 13px; padding: 4px 14px 10px; }
.newtab-back {
  font: inherit;
  font-size: var(--t-sm);
  color: var(--ink-faint);
  background: transparent;
  border: 0;
  padding: 8px 14px;
  cursor: pointer;
  text-align: left;
}
.newtab-back:hover { color: var(--ink); }

/* --------------------------- indicator picker (used by the chart panel) */
/* Panels this half added: the indicator picker, the per-indicator windows, and the key card.
 *
 * Kept in their own file so two people can work on the look at once without fighting over one
 * stylesheet. Everything reads the same custom properties as the rest of the app, so a theme
 * change moves these too.
 */

/* ------------------------------------------------------------ indicator picker */

.pick-root { display: flex; flex-direction: column; height: 100%; gap: 8px; padding: 10px; }
.pick-search {
  font: inherit;
  font-size: var(--t-md);
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 7px 10px;
}
.pick-search:focus { border-color: var(--focus); outline: none; }
.pick-body { display: flex; gap: 10px; flex: 1; min-height: 0; }

.pick-side { flex: 0 0 180px; display: flex; flex-direction: column; gap: 1px; overflow-y: auto; }
.pick-side-head {
  color: var(--ink-faint);
  font-size: var(--t-xs);
  letter-spacing: .08em;
  padding: 6px 8px 4px;
}
.pick-cat {
  font: inherit;
  font-size: var(--t-md);
  text-align: left;
  color: var(--ink-dim);
  background: transparent;
  border: 0;
  border-radius: var(--r);
  padding: 7px 9px;
  cursor: pointer;
}
.pick-cat:hover { background: var(--panel-2); color: var(--ink); }
.pick-cat.on { background: var(--sel); color: var(--ink); }

.pick-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.pick-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  border-radius: var(--r);
  padding: 2px 6px 2px 2px;
}
.pick-row:hover { background: var(--panel-2); }
.pick-main {
  display: flex;
  flex-direction: column;
  gap: 1px;
  text-align: left;
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 0;
  padding: 7px 8px;
  cursor: pointer;
}
.pick-name { font-size: var(--t-md); }
.pick-blurb { font-size: var(--t-xs); color: var(--ink-faint); line-height: 1.4; }
/* An indicator that is ON says so in words. A coloured dot alone makes the reader guess which
   state the colour means. */
.pick-state { font-size: var(--t-xs); color: var(--buy-hi); min-width: 18px; text-align: right; }
.pick-row.on { background: var(--sel); }
.pick-row.on .pick-name { color: var(--ink); }
.pick-gear {
  font-size: var(--t-md);
  color: var(--ink-faint);
  background: transparent;
  border: 0;
  padding: 4px 6px;
  cursor: pointer;
  border-radius: var(--r);
}
.pick-gear:hover { color: var(--ink); background: var(--panel-3); }

/* ---------------------------------------------------------------- theme panel */

.th-root { display: flex; flex-direction: column; gap: 10px; padding: 10px; height: 100%; }

/* The pair that does the job people actually came for. */
.th-quick { display: flex; gap: 6px; }
.th-preset {
  font: inherit;
  font-size: var(--t-md);
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 6px 16px;
  cursor: pointer;
}
.th-preset:hover { background: var(--panel-3); }
.th-preset.on { border-color: var(--sel); background: var(--sel); color: #fff; }

.th-split { display: flex; gap: 12px; flex: 1; min-height: 0; }
.th-col { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.th-head {
  font-size: var(--t-xs);
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 2px 2px 4px;
}
.th-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 2px;
  flex: 1;
  min-height: 120px;
}
.th-item {
  font: inherit;
  font-size: var(--t-sm);
  text-align: left;
  color: var(--ink-dim);
  background: transparent;
  border: 0;
  border-radius: 2px;
  padding: 5px 8px;
  cursor: pointer;
}
.th-item:hover { background: var(--panel-2); color: var(--ink); }
.th-item.on { background: var(--sel); color: #fff; }
/* Same inset as every other window footer, so the button clears the resize grip in the corner
   instead of sitting underneath it. */
.th-foot { display: flex; justify-content: flex-end; padding: 8px 12px; }

/* A theme row that names the choice and says what it is for, rather than a bare font stack. */
.th-item { display: flex; flex-direction: column; gap: 1px; }
.th-item-name { font-size: var(--t-sm); }
.th-item-blurb { font-size: var(--t-xs); color: var(--ink-faint); }
.th-item.on .th-item-blurb { color: rgba(255, 255, 255, .72); }
