/* ===== Reset & base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  background: #F0F2F5;
  color: #1E293B;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Header ===== */
header {
  background: linear-gradient(135deg, #1a3a5c 0%, #16213e 100%);
  color: #fff;
  padding: 1rem 2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.header-inner { display: flex; align-items: center; gap: 0.75rem; }
.header-icon  { font-size: 1.6rem; color: #e74c3c; }
.header-title { font-size: 1.3rem; font-weight: 700; letter-spacing: 0.02em; }
.header-sub   { font-size: 0.8rem; color: #aac4e8; margin-left: auto; }

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.75rem;
  color: #888;
  margin-top: auto;
}

/* ===== Main layout ===== */
main {
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  padding: 2rem 1.5rem;
}

section { margin-bottom: 2.5rem; }
h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: #1a3a5c;
  margin-bottom: 0.4rem;
  border-left: 4px solid #e74c3c;
  padding-left: 0.7rem;
}
.hint {
  font-size: 0.85rem;
  color: #555;
  margin-bottom: 1rem;
}

/* ===== Loading overlay ===== */
#loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
#loading-overlay[hidden] { display: none !important; }

/* ===== Error banner ===== */
#error-banner {
  position: sticky; top: 0; z-index: 500;
  background: #ffe0e0;
  border-bottom: 2px solid #e74c3c;
}
.error-inner {
  max-width: 1400px; margin: 0 auto;
  padding: 0.6rem 1.5rem;
  display: flex; align-items: center; gap: 1rem;
}
#error-msg { flex: 1; color: #c0392b; font-size: 0.9rem; }
#error-banner button {
  background: none; border: none;
  font-size: 1.3rem; color: #c0392b; cursor: pointer;
}

/* ===== Drop zone ===== */
#dropzone {
  border: 2px dashed #0d6efd;
  border-radius: 10px;
  padding: 40px;
  text-align: center;
  cursor: pointer;
  background: #ffffff;
  transition: border-color 0.2s, background-color 0.2s;
  user-select: none;
}
#dropzone:hover, #dropzone.drag-over {
  background: #e9ecef;
  border-color: #198754;
}
.dropzone-icon { font-size: 3rem; color: #ccc; margin-bottom: 0.5rem; }
.dropzone-text { font-size: 1.1rem; color: #444; font-weight: 500; }
.dropzone-sub  { font-size: 0.85rem; color: #999; margin-top: 0.3rem; }

/* ===== Caliper toolbar ===== */
.caliper-toolbar {
  display: flex; align-items: center; gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.caliper-status {
  font-size: 0.85rem;
  color: #555;
  background: #eef2ff;
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
}
.caliper-status.active { background: #fff3e0; color: #e67e22; font-weight: 600; }
.caliper-status.done   { background: #e8f5e9; color: #27ae60; font-weight: 600; }
.caliper-hint {
  font-size: 0.82rem;
  background: #fffde7;
  border-left: 3px solid #f9a825;
  padding: 0.5rem 0.9rem;
  border-radius: 4px;
  margin-top: 0.5rem;
  color: #555;
}

/* ===== Canvas wrapper ===== */
#canvas-wrapper {
  width: 100%;
  overflow: auto;
  max-height: 75vh;
  border: 1px solid #dee2e6;
  background: #e9ecef;
  border-radius: 8px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}
#ecg-canvas {
  max-width: none !important;
  display: block;
  margin: 0 auto;
  background: #ffffff;
  cursor: default;
}
#ecg-canvas.caliper-active { cursor: crosshair; }

/* ===== Buttons ===== */
.btn-primary {
  background: #e74c3c; color: #fff;
  border: none; border-radius: 6px;
  padding: 0.55rem 1.3rem;
  font-size: 0.9rem; font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover:not(:disabled) { background: #c0392b; }
.btn-primary:disabled { background: #ccc; cursor: default; }

.btn-secondary {
  background: #fff; color: #444;
  border: 1.5px solid #ccc; border-radius: 6px;
  padding: 0.5rem 1.2rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s;
}
.btn-secondary:hover { border-color: #e74c3c; color: #e74c3c; }

/* ===== Results ===== */
.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
@media (max-width: 900px) {
  .results-grid { grid-template-columns: 1fr; }
}

.card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
  padding: 1.25rem;
}
.card-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #1a3a5c;
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Signal plot fill */
#signal-plot { min-height: 300px; }

/* ===== Measurements table ===== */
.measurements {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.measurements th {
  background: #1a3a5c;
  color: #fff;
  padding: 5px 4px;
  text-align: center;
  font-weight: 600;
}
.measurements td {
  padding: 5px 4px;
  border-bottom: 1px solid #dee2e6;
}
.measurements .value-cell {
  font-family: 'Courier New', monospace;
  font-size: 1.05rem;
  font-weight: 700;
}
.measurements tr.normal  { background: #f0fff4; }
.measurements tr.abnormal { background: #fff5f5; }
.measurements tr.missing  { color: #aaa; }
.badge-ok  { color: #27ae60; font-weight: 700; }
.badge-bad { color: #e74c3c; font-weight: 700; }
.beats-note { font-size: 0.8rem; color: #888; margin-bottom: 0.6rem; }

/* ===== Peak marking toolbar ===== */
#marking-toolbar {
  background: #f7f8ff;
  border: 1.5px solid #d4d8f0;
  border-radius: 8px;
  padding: 0.85rem 1rem 0.75rem;
  margin-top: 0.75rem;
}
.mtb-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #666;
  margin-bottom: 0.65rem;
}
.mtb-grid {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: 0.45rem 0.75rem;
  align-items: center;
}
.mtb-group-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #444;
  text-align: right;
  padding-right: 0.5rem;
  border-right: 2px solid #ddd;
}
.mtb-group-btns {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
}
.mtb-actions { gap: 0.5rem; }

/* Mark buttons — color driven by CSS var --mc set inline */
.mbtn {
  background: var(--mc);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 0.28rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.12s, box-shadow 0.12s;
}
.mbtn:hover { opacity: 1; }
.mbtn.btn-marking-active {
  opacity: 1;
  box-shadow: 0 0 0 3px rgba(0,0,0,0.22), 0 0 0 5px rgba(255,255,255,0.6);
}

/* Undo button (tiny) */
.mbtn-undo {
  background: none;
  border: 1px solid #ccc;
  border-radius: 3px;
  padding: 0.2rem 0.35rem;
  font-size: 0.75rem;
  cursor: pointer;
  color: #777;
  line-height: 1;
}
.mbtn-undo:hover { border-color: #888; color: #333; }

/* Count badge */
.mbadge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.4rem;
  height: 1.4rem;
  border-radius: 3px;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0 0.3rem;
  background: color-mix(in srgb, var(--mc) 18%, white);
  color: color-mix(in srgb, var(--mc) 85%, black 30%);
  margin-right: 0.5rem;
}

/* Source badges in measurements table */
.source-badge {
  display: inline-block;
  font-size: 0.78rem; font-weight: 600;
  border-radius: 4px; padding: 0.15rem 0.5rem;
  margin-bottom: 0.4rem;
}
.source-manual { background: #e8f8e8; color: #1a7f37; }
.source-auto   { background: #eef2ff; color: #3a5bc7; }

/* ===== Warnings ===== */
.warnings-box {
  background: #fff8e1;
  border-left: 4px solid #ffc107;
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin-top: 1rem;
  font-size: 0.85rem;
  color: #555;
}
.warnings-box ul { margin: 0.3rem 0 0 1.2rem; }

/* ===== Review panel corner handles ===== */
.rev-handle {
  position: absolute;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border-radius: 50%;
  background: rgba(13, 110, 253, 0.95);
  border: 3px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.5);
  cursor: grab;
  touch-action: none;
  z-index: 5;
}
.rev-handle.dragging { cursor: grabbing; background: #ffc107; }
.rev-handle::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: #fff;
}

/* ===== Title (bigger), supporting text (smaller) ===== */
#app-title {
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 0.5rem;
}
#caliper-status { font-size: 0.85rem; }
#caliper-panel .btn { font-size: 0.82rem; }
#caliper-panel p,
#caliper-panel small { font-size: 0.78rem; }

/* ===== Experimental section ===== */
.exp-arrow { display: inline-block; transition: transform 0.2s ease; }
.exp-arrow.rotated { transform: rotate(180deg); }

/* ===== Compact measurement toolbar buttons ===== */
#marking-toolbar .tool-btn,
#marking-toolbar .btn {
  font-size: 0.78rem;
  padding: 0.28rem 0.6rem;
  line-height: 1.2;
}
#marking-toolbar .btn-group { margin-bottom: 0.35rem !important; }

/* ===== Mobile responsiveness ===== */
@media (max-width: 768px) {
  body { font-size: 0.88rem; }
  .container { padding-left: 0.6rem; padding-right: 0.6rem; }
  h2, h3 { font-size: 1.1rem; }
  #app-title { font-size: 1.7rem; }
  #caliper-panel .btn,
  #caliper-panel small,
  #caliper-panel p { font-size: 0.74rem; }
  #caliper-status { font-size: 0.78rem; }

  /* Wrap toolbars and reflow buttons on narrow screens */
  #image-controls .btn-group,
  #marking-toolbar .btn-group {
    flex-wrap: wrap;
    margin-right: 0 !important;
  }
  #image-controls .btn,
  #marking-toolbar .btn,
  #marking-toolbar .tool-btn {
    font-size: 0.72rem;
    padding: 0.22rem 0.48rem;
  }
  #image-controls .text-muted.fw-bold {
    display: block;
    margin: 0.35rem 0 0.15rem;
  }

  /* Canvas: shrink height, allow horizontal pan */
  #canvas-wrapper { max-height: 60vh; }

  /* Results panel pads tighter */
  #measurements-table { padding: 0.75rem !important; }
  .measurements { font-size: 0.7rem; }
  .measurements th, .measurements td { padding: 3px 2px; }

  /* Dropzone smaller on mobile */
  #dropzone { padding: 22px !important; font-size: 0.9rem; }
}

@media (max-width: 480px) {
  #image-controls .btn,
  #marking-toolbar .btn,
  #marking-toolbar .tool-btn {
    font-size: 0.68rem;
    padding: 0.2rem 0.4rem;
  }
  #canvas-wrapper { max-height: 55vh; }
}

/* ===== Control Panel Card ===== */
.control-panel-card {
  border: 1px solid #e2e8f0 !important;
  border-radius: 12px !important;
  background: #ffffff !important;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03) !important;
}

.tool-btn.active {
  background-color: var(--bs-btn-hover-bg) !important;
  color: white !important;
}

.btn-xs {
  padding: 1px 5px !important;
  font-size: 0.72rem !important;
  line-height: 1.5 !important;
  border-radius: 4px;
}

/* Accordion Custom Styling */
.accordion-item {
  border: 1px solid #e2e8f0;
  border-radius: 8px !important;
  margin-bottom: 0.5rem;
  overflow: hidden;
}

.accordion-button {
  background-color: #f8fafc;
  color: #334155;
  box-shadow: none !important;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.accordion-button:not(.collapsed) {
  background-color: #eff6ff;
  color: #1d4ed8;
}

.accordion-button::after {
  background-size: 0.8rem;
  width: 0.8rem;
  height: 0.8rem;
}

.accordion-body {
  background-color: #ffffff;
}

/* Label styling in manual caliper section */
.style-label {
  font-size: 0.68rem;
  color: #64748b;
  margin-top: 0.4rem;
  margin-bottom: 0.2rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

/* Alert styling inside sidebar */
#caliper-status {
  transition: all 0.25s ease;
  font-size: 0.74rem;
}

/* Align buttons nicely */
.btn-group-sm > .btn {
  font-size: 0.74rem;
  padding: 0.28rem 0.5rem;
}

/* Landmark Phase Badge */
#landmark-phase-badge {
  text-align: left;
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
  white-space: normal;
  display: block;
}

@media (min-width: 768px) {
  .border-start-md {
    border-left: 1px solid #dee2e6 !important;
  }
}

/* ===== Compact Overrides for Controls ===== */

#pwa-header-controls {
  margin-bottom: 0.25rem !important;
}

#image-controls {
  margin-bottom: 0.4rem !important;
}
#image-controls > .toolbar-group {
  padding: 0 !important;
  gap: 5px !important;
}
#image-controls .btn-group {
  margin: 0 !important;
}
#image-controls .btn, #image-controls label {
  font-size: 0.68rem !important;
  padding: 2px 6px !important;
}
#image-controls span {
  font-size: 0.68rem !important;
}

.control-panel-card {
  padding: 0.5rem !important;
}
.control-panel-card .row {
  --bs-gutter-x: 0.5rem !important;
  --bs-gutter-y: 0.5rem !important;
}

#caliper-panel .col-md-4, 
#caliper-panel .col-md-8 {
  padding-left: 0.25rem !important;
  padding-right: 0.25rem !important;
}
#caliper-panel h6 {
  font-size: 0.76rem !important;
  margin-bottom: 0.25rem !important;
}
#caliper-panel .btn {
  font-size: 0.7rem !important;
  padding: 3px 6px !important;
}
#caliper-status {
  font-size: 0.65rem !important;
  padding: 4px 6px !important;
  margin-top: 4px !important;
  line-height: 1.25 !important;
}

.accordion-item {
  margin-bottom: 0.25rem !important;
  border-radius: 6px !important;
}
.accordion-button {
  padding: 6px 10px !important;
  font-size: 0.74rem !important;
}
.accordion-button::after {
  background-size: 0.7rem;
  width: 0.7rem;
  height: 0.7rem;
}
.accordion-body {
  padding: 6px 8px !important;
}

.accordion-body .btn,
.accordion-body .tool-btn {
  font-size: 0.68rem !important;
  padding: 2px 5px !important;
}

.style-label {
  font-size: 0.62rem !important;
  margin-top: 0.2rem !important;
  margin-bottom: 0.1rem !important;
}

.accordion-body span,
.accordion-body .small, 
.accordion-body .text-muted,
.accordion-body .alert {
  font-size: 0.68rem !important;
  padding: 4px 8px !important;
  margin-bottom: 0.25rem !important;
}

/* ================= NEW DESIGN SYSTEM STYLES ================= */

.app-header-dark {
  background: linear-gradient(135deg, #0F172A 0%, #1E293B 100%);
  padding: 0;
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.header-grid-overlay {
  position: absolute;
  inset: 0;
  opacity: 0.04;
  background-image: 
    repeating-linear-gradient(0deg, transparent, transparent 39px, rgba(255,255,255,0.5) 39px, rgba(255,255,255,0.5) 40px), 
    repeating-linear-gradient(90deg, transparent, transparent 39px, rgba(255,255,255,0.5) 39px, rgba(255,255,255,0.5) 40px);
  pointer-events: none;
}
.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  position: relative;
  z-index: 1;
  flex-wrap: wrap;
  gap: 12px;
}
.header-logo-title {
  display: flex;
  align-items: center;
  gap: 12px;
}
.header-logo-box {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, #10B981, #059669);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(16, 185, 129, 0.3);
  color: white;
}
.header-title-text {
  font-size: 16px;
  font-weight: 700;
  color: #FFFFFF;
  letter-spacing: -0.3px;
  line-height: 1.2;
}
.header-subtitle-text {
  font-size: 10px;
  color: rgba(148, 163, 184, 0.7);
  font-weight: 400;
  margin-top: 1px;
}
.header-quick-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.05);
  color: #94A3B8;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.header-action-btn:hover {
  background: rgba(255,255,255,0.1);
  color: #E2E8F0;
  border-color: rgba(255,255,255,0.15);
}
.header-action-btn.btn-success-custom {
  border-color: rgba(16, 185, 129, 0.3);
  background: rgba(16, 185, 129, 0.1);
  color: #10B981;
}
.header-action-btn.btn-success-custom:hover {
  background: rgba(16, 185, 129, 0.2);
  border-color: rgba(16, 185, 129, 0.5);
}
.header-pwa-reload {
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-pwa-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid rgba(16, 185, 129, 0.3);
  background: rgba(16, 185, 129, 0.15);
  color: #10B981;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s;
}
.header-pwa-btn:hover {
  background: rgba(16, 185, 129, 0.25);
  border-color: rgba(16, 185, 129, 0.5);
}
.header-pwa-hint {
  font-size: 11px;
  color: #94A3B8;
  margin-right: 6px;
}
.header-reload-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.06);
  background: transparent;
  color: #64748B;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s;
}
.header-reload-btn:hover {
  color: #94A3B8;
  background: rgba(255,255,255,0.05);
}

.app-toolbar {
  background: #FFFFFF;
  border-bottom: 1px solid #E2E8F0;
  border-radius: 8px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.toolbar-label {
  font-size: 10px;
  font-weight: 600;
  color: #94A3B8;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.toolbar-pill {
  display: flex;
  align-items: center;
  gap: 2px;
  background: #F1F5F9;
  border-radius: 6px;
  padding: 2px;
}
.toolbar-pill-btn {
  padding: 4px 10px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: #64748B;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.toolbar-pill-btn:hover {
  color: #334155;
}
.toolbar-pill-btn.active {
  background: #0F172A;
  color: #FFFFFF;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.toolbar-divider {
  width: 1px;
  height: 20px;
  background: #E2E8F0;
}
.toolbar-level-buttons {
  display: flex;
  align-items: center;
  gap: 2px;
}
.toolbar-level-buttons-fine {
  display: flex;
  align-items: center;
  gap: 2px;
}
.toolbar-rect-btn {
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid #E2E8F0;
  background: #FFFFFF;
  color: #64748B;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.toolbar-rect-btn:hover {
  border-color: #CBD5E1;
  color: #334155;
}
.toolbar-rect-btn.font-mono {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  padding: 4px 6px;
}

.main-control-grid {
  display: grid;
  /* minmax(0, ...) lets the column shrink below its widest child (tab row scrolls instead) */
  grid-template-columns: 220px minmax(0, 1fr);
  background: #FFFFFF;
}
@media (max-width: 768px) {
  .main-control-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}
.calibration-column {
  border-right: 1px solid #E2E8F0;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #F8FAFC;
}
@media (max-width: 768px) {
  .calibration-column {
    border-right: none;
    border-bottom: 1px solid #E2E8F0;
  }
}
.measurement-column {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pulse-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10B981;
  animation: pulseGlow 2s ease-in-out infinite;
}
.indigo-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #6366F1;
}
.step-label {
  font-size: 10px;
  font-weight: 600;
  color: #94A3B8;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.step-label.text-indigo {
  color: #4F46E5;
}
.calibration-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
  width: 100%;
}
.calibration-btn.btn-x {
  border: 1px solid rgba(220, 38, 38, 0.2);
  background: rgba(220, 38, 38, 0.05);
  color: #0F172A;
}
.calibration-btn.btn-x:hover {
  border-color: rgba(220, 38, 38, 0.4);
  background: rgba(220, 38, 38, 0.1);
}
.calibration-btn.btn-x-outline {
  border: 1px solid #E2E8F0;
  background: #FFFFFF;
  color: #0F172A;
}
.calibration-btn.btn-x-outline:hover {
  border-color: #CBD5E1;
  background: #F8FAFC;
}
.calibration-btn.btn-y {
  border: 1px solid #E2E8F0;
  background: #FFFFFF;
  color: #0F172A;
}
.calibration-btn.btn-y:hover {
  border-color: #CBD5E1;
  background: #F8FAFC;
}
.calibration-btn.is-active {
  border-color: #2563EB;
  background: #EFF6FF;
  color: #1D4ED8;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}
.calibration-btn.is-active .btn-icon-box {
  background: #2563EB;
}
.calibration-btn.is-active .btn-icon-box svg {
  stroke: #FFFFFF;
}
.calibration-btn.btn-x.is-active,
.calibration-btn.btn-x-outline.is-active {
  border-color: #EF4444;
  background: #FEF2F2;
  color: #B91C1C;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.12);
}
.calibration-btn.btn-x.is-active .btn-icon-box,
.calibration-btn.btn-x-outline.is-active .btn-icon-box {
  background: #EF4444;
}
.calibration-btn.btn-y.is-active {
  border-color: #0EA5E9;
  background: #F0F9FF;
  color: #0369A1;
  box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.14);
}
.calibration-btn.btn-y.is-active .btn-icon-box {
  background: #0EA5E9;
}
.btn-icon-box {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  background: #EF4444;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.btn-icon-box.bg-slate-light {
  background: #F1F5F9;
}
.calibration-status-box {
  font-size: 10px;
  color: #94A3B8;
  line-height: 1.4;
  background: #F1F5F9;
  border-radius: 6px;
  padding: 6px 10px;
}

/* Active Path Card */
.active-path-card {
  border-radius: 8px;
  border: 1px solid rgba(99, 102, 241, 0.2);
  background: rgba(99, 102, 241, 0.02);
  padding: 10px 12px;
}
.active-path-header-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.path-icon-box {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.bg-indigo-gradient {
  background: linear-gradient(135deg, #6366F1, #4F46E5);
}
.bg-slate-dark {
  background: #334155;
}
.bg-red-soft {
  background: rgba(239, 68, 68, 0.1);
}
.bg-rose-soft {
  background: rgba(244, 63, 94, 0.1);
}
.bg-orange-soft {
  background: rgba(249, 115, 22, 0.1);
}
.active-path-info {
  flex: 1;
  min-width: 150px;
}
.active-path-title {
  font-size: 12px;
  font-weight: 600;
  color: #0F172A;
  line-height: 1.3;
}
.active-path-desc {
  font-size: 10px;
  color: #64748B;
  line-height: 1.3;
}
.active-path-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.path-action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid transparent;
}
.btn-danger-soft {
  border-color: rgba(239, 68, 68, 0.2);
  background: rgba(239, 68, 68, 0.05);
  color: #DC2626;
}
.btn-danger-soft:hover {
  background: rgba(239, 68, 68, 0.12);
}
.btn-secondary-soft {
  border-color: #E2E8F0;
  background: #FFFFFF;
  color: #64748B;
}
.btn-secondary-soft:hover {
  border-color: #CBD5E1;
  color: #334155;
}
.btn-indigo-soft {
  border-color: rgba(99, 102, 241, 0.2);
  background: rgba(99, 102, 241, 0.05);
  color: #4F46E5;
}
.btn-indigo-soft:hover {
  background: rgba(99, 102, 241, 0.12);
}
.btn-info-soft {
  border-color: rgba(6, 182, 212, 0.2);
  background: rgba(6, 182, 212, 0.05);
  color: #0891B2;
}
.btn-info-soft:hover {
  background: rgba(6, 182, 212, 0.12);
}
.btn-warning-soft {
  border-color: rgba(217, 119, 6, 0.2);
  background: rgba(217, 119, 6, 0.05);
  color: #D97706;
}
.btn-warning-soft:hover {
  background: rgba(217, 119, 6, 0.12);
}
.btn-primary-soft {
  border-color: rgba(13, 110, 253, 0.2);
  background: rgba(13, 110, 253, 0.05);
  color: #0d6efd;
}
.btn-primary-soft:hover {
  background: rgba(13, 110, 253, 0.12);
}
.btn-danger-solid {
  background: linear-gradient(135deg, #DC2626, #B91C1C);
  color: #FFFFFF;
  box-shadow: 0 1px 3px rgba(220, 38, 38, 0.2);
}
.btn-danger-solid:hover {
  box-shadow: 0 2px 6px rgba(220, 38, 38, 0.35);
}
.btn-dark-solid {
  background: #0F172A;
  color: #FFFFFF;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.btn-dark-solid:hover {
  background: #1E293B;
}

/* Collapsed Cards Grid */
#active-path-container {
  order: 2;
}
.collapsed-paths-grid {
  order: 1;
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 6px;
  margin-top: 0 !important;
  margin-bottom: 8px;
  overflow-x: auto;
}
.collapsed-path-card {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #F1F5F9;
  background: #FAFBFC;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.collapsed-path-card:hover {
  border-color: #E2E8F0;
  background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}
.collapsed-path-card.active {
  border-color: rgba(99, 102, 241, 0.35);
  background: rgba(99, 102, 241, 0.08);
  box-shadow: inset 0 -2px 0 #6366F1;
}
.collapsed-path-card.active .collapsed-path-title {
  color: #3730A3;
  font-weight: 700;
}
.collapsed-path-card.active .collapsed-arrow {
  display: none;
}
.collapsed-icon-box {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.collapsed-path-title {
  font-size: 11px;
  font-weight: 500;
  color: #475569;
}
.collapsed-arrow {
  display: none;
}
@media (max-width: 1200px) {
  .collapsed-paths-grid {
    grid-template-columns: repeat(6, minmax(140px, 1fr));
  }
}

/* Manual Calipers specific styles */
.manual-caliper-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
  border-top: 1px solid #F1F5F9;
  padding-top: 6px;
}
.tool-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.tool-row-label {
  font-size: 9px;
  font-weight: 700;
  color: #94A3B8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  width: 75px;
  flex-shrink: 0;
}
.tool-btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}
.tool-btn-group .tool-btn {
  font-size: 10px !important;
  padding: 2px 6px !important;
  border-radius: 4px;
}

/* Canvas styling */
.ecg-canvas-container {
  position: relative;
  width: 100%;
  overflow: auto;
  max-height: 75vh;
  border: 1px solid #dee2e6;
  background: #ffffff;
}
.canvas-grid-bg {
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image: 
    repeating-linear-gradient(0deg, transparent, transparent 19px, #FECACA 19px, #FECACA 20px), 
    repeating-linear-gradient(90deg, transparent, transparent 19px, #FECACA 19px, #FECACA 20px);
  pointer-events: none;
  z-index: 0;
}

/* ================================================================
   Paket 1 features: grid calibration card, QTc panel, resume card,
   March button state, toast
   ================================================================ */
.grid-calib-card {
  margin-top: 0.4rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid #c7d2fe;
  background: #eef2ff;
  border-radius: 8px;
  font-size: 0.78rem;
  color: #1e293b;
}
.grid-calib-msg { line-height: 1.35; }
.grid-calib-row { display: flex; flex-wrap: wrap; gap: 0.4rem 0.6rem; margin: 0.3rem 0; }
.grid-calib-row label { display: flex; align-items: center; gap: 0.3rem; font-weight: 600; color: #475569; }
.grid-calib-row select {
  font-size: 0.76rem; padding: 0.1rem 0.3rem; border: 1px solid #cbd5e1; border-radius: 6px; background: #fff;
}
.grid-calib-actions { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.grid-calib-actions .path-action-btn { padding: 0.15rem 0.5rem; }

#btn-march.active { background: #0f766e; color: #fff; border-color: #0f766e; }

.qtc-panel {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}
.qtc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.75rem; flex-wrap: wrap; }
.qtc-head-label { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: #64748b; }
.qtc-head-value { font-size: 2rem; font-weight: 800; line-height: 1.1; color: #0f172a; }
.qtc-head-value small { font-size: 0.9rem; font-weight: 600; color: #64748b; }
.qtc-head-value.qtc-prolonged { color: #b45309; }
.qtc-head-value.qtc-high { color: #b91c1c; }
.qtc-head-why { font-size: 0.75rem; color: #475569; }
.qtc-controls { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.qtc-sex { display: inline-flex; border: 1px solid #cbd5e1; border-radius: 6px; overflow: hidden; }
.qtc-sex button { border: 0; background: #fff; font-size: 0.74rem; padding: 0.2rem 0.6rem; color: #334155; }
.qtc-sex button.active { background: #1e293b; color: #fff; }
.qtc-auto-btn { border: 1px solid #cbd5e1; background: #fff; border-radius: 6px; font-size: 0.74rem; padding: 0.2rem 0.6rem; }
.qtc-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.qtc-chip {
  display: inline-flex; flex-direction: column; align-items: flex-start;
  min-width: 92px; padding: 0.3rem 0.55rem;
  border: 1px solid #e2e8f0; border-radius: 8px; background: #f8fafc; cursor: pointer;
}
.qtc-chip:hover { border-color: #94a3b8; }
.qtc-chip.is-headline { border-color: #1e293b; box-shadow: inset 0 0 0 1px #1e293b; background: #fff; }
.qtc-chip-name { font-size: 0.68rem; color: #64748b; font-weight: 600; }
.qtc-chip-val { font-size: 1rem; font-weight: 800; color: #0f172a; }
.qtc-chip.qtc-prolonged .qtc-chip-val { color: #b45309; }
.qtc-chip.qtc-high .qtc-chip-val { color: #b91c1c; }
.qtc-note { margin-top: 0.5rem; font-size: 0.7rem; color: #64748b; }

.resume-card {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap;
  padding: 0.7rem 0.9rem; border: 1px solid #bfdbfe; background: #eff6ff; border-radius: 10px;
}
.resume-text { font-size: 0.85rem; color: #1e3a8a; }
.resume-actions { display: flex; gap: 0.4rem; }

.ecg-toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  display: flex; align-items: center; gap: 0.75rem;
  background: #0f172a; color: #f8fafc; font-size: 0.85rem;
  padding: 0.55rem 0.9rem; border-radius: 10px; z-index: 2000;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.25);
}
.ecg-toast.is-warn { background: #7c2d12; }
.ecg-toast button { border: 0; background: transparent; color: #93c5fd; font-weight: 700; }
.ecg-toast[hidden] { display: none; }

/* ================================================================
   Paket 2: annotate bar, full-screen stage, fine-tune pad
   ================================================================ */
.canvas-stage { position: relative; display: flex; flex-direction: column; gap: 6px; }
.anno-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding: 6px; background: #fff; border: 1px solid #e2e8f0; border-radius: 10px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}
.anno-group { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.anno-group[hidden] { display: none; }
.anno-group-right { margin-left: auto; }
.anno-btn {
  display: inline-flex; align-items: center; gap: 5px;
  min-height: 34px; padding: 4px 10px;
  border: 1px solid #e2e8f0; border-radius: 8px; background: #f8fafc;
  color: #334155; font-size: 0.8rem; font-weight: 600; line-height: 1;
}
.anno-btn:hover:not(:disabled) { border-color: #94a3b8; background: #fff; }
.anno-btn.active { background: #0f172a; border-color: #0f172a; color: #fff; }
.anno-btn:disabled { opacity: 0.4; cursor: default; }
.anno-btn-sm { min-height: 30px; padding: 3px 8px; font-size: 0.75rem; }
.anno-btn-redact.active { background: #000; }
@media (max-width: 576px) {
  .anno-btn span { display: none; }   /* icons only on phones */
  .anno-btn { padding: 4px 8px; }
}

.finetune-pad {
  position: absolute; right: 10px; bottom: 10px; z-index: 20;
  display: grid; grid-template-columns: repeat(3, 44px); grid-auto-rows: 44px; gap: 4px;
  padding: 6px; background: rgba(15, 23, 42, 0.86); border-radius: 12px;
  touch-action: none; user-select: none;
}
.finetune-pad[hidden] { display: none; }
.finetune-pad button {
  border: 0; border-radius: 8px; background: rgba(255, 255, 255, 0.14);
  color: #fff; font-size: 1rem; font-weight: 700;
}
.finetune-pad button:active { background: rgba(255, 255, 255, 0.32); }
.finetune-pad .finetune-fine.active { background: #0ea5e9; }
.finetune-pad .finetune-delete { background: rgba(220, 38, 38, 0.75); }

/* Full screen: the stage covers the viewport, the bar stays on top. */
body.ecg-fs-open { overflow: hidden; }
.canvas-stage.is-fullscreen {
  position: fixed; inset: 0; z-index: 1500;
  padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right))
           max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  background: #0f172a;
}
.canvas-stage.is-fullscreen #canvas-wrapper { flex: 1; max-height: none; min-height: 0; }
.canvas-stage.is-fullscreen .anno-bar { flex: none; }
@media (orientation: landscape) and (max-height: 500px) {
  /* Phone sideways: bar as a column on the right so the tracing gets the height. */
  .canvas-stage.is-fullscreen { flex-direction: row-reverse; }
  .canvas-stage.is-fullscreen .anno-bar { flex-direction: column; flex-wrap: nowrap; overflow-y: auto; width: 56px; }
  .canvas-stage.is-fullscreen .anno-group { flex-direction: column; }
  .canvas-stage.is-fullscreen .anno-group-right { margin-left: 0; margin-top: auto; }
  .canvas-stage.is-fullscreen .anno-btn span { display: none; }
}

/* Phones: let the filter / zoom / level pills wrap instead of widening the page. */
@media (max-width: 576px) {
  .app-toolbar { padding: 8px 10px; gap: 8px; }
  .toolbar-group { min-width: 0; flex-wrap: wrap; }
  .toolbar-pill { flex-wrap: wrap; min-width: 0; }
}

/* ================================================================
   Compact top bars: header, filter/zoom/level toolbar, annotate bar.
   One slim row each on desktop; touch screens keep larger targets.
   ================================================================ */
.header-content { padding: 6px 16px; gap: 8px; }
.header-logo-title { gap: 8px; }
.header-logo-box { width: 28px; height: 28px; border-radius: 6px; box-shadow: none; }
.header-logo-box svg { width: 17px; height: 17px; }
.header-title-text { font-size: 14px; }
.header-subtitle-text { font-size: 9.5px; margin-top: 0; }
.header-quick-actions { gap: 4px; }
.header-action-btn,
.header-pwa-btn,
.header-reload-btn { padding: 4px 9px; gap: 5px; font-size: 11.5px; line-height: 1.2; }

#image-controls.app-toolbar { margin-bottom: 6px !important; }
.app-toolbar { padding: 4px 10px; gap: 10px; border-radius: 8px; }
.toolbar-group { gap: 5px; }
.toolbar-pill { padding: 2px; }
.toolbar-pill-btn { padding: 3px 8px; line-height: 1.2; }
.app-toolbar > .toolbar-divider { flex: 0 0 1px; width: 1px; min-width: 0; padding: 0; height: 18px; background: #E2E8F0; }

.canvas-stage { gap: 4px; }
.anno-bar { padding: 3px; gap: 4px; border-radius: 8px; }
.anno-group { gap: 2px; }
.anno-btn { min-height: 28px; padding: 3px 9px; border-radius: 6px; font-size: 0.76rem; }
.anno-btn-sm { min-height: 26px; padding: 2px 7px; }

@media (pointer: coarse) {
  .header-action-btn,
  .header-pwa-btn,
  .header-reload-btn { padding: 7px 11px; }
  .toolbar-pill-btn { padding: 6px 10px; }
  .anno-btn { min-height: 36px; }
  .anno-btn-sm { min-height: 32px; }
}

/* ================================================================
   Compact calibration column: one-line header, 2x2 buttons, slim
   grid card. Keeps Step 1 no taller than the measurement column.
   ================================================================ */
.calibration-column { padding: 8px 10px; gap: 6px; }
.calibration-column > .d-flex:first-child { margin-bottom: 0 !important; gap: 6px; }
.calibration-column .step-label { white-space: nowrap; }
#caliper-panel #btn-lock-caliper {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 1px 6px !important; font-size: 10px; line-height: 1.4; white-space: nowrap;
}
#caliper-panel #btn-lock-caliper .small { font-size: 10px; }
#btn-lock-caliper i { margin: 0 !important; }

.calibration-btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.calibration-btn-grid .calibration-btn { gap: 5px; padding: 3px 6px; min-height: 26px; white-space: nowrap; }
.calibration-btn-grid .btn-icon-box { width: 16px; height: 16px; }

.grid-calib-card { margin-top: 0; padding: 6px 8px; font-size: 11px; }
.grid-calib-msg { line-height: 1.3; }
.grid-calib-row { margin: 4px 0; gap: 4px 8px; flex-wrap: nowrap; }
.grid-calib-row label { font-size: 10.5px; gap: 3px; }
.grid-calib-row select { font-size: 10.5px; padding: 0 2px; max-width: 78px; }
.grid-calib-actions { flex-wrap: nowrap; }
.grid-calib-actions .path-action-btn { font-size: 10.5px; padding: 2px 6px; white-space: nowrap; }

/* While the grid card is open its text repeats the status line. */
#grid-calib-card:not([hidden]) + #caliper-status { display: none; }
#caliper-status { padding: 4px 8px; }

@media (pointer: coarse) {
  .calibration-btn-grid .calibration-btn { min-height: 36px; }
  .grid-calib-actions .path-action-btn { padding: 6px 10px; }
}
.grid-calib-row label { flex: 1 1 0; min-width: 0; }
.grid-calib-row select { width: 100%; max-width: none; }
.grid-calib-lbl {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
