:root {
  color: #e9edf0;
  background: #0e1317;
  font-family: ui-monospace, "Cascadia Mono", monospace;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  padding: 0;
}

main {
  display: grid;
  width: 100%;
  height: 100vh;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  background: #0e1418;
}

.app-bar {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 2.3rem;
  padding: 0.25rem 0.55rem;
  border-bottom: 1px solid #2a353c;
  background: #11191e;
}

.app-bar strong {
  color: #df9c51;
  font-size: 0.9rem;
  font-weight: 650;
  letter-spacing: 0.08em;
}

#status { color: #9eabb3; }
#status[data-state="failed"] { color: #ff8c7a; }
#evaluation-status { color: #70828d; }

.workbook-actions, .display-actions, #command-form, .app-status {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

button, #command-input {
  border: 1px solid #36434b;
  border-radius: 3px;
  color: #dfe5e8;
  background: #172127;
  font: inherit;
}

button { padding: 0.23rem 0.45rem; cursor: pointer; }
button:hover { border-color: #bd8548; background: #1c2930; }
#command-form { flex: 1; min-width: 10rem; }
#command-form label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
#command-form > span { color: #71828c; }
#command-input { width: 100%; min-width: 7rem; padding: 0.23rem 0.4rem; border-color: transparent; background: #0e161b; }
#command-input:focus { border-color: #53616a; outline: none; }
.display-actions button { min-width: 1.8rem; }
#grid-size-reset { min-width: 6.7rem; color: #9eabb3; }
.app-status { min-width: 0; justify-content: flex-end; font-size: 0.78rem; }
.app-status > span { white-space: nowrap; }
#status { max-width: 16rem; overflow: hidden; text-overflow: ellipsis; }

.lua-layout { display: grid; min-height: 0; flex: 1; grid-template-columns: 12rem minmax(0, 1fr); gap: 0.8rem; overflow: auto; }
.lua-script-list { overflow: auto; border: 1px solid #36434b; background: #0e161b; }
.lua-script-list button { display: block; width: 100%; border: 0; border-radius: 0; text-align: left; }
.lua-script-list button[aria-selected="true"] { color: #fff; background: #334552; }
.lua-editor { display: grid; min-width: 0; min-height: 0; grid-template-rows: auto auto auto auto minmax(12rem, 1fr) auto auto; gap: 0.35rem; }
.lua-field { display: grid; min-width: 0; gap: 0.35rem; }
.lua-field[hidden] { display: none; }
.lua-source-field { min-height: 0; grid-template-rows: auto minmax(12rem, 1fr); }
.lua-editor input, .lua-editor textarea, .lua-editor pre { width: 100%; border: 1px solid #36434b; border-radius: 3px; color: #e9edf0; background: #0e161b; font: inherit; }
.lua-editor input { padding: 0.3rem; }
.lua-editor textarea { min-height: 12rem; height: 100%; padding: 0.45rem; resize: vertical; tab-size: 2; }
.lua-editor pre { min-height: 4rem; max-height: 9rem; margin: 0; padding: 0.45rem; overflow: auto; white-space: pre-wrap; }
.lua-actions { display: flex; gap: 0.35rem; }
.lua-run-controls { display: grid; grid-template-columns: auto minmax(8rem, 0.7fr) auto minmax(10rem, 1fr); align-items: center; gap: 0.35rem 0.5rem; }
.lua-run-controls select, .lua-run-controls input { min-width: 0; padding: 0.3rem; border: 1px solid #36434b; border-radius: 3px; color: #e9edf0; background: #0e161b; font: inherit; }
#lua-script-status { min-height: 1.2rem; margin: 0; color: #9fc9d0; }
#lua-panel[aria-busy="true"] #lua-script-status { color: #e8b45c; }
#lua-panel[data-run-state="failed"] #lua-script-status { color: #ff8c7a; }
#lua-script-error { border-color: #8f4c45; color: #ffb1a4; }

.sheet-host {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

canvas:focus { box-shadow: inset 0 0 0 1px #e89c3d; }

#sheet-input {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  resize: none;
  overflow: hidden;
}

#cell-choice {
  position: absolute;
  z-index: 12;
  min-width: 10rem;
  max-width: calc(100% - 0.5rem);
  max-height: min(18rem, calc(100% - 0.5rem));
  padding: 0.2rem;
  overflow-y: auto;
  border: 1px solid #d49a55;
  border-radius: 3px;
  outline: none;
  background: #172127;
  box-shadow: 0 0.45rem 1.3rem #000b;
}

#cell-choice[hidden] { display: none; }
#cell-choice:focus-visible { border-color: #f0b66f; }
#cell-choice [role="option"] { display: block; width: 100%; border: 0; border-radius: 0; text-align: left; }
#cell-choice [role="option"][aria-selected="true"] { color: #fff; background: #334d75; }

#completion-popup {
  position: absolute;
  z-index: 13;
  min-width: 12rem;
  max-width: min(44rem, calc(100% - 0.5rem));
  padding: 0.2rem;
  border: 1px solid #d49a55;
  border-radius: 3px;
  background: #172127;
  box-shadow: 0 0.45rem 1.3rem #000b;
  font-size: 0.85rem;
  pointer-events: none;
}

#completion-popup[hidden] { display: none; }
#completion-popup [role="option"] { display: flex; justify-content: space-between; gap: 1.2rem; padding: 0.16rem 0.45rem; white-space: nowrap; }
#completion-popup [role="option"] small { min-width: 0; overflow: hidden; color: #8da0ac; text-overflow: ellipsis; }
#completion-popup [role="option"][aria-selected="true"] { color: #fff; background: #334d75; }
#completion-popup [role="option"][aria-selected="true"] small { color: #d6e0e8; }
#completion-popup .completion-usage { padding: 0.16rem 0.45rem 0.24rem; border-bottom: 1px solid #202c33; color: #8da0ac; white-space: pre; }
#completion-popup .completion-position { padding: 0.16rem 0.45rem 0; color: #71828c; font-size: 0.75rem; text-align: right; }

#cell-context-menu {
  position: absolute;
  z-index: 10;
  width: 15rem;
  max-height: calc(100% - 0.5rem);
  padding: 0.25rem;
  overflow-y: auto;
  border: 1px solid #53616a;
  border-radius: 3px;
  background: #192127;
  box-shadow: 0 0.4rem 1.2rem #000a;
}

#cell-context-menu button {
  display: flex;
  width: 100%;
  justify-content: space-between;
  padding: 0.3rem 0.5rem;
  border: 0;
  color: #e9edf0;
  background: transparent;
  text-align: left;
}

#cell-context-menu button[data-selected="true"] { background: #334d75; }
#cell-context-menu button[data-group-start="true"] { border-top: 1px solid #46545d; }
#cell-context-menu kbd { color: #8eb2e5; font: inherit; }
#cell-context-menu .menu-label { display: flex; align-items: center; gap: 0.5rem; }
#cell-context-menu .background-swatch { width: 0.9rem; height: 0.9rem; border: 1px solid #71808a; }
#cell-context-menu .background-none { background: transparent; }
#cell-context-menu .background-input { background: #17324a; }
#cell-context-menu .background-output { background: #173d31; }
#cell-context-menu .background-constant { background: #352a4a; }
#cell-context-menu .background-warning { background: #4a2d1c; }

.panel-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: #071015a8;
}

.panel-backdrop[hidden] { display: none; }

.browser-panel {
  position: relative;
  display: flex;
  width: min(90rem, 100%);
  height: min(54rem, 100%);
  min-width: min(24rem, 100%);
  min-height: min(18rem, 100%);
  max-width: 100%;
  max-height: 100%;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #53616a;
  border-left: 4px solid #3d9fc5;
  border-radius: 4px;
  background: #111a20;
  box-shadow: 0 0.7rem 2rem #000c;
}

#browser-panel-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 2;
  width: 1.25rem;
  height: 1.25rem;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: linear-gradient(135deg, transparent 45%, #53616a 46%, #53616a 56%, transparent 57%, transparent 67%, #8da0ac 68%, #8da0ac 78%, transparent 79%);
  cursor: nwse-resize;
  touch-action: none;
}

#browser-panel-resize:focus-visible { outline: 2px solid #8fd4ef; outline-offset: -2px; }

.panel-header {
  display: flex;
  min-height: 3rem;
  justify-content: space-between;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid #39434a;
}

.panel-header h2 { margin: 0; color: #8fd4ef; font-size: 1rem; text-transform: uppercase; }
.panel-header button { border: 0; font-size: 1.25rem; }
#functions-panel, #debug-panel, #calculator-panel, #formula-help-panel, #names-panel, #sheets-panel, #curve-plotter-panel, #calendar-panel, #tools-panel, #lua-panel, #plots-panel, #plot-panel, #metrics-panel, #graph-panel, #key-help-panel, .navigation-prompt { min-height: 0; flex: 1; padding: 0.75rem; }
#functions-panel:not([hidden]), #debug-panel:not([hidden]), #calculator-panel:not([hidden]), #formula-help-panel:not([hidden]), #names-panel:not([hidden]), #sheets-panel:not([hidden]), #curve-plotter-panel:not([hidden]), #calendar-panel:not([hidden]), #tools-panel:not([hidden]), #lua-panel:not([hidden]), #plots-panel:not([hidden]), #plot-panel:not([hidden]), #metrics-panel:not([hidden]), #graph-panel:not([hidden]), #key-help-panel:not([hidden]), .navigation-prompt:not([hidden]) { display: flex; flex-direction: column; gap: 0.55rem; }
#functions-filter { width: 100%; padding: 0.4rem 0.5rem; border: 1px solid #46545d; color: #e9edf0; background: #0d151a; font: inherit; }

.functions-content {
  display: grid;
  min-height: 0;
  flex: 1;
  grid-template-columns: minmax(16rem, 42%) minmax(0, 1fr);
  gap: 0.75rem;
}

#functions-list { overflow: auto; border: 1px solid #334048; }
#functions-list button { display: flex; width: 100%; justify-content: space-between; border: 0; border-radius: 0; text-align: left; }
#functions-list button[aria-selected="true"] { background: #334d75; }
#functions-list small { color: #8da0ac; }
#functions-details, #debug-details { min-height: 0; margin: 0; padding: 0.75rem; overflow: auto; border: 1px solid #334048; color: #dfe5e8; white-space: pre-wrap; font: inherit; }
#debug-details { flex: 1; }
.debug-summary { display: grid; margin: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.35rem 1rem; }
.debug-summary div { display: grid; grid-template-columns: 8rem minmax(0, 1fr); }
.debug-summary dt { color: #8da0ac; }
.debug-summary dd { margin: 0; overflow-wrap: anywhere; }
#debug-error-row { color: #ff8c7a; }
.panel-help { margin: 0; color: #8da0ac; font-size: 0.85rem; }

#calculator-status { min-height: 1.4rem; margin: 0; color: #9fc9d0; }
#calculator-form { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 0.5rem; }
#calculator-input { min-width: 0; padding: 0.4rem 0.5rem; border: 1px solid #46545d; color: #e9edf0; background: #0d151a; font: inherit; }
.calculator-content { display: grid; min-height: 0; flex: 1; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.calculator-content section { display: flex; min-height: 0; flex-direction: column; }
.calculator-content h3 { margin: 0 0 0.35rem; color: #79d5d8; font-size: 0.95rem; }
#calculator-stack, #calculator-variables { min-height: 0; flex: 1; overflow: auto; border: 1px solid #334048; }
.calculator-row { display: grid; grid-template-columns: minmax(4rem, auto) minmax(0, 1fr); gap: 0.75rem; padding: 0.3rem 0.5rem; }
.calculator-row:first-child { background: #163538; }
.calculator-row span:first-child { color: #8da0ac; }
.calculator-row span:last-child { overflow-wrap: anywhere; text-align: right; }

#formula-help-input { width: 100%; min-height: 4.5rem; resize: vertical; padding: 0.5rem; border: 1px solid #46545d; color: #e9edf0; background: #0d151a; font: inherit; }
#formula-help-input[data-line-mode="normal"] { border-color: #4682b4; caret-color: transparent; }
#formula-help-mode { align-self: flex-start; padding: 0.18rem 0.45rem; border-radius: 0.2rem; color: #eaf3ee; font-weight: 700; }
#formula-help-mode[data-mode="insert"] { background: #1a5730; }
#formula-help-mode[data-mode="normal"] { background: #244780; }
.formula-help-content { display: grid; min-height: 0; flex: 1; grid-template-columns: minmax(14rem, 32%) minmax(0, 1fr); gap: 0.75rem; }
.formula-help-suggestion-pane, .formula-help-detail-pane { display: flex; min-width: 0; min-height: 0; flex-direction: column; }
.formula-help-content h3 { margin: 0 0 0.35rem; color: #79d5d8; font-size: 0.9rem; }
#formula-help-suggestions { min-height: 0; flex: 1; overflow: auto; border: 1px solid #334048; background: #0d151a; }
#formula-help-suggestions[hidden] { display: none; }
.formula-help-suggestion { display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.32rem 0.5rem; border-bottom: 1px solid #202c33; }
.formula-help-suggestion small { color: #8da0ac; text-align: right; }
.formula-help-suggestion[data-contextual="true"] { color: #fff; background: #334d75; }
#formula-help-no-matches { min-height: 0; flex: 1; margin: 0; padding: 0.75rem; border: 1px solid #334048; color: #8da0ac; background: #0d151a; }
#formula-help-no-matches[hidden] { display: none; }
#formula-help-details { min-height: 0; flex: 1; margin: 0; padding: 0.75rem; overflow: auto; border: 1px solid #334048; color: #dfe5e8; white-space: pre-wrap; font: inherit; }

#names-list { min-height: 0; flex: 1; overflow: auto; border: 1px solid #334048; }
.name-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
.name-row > button:first-child { display: grid; width: 100%; grid-template-columns: minmax(8rem, 1fr) minmax(8rem, 1fr); border: 0; border-radius: 0; text-align: left; }
.name-row > button:first-child[aria-selected="true"] { background: #334d75; }
.name-row > button:first-child span:last-child { color: #aebac1; text-align: right; }
.name-row > button:last-child { border-radius: 0; }
#names-empty { margin: auto; color: #8da0ac; }
#names-form, #names-delete-confirmation { display: flex; align-items: center; gap: 0.5rem; }
#names-form[hidden], #names-delete-confirmation[hidden] { display: none; }
#names-form input { min-width: 0; flex: 1; padding: 0.4rem 0.5rem; border: 1px solid #46545d; color: #e9edf0; background: #0d151a; font: inherit; }
#names-status { min-height: 1.4rem; margin: 0; color: #9fc9d0; }
.sheets-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }
#sheets-list { min-height: 0; flex: 1; overflow: auto; border: 1px solid #334048; outline: none; }
#sheets-list:focus-visible { border-color: #8fd4ef; }
#sheets-list button { display: grid; width: 100%; grid-template-columns: auto minmax(0, 1fr) auto; gap: 0.6rem; border: 0; border-radius: 0; text-align: left; }
#sheets-list button[aria-selected="true"] { background: #334d75; }
#sheets-list button[aria-current="true"] .sheet-name::after { content: "  active"; color: #79d5d8; font-size: 0.78rem; }
#sheets-list .sheet-ordinal { color: #8da0ac; font-variant-numeric: tabular-nums; }
#sheets-list button span:last-child { color: #8da0ac; font-variant-numeric: tabular-nums; }
#sheets-form, #sheets-delete-confirmation { display: flex; align-items: center; gap: 0.5rem; }
#sheets-form[hidden], #sheets-delete-confirmation[hidden] { display: none; }
#sheets-form input { min-width: 0; flex: 1; padding: 0.4rem 0.5rem; border: 1px solid #46545d; color: #e9edf0; background: #0d151a; font: inherit; }
#sheets-status { min-height: 1.4rem; margin: 0; color: #9fc9d0; }
.navigation-prompt { justify-content: center; }
.navigation-prompt form { display: grid; grid-template-columns: auto minmax(12rem, 1fr) auto; align-items: center; gap: 0.5rem; }
.navigation-prompt input { min-width: 0; padding: 0.4rem 0.5rem; border: 1px solid #46545d; color: #e9edf0; background: #0d151a; font: inherit; }

.curve-toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: 0.55rem 0.8rem; }
.curve-toolbar label { display: flex; align-items: center; gap: 0.35rem; color: #aebac1; }
.curve-toolbar label[hidden] { display: none; }
.curve-toolbar label:has(select) { flex-direction: column; align-items: flex-start; }
.curve-toolbar select, .curve-toolbar input, .curve-sidebar select, .curve-sidebar input { min-width: 0; padding: 0.3rem 0.4rem; border: 1px solid #46545d; color: #e9edf0; background: #0d151a; font: inherit; }
#curve-tenor-amount { width: 5rem; }
#curve-discount-factor-index { width: 5rem; }
.curve-layout { display: grid; min-height: 0; flex: 1; grid-template-columns: minmax(0, 1fr) minmax(18rem, 25%); gap: 0.75rem; }
.curve-chart-section { display: flex; min-height: 0; flex-direction: column; }
.curve-chart-section h3, .curve-sidebar h3, .curve-sidebar h4 { margin: 0; color: #79d5d8; font-size: 0.9rem; }
#curve-chart { width: 100%; min-height: 18rem; flex: 1; border: 1px solid #334048; background: #0b1217; cursor: grab; touch-action: none; }
#curve-chart[data-dragging="true"] { cursor: grabbing; }
#curve-chart:focus-visible { outline: 2px solid #8fd4ef; outline-offset: -2px; }
.curve-grid line { stroke: #29363e; stroke-width: 1; }
.curve-grid text, .curve-empty { fill: #8da0ac; font-size: 12px; }
.curve-line { fill: none; stroke-width: 2.2; vector-effect: non-scaling-stroke; }
.curve-line.workbook { stroke-dasharray: 7 5; opacity: 0.8; }
.curve-pillar { stroke: #0b1217; stroke-width: 1; }
.curve-crosshair { stroke: #dce7eb; stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
.curve-crosshair-label { fill: #e9edf0; font-size: 12px; pointer-events: none; }
#curve-legend { display: flex; min-height: 1.5rem; flex-wrap: wrap; gap: 0.35rem 1rem; padding-top: 0.35rem; color: #aebac1; font-size: 0.8rem; }
#curve-legend > span { display: flex; align-items: center; gap: 0.35rem; }
#curve-legend i { display: inline-block; width: 1.2rem; height: 0.18rem; }
#curve-legend i[data-provenance="workbook"] { height: 0.1rem; opacity: 0.75; }
.curve-sidebar { min-height: 0; overflow: auto; border: 1px solid #334048; background: #0d151a; }
.curve-sidebar > section { padding: 0.55rem; border-bottom: 1px solid #334048; }
.curve-section-heading { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.curve-section-heading div { display: flex; gap: 0.35rem; }
#curve-selection { display: flex; flex-wrap: wrap; gap: 0.35rem 0.8rem; margin-top: 0.4rem; }
#curve-selection label { white-space: nowrap; }
#curve-builders > section { display: grid; gap: 0.35rem; padding: 0.5rem 0; border-bottom: 1px solid #29363e; }
.curve-hybrid { display: grid; grid-template-columns: 4rem minmax(0, 1fr); gap: 0.35rem; }
.curve-hybrid select:last-child { grid-column: 2; }
#curve-quotes { display: grid; gap: 0.3rem; padding-top: 0.5rem; }
#curve-quotes label { display: grid; grid-template-columns: minmax(5rem, 1fr) minmax(7rem, 1fr); align-items: center; gap: 0.4rem; }
#curve-quotes label[data-changed="true"] span { color: #e8b45c; }
#curve-status { min-height: 1.2rem; }

#calendar-months { display: grid; min-height: 0; flex: 1; grid-template-columns: repeat(3, minmax(13rem, 1fr)); align-content: start; gap: 0.9rem; overflow-y: auto; padding: 0.15rem; }
#calendar-target-form { display: grid; grid-template-columns: auto auto minmax(10rem, 1fr) auto; align-items: center; gap: 0.45rem; }
#calendar-target-form[hidden] { display: none; }
#calendar-target-input { min-width: 0; padding: 0.4rem 0.5rem; border: 1px solid #46545d; color: #e9edf0; background: #0d151a; font: inherit; }
#calendar-summary { min-height: 1.2rem; margin: 0; color: #c8d6dc; font-variant-numeric: tabular-nums; }
.calendar-month { padding: 0.55rem; border: 1px solid #334048; background: #0d151a; }
.calendar-month h3 { margin: 0 0 0.45rem; color: #79d5d8; font-size: 0.9rem; text-align: center; }
.calendar-weekdays, .calendar-days { display: grid; grid-template-columns: repeat(7, minmax(1.7rem, 1fr)); gap: 0.16rem; }
.calendar-weekdays { margin-bottom: 0.2rem; color: #71828c; font-size: 0.72rem; text-align: center; }
.calendar-day { position: relative; min-height: 2rem; padding: 0.2rem; border-color: transparent; background: transparent; font-variant-numeric: tabular-nums; }
.calendar-day[data-weekend="true"] { color: #8394a0; background: #182127; }
.calendar-day[data-holiday="true"] { color: #e8b45c; }
.calendar-holiday-cue { position: absolute; right: 0.18rem; bottom: -0.08rem; color: currentColor; font-size: 0.9rem; }
.calendar-day[aria-current="date"] { outline: 2px solid #8fd4ef; outline-offset: -2px; background: #29475a; color: #fff; }
.calendar-day:focus-visible { outline: 2px solid #e8b45c; outline-offset: -2px; }
#calendar-status { min-height: 1.2rem; margin: 0; color: #9fc9d0; }

#plots-list { min-height: 0; flex: 1; overflow: auto; border: 1px solid #334048; outline: none; }
#plots-list:focus-visible { border-color: #8fd4ef; }
#plots-list button { display: grid; width: 100%; grid-template-columns: minmax(8rem, auto) minmax(0, 1fr); gap: 0.6rem; border: 0; border-radius: 0; text-align: left; }
#plots-list button[aria-selected="true"] { background: #334d75; }
#plots-list button small { color: #8da0ac; text-align: right; }
.plots-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }
#plots-status { min-height: 1.4rem; margin: 0; color: #9fc9d0; }

.plot-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.plot-toolbar span { color: #aebac1; }
.plot-chart-section { display: flex; min-height: 0; flex-direction: column; }
.plot-chart-section h3 { margin: 0; color: #79d5d8; font-size: 0.9rem; }
#plot-chart { width: 100%; min-height: 18rem; flex: 1; border: 1px solid #334048; background: #0b1217; cursor: grab; touch-action: none; }
#plot-chart[data-dragging="true"] { cursor: grabbing; }
#plot-chart:focus-visible { outline: 2px solid #8fd4ef; outline-offset: -2px; }
.plot-grid line { stroke: #29363e; stroke-width: 1; }
.plot-grid text, .plot-empty { fill: #8da0ac; font-size: 12px; }
.plot-line { fill: none; stroke-width: 2.2; vector-effect: non-scaling-stroke; }
.plot-baseline { stroke: #9ea6b4; stroke-width: 1; }
#plot-legend { display: flex; min-height: 1.5rem; flex-wrap: wrap; gap: 0.35rem 1rem; padding-top: 0.35rem; color: #aebac1; font-size: 0.8rem; }
#plot-legend > span { display: flex; align-items: center; gap: 0.35rem; }
#plot-legend i { display: inline-block; width: 1.2rem; height: 0.18rem; }
#plot-status { min-height: 1.4rem; margin: 0; color: #9fc9d0; }

/* The legend, node, and edge colors come from the panel snapshot, which reads
   modules/sheet_graph.jai. */
.graph-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.35rem 1rem; }
#graph-summary, #graph-selected { margin: 0; color: #c6d0d6; font-size: 0.85rem; overflow-wrap: anywhere; }
.graph-legend { display: flex; gap: 0.9rem; color: #c6d0d6; font-size: 0.8rem; }
.graph-legend span { display: flex; align-items: center; gap: 0.35rem; }
.graph-legend i { display: inline-block; width: 0.8rem; height: 0.8rem; }
#graph-chart { width: 100%; min-height: 18rem; flex: 1; border: 1px solid #334048; background: #0b1217; cursor: grab; touch-action: none; user-select: none; }
#graph-chart[data-dragging="true"] { cursor: grabbing; }
#graph-chart:focus-visible { outline: 2px solid #8fd4ef; outline-offset: -2px; }
.graph-node { cursor: pointer; }
.graph-node text { font-size: 12px; pointer-events: none; }
.graph-edge { fill: none; }

#metrics-groups { display: grid; min-height: 0; flex: 1; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); align-content: start; gap: 0.75rem; overflow: auto; }
#metrics-status { min-height: 1.4rem; margin: 0; color: #9fc9d0; }

#key-help-groups { display: grid; min-height: 0; flex: 1; grid-template-columns: repeat(auto-fit, minmax(min(28rem, 100%), 1fr)); align-content: start; gap: 0.75rem; overflow: auto; }
#key-help-groups dl { grid-template-columns: calc(20ch + 1.2rem) minmax(0, 1fr); }
#key-help-groups dt { color: #ffc75c; white-space: pre; }
#key-help-groups dd { text-align: left; }
#key-help-status { min-height: 1.4rem; margin: 0; color: #9fc9d0; }

.tools-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.tools-heading p { margin: 0; color: #8da0ac; }
#tools-groups { display: grid; min-height: 0; flex: 1; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); align-content: start; gap: 0.75rem; overflow: auto; }
.tools-group { border: 1px solid #334048; background: #0d151a; }
.tools-group h3 { margin: 0; padding: 0.45rem 0.6rem; border-bottom: 1px solid #334048; color: #79d5d8; font-size: 0.85rem; text-transform: uppercase; }
.tools-group dl { display: grid; margin: 0; grid-template-columns: minmax(8rem, 1fr) minmax(0, 1fr); }
.tools-group dt, .tools-group dd { margin: 0; padding: 0.35rem 0.6rem; border-bottom: 1px solid #202c33; }
.tools-group dt { color: #8da0ac; }
.tools-group dd { overflow-wrap: anywhere; text-align: right; }

@media (max-width: 700px) {
  .functions-content { grid-template-columns: 1fr; grid-template-rows: minmax(10rem, 40%) minmax(0, 1fr); }
  .formula-help-content { grid-template-columns: 1fr; grid-template-rows: minmax(8rem, 35%) minmax(0, 1fr); }
  .debug-summary { grid-template-columns: 1fr; }
  .calculator-content { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .curve-layout { grid-template-columns: 1fr; grid-template-rows: minmax(20rem, 2fr) minmax(12rem, 1fr); }
  #calendar-months { grid-template-columns: 1fr; }
  .lua-layout { grid-template-columns: 1fr; grid-template-rows: minmax(6rem, 25%) minmax(0, 1fr); }
  .lua-run-controls { grid-template-columns: auto minmax(0, 1fr); }
}

@media (min-width: 701px) and (max-width: 1050px) {
  #calendar-months { grid-template-columns: repeat(2, minmax(13rem, 1fr)); }
}

@media (max-width: 600px) {
  .app-bar { flex-wrap: wrap; }
  .app-bar strong { margin-right: auto; }
  #command-form { flex-basis: 100%; order: 3; }
  .app-status { display: none; }
  .panel-backdrop { inset: 0; }
  .browser-panel { min-width: min(20rem, 100%); min-height: min(16rem, 100%); }
  #calendar-target-form { grid-template-columns: auto minmax(0, 1fr) auto; }
  #calendar-target-form label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
}
