/* Setpoint shell: layout and controls of the desktop MainWindow (Avalonia Fluent, 1920×1080 design).
   Colours only through the custom properties in theme.css. */
@font-face { font-family: "Inter"; font-weight: 400; font-style: normal; font-display: swap; src: url("../fonts/Inter-Regular.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 600; font-style: normal; font-display: swap; src: url("../fonts/Inter-SemiBold.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 700; font-style: normal; font-display: swap; src: url("../fonts/Inter-Bold.woff2") format("woff2"); }

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sp-font); font-size: 13px; line-height: 1.33; color: var(--sp-text); background: var(--sp-bg);
  -webkit-font-smoothing: antialiased; overflow: hidden; -webkit-text-size-adjust: 100%;
}
#app { height: 100%; }
button, input, select { font: inherit; color: inherit; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--sp-scrollbar); border-radius: 4px; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
* { scrollbar-width: thin; scrollbar-color: var(--sp-scrollbar) transparent; }

/* ---- Fluent-like controls -------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; white-space: nowrap;
  padding: 7px 12px; margin: 0 8px 0 0; min-height: 0; border: 1px solid transparent; border-radius: 4px;
  background: var(--sp-control-bg); color: var(--sp-control-text); cursor: default; line-height: 1.33; user-select: none;
}
.btn:hover { background: var(--sp-control-bg-hover); }
.btn:active { background: var(--sp-control-bg-pressed); }
.btn:disabled { color: var(--sp-control-disabled-text); background: var(--sp-control-bg-pressed); }
.btn:focus-visible, .tab:focus-visible, .text-input:focus-visible, .combo:focus-visible { outline: 2px solid var(--sp-text); outline-offset: 1px; }
.btn.small { padding: 3px 8px; margin-right: 4px; }
.btn.small.gap { margin-right: 12px; }
.btn.last, .btn.small.last { margin-right: 0; }
summary.btn { list-style: none; }
summary.btn::-webkit-details-marker { display: none; }

.text-input {
  padding: 4px 5px; border: 1px solid var(--sp-input-border); border-radius: 4px; background: var(--sp-input-bg);
  color: var(--sp-text); min-height: 0; outline: none;
}
.text-input:focus { background: var(--sp-input-bg-focus); border-color: var(--sp-accent); border-bottom-width: 2px; padding-bottom: 3px; }
.combo {
  min-width: 85px; min-height: 25px; padding: 3px 6px; border: 1px solid var(--sp-input-border); border-radius: 4px;
  background: var(--sp-input-bg); color: var(--sp-text);
}
.combo option { background: var(--sp-surface); color: var(--sp-text); }

input.check {
  appearance: none; -webkit-appearance: none; width: 20px; height: 20px; margin: 0; flex: none; border-radius: 4px;
  border: 1px solid var(--sp-check-border); background: transparent; display: inline-grid; place-content: center; cursor: default;
}
input.check:checked { background: var(--sp-accent); border-color: var(--sp-accent); }
input.check:checked::after {
  content: ""; width: 10px; height: 5px; border: solid var(--sp-check-mark); border-width: 0 0 2px 2px; transform: translateY(-1px) rotate(-45deg);
}
label.checkbox { display: inline-flex; align-items: center; gap: 0; cursor: default; user-select: none; }
label.checkbox input.check { margin-right: 0; }
label.checkbox.strong { font-weight: 600; }

.toggle-switch { display: inline-flex; align-items: center; margin-left: 8px; color: var(--sp-header-text); cursor: default; user-select: none; }
.toggle-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
  width: 40px; height: 20px; border-radius: 10px; border: 1px solid var(--sp-toggle-off); position: relative; flex: none; margin-right: 12px;
  transition: background .12s;
}
.toggle-knob { position: absolute; top: 4px; left: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--sp-toggle-off); transition: left .12s, background .12s; }
.toggle-switch input:checked + .toggle-track { background: var(--sp-accent); border-color: var(--sp-accent); }
.toggle-switch input:checked + .toggle-track .toggle-knob { left: 24px; background: var(--sp-toggle-knob-on); }
.toggle-switch input:focus-visible + .toggle-track { outline: 2px solid var(--sp-header-text); outline-offset: 2px; }

.muted-label { color: var(--sp-text-muted); }

/* ---- tooltip (js/app.js) ----------------------------------------------------------------- */
.sp-tooltip {
  position: fixed; z-index: 1000; display: none; max-width: 420px; padding: 6px 9px; border-radius: 4px; pointer-events: none;
  background: var(--sp-tooltip-bg); color: var(--sp-tooltip-text); border: 1px solid var(--sp-tooltip-border);
  box-shadow: 0 4px 12px var(--sp-shadow); white-space: pre-line; font-size: 13px; line-height: 1.4;
}

/* ---- window ------------------------------------------------------------------------------ */
.shell { display: grid; grid-template-rows: auto minmax(0, 1fr) 28px; height: 100%; height: 100dvh; background: var(--sp-bg); }
.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 18px; min-height: 54px;
  background: var(--sp-header-bg); color: var(--sp-header-text);
}
.brand { display: flex; align-items: center; min-width: 0; }
.brand-icon { width: 26px; height: 26px; margin-right: 10px; flex: none; }
.wordmark { font-size: 18px; font-weight: 700; color: var(--sp-header-text); white-space: nowrap; }
.tagline { margin: 2px 0 0 14px; color: var(--sp-header-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-actions { display: flex; align-items: center; flex: none; }
.header-btn { background: var(--sp-header-button); color: var(--sp-header-text); }
.header-btn:hover { background: color-mix(in srgb, var(--sp-header-button) 80%, var(--sp-header-text)); }
.add-btn { background: var(--sp-accent); border-color: var(--sp-accent); color: var(--sp-accent-ink); font-weight: 700; }
.add-btn:hover { background: color-mix(in srgb, var(--sp-accent) 88%, var(--sp-header-text)); }
.add-btn:disabled { background: color-mix(in srgb, var(--sp-accent) 45%, var(--sp-header-bg)); color: var(--sp-accent-ink); }

.app-body { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: 0; position: relative; }
.sidebar-closed .app-body { grid-template-columns: 0 minmax(0, 1fr); }
.sidebar-closed .recordings { visibility: hidden; padding: 0; border: 0; }

/* recordings list */
.recordings {
  display: flex; flex-direction: column; min-height: 0; overflow: hidden; padding: 12px 14px;
  background: var(--sp-surface); border-right: 1px solid var(--sp-border);
}
.recordings-title { font-size: 13px; font-weight: 700; color: var(--sp-text-muted); margin: 0 0 4px; }
.log-list { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; }
.log-item { display: flex; align-items: flex-start; padding: 14px 12px 13px 19px; border-radius: 3px; cursor: default; user-select: none; }
.log-item:hover { background: var(--sp-hover-bg); }
.log-item.selected { background: var(--sp-selected-bg); }
.log-item.selected:hover { background: var(--sp-selected-hover-bg); }
.log-item .check { margin: 1px 6px 0 0; }
.swatch { width: 10px; height: 10px; border-radius: 50%; flex: none; margin: 5px 8px 0 0; }
.log-text { min-width: 0; max-width: 200px; }
.log-name { font-weight: 600; overflow-wrap: anywhere; }
.log-subtitle { margin-top: 3px; font-size: 13px; color: var(--sp-text-muted); overflow-wrap: anywhere; white-space: pre-wrap; }
.recordings-actions { display: flex; align-items: center; margin-top: 6px; }
.recordings-actions .muted-label { margin-right: 6px; }
.scrim { display: none; }

/* main area */
.main-area { display: grid; grid-template-rows: auto minmax(0, 1fr); min-width: 0; min-height: 0; padding: 10px 16px 8px; }
.main-head { display: flex; flex-direction: row-reverse; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; min-width: 0; }
.recording-head { min-width: 0; flex: 1; }
.recording-title { font-size: 19px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recording-info { font-size: 14px; color: var(--sp-text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.range { display: flex; flex-wrap: wrap; align-items: center; flex: none; row-gap: 4px; }
.range-label { margin-right: 8px; }
.text-input.start { width: 64px; }
.text-input.end { width: 64px; }
.range-to { margin: 0 6px; }
.range-s { margin: 0 8px 0 4px; }
.range-btn { padding: 5px 10px; }

/* tabs (Fluent TabControl) */
.tabs { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; min-width: 0; background: var(--sp-surface); }
.tab-strip { display: flex; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; padding: 2px 0 0 0; }
.tab-strip::-webkit-scrollbar { display: none; }
.tab {
  position: relative; flex: none; padding: 9px 12px 13px; margin: 0; border: 0; background: transparent; font-size: 13px; font-weight: 600;
  color: color-mix(in srgb, var(--sp-text) 62%, transparent); cursor: default; white-space: nowrap;
}
.tab:hover { color: color-mix(in srgb, var(--sp-text) 80%, transparent); }
.tab.active { color: var(--sp-text); }
.tab.active::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: 6px; height: 3px; border-radius: 2px; background: var(--sp-accent); }
.tab-pages { position: relative; min-height: 0; min-width: 0; }
/* Fluent TabControl content padding (all tabs): 8 top, 12 left/right, 0 bottom. */
.tab-page { position: absolute; inset: 0; display: none; min-height: 0; overflow: hidden; padding: 8px 12px 0; }
.tab-page.active { display: block; }

/* step response / tracking grids */
.split-grid {
  display: grid; height: 100%; padding: 8px 10px; grid-template-rows: auto repeat(3, minmax(0, 1fr));
}
.grid-bar { grid-column: 1 / 4; grid-row: 1; display: flex; align-items: center; margin: 0 0 6px 2px; min-height: 29px; flex-wrap: wrap; row-gap: 4px; }
.step-grid .grid-bar { justify-content: space-between; }
.bar-right { display: inline-flex; align-items: center; }
.reset-view { padding: 3px 10px; margin: 0 0 0 14px; }
.how-to-read { font-weight: 600; cursor: help; }
.checkbox.ff { margin-left: 16px; }
.zoom-mode { margin-left: 16px; min-width: 150px; }
.plot-cell { grid-column: 1; min-width: 0; min-height: 0; position: relative; }
.stats-cell { grid-column: 3; min-width: 0; min-height: 0; display: flex; }
.row0 { grid-row: 2; } .row1 { grid-row: 3; } .row2 { grid-row: 4; }
.splitter { grid-column: 2; grid-row: 2 / 5; cursor: col-resize; touch-action: none; }


/* tune */
.tune-page { display: flex; height: 100%; min-height: 0; }
.tune-left { width: 340px; flex: none; padding: 14px 16px; border-right: 1px solid var(--sp-border); overflow-y: auto; }


/* details */
.details-scroll { height: 100%; overflow-y: auto; }

/* flyouts (filter guide, export menu) */
.sp-flyout { position: relative; display: inline-block; }
.sp-flyout > .flyout-panel {
  position: absolute; z-index: 50; top: calc(100% + 4px); left: 0; padding: 12px 0 12px 14px; border-radius: 8px;
  background: var(--sp-surface-raised); border: 1px solid var(--sp-border); box-shadow: 0 8px 24px var(--sp-shadow); color: var(--sp-text);
}
.export-menu > .flyout-panel.menu { left: auto; right: 8px; padding: 4px; min-width: 190px; }
.menu-item { display: flex; width: 100%; justify-content: space-between; gap: 16px; padding: 7px 10px; border: 0; border-radius: 4px; background: transparent; text-align: left; cursor: default; }
.menu-item:hover { background: var(--sp-hover-bg); }
.menu-hint { color: var(--sp-text-muted); }
.export-menu { margin-right: 8px; }
.export-menu > summary.btn { margin-right: 0; }

/* run picker (modal, desktop RunPicker window) */
.modal-backdrop { position: fixed; inset: 0; z-index: 900; display: grid; place-items: center; padding: 16px; background: var(--sp-shadow); }
.modal {
  min-width: min(340px, 100%); max-width: 100%; max-height: calc(100dvh - 32px); display: flex; flex-direction: column; padding: 18px 22px;
  border-radius: 8px; background: var(--sp-surface); color: var(--sp-text); border: 1px solid var(--sp-border); box-shadow: 0 12px 32px var(--sp-shadow);
}
.modal-title { font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.run-list { margin-top: 10px; overflow-y: auto; min-height: 0; }
label.checkbox.run-row { display: flex; align-items: center; margin: 2px 0; padding: 3px 0; font-size: 14px; color: var(--sp-text); }
label.checkbox.run-row input.check { margin-right: 8px; }
.run-cols { display: inline-flex; font-variant-numeric: tabular-nums; }
.run-name { width: 64px; }
.run-start { width: 80px; text-align: right; }
.run-arrow { width: 34px; text-align: center; }
.run-end { width: 80px; }
.modal-actions { display: flex; justify-content: flex-end; margin-top: 14px; }
.modal-actions .btn { margin-right: 6px; }
.modal-actions .btn.last { margin-right: 0; }
@media (max-width: 420px) { .run-name { width: 56px; } .run-start, .run-end { width: 66px; } .run-arrow { width: 26px; } }

/* status bar */
.status-bar { display: flex; align-items: center; gap: 10px; padding: 0 14px; background: var(--sp-surface-sunken); color: var(--sp-text-secondary); font-size: 13px; min-width: 0; overflow: hidden; }
.status-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn.cancel { padding: 0 10px; margin: 0; }
.progress { position: relative; flex: none; width: 120px; height: 4px; border-radius: 2px; background: var(--sp-border); overflow: hidden; }
.progress-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--sp-accent); border-radius: 2px; transition: width .2s; }
.progress.indeterminate .progress-fill { width: 30%; animation: sp-indeterminate 1.1s ease-in-out infinite; }
@keyframes sp-indeterminate { from { left: -30%; } to { left: 100%; } }
.boot-fill { width: var(--blazor-load-percentage, 0%); }
.boot-status::after { content: var(--blazor-load-percentage-text, ""); }
.boot-body { display: block; padding: 10px 16px 8px 316px; }
body.dropping .main-area { outline: 2px dashed var(--sp-accent); outline-offset: -6px; }

/* ---- narrower windows ---------------------------------------------------------------------- */
@media (max-width: 1150px) {
  .tagline { display: none; }
}
@media (max-width: 900px) {
  .app-header { padding: 8px 10px; gap: 8px; }
  .hide-narrow { display: none; }
  .main-head { flex-direction: column; align-items: stretch; }
  .range { order: 2; }
  .boot-body { padding-left: 16px; }
}
@media (max-width: 700px) {
  /* recordings list becomes a drawer over the content (☰) */
  .app-body, .sidebar-closed .app-body { grid-template-columns: minmax(0, 1fr); }
  .recordings { position: absolute; z-index: 40; top: 0; bottom: 0; left: 0; width: min(300px, 86vw); box-shadow: 4px 0 18px var(--sp-shadow); }
  .sidebar-open .scrim { display: block; position: absolute; inset: 0; z-index: 39; background: var(--sp-shadow); }
  .main-area { grid-column: 1; padding: 8px 8px 6px; }
  .header-actions .btn { padding: 7px 10px; margin-right: 6px; }
  .toggle-switch { margin-left: 2px; }
  .toggle-label { display: none; }
  .toggle-track { margin-right: 0; }
  .wordmark { font-size: 16px; }
  .brand-icon { margin-right: 8px; }
  .recording-title { font-size: 17px; }
  .recording-info { font-size: 13px; white-space: normal; }
  .tab-page { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 4px 0; }
  .split-grid { height: auto; grid-template-columns: minmax(0, 1fr) !important; grid-template-rows: none; padding: 8px 4px; }
  .grid-bar { grid-column: 1; }
  .plot-cell, .stats-cell { grid-column: 1; grid-row: auto; }
  .plot-cell { height: 300px; }
  .step-grid .stats-cell { height: 250px; }
  .track-grid .stats-cell { height: auto; }
  .splitter { display: none; }
  .tune-page { flex-direction: column; height: auto; }
  .tune-left { width: auto; border-right: 0; border-bottom: 1px solid var(--sp-border); overflow: visible; }
  .status-bar { padding: 0 8px; font-size: 12px; }
  .progress { width: 60px; }
}

/* ---- Blazor error UI ------------------------------------------------------------------------ */
#blazor-error-ui {
  background: var(--sp-error-bg); color: var(--sp-error-text); bottom: 0; box-shadow: 0 -1px 2px var(--sp-shadow);
  display: none; left: 0; padding: 0.6rem 1.25rem 0.7rem 1.25rem; position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui a { color: inherit; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
