:root {
  color-scheme: light dark;
  --bg: #0f1419;
  --card: #1a2332;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --ok: #3dd68c;
  --error: #f07178;
  --pending: #e7c547;
  --border: #2d3a4f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, "Noto Sans SC", sans-serif;
  background: radial-gradient(circle at top, #1b2838, var(--bg));
  color: var(--text);
}

.shell {
  max-width: 56rem;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
}

.tagline {
  margin: 0;
  color: var(--muted);
}

.card {
  margin-top: 1.75rem;
  padding: 1.25rem 1.5rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
}

.hint {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
}

#upload-form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
}

#upload-form button[type="submit"] {
  align-self: flex-start;
}

.file-label {
  display: block;
  min-width: 0;
  max-width: 100%;
  cursor: pointer;
}

.file-label-caption {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.file-label input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}

.file-name-display {
  display: block;
  width: 100%;
  max-width: 100%;
  padding: 0.65rem 0.9rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-label:hover .file-name-display {
  border-color: #5eb3ff;
  color: var(--text);
}

.meta-row--filename {
  grid-column: 1 / -1;
  min-width: 0;
}

.meta-row--filename dd {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
  font-size: 0.9rem;
}

.extract-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin: 0 0 0.5rem;
}

#export-csv-hint {
  margin: 0 0 0.75rem;
}

#qa-overlay-btn,
#export-csv-btn {
  margin-top: 0;
}

.tool-panel,
.nav-panel {
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #121a26;
}

.tool-panel-title,
.nav-panel-title {
  margin: 0 0 0.65rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.tool-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.55rem 0.65rem;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 9rem;
}

.filter-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

#filter-select {
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #1a2332;
  color: var(--text);
  font-size: 0.85rem;
}

.signal-state {
  margin: 0.65rem 0 0;
  font-size: 0.82rem;
  color: #a8c4e8;
}

.disclaimer-inline {
  margin: 1rem 0 0;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(240, 113, 120, 0.08);
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.5;
}

.viz-panel {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.vcg-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.65rem;
}

.plot-stack {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.plot-host {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0;
  overflow: visible;
}

.plot-host .js-plotly-plot,
.plot-host .plot-container {
  width: 100% !important;
}

.plot-vcg {
  min-height: 400px;
  margin-bottom: 0.85rem;
}

.plot-wave {
  min-height: 240px;
}

.plot-map {
  min-height: 380px;
}

.nav-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem 1.25rem;
}

.nav-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.nav-group-label {
  min-width: 4.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
}

.nav-help {
  margin: 0.75rem 0 0;
  padding-left: 1.15rem;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.55;
}

.nav-help li {
  margin-bottom: 0.2rem;
}

.zoom-info {
  margin: 0.65rem 0 0;
  font-size: 0.85rem;
  color: #a8c4e8;
  font-variant-numeric: tabular-nums;
}

.btn-secondary {
  padding: 0.45rem 0.8rem;
  background: #243044;
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.btn-secondary:hover:not(:disabled) {
  background: #2d3a4f;
}

button {
  padding: 0.65rem 1.25rem;
  border: none;
  border-radius: 8px;
  background: #3d7dd6;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #5090e8;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.5rem 1rem;
  margin: 0 0 1rem;
}

.meta-row dt {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.meta-row dd {
  margin: 0.15rem 0 0;
  font-weight: 600;
}

.warning {
  margin: 0 0 1rem;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  background: rgba(231, 197, 71, 0.12);
  border: 1px solid rgba(231, 197, 71, 0.35);
  color: #e7c547;
  font-size: 0.85rem;
  line-height: 1.45;
}

.preview-wrap {
  overflow-x: auto;
  overscroll-behavior: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
}

#ecg-preview.panning {
  cursor: grab;
}

#ecg-preview {
  display: block;
  max-width: 100%;
  height: auto;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.selection-info {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.actions {
  margin-top: 1rem;
}

.results-grid .meta-row dd {
  font-variant-numeric: tabular-nums;
}

.status {
  margin: 0;
  font-weight: 600;
}

.status.pending {
  color: var(--pending);
}

.status.ok {
  color: var(--ok);
}

.status.error {
  color: var(--error);
}

.mono {
  margin: 1rem 0 0;
  padding: 0.75rem 1rem;
  background: #0b1017;
  border-radius: 8px;
  font-size: 0.85rem;
  overflow-x: auto;
}

.hidden {
  display: none;
}

.disclaimer {
  margin-top: 2rem;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.5;
}
