/* Lineal & Mass – Stahlblau-Mess-Look */
:root {
  --steel-900: #082f49;
  --steel-800: #0c4a6e;
  --steel-700: #075985;
  --steel-600: #0369a1;   /* Primärfarbe */
  --steel-500: #0284c7;
  --steel-400: #38bdf8;
  --steel-100: #e0f2fe;
  --steel-50:  #f0f9ff;

  --bg: #f4f7fa;
  --surface: #ffffff;
  --surface-2: #eef4f8;
  --text: #0b2233;
  --text-soft: #4a657a;
  --border: #cfe0ec;
  --line: #d7e3ec;
  --accent: var(--steel-600);
  --accent-strong: var(--steel-700);
  --danger: #b91c1c;
  --ruler-bg: #ffffff;
  --ruler-tick: #1b3a4d;
  --ruler-tick-soft: #6b8499;
  --marker: #0369a1;
  --marker-zero: #5c768a;
  --shadow: 0 6px 22px rgba(8, 47, 73, 0.10);
  --radius: 14px;
  --radius-sm: 9px;
  --focus: #f59e0b;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #061521;
  --surface: #0d2433;
  --surface-2: #0a1c29;
  --text: #e6f1f8;
  --text-soft: #9bb6c8;
  --border: #1c3a4d;
  --line: #173040;
  --accent: var(--steel-400);
  --accent-strong: var(--steel-400);
  --danger: #f87171;
  --ruler-bg: #0d2433;
  --ruler-tick: #cfe6f3;
  --ruler-tick-soft: #5f7e92;
  --marker: #38bdf8;
  --marker-zero: #7e98ab;
  --shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
  --focus: #fbbf24;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Fokus */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  z-index: 200;
  border-radius: 0 0 8px 0;
}
.skip-link:focus {
  left: 0;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(135deg, var(--steel-700), var(--steel-600));
  color: #fff;
  box-shadow: var(--shadow);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand-mark {
  display: inline-flex;
  color: #fff;
}
.brand-name {
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 1.05rem;
  white-space: nowrap;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Buttons */
.btn {
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  padding: 10px 16px;
  transition: transform .08s ease, background .15s ease, color .15s ease, border-color .15s ease;
  line-height: 1.2;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-strong); }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-ghost:hover { background: var(--surface-2); }

.app-header .btn-ghost {
  border-color: rgba(255,255,255,.55);
  color: #fff;
}
.app-header .btn-ghost:hover { background: rgba(255,255,255,.15); }

.btn-icon {
  background: rgba(255,255,255,.14);
  color: #fff;
  border: 1px solid rgba(255,255,255,.4);
  width: 42px;
  height: 42px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
}
.btn-icon:hover { background: rgba(255,255,255,.26); }

.modal .btn-icon {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

/* Main / Cards */
.app-main {
  max-width: 820px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card-title {
  margin: 0 0 8px;
  font-size: 1.2rem;
  color: var(--accent-strong);
}
[data-theme="dark"] .card-title { color: var(--steel-400); }

h1.card-title { font-size: 1.35rem; }

.lead {
  margin: 0 0 14px;
  color: var(--text-soft);
}
.lead strong { color: var(--text); }

.status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-bottom: 14px;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-soft);
  border: 1px solid var(--border);
}
.status-pill.is-ok {
  background: var(--steel-100);
  color: var(--steel-700);
  border-color: var(--steel-400);
}
[data-theme="dark"] .status-pill.is-ok {
  background: rgba(56,189,248,.14);
  color: var(--steel-400);
}
.status-detail {
  font-family: var(--mono);
  color: var(--text-soft);
  font-size: .9rem;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.hint {
  margin: 8px 0 0;
  font-size: .88rem;
  color: var(--text-soft);
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  padding: 10px 12px;
}
.hint-inline {
  background: none;
  border-left: none;
  padding: 0;
  margin-top: 10px;
}

/* Messen */
.measure-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.unit-switch {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}
.unit-btn {
  font: inherit;
  font-weight: 700;
  border: none;
  background: transparent;
  color: var(--text-soft);
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.unit-btn.is-active {
  background: var(--accent);
  color: #fff;
}

.readout {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
}
.readout-label {
  font-size: .78rem;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.readout-value {
  font-family: var(--mono);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent-strong);
  line-height: 1.1;
}
[data-theme="dark"] .readout-value { color: var(--steel-400); }

/* Lineal */
.card-ruler { padding: 14px; }

.ruler-wrap {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--ruler-bg);
}
.ruler-canvas {
  position: relative;
  height: 170px;
  min-width: 100%;
  touch-action: pan-x;
  user-select: none;
}
.ruler-canvas canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Marker */
.marker {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0;
  cursor: ew-resize;
  z-index: 4;
}
.marker-zero { z-index: 3; }

.marker-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 2px;
  transform: translateX(-1px);
  background: var(--marker);
}
.marker-zero .marker-line {
  background: var(--marker-zero);
  width: 2px;
  background-image: repeating-linear-gradient(
    to bottom, var(--marker-zero) 0 6px, transparent 6px 11px);
}

.marker-handle {
  position: absolute;
  top: 8px;
  left: 0;
  transform: translateX(-50%);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--marker);
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(8,47,73,.35);
  display: flex;
  align-items: center;
  justify-content: center;
}
.marker-handle-zero { background: var(--marker-zero); }
[data-theme="dark"] .marker-handle { border-color: #0d2433; }

.marker-grip {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: rgba(255,255,255,.85);
}

.marker-badge {
  position: absolute;
  bottom: 8px;
  left: 0;
  transform: translateX(-50%);
  background: var(--marker);
  color: #fff;
  font-family: var(--mono);
  font-weight: 700;
  font-size: .8rem;
  padding: 3px 8px;
  border-radius: 6px;
  white-space: nowrap;
}
.marker-badge-zero { background: var(--marker-zero); }

.ruler-help {
  margin: 10px 2px 2px;
  font-size: .85rem;
  color: var(--text-soft);
}

/* Footer */
.app-footer {
  text-align: center;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  color: var(--text-soft);
  font-size: .82rem;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 21, 33, .55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 18px 50px rgba(8,47,73,.35);
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: linear-gradient(135deg, var(--steel-700), var(--steel-600));
  color: #fff;
}
.modal-head h2 { margin: 0; font-size: 1.15rem; }
.modal-head .btn-icon {
  background: rgba(255,255,255,.16);
  color: #fff;
  border-color: rgba(255,255,255,.4);
  width: 36px;
  height: 36px;
}
.modal-body {
  padding: 18px;
  overflow-y: auto;
}
.modal-desc {
  margin: 0 0 16px;
  color: var(--text-soft);
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}

.field {
  display: block;
  margin-bottom: 14px;
}
.field-label {
  display: block;
  font-weight: 600;
  font-size: .9rem;
  margin-bottom: 6px;
  color: var(--text);
}
.field-input {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.field-input:focus-visible {
  border-color: var(--accent);
}

/* Kalibrier-Bühne */
.cal-stage {
  position: relative;
  height: 130px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  margin: 8px 0 14px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}
.cal-baseline {
  position: absolute;
  left: 0; right: 0;
  bottom: 38px;
  height: 2px;
  background: var(--ruler-tick-soft);
}
.cal-handle {
  position: absolute;
  bottom: 38px;
  width: 0;
  height: 64px;
  transform: translateY(-100%);
  z-index: 2;
}
.cal-handle::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 2px;
  transform: translateX(-1px);
  background: var(--accent);
}
.cal-handle-left::before { background: var(--ruler-tick-soft); }
.cal-handle-right { cursor: ew-resize; }
.cal-cap {
  position: absolute;
  top: -8px;
  left: 0;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  font-family: var(--mono);
  font-size: .72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  white-space: nowrap;
}
.cal-handle-left .cal-cap { background: var(--ruler-tick-soft); }
.cal-handle-right .cal-cap::after {
  content: "";
  display: block;
  position: absolute;
  left: 50%;
  bottom: -22px;
  width: 24px;
  height: 24px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--surface);
  box-shadow: 0 2px 6px rgba(8,47,73,.35);
}
.cal-measure {
  position: absolute;
  left: 0; right: 0;
  bottom: 8px;
  text-align: center;
  font-family: var(--mono);
  font-weight: 700;
  color: var(--accent-strong);
}
[data-theme="dark"] .cal-measure { color: var(--steel-400); }

/* Toast */
.toast-stack {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
  width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  background: var(--steel-900);
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
  font-size: .92rem;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .25s ease, transform .25s ease;
  border-left: 4px solid var(--steel-400);
}
.toast.is-show { opacity: 1; transform: translateY(0); }
.toast.is-ok { border-left-color: #34d399; }
.toast.is-warn { border-left-color: #fbbf24; }
.toast.is-err { border-left-color: #f87171; }

[hidden] { display: none !important; }

/* Responsive */
@media (max-width: 460px) {
  .brand-name { font-size: .98rem; }
  .readout-value { font-size: 1.5rem; }
  .measure-top { flex-direction: column; align-items: stretch; }
  .readout { align-items: flex-start; text-align: left; }
  .btn { padding: 10px 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}
