/* EZN Sensor (v2) — base styles & design tokens.
   Screen-specific styles are added in their steps. */

/* ---------- Fonts: self-hosted Inter (offline-safe) ---------- */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../assets/fonts/inter-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../assets/fonts/inter-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../assets/fonts/inter-700.woff2') format('woff2');
}

/* ---------- Design tokens (from the EZN CD sheet) ---------- */
:root {
  --blue-dark: #00527F;   /* Pant 302U */
  --blue:      #007CA6;   /* Pant 314U — primary action */
  --gold:      #D09B2C;
  --text:      #2E2E2E;   /* CD "black" — primary text */
  --muted:     #666666;   /* gray — secondary text */
  --line:      #E6E6E6;   /* light gray — borders */

  --red:        #F04E23;              /* Signalfarbe */
  --red-fill:   rgba(240, 78, 35, 0.10);
  --green-stroke: #BBE5C8;
  --green-fill:   #EAF7EE;
  --green-text:   #1f9d55;

  --bg:      #F4F6F8;
  --surface: #FFFFFF;
  --field-bg:     #F7FAFB;
  --field-border: #E1E8EC;

  --radius: 12px;
  --shadow: 0 1px 3px rgba(16,33,51,.12), 0 1px 2px rgba(16,33,51,.08);
  --appbar-h: 56px;
}

/* ---------- Reset / fluid base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }

/* Fluid root: scales smoothly between phone and tablet (no fixed px sizing). */
html { font-size: clamp(15px, 1.6vw + 0.6rem, 19px); }

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--surface);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  /* Column layout so the version tag can sit at the bottom of the viewport. */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); }

/* ---------- App bar (hidden on the login screen) ---------- */
.app-bar {
  position: sticky;
  top: 0;
  /* min-height (not height): on notched iOS the safe-area padding ADDS clearance
     below the status bar instead of eating into a fixed 56px (which crushed the
     header when added to the home screen). */
  min-height: var(--appbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  z-index: 10;
}
.app-bar__logo { height: 1.6rem; width: auto; display: block; }
body[data-screen="login"] .app-bar { display: none; }

/* ---------- Version tag (small, bottom of every screen) ---------- */
.version-tag {
  flex: 0 0 auto;
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.02em;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}

/* ---------- Layout container ---------- */
.app {
  flex: 1 0 auto;          /* grow so the version tag is pushed to the bottom */
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
}
.screen[hidden] { display: none; }

/* ---------- Card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card__title { font-size: 1.35rem; font-weight: 700; margin-bottom: 6px; }
.card__subtitle { color: var(--muted); font-size: 0.92rem; margin-bottom: 4px; }

/* Small uppercase group header inside a form (Monteur / Objekt / …). */
.section-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #9DB0B8;
  margin: 22px 0 10px;
}
.section-label:first-of-type { margin-top: 18px; }

/* ---------- Page heading (sits above cards, not inside) ---------- */
.page-title { font-size: 1.35rem; font-weight: 700; color: var(--text); margin: 6px 0 4px; }
.page-subtitle { font-size: 0.85rem; color: #6B828D; margin: 0 0 18px; }

/* ---------- Bordered form card (Einsatzdetails and later forms) ---------- */
.form-card {
  background: #fff;
  border: 1.5px solid #E8EDF0;
  border-radius: 20px;
  padding: 18px 22px 20px;
}
.form-card .section-label:first-child { margin-top: 4px; }

/* Two-column field rows — widths taken from the Penpot geometry. */
.form-row { display: grid; gap: 16px; margin: 0 0 16px; }
.form-row .field { margin-bottom: 0; }
.form-row--name { grid-template-columns: 196fr 108fr; }  /* Name wide · Initialen narrow */
.form-row--addr { grid-template-columns: 196fr 108fr; }  /* Straße wide · Hausnummer narrow */
.form-row--plz  { grid-template-columns: 108fr 196fr; }  /* PLZ narrow · Ort wide */

.einsatz__submit { margin-top: 18px; }

/* ---------- Scannen ---------- */
body[data-screen="scan"] .app-bar { display: none; }   /* the board has no header */
/* Centered, slightly narrower column so the page reads as one tidy stack. */
.screen--scan { position: relative; text-align: center; padding-top: 1.6rem; max-width: 360px; margin: 0 auto; }
/* Scan-page messages: small, centred, red (errors + the camera-unavailable notice). */
.scan__status { font-size: 0.9rem; font-weight: 700; color: #E11900; margin: 6px auto 10px; text-align: center; max-width: 300px; line-height: 1.4; }
.scan__status[hidden] { display: none; }
.scan__title { text-align: center; margin: 8px 0 16px; }

/* Back → Sensorliste (requested; not on the board). */
.scan__back {
  position: absolute; top: 2px; left: 0;
  display: inline-flex; align-items: center; gap: 3px;
  background: none; border: none; cursor: pointer;
  font: inherit; font-size: 0.9rem; font-weight: 600; color: var(--blue);
  padding: 6px 8px 6px 4px;
}
.scan__back svg { width: 18px; height: 18px; }
.scan__back:hover { color: var(--blue-dark); }

/* PRIMARY: photo-capture button (a <label> wrapping a visually-hidden file input). */
.scan__capture {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; max-width: 320px; margin: 0 auto;
  background: #127CA6; color: #fff; border: 1.6px solid #127CA6;
  border-radius: 12px; padding: 16px 18px;
  font: inherit; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.scan__capture:hover { background: #0F6A8E; border-color: #0F6A8E; }
.scan__capture svg { width: 22px; height: 22px; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
/* Guidance under the live camera (fallback to the photo button). */
.scan__hint { max-width: 320px; margin: 8px auto 16px; font-size: 0.82rem; color: #6B828D; line-height: 1.45; }

/* Gap + divider between the two scanning options and manual entry. */
.scan__divider { max-width: 300px; margin: 30px auto 20px; border: 0; border-top: 1px solid #E6ECEF; }

/* Camera controls: zoom slider + torch (shown only when supported). */
.scan__controls {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  max-width: 300px; margin: 0 auto 16px;
}
.scan__controls[hidden] { display: none; }
.scan__zoom { flex: 1; display: flex; align-items: center; gap: 8px; color: #6B828D; font-size: 1.05rem; }
.scan__zoom[hidden] { display: none; }
.scan__zoom input[type="range"] { flex: 1; height: 26px; accent-color: var(--blue); }
.scan__torch {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 10px;
  background: var(--field-bg); border: 1.5px solid var(--field-border); color: #33505C;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.scan__torch[hidden] { display: none; }
.scan__torch.is-on { background: var(--blue); border-color: var(--blue); color: #fff; }
.scan__torch svg { width: 22px; height: 22px; }

.scan__card {
  width: min(72vw, 268px);
  height: min(80vw, 300px);
  margin: 16px auto 20px;
  background: #fff;
  border: 1.5px solid #EEF0F2;
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.scan__viewport {
  position: relative;
  width: min(56vw, 213px);
  height: min(56vw, 213px);
  border-radius: 10px;
  overflow: hidden;
  background: #f2f5f7;
}
.scan__viewport video { width: 100% !important; height: 100% !important; object-fit: cover; display: block; }
/* Subtle scanner corner-guides overlaid on the live feed. */
.scan__viewport::after {
  content: ""; position: absolute; inset: 12px; z-index: 2; pointer-events: none;
  --c: #ffffff; --t: 3px; --l: 20px;
  background:
    linear-gradient(var(--c), var(--c)) top left    / var(--l) var(--t) no-repeat,
    linear-gradient(var(--c), var(--c)) top left    / var(--t) var(--l) no-repeat,
    linear-gradient(var(--c), var(--c)) top right    / var(--l) var(--t) no-repeat,
    linear-gradient(var(--c), var(--c)) top right    / var(--t) var(--l) no-repeat,
    linear-gradient(var(--c), var(--c)) bottom left  / var(--l) var(--t) no-repeat,
    linear-gradient(var(--c), var(--c)) bottom left  / var(--t) var(--l) no-repeat,
    linear-gradient(var(--c), var(--c)) bottom right / var(--l) var(--t) no-repeat,
    linear-gradient(var(--c), var(--c)) bottom right / var(--t) var(--l) no-repeat;
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.45));
}

.scan__manual-label {
  display: block; text-align: center;
  max-width: 300px; margin: 0 auto 8px;
  color: #33505C; font-size: 0.8rem; font-weight: 600;
}
.input-group { display: flex; align-items: stretch; max-width: 300px; margin: 0 auto; }
.input-group input {
  flex: 1; min-width: 0;
  font: inherit; font-size: 16px;   /* 16px avoids iOS focus auto-zoom */
  padding: 13px 14px;
  color: var(--text);
  background: var(--field-bg);
  border: 1.5px solid var(--field-border);
  border-right: none;
  border-radius: 12px 0 0 12px;
}
.input-group input:focus { outline: none; }
.input-group__btn {
  flex: 0 0 52px;
  background: var(--blue); color: #fff;
  border: none; border-radius: 0 12px 12px 0;
  font-size: 1.3rem; line-height: 1; cursor: pointer;
}
.input-group__btn:hover { background: var(--blue-dark); }
/* Higher specificity so it wins over the shared .form-error colour/size below. */
.screen--scan .scan__error { max-width: 300px; margin: 10px auto 0; text-align: center; font-size: 0.9rem; font-weight: 700; color: #E11900; line-height: 1.4; }

/* ---------- Sensordetails ---------- */
/* MAC-Adresse card: RED until confirmed → GREEN once "Bestätigen" is pressed. */
.mac-box {   /* amber while unconfirmed (turns green once confirmed) */
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: #FFF7E6;
  border: 1.5px solid #E6B54A;
  border-radius: 16px;
  padding: 15px 16px 15px 20px;
  margin: 0 0 10px;
}
.mac-box.is-confirmed {
  background: var(--green-fill);
  border-color: var(--green-stroke);
}
.mac-box__info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.mac-box__label {
  font-size: 0.66rem; font-weight: 700; letter-spacing: 0.04em; color: #33505C;
}
.mac-box__value {
  font-size: 1.05rem; font-weight: 600; color: #10202A;
  letter-spacing: 0.01em; word-break: break-all;
}
.mac-box__confirm {                 /* amber pill while unconfirmed */
  flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 0.78rem; font-weight: 700;
  color: #3A2A00; background: var(--gold);
  border: none; border-radius: 8px;
  padding: 7px 12px; cursor: pointer;
}
.mac-box__confirm:hover { background: #C08F27; }
.mac-box.is-confirmed .mac-box__confirm {   /* green, non-interactive once confirmed */
  background: transparent; color: var(--green-text);
  cursor: default; padding: 7px 4px 7px 0;
}

/* "Neu scannen": corrects a wrong MAC (returns to Scannen). Not on the board. */
.mac-rescan {
  display: block; margin: 0 0 16px auto;
  background: none; border: none; padding: 4px 2px;
  font: inherit; font-size: 0.8rem; font-weight: 600;
  color: var(--blue); cursor: pointer;
}
.mac-rescan:hover { text-decoration: underline; }
.mac-rescan[hidden] { display: none; }

/* Styled <select> with a chevron (appearance is removed on .field select). */
.select-wrap { position: relative; }
.select-wrap::after {
  content: "▾";
  position: absolute; right: 15px; top: 50%; transform: translateY(-52%);
  color: #6B828D; font-size: 1.15rem; line-height: 1; pointer-events: none;
}
.field select { padding-right: 36px; cursor: pointer; }
.field select.is-placeholder { color: #9AAAB2; }   /* grey "Bitte wählen" */

/* Last field sits flush with the card's bottom padding. */
.form-card .field--last { margin-bottom: 0; }

/* "+ Sensor hinzufügen" — the board uses #127CA6 for this button. */
.btn--add { background: #127CA6; color: #fff; margin-top: 20px; font-size: 0.98rem; }
.btn--add:hover { background: #0F6A8E; }
.btn--add:disabled { opacity: 0.5; cursor: default; }

/* ---------- Sensorliste ---------- */
.tbl {
  background: #fff;
  border: 1.5px solid #E8EDF0;
  border-radius: 16px;
  overflow: hidden;
}
.tbl__head, .tbl__row {
  display: grid;
  grid-template-columns: 44px 1fr 64px;
  align-items: center;
  gap: 8px;
  padding: 0 22px;
}
.tbl__head {
  height: 42px;
  border-bottom: 1px solid #EEF2F4;
}
.tbl__head span {
  font-size: 0.66rem; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: #9DB0B8;
}
.tbl__row {
  min-height: 62px;
  border-bottom: 1px solid #EEF2F4;
}
.tbl__row:last-child { border-bottom: none; }
.tbl__nr   { font-size: 0.9rem; font-weight: 600; color: #152C36; }
.tbl__name { font-size: 0.9rem; color: #33505C; word-break: break-word; }
.tbl__actions { display: inline-flex; gap: 4px; justify-content: flex-end; }
.tbl__empty { padding: 26px 22px; text-align: center; color: #8DA0A8; font-size: 0.9rem; }

/* Row action icons (inline SVG): pen = edit (slate), trash = delete (red). */
.ic {
  background: none; border: none; cursor: pointer;
  padding: 6px; border-radius: 8px; display: inline-flex; line-height: 0;
}
.ic svg { width: 19px; height: 19px; }
.ic--edit { color: #64748B; }
.ic--del  { color: #DC2626; }
.ic:hover { background: #F2F5F7; }

/* Bottom actions: outline "Sensor hinzufügen" + teal "Abschließen". */
.list-actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 20px;
}
/* Scoped so the border/fill win over the later base .btn rule (used on the
   Sensorliste and the Export screen). */
.list-actions .btn, .export-actions .btn { padding: 15px 12px; border-radius: 12px; font-size: 0.95rem; }
.list-actions .btn--teal, .export-actions .btn--teal { background: #127CA6; color: #fff; border: 1.6px solid #127CA6; }
.list-actions .btn--teal:hover, .export-actions .btn--teal:hover { background: #0F6A8E; border-color: #0F6A8E; }
.list-actions .btn--teal-o, .export-actions .btn--teal-o { background: #fff; color: #127CA6; border: 1.6px solid #127CA6; }
.list-actions .btn--teal-o:hover, .export-actions .btn--teal-o:hover { background: #EFF6FA; }

/* ---------- Zusammenfassung / Export ---------- */
.sum-card {
  background: #fff;
  border: 1.5px solid #E8EDF0;
  border-radius: 16px;
  padding: 16px 20px 6px;
  margin: 0 0 14px;
}
.sum-card__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.sum-card__label {
  font-size: 0.66rem; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: #9DB0B8;
}
.sum-edit {
  background: none; border: none; cursor: pointer; padding: 2px 2px;
  font: inherit; font-size: 0.8rem; font-weight: 600; color: #127CA6;
}
.sum-edit:hover { text-decoration: underline; }
.sum-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 12px 0; border-top: 1px solid #EEF2F4;
}
.sum-card__head + .sum-row { border-top: none; }
.sum-row__k { font-size: 0.82rem; color: #6B828D; flex: 0 0 auto; }
.sum-row__v { font-size: 0.92rem; font-weight: 600; color: #152C36; text-align: right; word-break: break-word; }

/* Count-validation card: green when OK, amber when the count differs (advisory). */
.status-card {
  display: flex; align-items: center; gap: 12px;
  border: 1.5px solid; border-radius: 16px;
  padding: 16px 18px; margin: 0 0 8px;
}
.status-card__icon { flex: 0 0 auto; display: inline-flex; line-height: 0; }
.status-card__icon svg { width: 24px; height: 24px; }
.status-card__text { display: flex; flex-direction: column; gap: 2px; }
.status-card__title { font-size: 0.9rem; font-weight: 700; }
.status-card__sub { font-size: 0.8rem; }
.status-card__hint { font-size: 0.75rem; font-weight: 600; margin-top: 3px; }
.status-card__hint:empty { display: none; }
.status-card.is-warn .status-card__hint { color: #B45309; }
.status-card.is-ok   { background: var(--green-fill); border-color: var(--green-stroke); }
.status-card.is-ok   .status-card__icon { color: #16A34A; }
.status-card.is-ok   .status-card__title { color: #15803D; }
.status-card.is-ok   .status-card__sub   { color: #3F7A52; }
.status-card.is-warn { background: #FEF4E6; border-color: #F6C98A; }
.status-card.is-warn .status-card__icon { color: #E08600; }
.status-card.is-warn .status-card__title { color: #B45309; }
.status-card.is-warn .status-card__sub   { color: #96692B; }

/* When the count differs, the amber card is tappable → back to Scannen. */
.status-card.is-warn { cursor: pointer; }
.status-card.is-warn:hover { background: #FDECD2; }
.status-card.is-warn:focus-visible { outline: 2px solid #E08600; outline-offset: 2px; }
.status-card__go { margin-left: auto; flex: 0 0 auto; display: none; align-items: center; color: #B45309; }
.status-card__go svg { width: 22px; height: 22px; }
.status-card.is-warn .status-card__go { display: inline-flex; }

.export-note {
  text-align: center; font-size: 0.78rem; color: #6B828D;
  margin: 22px 0 12px;
}
/* Success confirmation after a download/save/share. */
.export-msg {
  margin: 12px 0 0; padding: 11px 13px; text-align: center;
  font-size: 0.9rem; font-weight: 700; color: #15803D;
  background: var(--green-fill); border: 1px solid var(--green-stroke); border-radius: 10px;
}
.export-msg[hidden] { display: none; }
.export-actions { display: grid; grid-template-columns: 120px 1fr; gap: 16px; }
#export-error { margin-top: 12px; justify-content: center; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  padding: 12px 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  line-height: 1.1;
}
.btn--sm { padding: 7px 12px; font-size: 0.9rem; border-radius: 8px; }
.btn--primary { background: var(--blue); color: #fff; }
.btn--primary:hover { background: var(--blue-dark); }
.btn--outline { background: #fff; border-color: var(--blue); color: var(--blue); }
.btn--outline:hover { background: #eef5f9; }

/* ---------- Form fields ---------- */
.field { margin: 0 0 16px; text-align: left; }
.field > label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #33505C;
  margin: 0 0 6px;
}
.field input, .field select {
  width: 100%;
  font: inherit;
  font-size: 16px;                 /* 16px avoids iOS focus auto-zoom */
  padding: 13px 14px;
  color: var(--text);
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  border-radius: 11px;
  -webkit-appearance: none; appearance: none;
}
.field input::placeholder { color: #9AAAB2; }
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0,124,166,.15);
  background: #fff;
}

/* Error messages: bright, bold, hard to miss — a red badge on a soft red pill. */
.form-error {
  margin: 0 0 14px;
  padding: 11px 13px;
  font-size: 0.95rem;
  font-weight: 700;
  color: #E11900;
  background: #FDECEC;
  border: 1px solid #F6C6C6;
  border-left: 4px solid #E11900;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 9px;
}
.form-error::before {
  content: "!";
  flex: 0 0 auto;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #E11900; color: #fff;
  font-size: 0.85rem; font-weight: 800; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.form-error[hidden] {
  display: none;
}

.btn--block { width: 100%; display: block; }

/* ---------- Login screen ---------- */
body[data-screen="login"] { background: #fff; }
.screen--login {
  /* Leave room for the version tag at the bottom (login has no app-bar). */
  min-height: calc(100vh - 96px);
  min-height: calc(100dvh - 96px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.login { width: 100%; max-width: 360px; text-align: center; }
.login__logo { width: min(66vw, 240px); height: auto; margin: 0 auto 24px; display: block; }
.login__title { font-size: 1.5rem; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.login__subtitle { font-size: 0.95rem; color: var(--muted); margin-bottom: 26px; }
.login__hint { margin: 16px 0 0; font-size: 0.78rem; color: #93A6AF; }

/* Help button (top-right, login only) -> opens the Anleitung page. */
.login-help {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  right: 14px;
  z-index: 20;
  width: 40px; height: 40px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: #fff; border: 1.5px solid var(--blue); color: var(--blue);
  font-weight: 700; font-size: 1.25rem; line-height: 1;
  text-decoration: none;
  box-shadow: var(--shadow);
}
.login-help:hover { background: #eef5f9; }
.login-help:active { transform: translateY(1px); }

.app-status {
  position: fixed;
  bottom: calc(14px + env(safe-area-inset-bottom));
  left: 0; right: 0;
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
}
