*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #0f766e;
  --primary-dark: #115e59;
  --bg: #f0fdfa;
  --card: #ffffff;
  --text: #134e4a;
  --muted: #5b7c7a;
  --border: #ccfbf1;
  --danger: #dc2626;
  --shadow: 0 4px 14px rgba(15, 118, 110, 0.12);
  --radius: 12px;
  --touch: 44px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  -webkit-overflow-scrolling: touch;
}

#app { max-width: 560px; margin: 0 auto; min-height: 100vh; background: var(--bg); }

.header {
  background: linear-gradient(135deg, #0f766e, #0d9488);
  color: #fff;
  padding: calc(0.75rem + env(safe-area-inset-top, 0px)) 1rem 0.85rem;
}
.header-top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.header h1 { font-size: 1.15rem; font-weight: 700; }
.header-actions { display: flex; gap: 0.25rem; }
.icon-btn {
  width: var(--touch); height: var(--touch);
  border: none; border-radius: 10px;
  background: rgba(255,255,255,0.15); color: #fff;
  font-size: 1.15rem; cursor: pointer;
}
.monteur-line, .date-line { font-size: 0.85rem; opacity: 0.95; margin-top: 0.25rem; }

.tabs {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
  overflow-x: auto;
}
.tab {
  flex: 1; min-width: 4.5rem;
  padding: 0.75rem 0.4rem;
  border: none; background: transparent;
  font-size: 0.88rem; font-weight: 600;
  color: var(--muted); cursor: pointer;
  border-bottom: 3px solid transparent;
  touch-action: manipulation;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.view { display: none; padding: 1rem 1rem calc(1.5rem + var(--safe-bottom)); }
.view.active { display: block; }

.section-title { font-size: 1.05rem; margin-bottom: 0.75rem; }

.summary-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.summary-cards-1 { max-width: 220px; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 0.85rem 0.75rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.card-label { display: block; font-size: 0.75rem; color: var(--muted); margin-bottom: 0.2rem; }
.card strong { font-size: 1.35rem; }

.entry {
  background: var(--card);
  border-radius: var(--radius);
  padding: 0.85rem;
  margin-bottom: 0.55rem;
  box-shadow: var(--shadow);
  display: flex; gap: 0.65rem; align-items: flex-start;
}
.entry-icon { font-size: 1.25rem; flex-shrink: 0; }
.entry-body { flex: 1; min-width: 0; }
.entry-title { font-weight: 700; font-size: 0.95rem; }
.entry-meta { font-size: 0.82rem; color: var(--muted); margin-top: 0.15rem; }
.entry-del {
  border: none; background: #fef2f2; color: var(--danger);
  width: 36px; height: 36px; border-radius: 8px; cursor: pointer; flex-shrink: 0;
}

.form-group { margin-bottom: 0.85rem; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.3rem; }
input, textarea, select {
  width: 100%;
  min-height: var(--touch);
  padding: 0.55rem 0.75rem;
  border: 1px solid #99f6e4;
  border-radius: 10px;
  font-size: 16px;
  background: #fff;
  color: var(--text);
}
textarea { min-height: 4rem; resize: vertical; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.65rem; }

.btn {
  min-height: var(--touch);
  padding: 0.55rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 0.95rem; font-weight: 600;
  cursor: pointer; touch-action: manipulation;
}
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.block { width: 100%; margin-top: 0.45rem; }
.btn:disabled { opacity: 0.5; }

.hint { color: var(--muted); font-size: 0.9rem; margin: 0.5rem 0; }
.hint.tiny { font-size: 0.78rem; }

.preview-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  white-space: pre-wrap;
  font-size: 0.88rem;
  line-height: 1.4;
  margin-bottom: 0.85rem;
  box-shadow: var(--shadow);
  max-height: 40vh;
  overflow-y: auto;
}

.back-btn {
  border: none; background: transparent;
  color: var(--primary); font-weight: 600;
  font-size: 0.95rem; margin-bottom: 0.5rem; cursor: pointer;
  padding: 0.35rem 0;
}

.overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.overlay.hidden { display: none !important; }
.overlay-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 1.35rem;
  width: 100%; max-width: 22rem;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
}
.overlay-card h2 { margin-bottom: 0.5rem; }
.overlay-card input { margin: 0.75rem 0; }

.suggest-wrap { position: relative; }
.suggest-box {
  position: absolute; left: 0; right: 0; top: 100%;
  z-index: 50;
  background: #fff;
  border: 1px solid #99f6e4;
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-height: 200px; overflow-y: auto;
}
.suggest-box.hidden { display: none !important; }
.suggest-item {
  display: block; width: 100%; text-align: left;
  padding: 0.65rem 0.8rem;
  border: none; border-bottom: 1px solid #f0fdfa;
  background: #fff; font-size: 0.92rem; cursor: pointer;
}
.suggest-item:active { background: #ccfbf1; }

.history-item {
  background: var(--card);
  border-radius: var(--radius);
  padding: 0.85rem;
  margin-bottom: 0.55rem;
  box-shadow: var(--shadow);
}
.history-item h4 { font-size: 0.95rem; }
.history-item .meta { font-size: 0.8rem; color: var(--muted); }

.role-row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.role-opt {
  display: flex; align-items: center; gap: 0.35rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  font-weight: 600;
  cursor: pointer;
}
.role-opt input { width: auto; min-height: auto; }
.sign-block {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem;
  margin: 0.85rem 0;
  box-shadow: var(--shadow);
}
.sign-title { font-size: 0.95rem; margin-bottom: 0.35rem; }
.sign-pad-wrap {
  border: 2px dashed #99f6e4;
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
  margin: 0.4rem 0 0.5rem;
  touch-action: none;
}
.sign-pad {
  display: block;
  width: 100%;
  height: 140px;
  touch-action: none;
  cursor: crosshair;
}
#sign-status { font-weight: 600; min-height: 1.2em; }

/* Print area – hidden on screen */
.print-only { display: none; }

/* ===== PRINT / PDF A5 ===== */
@media print {
  @page {
    size: A5 portrait;
    margin: 10mm;
  }

  html, body {
    background: #fff !important;
    color: #000 !important;
    font-size: 10pt;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body * { visibility: hidden; }
  body.printing #print-area,
  body.printing #print-area * {
    visibility: visible;
  }
  body.printing #print-area {
    display: block !important;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    padding: 0;
    margin: 0;
  }

  .print-sheet {
    font-family: Helvetica, Arial, sans-serif;
    color: #000;
    line-height: 1.35;
  }
  .print-header {
    font-size: 11pt;
    margin-bottom: 6pt;
    border-bottom: 1.5pt solid #000;
    padding-bottom: 4pt;
  }
  .print-meta {
    margin: 6pt 0 8pt;
    font-size: 10pt;
  }
  .print-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 9pt;
    margin-bottom: 8pt;
  }
  .print-table th,
  .print-table td {
    border: 0.6pt solid #333;
    padding: 3pt 4pt;
    text-align: left;
    vertical-align: top;
  }
  .print-table th {
    background: #eee;
    font-weight: 700;
  }
  .print-table .num { text-align: right; white-space: nowrap; }
  .print-table tfoot td { font-weight: 700; background: #f5f5f5; }
  .print-note {
    font-size: 9pt;
    margin: 6pt 0;
  }
  .print-sigs {
    display: flex;
    gap: 12pt;
    margin-top: 12pt;
    page-break-inside: avoid;
  }
  .print-sig-block {
    flex: 1;
    border: 0.6pt solid #999;
    padding: 4pt;
    min-height: 55pt;
  }
  .sig-label {
    font-size: 8pt;
    color: #444;
    margin-bottom: 2pt;
  }
  .sig-img {
    display: block;
    max-width: 100%;
    height: 38pt;
    object-fit: contain;
    object-position: left center;
  }
  .sig-name {
    font-size: 8pt;
    margin-top: 2pt;
  }
  .print-footer {
    margin-top: 10pt;
    font-size: 7.5pt;
    color: #666;
    border-top: 0.4pt solid #ccc;
    padding-top: 3pt;
  }
}

@media (min-width: 900px) and (hover: hover) and (pointer: fine) {
  #app { max-width: 640px; box-shadow: 0 0 40px rgba(0,0,0,0.06); }
}

/* ===== Fahrtenbuch specific ===== */
.mode-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  background: rgba(255,255,255,0.2);
  margin-left: 0.35rem;
  vertical-align: middle;
}
.gps-status {
  background: #ecfdf5;
  border: 1px solid #99f6e4;
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  text-align: center;
}
.gps-status.running {
  background: #fef3c7;
  border-color: #fbbf24;
}
.gps-status .big {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0.35rem 0;
}
.gps-coords {
  font-size: 0.78rem;
  color: var(--muted);
  word-break: break-all;
}
.consent-box {
  background: #fff7ed;
  border: 1px solid #fdba74;
  border-radius: var(--radius);
  padding: 0.85rem;
  margin: 0.75rem 0;
  font-size: 0.88rem;
}
.consent-box label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-weight: 500;
  cursor: pointer;
}
.consent-box input[type="checkbox"] {
  width: auto;
  min-height: auto;
  margin-top: 0.2rem;
}
.art-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.art-opt {
  flex: 1;
  min-width: 7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.65rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: #fff;
  font-weight: 600;
  cursor: pointer;
}
.art-opt input { width: auto; min-height: auto; }
.art-opt.active, .art-opt:has(input:checked) {
  border-color: var(--primary);
  background: #ccfbf1;
}
.km-big {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--primary);
}
.entry.privat { border-left: 4px solid #a78bfa; }
.entry.geschaeft { border-left: 4px solid var(--primary); }
.summary-cards-2 {
  grid-template-columns: 1fr 1fr;
}
.btn.danger {
  background: #fef2f2;
  color: var(--danger);
  border-color: #fecaca;
}
.btn.secondary {
  background: #f0fdfa;
  border-color: #99f6e4;
}
.vehicle-list {
  margin: 0.5rem 0 1rem;
}
.vehicle-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 0.75rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}
.hidden { display: none !important; }
.toast {
  position: fixed;
  bottom: calc(1.5rem + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #134e4a;
  color: #fff;
  padding: 0.65rem 1.2rem;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
}
.toast.show { opacity: 1; }
