:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-alt: #eef3f7;
  --text: #17202a;
  --muted: #637083;
  --border: #d7dee8;
  --border-strong: #bdc8d5;
  --teal: #008c8c;
  --teal-dark: #006f72;
  --amber: #d28a00;
  --blue: #2767c9;
  --red: #c83232;
  --shadow: 0 14px 36px rgba(22, 32, 42, 0.08);
  --radius: 8px;
  font-family: "Segoe UI", "Malgun Gothic", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 980px;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  min-width: 0;
  min-height: 36px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}

button:hover:not(:disabled) {
  border-color: var(--teal);
  color: var(--teal-dark);
}

button:disabled {
  cursor: not-allowed;
  color: #9aa6b4;
  background: #f2f5f8;
}

.primary-button {
  border-color: var(--teal);
  background: var(--teal);
  color: #ffffff;
}

.primary-button:hover:not(:disabled) {
  background: var(--teal-dark);
  color: #ffffff;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 7px;
  background: #14242b;
  color: #ffffff;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.2;
  letter-spacing: 0;
}

.browser-recommendation {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.1;
}

h2 {
  font-size: 14px;
  line-height: 1.2;
  letter-spacing: 0;
}

.brand p,
.plot-toolbar p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid rgba(0, 140, 140, 0.28);
  border-radius: 999px;
  padding: 0 10px;
  background: rgba(0, 140, 140, 0.08);
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 700;
}

.status-pill.muted {
  border-color: var(--border);
  background: var(--surface-alt);
  color: var(--muted);
}

.status-pill.warning {
  border-color: rgba(210, 138, 0, 0.28);
  background: rgba(210, 138, 0, 0.11);
  color: #7a5100;
}

.status-pill.error {
  border-color: rgba(200, 50, 50, 0.28);
  background: rgba(200, 50, 50, 0.08);
  color: var(--red);
}

.workspace {
  display: grid;
  grid-template-columns: 270px minmax(520px, 1fr) 290px;
  grid-template-rows: auto 240px;
  align-items: start;
  gap: 14px;
  margin-top: 14px;
}

.panel,
.plot-panel,
.data-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.controls-panel,
.settings-panel {
  max-height: calc(100vh - 116px);
  overflow: auto;
}

.plot-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px;
}

.data-panel {
  grid-column: 1 / 4;
  min-height: 220px;
  padding: 16px;
}

.panel-header,
.plot-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.plot-actions {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.view-tabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.view-tab {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.view-tab.active {
  border-color: var(--teal);
  background: var(--teal);
  color: #ffffff;
}

.adc-plot-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: flex-end;
  gap: 8px;
}

.adc-plot-controls label {
  display: grid;
  gap: 3px;
  min-width: 132px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.adc-plot-controls select {
  min-height: 30px;
  padding: 0 8px;
  font-size: 12px;
}

.adc-format-state {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-alt);
  color: var(--muted);
  white-space: nowrap;
}

.adc-line-inspector {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfd;
}

.adc-line-inspector .panel-header {
  align-items: start;
}

.panel-header span,
.plot-toolbar span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.panel-header.compact {
  margin-top: 2px;
}

.button-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.field {
  display: grid;
  gap: 6px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

input,
select {
  min-width: 0;
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 0 10px;
  background: #ffffff;
  color: var(--text);
  font-size: 13px;
}

input[type="range"] {
  min-height: 28px;
  padding: 0;
}

input[type="file"] {
  padding: 7px 8px;
}

.is-hidden {
  display: none !important;
}

.flash-progress {
  display: block;
  width: 100%;
  height: 10px;
  margin-top: 10px;
  accent-color: var(--teal);
}

.flash-main-action {
  margin-top: 12px;
}

.flash-main-action button {
  width: 100%;
}

.flash-recovery-row {
  display: flex;
  gap: 7px;
  justify-content: flex-end;
  margin-top: 7px;
}

.helper-download-row {
  display: flex;
  gap: 7px;
  justify-content: flex-end;
  margin-top: 7px;
}

.helper-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: -4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.download-button {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 8px;
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
}

.download-button:hover {
  border-color: var(--teal);
  color: var(--teal-dark);
  background: #ffffff;
}

.recovery-button {
  min-height: 26px;
  border-color: transparent;
  padding: 0 6px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.recovery-button:hover:not(:disabled) {
  border-color: var(--border);
  color: var(--teal-dark);
  background: var(--surface-alt);
}

.inline-input {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
}

.inline-input span,
.inline-input output {
  min-width: 44px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: right;
}

.controls-panel > button,
.settings-panel > button {
  width: 100%;
  margin-top: 12px;
}

.settings-section + .settings-section {
  border-top: 1px solid var(--border);
  margin-top: 18px;
  padding-top: 18px;
}

.settings-section > button {
  width: 100%;
  margin-top: 12px;
}

.device-log-section .log-output {
  margin-top: 8px;
}

.dsp-panel {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.dsp-panel .panel-header {
  align-items: start;
}

.dsp-panel .panel-header p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.dsp-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(280px, 1fr) minmax(320px, 1.2fr);
  gap: 12px;
  align-items: stretch;
  margin-top: 10px;
}

.dsp-controls,
.dsp-transfer,
.dsp-response {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  background: #fbfcfd;
}

.dsp-mode-row {
  grid-template-columns: minmax(0, 1.3fr) minmax(130px, 0.8fr) minmax(88px, 0.45fr);
}

.dsp-formula {
  min-height: 42px;
  overflow: auto;
  margin: 8px 0 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  background: #ffffff;
  color: var(--text);
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.35;
  white-space: pre-wrap;
}

.muted-formula {
  color: var(--muted);
}

.dsp-coefficient-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.dsp-coefficient-grid div {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 8px;
  background: #ffffff;
}

.dsp-coefficient-grid span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
}

.dsp-coefficient-grid strong {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  color: var(--text);
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
}

.dsp-note {
  display: inline-flex;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.dsp-response canvas {
  display: block;
  width: 100%;
  height: 220px;
  margin-top: 8px;
}

.divider {
  height: 1px;
  margin: 18px 0;
  background: var(--border);
}

.toggle-group {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.toggle-group label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.toggle-group input {
  width: 14px;
  min-height: 14px;
  padding: 0;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.check-field input {
  width: 15px;
  min-height: 15px;
  padding: 0;
}

#signalCanvas {
  width: 100%;
  height: clamp(360px, 34vw, 700px);
  min-height: 360px;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fbfcfd;
}

.lab-view {
  min-height: clamp(360px, 34vw, 700px);
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 16px;
  background: #fbfcfd;
}

.lab-view-header,
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.lab-view-header p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.summary-stack {
  display: grid;
  justify-items: end;
  gap: 2px;
  min-width: max-content;
}

.summary-stack span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.lab-view-header strong,
.section-title span {
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
}

.lab-grid {
  display: grid;
  grid-template-columns: minmax(270px, 0.85fr) minmax(320px, 1.15fr);
  gap: 16px;
  margin-top: 16px;
}

.lab-section {
  min-width: 0;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.lab-section h3 {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.2;
}

.compact-title h3 {
  font-size: 12px;
}

.dataset-preview {
  margin-top: 12px;
}

#datasetPreviewCanvas,
#modelArchitectureCanvas,
#ppgCanvas,
#ppgCnnCanvas {
  width: 100%;
  min-height: 190px;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #ffffff;
}

#datasetPreviewCanvas {
  height: 240px;
}

#modelArchitectureCanvas {
  height: 260px;
  margin-bottom: 14px;
}

#ppgCanvas {
  height: 300px;
}

#ppgCnnCanvas {
  height: 220px;
}

.ppg-cnn-title {
  margin-top: 14px;
}

.file-button {
  display: grid;
  min-height: 36px;
  place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}

.file-button:hover {
  border-color: var(--teal);
  color: var(--teal-dark);
}

.file-button input {
  display: none;
}

.dataset-label-list,
.model-metrics {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.dataset-label-row,
.metric-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.dataset-window-table {
  max-height: 280px;
  overflow: auto;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #ffffff;
}

.model-log {
  height: 260px;
  overflow: auto;
  margin: 12px 0 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px;
  background: #111b20;
  color: #d7f0ef;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.metric-grid div {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px;
  background: #fbfcfd;
}

.metric-grid span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

.metric-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
  line-height: 1.2;
}

.classification-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: baseline;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px;
  background: #fbfcfd;
}

.classification-summary span {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.classification-summary strong {
  color: var(--teal-dark);
  font-size: 18px;
}

.classification-window-state {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.35;
}

.classification-list {
  display: grid;
  gap: 7px;
  max-height: 220px;
  overflow: auto;
  margin-top: 10px;
}

.classification-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px;
  gap: 8px;
  align-items: center;
  font-size: 12px;
}

.classification-name {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.classification-score {
  color: var(--text);
  font-weight: 750;
  text-align: right;
}

.classification-bar {
  grid-column: 1 / 3;
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-alt);
}

.classification-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
}

.log-output {
  height: 280px;
  overflow: auto;
  margin: 12px 0 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px;
  background: #111b20;
  color: #d7f0ef;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.table-wrap {
  height: 176px;
  overflow: auto;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  text-align: right;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: var(--surface-alt);
  color: var(--muted);
  font-weight: 800;
}

td:first-child,
th:first-child {
  text-align: left;
}

@media (max-width: 1120px) {
  body {
    min-width: 0;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto;
  }

  .controls-panel,
  .settings-panel {
    max-height: none;
    overflow: visible;
  }

  .data-panel {
    grid-column: auto;
  }

  .lab-grid {
    grid-template-columns: 1fr;
  }

  .dsp-layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-strip {
    justify-content: flex-start;
  }
}

@media (max-width: 600px) {
  .app-shell {
    padding: 10px;
  }

  .brand {
    min-width: 0;
  }

  .brand p {
    max-width: 260px;
  }

  .button-row {
    grid-template-columns: 1fr;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .dsp-coefficient-grid {
    grid-template-columns: 1fr;
  }

  .toggle-group {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .plot-toolbar,
  .plot-actions,
  .view-tabs {
    align-items: flex-start;
    justify-items: start;
    justify-content: flex-start;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #signalCanvas {
    height: 340px;
    min-height: 340px;
  }

  .panel,
  .plot-panel,
  .data-panel,
  .topbar {
    max-width: 100%;
  }
}
