:root {
  --bg: #0f0f0f;
  --bg-card: #1a1a1a;
  --bg-input: #252525;
  --border: #333;
  --text: #e8e8e8;
  --text-dim: #888;
  --accent: #4a9eff;
  --accent-dim: #2a6fc0;
  --success: #34c759;
  --danger: #ff453a;
  --warning: #ff9f0a;
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  padding-bottom: 80px;
}

/* --- Layout --- */
.app-content {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
}

.page { display: none; }
.page.active { display: block; }

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
  max-width: 600px;
  margin: 0 auto;
}

.header h1 {
  font-size: 18px;
  font-weight: 600;
}

.header-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 16px;
  cursor: pointer;
  padding: 8px;
}

/* --- Bottom Nav --- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
  z-index: 100;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 0;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.nav-btn.active { color: var(--accent); }
.nav-btn svg { width: 24px; height: 24px; }

/* --- Sonden Grid --- */
.sonden-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.grid-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.grid-card-top {
  display: flex;
  align-items: center;
}

.grid-card-name {
  font-size: 16px;
  font-weight: 600;
}

.grid-card-date {
  font-size: 12px;
  color: var(--text-dim);
  padding-left: 18px;
}

/* --- Cards --- */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

.card-title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 4px;
}

.card-sub {
  font-size: 13px;
  color: var(--text-dim);
}

.card-clickable {
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.card-clickable:active {
  background: var(--bg-input);
}

/* --- Status-Dot --- */
.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
}

.status-dot.green { background: var(--success); }
.status-dot.gray { background: var(--text-dim); }

/* --- Forms --- */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-input {
  width: 100%;
  padding: 14px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 17px;
  outline: none;
  -webkit-appearance: none;
}

.form-input:focus {
  border-color: var(--accent);
}

.form-input-unit {
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-input-unit .form-input {
  flex: 1;
}

.form-input-unit .unit {
  font-size: 14px;
  color: var(--text-dim);
  white-space: nowrap;
  min-width: 40px;
}

/* --- Toggle Switch --- */
.toggle-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
}

.toggle {
  position: relative;
  width: 56px;
  height: 32px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 26px;
  height: 26px;
  left: 2px;
  top: 2px;
  background: var(--text);
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-slider {
  background: var(--success);
  border-color: var(--success);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(24px);
}

/* --- Buttons --- */
.btn {
  display: block;
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  text-align: center;
}

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

.btn-primary:active { background: var(--accent-dim); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-sm {
  padding: 10px 16px;
  font-size: 14px;
  width: auto;
  display: inline-block;
}

.btn-sticky {
  position: sticky;
  bottom: 80px;
  z-index: 5;
}

/* --- Lists --- */
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.list-item-text {
  font-size: 15px;
}

.list-item-sub {
  font-size: 12px;
  color: var(--text-dim);
}

/* --- Checkbox List (Config) --- */
.check-list label {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.check-list input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

/* --- Tabs --- */
.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.tab {
  flex: 1;
  padding: 10px 0;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  border: none;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 6px;
  -webkit-tap-highlight-color: transparent;
}

.tab.active {
  background: var(--accent);
  color: #fff;
}

/* --- Toast / Feedback --- */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--success);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.show { opacity: 1; }

/* --- Login Screen --- */
.login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80dvh;
  text-align: center;
  padding: 32px;
}

.login-screen h1 {
  font-size: 28px;
  margin-bottom: 8px;
}

.login-screen p {
  color: var(--text-dim);
  margin-bottom: 32px;
}

.login-icon {
  font-size: 64px;
  margin-bottom: 24px;
}

/* --- Export Preview --- */
.export-preview {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-family: 'SF Mono', 'Menlo', monospace;
  font-size: 12px;
  white-space: pre-wrap;
  max-height: 400px;
  overflow-y: auto;
  margin-bottom: 16px;
  color: var(--text-dim);
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-dim);
  font-size: 15px;
}

/* --- Utility --- */
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.flex-row { display: flex; gap: 8px; }
.flex-1 { flex: 1; }
.text-center { text-align: center; }
.text-dim { color: var(--text-dim); }
.text-sm { font-size: 13px; }

/* --- Messung Grid (2 Spalten) --- */
.messung-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.messung-divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* --- Checkbox Items (Messung) --- */
.check-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.check-item input[type="checkbox"] {
  width: 24px;
  height: 24px;
  accent-color: var(--success);
  flex-shrink: 0;
}

.check-item span {
  line-height: 1.2;
}

/* --- History Button --- */
.form-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.form-label-row .form-label {
  margin-bottom: 0;
}

.history-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--accent);
  padding: 4px 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.history-btn:active {
  background: var(--bg-input);
}

.check-item-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.check-item-wrap .check-item {
  flex: 1;
}

.history-btn-check {
  padding: 3px 5px;
}

/* --- History Panel --- */
.history-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 8px;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.history-header h3 {
  font-size: 17px;
  font-weight: 600;
}

.history-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  -webkit-tap-highlight-color: transparent;
}

/* Stats */
.history-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--bg-input);
  border-radius: 8px;
  padding: 10px 8px;
  text-align: center;
}

.stat-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 16px;
  font-weight: 700;
}

.stat-diff {
  font-size: 11px;
  margin-top: 2px;
}

.history-up { color: var(--success); }
.history-down { color: var(--danger); }

/* Chart */
.history-chart {
  width: 100%;
  height: auto;
  display: block;
  margin-bottom: 16px;
}

/* Table */
.history-table-wrap {
  max-height: 300px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.history-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-card);
}

.history-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
}

.history-ok { color: var(--success); font-weight: 600; }
.history-no { color: var(--text-dim); }

.notiz-row td {
  padding-top: 0 !important;
  border-bottom: 1px solid var(--border);
}

.history-notiz {
  font-size: 12px;
  color: var(--warning);
  font-style: italic;
}

@media (max-width: 380px) {
  .history-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* --- Back Button --- */
.back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 16px;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}
