:root {
  --bg: #0b0f19;
  --surface: #151a28;
  --surface-2: #1e2436;
  --text: #eef1f7;
  --text-dim: #9aa3b8;
  --accent: #4f7cff;
  --accent-press: #3d63d8;
  --danger: #ff5470;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

body { min-height: 100dvh; }

.hidden { display: none !important; }

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--safe-top) + 14px) 20px 14px;
  background: rgba(11, 15, 25, 0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.app-header h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
}
.count-badge {
  margin-left: auto;
  min-width: 30px;
  height: 30px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  color: var(--text-dim);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
}

/* Liste */
.list {
  padding: 16px 16px calc(120px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
}
.card:active { transform: scale(0.98); }

.card-img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
  background: #fff;
}
.card-img.placeholder {
  height: 200px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 64px;
}

.card-body { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.card-title {
  font-size: 21px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.3px;
}
.reps-badge {
  align-self: flex-start;
  padding: 4px 12px;
  background: rgba(79, 124, 255, 0.16);
  color: #9db6ff;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
}
.card-desc {
  font-size: 15px;
  color: var(--text-dim);
  line-height: 1.4;
}

/* Empty / loading */
.empty { text-align: center; padding: 80px 24px; color: var(--text-dim); }
.empty-icon { font-size: 56px; margin-bottom: 12px; }
.empty p { margin: 6px 0; font-size: 16px; }
.empty-sub { font-size: 14px !important; }
.loading { text-align: center; padding: 60px; color: var(--text-dim); }

/* FAB */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(24px + var(--safe-bottom));
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 34px;
  font-weight: 300;
  line-height: 1;
  box-shadow: 0 10px 30px rgba(79, 124, 255, 0.5);
  z-index: 20;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
}
.fab:active { transform: scale(0.92); background: var(--accent-press); }

/* Sheet */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  animation: fade 0.2s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  width: 100%;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 10px 20px calc(24px + var(--safe-bottom));
  animation: slideup 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }

.sheet-handle {
  width: 40px;
  height: 5px;
  border-radius: 999px;
  background: var(--surface-2);
  margin: 6px auto 14px;
}
.sheet h2 { margin: 0 0 18px; font-size: 22px; font-weight: 800; }

.photo-picker { display: block; cursor: pointer; }
.photo-preview {
  width: 100%;
  height: 200px;
  border-radius: var(--radius);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1.5px dashed rgba(255, 255, 255, 0.15);
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-placeholder { color: var(--text-dim); font-size: 16px; }

.link-btn {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 0;
  cursor: pointer;
}

.field { display: block; margin-top: 16px; }
.field span {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 7px;
  padding-left: 2px;
}
.field input, .field textarea {
  width: 100%;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 14px;
  color: var(--text);
  font-size: 17px;
  font-family: inherit;
  resize: none;
}
.field input:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.sheet-actions { display: flex; gap: 12px; margin-top: 24px; }
.btn {
  flex: 1;
  padding: 15px;
  border-radius: 14px;
  border: none;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.1s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-danger {
  background: rgba(255, 84, 112, 0.14);
  color: var(--danger);
  width: 100%;
  margin-top: 12px;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--surface-2);
  color: var(--text);
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  z-index: 40;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: fade 0.2s ease;
}

/* ===== Abschnitte & Verwaltung ===== */
.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { transform: scale(0.92); }

/* Abschnitts-Überschrift in der Liste */
.section-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 4px 2px;
  margin-top: 6px;
}
.section-head:first-child { margin-top: 0; }
.section-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
}
.section-head .sec-count { font-size: 13px; color: var(--text-dim); opacity: 0.7; }

/* Select-Felder */
.field select {
  width: 100%;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 14px;
  color: var(--text);
  font-size: 17px;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%239aa3b8' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
}
.field select:focus { outline: none; border-color: var(--accent); }

/* Verwaltungs-Overlay */
.manage-sheet { max-height: 92dvh; }
.manage-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.manage-head h2 { margin: 0; }
.link-btn2 { background: none; border: none; color: var(--accent); font-size: 17px; font-weight: 700; cursor: pointer; padding: 6px 4px; }

.btn-sm { flex: 0 0 auto; padding: 12px 16px; font-size: 15px; }
.manage-section-add { display: flex; gap: 10px; margin-bottom: 20px; }
.manage-section-add input {
  flex: 1;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
}
.manage-section-add input:focus { outline: none; border-color: var(--accent); }

.manage-list { display: flex; flex-direction: column; gap: 18px; }
.manage-sec {
  background: var(--surface-2);
  border-radius: 16px;
  padding: 12px;
}
.manage-sec-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.manage-sec-head .sec-name {
  flex: 1;
  font-size: 16px;
  font-weight: 800;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mini-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: none;
  background: rgba(255,255,255,0.06);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.mini-btn:active { transform: scale(0.9); }
.mini-btn:disabled { opacity: 0.28; }
.mini-btn.danger { color: var(--danger); }

.manage-ex-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 6px;
  border-top: 1px solid rgba(255,255,255,0.05);
}
.manage-ex-row .ex-name {
  flex: 1;
  font-size: 15px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.manage-ex-empty { padding: 8px 6px; color: var(--text-dim); font-size: 14px; }
