:root {
  color-scheme: dark;
  --header-height: 64px;
  --sidebar-width: 348px;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0f1115;
  color: #e8e8e8;
}

header {
  min-height: var(--header-height);
  padding: 11px 18px;
  border-bottom: 1px solid #2a2f3a;
  background: #151923;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.header-action-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-dashboard-button,
.header-status-button {
  width: auto;
  min-width: 150px;
  padding: 9px 14px;
  border: 1px solid #60a5fa;
  background: #1d4ed8;
}
.header-dashboard-button:hover { background: #2563eb; }
.header-status-button {
  width: auto;
  min-width: 130px;
  padding: 9px 14px;
  border: 1px solid #6b7280;
  background: #303743;
}
.header-status-button:hover { background: #3f4755; }
h1 { margin: 0 0 3px; font-size: 20px; }
.status { color: #aeb6c2; font-size: 12px; }

main {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
  align-items: start;
}

.control-sidebar {
  position: sticky;
  top: calc(var(--header-height) + 10px);
  height: calc(100vh - var(--header-height) - 24px);
  min-height: 0;
  overflow: hidden;
}
.sidebar-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}
.sidebar-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  flex: 0 0 auto;
  margin-bottom: 8px;
}
.sidebar-tab-button {
  position: relative;
  min-width: 0;
  padding: 9px 10px;
  color: #cbd5e1;
  border: 1px solid #343b49;
  background: #151923;
}
.sidebar-tab-button:hover { background: #1b2130; }
.sidebar-tab-button.active {
  color: #0f172a;
  border-color: #93c5fd;
  background: #dbeafe;
}
.alert-unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 19px;
  height: 19px;
  margin-left: 5px;
  padding: 0 5px;
  color: #ffffff;
  border-radius: 999px;
  background: #dc2626;
  font-size: 10px;
  font-weight: 850;
}
.sidebar-tab-panel {
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding-right: 4px;
}
.sidebar-tab-panel[hidden] { display: none !important; }
.sidebar-stack { display: grid; gap: 9px; }

.quick-controls-tab {
  display: grid;
  gap: 12px;
}
.quick-controls-section {
  display: grid;
  gap: 9px;
  padding: 12px;
  border: 1px solid #2a2f3a;
  border-radius: 11px;
  background: #151923;
}
.quick-controls-heading {
  color: #e5e7eb;
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.quick-trade-summary,
.quick-playback-speed {
  color: #94a3b8;
}
.quick-strategy-control {
  margin: 0;
}
.quick-strategy-control span {
  display: block;
  margin-bottom: 4px;
  color: #e2e8f0;
  font-size: 12px;
  font-weight: 600;
}
.quick-strategy-control select:disabled {
  color: #7f8793;
  background: #202633;
  cursor: not-allowed;
}
.quick-trade-entry-grid,
.quick-two-button-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}
.quick-three-button-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}
.quick-trade-entry-grid button,
.quick-two-button-grid button,
.quick-three-button-grid button,
.quick-full-width-button {
  min-height: 42px;
}
.quick-buy-button {
  background: #86efac;
  color: #052e16;
}
.quick-sell-button {
  background: #fca5a5;
  color: #450a0a;
}
.quick-buy-button:disabled,
.quick-sell-button:disabled {
  background: #2a2f3a;
  color: #7f8793;
  opacity: 0.58;
  cursor: not-allowed;
}
.quick-close-all-button {
  background: #fca5a5;
  color: #450a0a;
}
.quick-close-all-button:disabled {
  background: #2a2f3a;
  color: #7f8793;
  opacity: 0.58;
  cursor: not-allowed;
}
#quickBreakEvenBtn:disabled {
  background: #2a2f3a;
  color: #7f8793;
  opacity: 0.58;
  cursor: not-allowed;
}
.quick-pnl-block {
  display: grid;
  gap: 4px;
  padding: 8px 9px;
  border: 1px solid #343b49;
  border-radius: 7px;
  background: #0f1115;
}
.quick-pnl-line {
  font-size: 12px;
  font-weight: 750;
  line-height: 1.35;
}
.quick-pnl-line.positive { color: #86efac; }
.quick-pnl-line.negative { color: #fca5a5; }
.quick-pnl-line.neutral { color: #cbd5e1; }
.quick-full-width-button {
  width: 100%;
}
.quick-tradalyzer-toggle {
  margin-top: 1px;
}
.quick-time-grid button {
  padding-left: 5px;
  padding-right: 5px;
}
.quick-controls-status {
  min-height: 18px;
  padding: 0 2px;
  color: #94a3b8;
}
.quick-controls-status[data-kind="error"] { color: #fca5a5; }
.quick-controls-status[data-kind="ok"] { color: #86efac; }

.panel, .alert, .control-group, .chart-time-hud {
  border: 1px solid #2a2f3a;
  background: #151923;
  border-radius: 11px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.16);
}
.panel { padding: 12px; }

.control-group { overflow: hidden; }
.control-group summary {
  position: relative;
  cursor: pointer;
  list-style: none;
  padding: 11px 35px 11px 13px;
  color: #f3f4f6;
  font-size: 13px;
  font-weight: 800;
  user-select: none;
}
.control-group summary::-webkit-details-marker { display: none; }
.control-group summary::after {
  content: "▸";
  position: absolute;
  right: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  transition: transform 120ms ease;
}
.control-group[open] summary {
  border-bottom: 1px solid #2a2f3a;
  background: #191e29;
}
.control-group[open] summary::after {
  transform: translateY(-50%) rotate(90deg);
}
.control-group-body { padding: 10px 12px 12px; }

.control-group.is-disabled {
  border-color: #252a33;
}
.control-group.is-disabled summary {
  color: #7f8793;
}
.control-group.is-disabled .control-group-body > :not(.live-disabled-note) {
  opacity: 0.42;
}
.control-group.is-disabled button,
.control-group.is-disabled input,
.control-group.is-disabled select,
.control-group.is-disabled textarea {
  cursor: not-allowed;
}
.live-disabled-note {
  margin-top: 10px;
  padding: 8px 9px;
  border: 1px solid #4b5563;
  border-radius: 7px;
  color: #d1d5db;
  background: #202633;
  opacity: 1 !important;
}

label {
  display: block;
  margin: 9px 0 4px;
  color: #c7ced8;
  font-size: 12px;
}
input, textarea, select {
  width: 100%;
  background: #0f1115;
  color: #e8e8e8;
  border: 1px solid #343b49;
  border-radius: 7px;
  padding: 8px 9px;
  font-size: 13px;
}
textarea {
  min-height: 62px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

button {
  cursor: pointer;
  border: 0;
  border-radius: 8px;
  padding: 8px 10px;
  font-weight: 750;
  color: #0f1115;
  background: #8bc3ff;
}
button.secondary { background: #f59f9f; }
button.ghost { background: #2a2f3a; color: #e8e8e8; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 2px solid #60a5fa;
  outline-offset: 2px;
}
.full-width { width: 100%; margin-top: 8px; }
.button-grid { display: grid; gap: 7px; margin-top: 2px; }
.button-grid.two { grid-template-columns: 1fr 1fr; }
.preset-grid { display: grid; gap: 6px; margin-top: 6px; }
.preset-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.preset-grid button { padding: 7px 5px; font-size: 12px; }
.compact-stepper {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 38px;
  gap: 6px;
  align-items: center;
}
.compact-stepper input { text-align: center; }
.compact-stepper button { padding: 8px 4px; }

.checkbox-group-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 9px;
}
.checkbox-group-actions button {
  padding: 5px 9px;
  border: 1px solid #4b5563;
  border-radius: 6px;
  background: #202633;
  color: #e5e7eb;
  font-size: 11px;
  font-weight: 700;
}
.checkbox-group-actions button:hover { background: #30394a; }
.check-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 10px;
}
.check-section-title {
  grid-column: 1 / -1;
  margin-top: 5px;
  padding: 7px 2px 3px;
  color: #93c5fd;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom: 1px solid #2f3745;
}
.check-section-title:first-child { margin-top: 0; }
.check-control[hidden] {
  display: none !important;
}

.check-control {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  padding: 8px 9px;
  color: #e5e7eb;
  border: 1px solid #343b49;
  border-radius: 7px;
  background: #0f1115;
  font-size: 12px;
}
.check-control input { width: auto; margin: 0; }
.check-control-label {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  flex: 1 1 auto;
  margin: 0;
  cursor: pointer;
}
.check-control-label span {
  min-width: 0;
  line-height: 1.25;
}
.info-tooltip-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  min-width: 17px;
  height: 17px;
  margin-left: auto;
  padding: 0;
  color: #cbd5e1;
  border: 1px solid #64748b;
  border-radius: 999px;
  background: #1e293b;
  font-family: Georgia, serif;
  font-size: 11px;
  font-weight: 700;
  font-style: italic;
  line-height: 1;
  cursor: help;
}
.info-tooltip-trigger:hover,
.info-tooltip-trigger:focus-visible {
  color: #ffffff;
  border-color: #93c5fd;
  background: #334155;
  outline: none;
}
.info-tooltip-popup {
  position: fixed;
  z-index: 1000;
  width: min(280px, calc(100vw - 20px));
  padding: 9px 10px;
  color: #f8fafc;
  border: 1px solid #64748b;
  border-radius: 7px;
  background: #111827;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  font-size: 12px;
  line-height: 1.4;
  pointer-events: none;
}
.info-tooltip-popup[hidden] { display: none; }
.alert-type-grid {
  grid-template-columns: 1fr;
}
.alert-type-control {
  align-items: flex-start;
}
.alert-type-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
  line-height: 1.25;
}
.alert-type-copy code {
  overflow-wrap: anywhere;
  color: #94a3b8;
  font-size: 10px;
}
.alert-type-summary {
  margin-top: 9px;
  color: #aeb6c2;
}
.status-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip {
  display: inline-block;
  border: 1px solid #343b49;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  color: #c7ced8;
}
.block-chip { display: block; margin-top: 8px; text-align: center; }
.internal-sync-control { display: none !important; }

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 10px;
}
.metric {
  min-width: 0;
  background: #0f1115;
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  padding: 8px;
}
.metric .value {
  overflow: hidden;
  font-size: 17px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.metric .compact-value { font-size: 11px; }
.metric .label { color: #aeb6c2; font-size: 10px; margin-top: 2px; }

.right-col {
  display: block;
  min-width: 0;
}
.chart-panel {
  padding: 10px;
  background: #ffffff;
  color: #111827;
}
.chart-panel .small { color: #4b5563; }
.chart-panel .chip { color: #111827; border-color: #d1d5db; background: #f9fafb; }
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 9px;
}
.chart-toolbar { min-height: 36px; }

.timeframe-switcher {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  margin: 0 0 8px;
  padding: 0 2px;
}
.timeframe-switcher-label {
  margin-right: 3px;
  color: #aeb6c2;
  font-size: 11px;
  font-weight: 750;
}
.timeframe-button {
  min-width: 40px;
  padding: 5px 8px;
  color: #dbe3ec;
  border: 1px solid #3b4352;
  border-radius: 6px;
  background: #151923;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}
.timeframe-button:hover {
  color: #ffffff;
  border-color: #60a5fa;
  background: #1b2433;
}
.timeframe-button.active {
  color: #eff6ff;
  border-color: #3b82f6;
  background: #1d4ed8;
  box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.22);
}

.small { font-size: 12px; color: #aeb6c2; }

#chartWrap {
  width: 100%;
  height: calc(100vh - var(--header-height) - 124px);
  min-height: 520px;
  max-height: 840px;
  position: relative;
  background: #ffffff;
}
#chart { width: 100%; height: 100%; background: #ffffff; }
#zoneOverlay {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
}

.alert-tab-content {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}
.alert-filter-panel {
  position: sticky;
  top: 0;
  z-index: 5;
  margin-bottom: 9px;
  padding: 10px;
  border: 1px solid #2a2f3a;
  border-radius: 10px;
  background: #151923;
  box-shadow: 0 8px 20px rgba(0,0,0,0.20);
}
.alert-filter-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.alert-filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 9px;
}
.alert-filter-summary {
  margin-top: 7px;
  line-height: 1.35;
}
.alert-navigation-help {
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid #2a2f3a;
  line-height: 1.35;
}
.alert-focus-status {
  min-height: 31px;
  margin-top: 7px;
  padding: 7px 8px;
  color: #fecaca;
  border: 1px solid #4b2430;
  border-radius: 7px;
  background: #211218;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.alert-action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 8px;
}
.alert-action-grid button { min-width: 0; }
.alert-action-grid button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}
.sidebar-alert-stream {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding-bottom: 12px;
}
.sidebar-alert-stream .alert { padding: 10px 11px; }
.sidebar-alert-stream .alert-navigable {
  cursor: pointer;
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}
.sidebar-alert-stream .alert-navigable:hover {
  border-color: #60a5fa;
  box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.30), 0 8px 24px rgba(0,0,0,0.22);
  transform: translateY(-1px);
}
.sidebar-alert-stream .alert-navigable:focus-visible {
  outline: 2px solid #60a5fa;
  outline-offset: 2px;
}
.sidebar-alert-stream .alert-selected {
  border-color: #ef4444;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.32), 0 8px 24px rgba(0,0,0,0.24);
}
.sidebar-alert-stream .event-line {
  align-items: flex-start;
  flex-direction: column;
  gap: 2px;
}
.sidebar-alert-stream .time {
  white-space: normal;
  overflow-wrap: anywhere;
}
.sidebar-alert-stream .meta,
.sidebar-alert-stream .zone,
.sidebar-alert-stream .message {
  overflow-wrap: anywhere;
}
.alert[data-alert-category="routine"].filtered-out,
.alert[data-alert-category="trading"].filtered-out {
  display: none;
}
.alert { padding: 12px 14px; }
.alert.system { border-color: #4c566a; }
.alert.fvg { border-left: 5px solid #8bc3ff; }
.alert.ifvg { border-left: 5px solid #c6a0ff; }
.alert.bpr { border-left: 5px solid #ffd166; }
.event-line { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.event-type { font-weight: 800; }
.time { color: #aeb6c2; font-size: 12px; white-space: nowrap; }
.meta { color: #c7ced8; font-size: 13px; margin: 5px 0; }
.message { margin-top: 7px; line-height: 1.35; }
.zone { color: #aeb6c2; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.diagnostic-id { color: #93c5fd; font-weight: 700; margin-bottom: 3px; }

#resumeAt1xBtn:disabled { cursor: not-allowed; opacity: 0.5; }
#resumeAt1xBtn:not(:disabled) {
  background: #fecaca;
  border: 1px solid #ef4444;
  color: #7f1d1d;
}

/* Compact replay clock remains visible above both sidebar tabs. */
.chart-time-hud {
  flex: 0 0 auto;
  width: 100%;
  padding: 8px 10px 7px;
  color: #111827;
  border-color: #cbd5e1;
  background: #f8fafc;
}
.chart-time-hud-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 3px;
}
.chart-clock-mode {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 999px;
  background: #dbeafe;
  color: #1e3a8a;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
}
.chart-market-date {
  overflow: hidden;
  color: #64748b;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chart-time-main-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.chart-market-time {
  min-width: 0;
  font-variant-numeric: tabular-nums;
  font-size: 16px;
  font-weight: 850;
  line-height: 1.05;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.bar-close-inline {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 6px;
  color: #334155;
  font-size: 9px;
  white-space: nowrap;
}
#barCloseCountdown {
  color: #0f172a;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}
.bar-progress-track {
  width: 100%;
  height: 4px;
  margin: 5px 0 3px;
  overflow: hidden;
  border-radius: 999px;
  background: #e2e8f0;
}
.bar-progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: #2563eb;
  transition: width 120ms linear;
}
.bar-window-text {
  overflow: hidden;
  color: #64748b;
  font-size: 9px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chart-time-hud.is-paused .chart-clock-mode { background: #fee2e2; color: #991b1b; }
.chart-time-hud.is-seeking .chart-clock-mode { background: #fef3c7; color: #92400e; }
.chart-time-hud.closing-soon { border-color: #f59e0b; }
.chart-time-hud.closing-soon .bar-progress-fill { background: #f59e0b; }
.chart-time-hud.closing-now { border-color: #ef4444; }
.chart-time-hud.closing-now #barCloseCountdown { color: #b91c1c; }
.chart-time-hud.closing-now .bar-progress-fill { background: #ef4444; }

@media (max-width: 1100px) {
  :root { --sidebar-width: 320px; }
}

@media (max-width: 820px) {
  main { grid-template-columns: 1fr; }
  .control-sidebar {
    position: static;
    height: auto;
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }
  #chartWrap {
    height: 62vh;
    min-height: 420px;
  }
}

@media (max-width: 520px) {
  main { padding: 8px; gap: 8px; }
  .row, .check-grid { grid-template-columns: 1fr; }
  .preset-grid.four { grid-template-columns: 1fr 1fr; }
}
.alert.smt { border-left: 5px solid #16a34a; }
.alert.smt[data-alert-category="trading"] .event-type { color: #86efac; }
.detector-note {
  margin: 8px 0 2px;
  padding: 8px 9px;
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  background: #0f1115;
  line-height: 1.4;
}
.smt-legs { margin-top: 4px; }
.alert.smt.bearish { border-left-color: #dc2626; }
.alert.smt.bearish[data-alert-category="trading"] .event-type { color: #fca5a5; }

.detector-subsection {
  margin: 10px 0 12px;
  padding: 9px;
  border: 1px solid #dbe3ec;
  border-radius: 8px;
  background: #f8fafc;
}
.fvg-boundary-grid {
  margin-top: 8px;
}

/* v2.59: every visible checkbox receives the same local info tooltip control. */
.check-control.has-info-tooltip {
  gap: 7px;
}
.check-control.has-info-tooltip > .info-tooltip-trigger {
  align-self: center;
  flex: 0 0 17px;
}
.alert-type-control.has-info-tooltip > .info-tooltip-trigger {
  align-self: flex-start;
  margin-top: 1px;
}

.manual-trade-status {
  min-height: 34px;
  padding: 8px 9px;
  border: 1px solid #343b49;
  border-radius: 7px;
  background: #0f1115;
  color: #cbd5e1;
  font-size: 12px;
  line-height: 1.35;
}
.manual-trade-status.error {
  border-color: #ef4444;
  color: #fecaca;
}
.manual-trade-status.active {
  border-color: #60a5fa;
  color: #dbeafe;
}
.manual-entry-buttons button:disabled,
.manual-level-stepper button:disabled,
#manualCloseTradeBtn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}
.manual-long-button {
  color: #052e16;
  background: #4ade80;
}
.manual-long-button:hover { background: #86efac; }
.manual-short-button {
  color: #450a0a;
  background: #f87171;
}
.manual-short-button:hover { background: #fca5a5; }
.manual-trade-summary {
  margin: 9px 0 5px;
  color: #f3f4f6;
  font-size: 13px;
  font-weight: 800;
}
.manual-level-stepper {
  grid-template-columns: 38px minmax(0, 1fr) 38px;
}
.manual-level-price {
  display: flex;
  min-height: 35px;
  align-items: center;
  justify-content: center;
  border: 1px solid #343b49;
  border-radius: 7px;
  background: #0f1115;
  color: #f8fafc;
  font-size: 14px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

/* v2.69: controls/manual/closed left rail and compact clock in the header. */
:root { --header-height: 88px; }

header {
  min-height: var(--header-height);
}
.header-action-buttons {
  min-width: 0;
  justify-content: flex-end;
}
.header-chart-time-hud {
  width: 330px;
  min-width: 290px;
  box-shadow: none;
}

main.sidebar-collapsed {
  grid-template-columns: minmax(0, 1fr);
}
main.sidebar-collapsed .control-sidebar {
  display: none;
}

.control-sidebar {
  display: flex;
  flex-direction: column;
}
.sidebar-mode-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  gap: 6px;
  flex: 0 0 auto;
  margin-bottom: 8px;
}
.sidebar-mode-label {
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 0 10px;
  color: #cbd5e1;
  border: 1px solid #343b49;
  border-radius: 6px;
  background: #151923;
  font-size: 13px;
}
.sidebar-mode-button,
.sidebar-close-button {
  min-width: 0;
  min-height: 38px;
  color: #cbd5e1;
  border: 1px solid #343b49;
  background: #151923;
}
.sidebar-mode-button:hover,
.sidebar-close-button:hover { background: #1b2130; }
.sidebar-mode-button.active {
  color: #0f172a;
  border-color: #93c5fd;
  background: #dbeafe;
}
.sidebar-close-button {
  padding: 0;
  color: #93c5fd;
  font-size: 22px;
  line-height: 1;
}
.sidebar-mode-view {
  flex: 1 1 auto;
  min-height: 0;
}
.sidebar-mode-view[hidden] { display: none !important; }
.sidebar-controls-view .sidebar-shell { height: 100%; }
.sidebar-manual-view {
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding-right: 4px;
}

.sidebar-reopen-row {
  margin-bottom: 8px;
}
.sidebar-reopen-row[hidden] { display: none !important; }
.sidebar-reopen-button {
  width: auto;
  min-width: 170px;
  padding: 7px 12px;
  color: #e5e7eb;
  border: 1px solid #4b5563;
  background: #202633;
}
.sidebar-reopen-button:hover { background: #30394a; }

.manual-trade-panel {
  min-width: 0;
  padding: 11px 12px 12px;
  border: 1px solid #2a2f3a;
  border-radius: 11px;
  background: #151923;
  box-shadow: 0 8px 24px rgba(0,0,0,0.16);
}
.manual-trade-panel-heading {
  display: block;
  margin-bottom: 10px;
}
.manual-trade-panel-heading > strong {
  display: block;
  margin-bottom: 7px;
}
.manual-trade-panel .manual-trade-status {
  min-height: 34px;
  padding: 8px 9px;
  white-space: normal;
}
.manual-trade-entry-controls[hidden],
.manual-trade-active-controls[hidden] { display: none !important; }
.manual-trade-entry-controls,
.manual-trade-active-controls,
.manual-active-levels {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.manual-config-field {
  min-width: 0;
  margin: 0;
}
.manual-config-field > span:first-child {
  display: block;
  margin-bottom: 4px;
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 750;
}
.manual-input-with-unit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
}
.manual-input-with-unit input {
  min-width: 0;
  text-align: right;
}
.manual-input-with-unit small {
  color: #94a3b8;
  font-size: 10px;
  white-space: nowrap;
}
.manual-entry-buttons,
.manual-active-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.manual-entry-buttons button,
.manual-active-actions button { min-height: 38px; }
.manual-active-heading { min-width: 0; }
.manual-trade-panel .manual-trade-summary {
  margin: 0 0 5px;
  white-space: normal;
}
.manual-unrealized-pnl {
  display: block;
  font-size: 14px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}
.manual-unrealized-pnl.positive { color: #86efac; }
.manual-unrealized-pnl.negative { color: #fca5a5; }
.manual-unrealized-pnl.neutral { color: #cbd5e1; }
.manual-active-levels label {
  display: block;
  margin-bottom: 4px;
  color: #cbd5e1;
  font-size: 10px;
}
.manual-target-readout {
  display: flex;
  min-height: 35px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid #343b49;
  border-radius: 7px;
  background: #0f1115;
  color: #f8fafc;
  font-variant-numeric: tabular-nums;
}
#manualRiskRewardValue {
  color: #93c5fd;
  font-size: 12px;
  font-weight: 850;
}
#manualTargetPrice {
  font-size: 12px;
  font-weight: 750;
}
#manualBreakEvenBtn:disabled,
#manualCloseTradeBtn:disabled,
.manual-trade-panel button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

@media (max-width: 1400px) {
  .header-chart-time-hud {
    width: 290px;
    min-width: 260px;
  }
  .header-dashboard-button { min-width: 135px; }
  .header-status-button { min-width: 115px; }
}

@media (max-width: 1060px) {
  :root { --header-height: 146px; }
  header {
    align-items: flex-start;
    flex-wrap: wrap;
  }
  .header-action-buttons {
    width: 100%;
    justify-content: flex-start;
  }
  .header-chart-time-hud {
    flex: 1 1 300px;
    width: auto;
  }
}

@media (max-width: 820px) {
  :root { --header-height: 198px; }
  main,
  main.sidebar-collapsed { grid-template-columns: 1fr; }
  .control-sidebar {
    position: static;
    height: auto;
    max-height: none;
    overflow: visible;
  }
  .sidebar-mode-view { max-height: 70vh; }
  .header-action-buttons { flex-wrap: wrap; }
  .header-chart-time-hud { flex: 1 1 100%; }
}

@media (max-width: 520px) {
  :root { --header-height: 252px; }
  .header-dashboard-button,
  .header-status-button { flex: 1 1 140px; }
  .manual-entry-buttons,
  .manual-active-actions { grid-template-columns: 1fr; }
}


/* v2.70: stacked Dashboard/Status buttons with a matching-height clock block. */
:root {
  --header-height: 104px;
  --header-action-height: 80px;
}

.header-action-buttons {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.header-window-buttons {
  display: grid;
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 4px;
  width: 150px;
  height: var(--header-action-height);
  flex: 0 0 150px;
}

.header-window-buttons .header-trading-button,
.header-window-buttons .header-dashboard-button,
.header-window-buttons .header-status-button {
  width: 100%;
  min-width: 0;
  min-height: 0;
  height: 100%;
  margin: 0;
  box-sizing: border-box;
  padding: 4px 10px;
  line-height: 1.1;
  font-size: 12px;
}

.header-chart-time-hud {
  width: 330px;
  min-width: 290px;
  height: var(--header-action-height);
  min-height: var(--header-action-height);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 8px 10px 7px;
}

.header-sidebar-reopen-button {
  width: auto;
  min-width: 170px;
  min-height: 38px;
  padding: 9px 14px;
  color: #f8fafc;
  border: 1px solid #60a5fa;
  background: #1d4ed8;
  white-space: nowrap;
}
.header-sidebar-reopen-button:hover { background: #2563eb; }
.header-sidebar-reopen-button[hidden] { display: none !important; }

@media (max-width: 1400px) {
  .header-chart-time-hud {
    width: 290px;
    min-width: 260px;
  }
  .header-window-buttons {
    width: 135px;
    flex-basis: 135px;
  }
  .header-sidebar-reopen-button { min-width: 155px; }
}

@media (max-width: 1060px) {
  :root { --header-height: 170px; }
  header {
    align-items: flex-start;
    flex-wrap: wrap;
  }
  .header-action-buttons {
    width: 100%;
    justify-content: flex-start;
  }
  .header-chart-time-hud {
    flex: 1 1 300px;
    width: auto;
  }
}

@media (max-width: 820px) {
  :root { --header-height: 258px; }
  .header-action-buttons { flex-wrap: wrap; }
  .header-chart-time-hud { flex: 1 1 calc(100% - 145px); }
  .header-sidebar-reopen-button {
    order: 3;
    min-width: 190px;
  }
}

@media (max-width: 520px) {
  :root { --header-height: 350px; }
  .header-chart-time-hud { flex: 1 1 100%; }
  .header-window-buttons {
    width: 100%;
    flex: 1 1 100%;
  }
  .header-sidebar-reopen-button {
    width: 100%;
    min-width: 0;
  }
}


/* v2.71: keep chart timeframe controls in the fixed header action card. */
.header-timeframe-card {
  box-sizing: border-box;
  width: 500px;
  min-width: 455px;
  height: var(--header-action-height);
  flex: 0 1 500px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 7px;
  padding: 8px 10px;
  border: 1px solid #303746;
  border-radius: 8px;
  background: #10141d;
}

.header-timeframe-card-top {
  min-height: 27px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.header-timeframe-card-title {
  padding-top: 4px;
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}

.header-timeframe-card .timeframe-switcher {
  display: grid;
  grid-template-columns: repeat(11, minmax(34px, 1fr));
  align-items: center;
  gap: 5px;
  margin: 0;
  padding: 0;
  flex-wrap: nowrap;
}

.header-timeframe-card .timeframe-button {
  min-width: 0;
  width: 100%;
  padding: 6px 4px;
}

.header-timeframe-card .header-sidebar-reopen-button {
  min-width: 0;
  min-height: 27px;
  height: 27px;
  padding: 4px 10px;
  font-size: 11px;
  line-height: 1;
}

#chartWrap {
  height: calc(100vh - var(--header-height) - 88px);
}

@media (max-width: 1400px) {
  .header-timeframe-card {
    width: 450px;
    min-width: 420px;
    flex-basis: 450px;
  }
  .header-timeframe-card .timeframe-switcher {
    gap: 4px;
  }
  .header-timeframe-card .timeframe-button {
    font-size: 10px;
    padding-inline: 2px;
  }
}

@media (max-width: 1060px) {
  .header-timeframe-card {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 620px) {
  .header-timeframe-card {
    height: auto;
    min-height: var(--header-action-height);
  }
  .header-timeframe-card .timeframe-switcher {
    grid-template-columns: repeat(5, minmax(42px, 1fr));
  }
}

/* v2.88: independent simulated contract-leg planning and management. */
.manual-entry-config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.manual-entry-config-grid select,
.manual-entry-config-grid input,
.manual-leg-plan-row input,
.manual-active-leg-fields input {
  width: 100%;
  min-width: 0;
  font-variant-numeric: tabular-nums;
}
.manual-plan-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: #cbd5e1;
  font-size: 11px;
}
.manual-plan-heading > strong { font-size: 11px; }
.manual-plan-heading > span {
  color: #64748b;
  font-size: 10px;
}
.manual-apply-defaults {
  width: auto;
  min-height: 28px;
  padding: 4px 8px;
  font-size: 10px;
}
.manual-leg-plan-list,
.manual-active-leg-list {
  display: grid;
  gap: 6px;
  max-height: 310px;
  overflow-y: auto;
  padding-right: 2px;
}
.manual-leg-plan-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) minmax(0, 1fr);
  gap: 6px;
  align-items: end;
  padding: 7px;
  border: 1px solid #2c3442;
  border-radius: 8px;
  background: #10141c;
}
.manual-leg-plan-row > strong {
  align-self: center;
  color: #e2e8f0;
  font-size: 11px;
}
.manual-leg-plan-row label,
.manual-active-leg-fields label {
  display: grid;
  gap: 3px;
  color: #94a3b8;
  font-size: 9px;
  font-weight: 750;
}
.manual-active-leg-heading { margin-top: 1px; }
.manual-active-leg-row {
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid #334155;
  border-radius: 8px;
  background: #10141c;
}
.manual-active-leg-row.closed {
  border-color: #27303c;
  opacity: 0.78;
}
.manual-active-leg-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.manual-active-leg-title strong {
  color: #f8fafc;
  font-size: 11px;
}
.manual-active-leg-title span {
  color: #86efac;
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 0.05em;
}
.manual-active-leg-row.closed .manual-active-leg-title span { color: #94a3b8; }
.manual-active-leg-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 6px;
  align-items: end;
}
.manual-leg-apply {
  width: auto;
  min-height: 32px;
  padding: 5px 8px;
  font-size: 10px;
}
.manual-active-leg-exit {
  color: #cbd5e1;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}
.manual-realized-pnl {
  display: block;
  margin-top: 3px;
  color: #94a3b8;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 1050px) {
  .manual-entry-config-grid { grid-template-columns: 1fr; }
}

/* v2.89 historical replay and separate trade-controls window.
 * Step 17: keep the three chart-window navigation buttons visually identical. */
.header-trading-button,
.header-dashboard-button,
.header-status-button {
  border-color: #3b82f6;
  background: #172554;
  color: #dbeafe;
}
.header-trading-button:hover,
.header-dashboard-button:hover,
.header-status-button:hover {
  background: #172554;
}

#historicalReplayDetails {
  display: grid;
  gap: 10px;
  margin-top: 10px;
  padding: 11px;
  border: 1px solid var(--border, #334155);
  border-radius: 9px;
  background: rgba(15, 23, 42, 0.62);
}

#historicalReplayDetails[hidden] {
  display: none;
}

.historical-replay-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.historical-replay-grid label {
  min-width: 0;
}

.historical-date-field {
  grid-column: 1 / -1;
}

.historical-start-paused {
  margin-top: 1px;
}

.historical-replay-status-row {
  align-items: center;
  justify-content: space-between;
}

.historical-replay-status-row .chip {
  flex: 1 1 auto;
  min-width: 0;
  white-space: normal;
}

.compact-button {
  flex: 0 0 auto;
  padding: 6px 8px;
}

.manual-input-with-unit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
}

.manual-input-with-unit small {
  color: var(--muted, #94a3b8);
}

@media (max-width: 620px) {
  .historical-replay-grid {
    grid-template-columns: 1fr;
  }

  .historical-date-field {
    grid-column: auto;
  }
}

/* v2.91 native replay-date picker */
.historical-date-field input[type="date"] { color-scheme: dark; }
.historical-date-field .field-help { color: var(--muted, #94a3b8); font-size: 11px; font-weight: 500; }

/* v2.92: direct, large per-leg controls and draggable chart orders. */
.manual-active-leg-fields {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}
.manual-leg-level-control {
  display: grid;
  gap: 4px;
}
.manual-leg-level-label {
  color: #94a3b8;
  font-size: 9px;
  font-weight: 800;
}
.leg-price-stepper {
  display: grid;
  grid-template-columns: 42px minmax(84px, 1fr) 42px;
  min-height: 40px;
  overflow: hidden;
  border: 1px solid #343b49;
  border-radius: 8px;
  background: #0f1115;
}
.leg-price-stepper button {
  min-width: 42px;
  border: 0;
  border-radius: 0;
  padding: 0;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.leg-price-stepper button:first-child { border-right: 1px solid #343b49; }
.leg-price-stepper button:last-child { border-left: 1px solid #343b49; }
.leg-price-stepper output {
  display: grid;
  place-items: center;
  padding: 0 5px;
  color: #f8fafc;
  font-size: 11px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  user-select: none;
}
#tradeLevelInteractionLayer {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  overflow: hidden;
}
.trade-level-handle {
  position: absolute;
  transform: translateY(-50%);
  width: 86px;
  min-height: 26px;
  padding: 3px 6px;
  border: 1px solid;
  border-radius: 6px;
  color: #ffffff;
  font-size: 10px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  white-space: nowrap;
  cursor: ns-resize;
  touch-action: none;
  pointer-events: auto;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  user-select: none;
}
.trade-level-handle.stop {
  border-color: #b91c1c;
  background: #dc2626;
}
.trade-level-handle.target {
  border-color: #15803d;
  background: #16a34a;
}
.trade-level-handle.dragging {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
}
.trade-level-handle.pending { opacity: 0.65; }
.trade-level-handle.error {
  border-color: #fbbf24;
  background: #7f1d1d;
}

.replay-warmup-overlay {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(248, 250, 252, 0.82);
  pointer-events: none;
}

.replay-warmup-overlay[hidden] {
  display: none;
}

.replay-warmup-overlay-card {
  width: min(560px, 92%);
  padding: 22px;
  border: 1px solid rgba(180, 83, 9, 0.34);
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.96);
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.28);
  color: #f8fafc;
}

.replay-warmup-overlay-heading {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.replay-warmup-overlay-heading strong {
  display: block;
  margin-bottom: 4px;
  color: #fde68a;
  font-size: 18px;
}

#replayWarmupOverlayDetail,
#replayWarmupOverlayMetrics,
.replay-warmup-overlay-note {
  color: #cbd5e1;
  font-size: 13px;
  line-height: 1.45;
}

.replay-warmup-spinner {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  border: 3px solid rgba(253, 230, 138, 0.24);
  border-top-color: #facc15;
  border-radius: 50%;
  animation: replay-warmup-spin 0.85s linear infinite;
}

.replay-warmup-overlay-track {
  height: 12px;
  margin: 18px 0 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #334155;
}

#replayWarmupOverlayFill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #f59e0b, #fde047);
  transition: width 220ms ease-out;
}

.replay-warmup-overlay-note {
  margin-top: 12px;
  color: #94a3b8;
}

.replay-warmup-overlay.is-indeterminate #replayWarmupOverlayFill {
  width: 36%;
  animation: replay-warmup-indeterminate 1.15s ease-in-out infinite;
}

.replay-paused-overlay {
  position: absolute;
  inset: 0;
  z-index: 11;
  display: grid;
  place-items: start center;
  padding-top: 72px;
  pointer-events: none;
}

.replay-paused-overlay[hidden] {
  display: none;
}

.replay-paused-overlay-card {
  min-width: 220px;
  padding: 10px 18px;
  border: 1px solid rgba(248, 113, 113, 0.5);
  border-radius: 999px;
  background: rgba(127, 29, 29, 0.92);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.25);
  color: #fee2e2;
  text-align: center;
}

.replay-paused-overlay-card strong {
  display: block;
  font-size: 13px;
  letter-spacing: 0.08em;
}

#replayPausedOverlayDetail {
  margin-top: 2px;
  color: #fecaca;
  font-size: 11px;
}

@keyframes replay-warmup-indeterminate {
  0% { transform: translateX(-120%); }
  50% { transform: translateX(90%); }
  100% { transform: translateX(280%); }
}

@keyframes replay-warmup-spin {
  to { transform: rotate(360deg); }
}


/* v3.2.8: compact two-row timeframe controls, 2x2 navigation grid,
 * left-positioned replay HUD, and sidebar drawer-open icon. */
.header-identity {
  flex: 0 0 auto;
  min-width: 205px;
}

.header-identity-meta {
  min-height: 28px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-drawer-reopen-button {
  width: 28px;
  min-width: 28px;
  height: 26px;
  min-height: 26px;
  padding: 3px;
  border-radius: 6px;
  color: #dbeafe;
  border: 1px solid #3b82f6;
  background: #172554;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 28px;
}

.header-drawer-reopen-button:hover {
  background: #1e3a8a;
}

.header-drawer-reopen-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.header-action-buttons {
  gap: 10px;
}

/* The HUD itself is intentionally unchanged; only its position/outer width is adjusted. */
.header-chart-time-hud {
  order: 1;
  width: 260px;
  min-width: 245px;
  flex: 0 1 260px;
}

.header-timeframe-card {
  order: 2;
  width: 390px;
  min-width: 350px;
  height: var(--header-action-height);
  flex: 1 1 390px;
  justify-content: center;
  gap: 0;
  padding: 7px 9px;
}

.header-timeframe-card .timeframe-switcher {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

.header-timeframe-card .timeframe-row {
  display: grid;
  align-items: stretch;
  gap: 5px;
  min-width: 0;
}

.header-timeframe-card .timeframe-row-entry {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.header-timeframe-card .timeframe-row-higher {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.header-timeframe-card .timeframe-button {
  min-width: 0;
  width: 100%;
  height: 100%;
  padding: 4px 5px;
}

.header-window-buttons {
  order: 3;
  width: 280px;
  height: var(--header-action-height);
  flex: 0 0 280px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 5px;
}

.header-window-buttons .header-trading-button,
.header-window-buttons .header-dashboard-button,
.header-window-buttons .header-status-button {
  padding: 5px 8px;
  font-size: 12px;
  line-height: 1.1;
  white-space: nowrap;
}

@media (max-width: 1400px) {
  .header-chart-time-hud {
    width: 250px;
    min-width: 235px;
    flex-basis: 250px;
  }
  .header-timeframe-card {
    width: 365px;
    min-width: 335px;
    flex-basis: 365px;
  }
  .header-window-buttons {
    width: 250px;
    flex-basis: 250px;
  }
}

@media (max-width: 1060px) {
  .header-identity {
    min-width: 0;
  }
  .header-action-buttons {
    width: 100%;
    flex-wrap: nowrap;
  }
  .header-chart-time-hud {
    width: 250px;
    min-width: 225px;
    flex: 0 1 250px;
  }
  .header-timeframe-card {
    width: auto;
    min-width: 330px;
    flex: 1 1 360px;
  }
  .header-window-buttons {
    width: 250px;
    flex: 0 0 250px;
  }
}

@media (max-width: 820px) {
  :root { --header-height: 260px; }
  .header-action-buttons {
    flex-wrap: wrap;
  }
  .header-chart-time-hud {
    flex: 1 1 calc(50% - 5px);
    width: auto;
    min-width: 270px;
  }
  .header-window-buttons {
    flex: 1 1 calc(50% - 5px);
    width: auto;
    min-width: 250px;
  }
  .header-timeframe-card {
    order: 3;
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
  }
  .header-window-buttons {
    order: 2;
  }
}

@media (max-width: 620px) {
  :root { --header-height: 350px; }
  .header-chart-time-hud,
  .header-window-buttons,
  .header-timeframe-card {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
  }
  .header-timeframe-card {
    min-height: var(--header-action-height);
  }
}

/* v3.2.23: compact multi-tool drawing rail, clear-visible action, and matched drawer chevrons. */
:root {
  --drawing-rail-width: 46px;
  --drawing-rail-collapsed-width: 18px;
}

main {
  grid-template-columns: var(--sidebar-width) var(--drawing-rail-width) minmax(0, 1fr);
  gap: 10px;
}

main.sidebar-collapsed {
  grid-template-columns: var(--drawing-rail-width) minmax(0, 1fr);
}

main.drawing-rail-collapsed {
  grid-template-columns: var(--sidebar-width) var(--drawing-rail-collapsed-width) minmax(0, 1fr);
}

main.sidebar-collapsed.drawing-rail-collapsed {
  grid-template-columns: var(--drawing-rail-collapsed-width) minmax(0, 1fr);
}

.drawing-sidebar {
  position: sticky;
  top: calc(var(--header-height) + 10px);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: var(--drawing-rail-width);
  height: calc(100vh - var(--header-height) - 24px);
  min-height: 0;
  overflow: hidden;
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  background: #151923;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}

.drawing-sidebar.collapsed {
  width: var(--drawing-rail-collapsed-width);
  border-radius: 6px;
}

.drawing-rail-toggle,
.drawing-tool-button,
.drawing-option-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-width: 0;
  padding: 0;
  color: #cbd5e1;
  border: 0;
  border-bottom: 1px solid #2a2f3a;
  border-radius: 0;
  background: transparent;
}

.drawing-rail-toggle {
  height: 32px;
  min-height: 32px;
  color: #93c5fd;
  font-size: 22px;
  line-height: 1;
}

.drawing-tool-button,
.drawing-option-button {
  height: 42px;
  min-height: 42px;
}

.drawing-rail-toggle:hover,
.drawing-tool-button:hover,
.drawing-option-button:hover {
  background: #1f2937;
}

.drawing-tool-button.active {
  color: #ffffff;
  background: #1d4ed8;
  box-shadow: inset 3px 0 0 #93c5fd;
}

.drawing-tool-button svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

.drawing-tools-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.drawing-tools-body[hidden] {
  display: none !important;
}

.drawing-tool-separator {
  height: 6px;
  min-height: 6px;
  border-bottom: 1px solid #2a2f3a;
  background: #10141c;
}

.drawing-color-control {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  min-height: 42px;
  border-bottom: 1px solid #2a2f3a;
  cursor: pointer;
}

.drawing-color-control:hover {
  background: #1f2937;
}

.drawing-color-control input[type="color"] {
  width: 25px;
  height: 25px;
  padding: 0;
  border: 1px solid #64748b;
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
}

.drawing-option-button {
  color: #dbeafe;
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.drawing-scope-button {
  color: #fde68a;
}

.drawing-option-button:disabled {
  opacity: 0.32;
  cursor: default;
}

.drawing-option-button:disabled:hover {
  background: transparent;
}

.drawing-delete-button:not(:disabled) {
  color: #fca5a5;
}

.drawing-clear-all-button:not(:disabled) {
  color: #fda4af;
}

.drawing-clear-all-button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}


.drawing-scope-button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

.drawing-scope-button.multi-scope {
  color: #fef3c7;
}

.drawing-scope-popover {
  position: fixed;
  z-index: 1600;
  min-width: 150px;
  padding: 7px;
  border: 1px solid #475569;
  border-radius: 8px;
  background: #151923;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.42);
}

.drawing-scope-popover[hidden] {
  display: none !important;
}

.drawing-scope-popover-label {
  margin: 0 0 6px;
  color: #94a3b8;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.drawing-scope-popover-buttons {
  display: flex;
  gap: 5px;
}

.drawing-scope-popover-buttons button {
  width: 36px;
  height: 32px;
  padding: 0;
  border: 1px solid #475569;
  border-radius: 6px;
  color: #cbd5e1;
  background: #0f131b;
  font-size: 13px;
  font-weight: 800;
}

.drawing-scope-popover-buttons button:hover {
  background: #1f2937;
}

.drawing-scope-popover-buttons button.active {
  color: #ffffff;
  border-color: #60a5fa;
  background: #1d4ed8;
}

body.drawing-mode-active #chartWrap {
  cursor: crosshair;
}

@media (max-width: 820px) {
  main,
  main.sidebar-collapsed,
  main.drawing-rail-collapsed,
  main.sidebar-collapsed.drawing-rail-collapsed {
    grid-template-columns: 1fr;
  }
  .drawing-sidebar {
    position: static;
    width: 100%;
    height: 46px;
    flex-direction: row;
  }
  .drawing-sidebar.collapsed {
    width: 100%;
    height: 18px;
  }
  .drawing-tools-body {
    flex: 1 1 auto;
    flex-direction: row;
  }
  .drawing-rail-toggle,
  .drawing-tool-button,
  .drawing-option-button,
  .drawing-color-control {
    width: 46px;
    height: 100%;
    min-height: 0;
    border-right: 1px solid #2a2f3a;
    border-bottom: 0;
  }
  .drawing-tool-separator {
    width: 6px;
    height: 100%;
    min-height: 0;
    border-right: 1px solid #2a2f3a;
    border-bottom: 0;
  }
}

/* v3.2.24: immediate, consistent tooltips for Drawing Tools controls. */
.drawing-tool-tooltip {
  position: fixed;
  z-index: 1750;
  max-width: 290px;
  padding: 7px 9px;
  border: 1px solid #475569;
  border-radius: 6px;
  color: #e2e8f0;
  background: #0f131b;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
  pointer-events: none;
  white-space: normal;
}

.drawing-tool-tooltip[hidden] {
  display: none !important;
}
