/* ==========================================================================
   LightWeight Physics Tracker – stijlen
   ========================================================================== */

:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --border: #e1e5ee;
  --text: #172033;
  --muted: #5d6b82;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #e6eefe;
  --danger: #dc2626;
  --warn-bg: #fff4e0;
  --warn-text: #8a5300;
  --ok-bg: #e3f6ec;
  --ok-text: #126b3c;
  --stage-bg: #0d111a;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --radius-sm: 7px;
  --row-active: #fff1c2;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f131b;
    --surface: #171c27;
    --surface-2: #1d2331;
    --border: #2a3242;
    --text: #e6e9f0;
    --muted: #97a2b6;
    --primary: #4f86f7;
    --primary-hover: #6b9bff;
    --primary-soft: #1d2a48;
    --danger: #f05252;
    --warn-bg: #3a2c12;
    --warn-text: #f5c26b;
    --ok-bg: #123122;
    --ok-text: #74d6a0;
    --stage-bg: #05070b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --row-active: #3b3416;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

h1, h2 { margin: 0; font-weight: 650; }
h1 { font-size: 16px; letter-spacing: -.01em; }
h2 { font-size: 14px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

.icon {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Knoppen & velden ---------- */

.btn, .tool, .icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
  user-select: none;
}
.btn:hover:not(:disabled), .tool:hover:not(:disabled), .icon-btn:hover:not(:disabled) { background: var(--surface-2); border-color: #c8cfdc; }
.btn:focus-visible, .tool:focus-visible, .icon-btn:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
.btn:disabled, .tool:disabled, .icon-btn:disabled { opacity: .45; cursor: not-allowed; }

.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small, .icon-btn.small { min-height: 32px; padding: 0 10px; font-size: 13px; }
.icon-btn { padding: 0; width: 38px; }
.icon-btn.small { width: 32px; padding: 0; }

.link-btn {
  background: none; border: 0; padding: 0 0 0 6px; color: var(--primary);
  font: inherit; font-size: 12px; cursor: pointer; text-decoration: underline;
}

.field { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.field input[type="number"], .field input[type="text"], select {
  height: 34px; padding: 0 8px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit;
}
.field input[type="number"] { width: 72px; }
.field .unit { color: var(--muted); }
.field.stacked { display: flex; flex-direction: column; align-items: stretch; gap: 4px; }
.field.stacked > span { display: flex; justify-content: space-between; }
.field.stacked output { color: var(--text); font-variant-numeric: tabular-nums; }
.field.big input { height: 44px; font-size: 20px; width: 160px; }
.field.big .unit { font-size: 18px; }

.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }

input[type="range"] { accent-color: var(--primary); width: 100%; }

/* ---------- Topbalk ---------- */

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 8px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo { width: 32px; height: 32px; flex: none; }
.brand-logo rect { fill: var(--primary); }
.brand-logo circle { fill: #fff; }
.brand p { margin: 0; font-size: 12px; max-width: 40ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.field-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- Layout ---------- */

.layout {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 12px;
  padding: 12px;
}

.workspace {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}

/* ---------- Toolbar ---------- */

.toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.tool[aria-pressed="true"] {
  background: var(--primary-soft); border-color: var(--primary); color: var(--primary);
}
.hint {
  margin: 0 0 0 auto; padding-left: 8px;
  color: var(--muted); font-size: 13px; text-align: right;
  flex: 1 1 220px;
}
.hint strong { color: var(--text); }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; padding: 0 6px; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  position: relative; width: 34px; height: 20px; border-radius: 999px;
  background: var(--border); transition: background .15s;
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s;
}
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(14px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--primary); outline-offset: 2px; }
.switch input:disabled ~ * { opacity: .45; cursor: not-allowed; }
.switch-label { display: inline-flex; align-items: center; gap: 5px; font-weight: 550; }

/* ---------- Stage ---------- */

.stage {
  position: relative; flex: 1; min-height: 200px;
  background: var(--stage-bg);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.frame-wrap { position: relative; flex: none; }
.frame-wrap video, .frame-wrap canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
}
.frame-wrap canvas { touch-action: none; }
.frame-wrap canvas.tool-active { cursor: crosshair; }
.frame-wrap canvas.tool-active.loupe-on { cursor: none; }
.frame-wrap canvas.dragging { cursor: grabbing; }
.frame-wrap canvas.can-drag { cursor: grab; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  padding: 36px 40px; margin: 24px;
  border: 2px dashed #3a4459; border-radius: 16px;
  color: #c9d1e0; cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .stage.drag-over .dropzone { border-color: var(--primary); background: rgba(79, 134, 247, .08); }
.dropzone strong { font-size: 16px; color: #fff; }
.dropzone .muted { color: #8792a8; }
.dropzone-icon { width: 44px; height: 44px; fill: none; stroke: #8fb1ff; stroke-width: 1.6; stroke-linejoin: round; margin-bottom: 4px; }
.stage.drag-over .frame-wrap { opacity: .4; }

.auto-banner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  padding: 6px 6px 6px 14px; border-radius: 999px;
  background: rgba(15, 19, 27, .88); color: #fff; font-weight: 550;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .35);
}
.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.3); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Transport ---------- */

.transport { padding: 8px 10px 10px; border-top: 1px solid var(--border); }
.transport-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: space-between; }
.btn-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.readout {
  display: flex; gap: 16px; font-variant-numeric: tabular-nums; color: var(--muted);
  margin-right: auto; padding-left: 6px;
}
.readout strong { color: var(--text); font-weight: 650; }
#playBtn .icon-pause { display: none; }
#playBtn.playing .icon-play { display: none; }
#playBtn.playing .icon-pause { display: block; }

.timeline { position: relative; height: 28px; margin-top: 8px; }
.timeline canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.timeline input[type="range"] {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0;
  -webkit-appearance: none; appearance: none; background: transparent; cursor: pointer;
}
.timeline input[type="range"]:disabled { cursor: default; }
.timeline input[type="range"]::-webkit-slider-runnable-track { height: 100%; background: transparent; }
.timeline input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 28px; border-radius: 4px;
  background: var(--primary); border: 2px solid var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.35);
}
.timeline input[type="range"]::-moz-range-track { height: 100%; background: transparent; }
.timeline input[type="range"]::-moz-range-thumb {
  width: 10px; height: 24px; border-radius: 4px;
  background: var(--primary); border: 2px solid var(--surface);
}
.timeline input[type="range"]:disabled::-webkit-slider-thumb { background: var(--border); }

/* ---------- Zijpaneel ---------- */

.sidebar { display: flex; flex-direction: column; gap: 12px; min-height: 0; overflow-y: auto; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 14px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.count {
  display: inline-block; min-width: 22px; padding: 1px 7px; margin-left: 4px;
  border-radius: 999px; background: var(--primary-soft); color: var(--primary);
  font-size: 12px; text-align: center; font-variant-numeric: tabular-nums;
}

.setup-card h2 { margin-bottom: 8px; }
.status-list { margin: 0; display: grid; gap: 6px; }
.status-list > div { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.status-list dt { color: var(--muted); }
.status-list dd { margin: 0; text-align: right; }
.angle-field { display: flex; align-items: center; gap: 4px; }
.angle-field .link-btn { padding: 0 6px 0 0; }
.angle-field input {
  width: 64px; height: 26px; padding: 0 6px; text-align: right;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 12px; font-variant-numeric: tabular-nums;
}
.angle-field input:disabled { opacity: .5; }
.angle-field .unit { color: var(--muted); font-size: 12px; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12px; font-variant-numeric: tabular-nums;
}
.badge.warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.badge.ok { background: var(--ok-bg); color: var(--ok-text); border-color: transparent; }

.table-card { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 260px; }
.table-wrap {
  position: relative; flex: 1; min-height: 120px; overflow: auto;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.data-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 13px; }
.data-table th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: 12px;
  text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--border);
}
.data-table td { text-align: right; padding: 4px 8px; border-bottom: 1px solid var(--border); }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tbody tr.current { background: var(--row-active); }
.data-table .col-frame { color: var(--muted); width: 40px; }
.data-table td.col-frame { font-size: 12px; }
.data-table .col-del { width: 30px; padding: 0 4px; text-align: center; }
.data-table tr.out-of-range td { color: var(--muted); opacity: .55; }
.data-table tr.auto td.col-frame::after { content: "•"; color: var(--primary); margin-left: 2px; }
.del-btn {
  width: 24px; height: 24px; border: 0; border-radius: 5px; background: transparent;
  color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; opacity: 0;
}
.data-table tr:hover .del-btn, .del-btn:focus-visible { opacity: 1; }
.del-btn:hover { background: var(--border); color: var(--danger); }
.empty { position: absolute; inset: 40px 12px auto; text-align: center; color: var(--muted); margin: 0; }

.export-row { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 10px; }
.export-row .btn { width: 100%; }

.settings-card { padding: 0; }
.settings-card summary {
  list-style: none; cursor: pointer; padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between;
}
.settings-card summary::-webkit-details-marker { display: none; }
.settings-card > summary::after { content: "▾"; color: var(--muted); transition: transform .15s; }
.settings-card[open] > summary::after { transform: rotate(180deg); }
.settings-grid { display: grid; gap: 12px; padding: 0 14px 14px; }
.settings-grid select { width: 100%; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; margin: 0; display: grid; gap: 10px; }
legend { padding: 0 4px; font-weight: 600; font-size: 13px; }
fieldset p { margin: 0; }
.shortcuts summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.shortcuts ul { margin: 8px 0 0; padding-left: 18px; display: grid; gap: 4px; font-size: 13px; }
kbd {
  display: inline-block; min-width: 20px; padding: 0 5px; text-align: center;
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px;
  background: var(--surface-2); font: 12px/18px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- Dialoog & melding ---------- */

.dialog {
  border: 0; border-radius: 14px; padding: 20px 22px; width: min(380px, calc(100vw - 32px));
  background: var(--surface); color: var(--text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
.dialog::backdrop { background: rgba(10, 14, 22, .45); }
.dialog h2 { font-size: 17px; }
.dialog p { margin: 6px 0 14px; }
.dialog-actions { display: flex; flex-direction: row-reverse; justify-content: flex-start; gap: 8px; margin-top: 18px; }
.error { color: var(--danger); font-size: 13px; margin: 8px 0 0 !important; }

.toast {
  position: fixed; right: 20px; bottom: 20px;
  max-width: min(400px, calc(100vw - 32px));
  padding: 10px 16px; border-radius: 10px;
  background: #172033; color: #fff; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); z-index: 100;
  animation: toast-in .18s ease-out;
}
.toast.success { background: #126b3c; }
.toast.error { background: #b42318; }
.toast.warn { background: #8a5300; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Kleinere schermen ---------- */

@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(0, 1fr) 310px; }
  .btn-row .btn.small { padding: 0 8px; }
}

@media (max-width: 860px) {
  body { overflow: auto; }
  .layout { grid-template-columns: 1fr; padding: 8px; gap: 8px; }
  .workspace { min-height: 70vh; }
  .sidebar { overflow: visible; }
  .hint { text-align: left; margin-left: 0; padding-left: 0; flex-basis: 100%; }
  .topbar { padding: 8px; }
  .toast { right: 16px; left: 16px; bottom: 16px; max-width: none; }
}
