:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --danger: #dc2626;
  --star: #f59e0b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--primary);
  color: #fff;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
}
.app-header h1 { margin: 0; font-size: 1.2rem; }
.header-right { display: flex; align-items: center; gap: 12px; }
.header-stars { font-weight: 600; }

main { max-width: 720px; margin: 0 auto; padding: 12px 12px 24px; }

/* --- Buttons --- */
.link-btn {
  background: none; border: none; color: inherit;
  text-decoration: underline; cursor: pointer; font-size: 0.9rem; padding: 4px;
}
.icon-btn {
  background: var(--card); border: 1px solid var(--border); border-radius: 50%;
  width: 40px; height: 40px; font-size: 1.4rem; line-height: 1; cursor: pointer;
}
.primary-btn, .secondary-btn, .danger-btn {
  border: none; border-radius: var(--radius); padding: 10px 16px;
  font-size: 0.95rem; font-weight: 600; cursor: pointer;
}
.primary-btn { background: var(--primary); color: #fff; }
.secondary-btn { background: var(--card); color: var(--primary); border: 1px solid var(--primary); }
.danger-btn { background: var(--card); color: var(--danger); border: 1px solid var(--danger); }
button:disabled { opacity: 0.5; cursor: default; }

/* --- Login --- */
.login-form {
  max-width: 360px; margin: 48px auto; background: var(--card);
  padding: 24px; border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
}
.login-form h2 { margin: 0 0 8px; }
.login-form label { font-size: 0.85rem; color: var(--muted); }
.login-form input {
  padding: 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 1rem;
}
.login-form button {
  margin-top: 12px; padding: 12px; background: var(--primary); color: #fff;
  border: none; border-radius: 8px; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.form-error { color: var(--danger); font-size: 0.9rem; margin: 4px 0 0; }

/* --- Wochenansicht --- */
.week-nav {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-bottom: 8px;
}
.week-title { text-align: center; display: flex; flex-direction: column; align-items: center; }
.week-title .link-btn { color: var(--primary); }
.week-actions { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 12px; }

/* Board: Zeitskala + 7 Tages-Spalten, horizontal scrollbar */
.board {
  display: flex; gap: 6px; overflow-x: auto;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 8px;
}
.time-ruler {
  flex: none; width: 42px;
  position: sticky; left: -8px; z-index: 3;
  background: var(--card);
}
.ruler-grid { position: relative; }
.ruler-label {
  position: absolute; right: 4px; transform: translateY(-50%);
  font-size: 0.62rem; color: var(--muted); white-space: nowrap;
}
.day-col { flex: 1 0 150px; min-width: 150px; border-radius: 8px; }
.day-col.today .col-header { color: var(--primary); }
.day-col.drop-target { background: #e0e7ff; }
.col-header {
  display: flex; justify-content: space-between; align-items: baseline;
  font-weight: 600; font-size: 0.85rem; padding: 4px 4px 6px; min-height: 27px;
}
.col-total { font-weight: 400; font-size: 0.7rem; color: var(--muted); }
/* Zeitraster: feine Linie je 30 min, kräftigere je Stunde */
.col-grid {
  position: relative;
  background:
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.10) 0 1px, transparent 1px 60px),
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.045) 0 1px, transparent 1px 30px);
}

/* Aufgabenkarte */
.task {
  display: flex; align-items: flex-start; gap: 6px;
  border-left: 4px solid var(--assignee, #cbd5e1);
  background: #f9fafb; border-radius: 6px;
  padding: 4px 6px; cursor: grab;
  min-height: 40px; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07);
  /* Touch: Wischen/Scrollen bleibt nativ, Drag startet erst per langem Drücken */
  touch-action: pan-x pan-y;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.task.timed { position: absolute; left: 2px; right: 2px; overflow: hidden; z-index: 2; }
/* ohne feste Uhrzeit (automatisch einsortiert): gestrichelter Rand */
.task.auto { border-left-style: dashed; }
.task.dragging { opacity: 0.35; }
.task.done { opacity: 0.55; }
.task.done .task-name { text-decoration: line-through; }
.drag-ghost {
  position: fixed; z-index: 100; pointer-events: none;
  opacity: 0.92; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
}
.no-select, .no-select * { user-select: none; -webkit-user-select: none; }
.task-check {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border); background: #fff;
  font-size: 0.72rem; line-height: 1; cursor: pointer; padding: 0;
}
.task.done .task-check { background: #16a34a; border-color: #16a34a; color: #fff; }
.task-main { flex: 1; min-width: 0; }
.task-name { font-size: 0.76rem; line-height: 1.25; }
.task-meta { display: flex; gap: 4px; align-items: center; margin-top: 2px; flex-wrap: wrap; }
.chip {
  font-size: 0.62rem; color: var(--muted); background: #eef0f3;
  border-radius: 999px; padding: 0 6px; white-space: nowrap;
}
.chip.stars { color: var(--star); background: #fef3c7; font-weight: 600; }
.avatar {
  flex: none; width: 20px; height: 20px; border-radius: 50%;
  color: #fff; font-size: 0.58rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  background: var(--assignee, #cbd5e1);
}
.avatar.unassigned { color: var(--muted); border: 1px dashed var(--muted); background: #fff; }

/* --- Belohnungen --- */
.balances { display: flex; gap: 12px; }
.balance-card {
  flex: 1; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; text-align: center;
  border-top: 4px solid var(--user-color, var(--primary));
}
.balance-card .balance-name { font-weight: 600; }
.balance-card .balance-stars { font-size: 1.6rem; font-weight: 700; color: var(--star); }
.balance-card .balance-next { font-size: 0.78rem; color: var(--muted); margin-top: 4px; }
.progress { height: 6px; background: var(--border); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.progress > div { height: 100%; background: var(--star); }

.section-title { font-size: 1rem; margin: 20px 0 8px; }
.reward {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px; margin-bottom: 8px;
}
.reward.inactive { opacity: 0.5; }
.reward-name { cursor: pointer; }
.reward-cost { color: var(--star); font-weight: 700; white-space: nowrap; }
.history { list-style: none; padding: 0; margin: 0; }
.history li {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 8px 4px; border-bottom: 1px solid var(--border); font-size: 0.88rem;
}
.history .delta-plus { color: #16a34a; font-weight: 600; }
.history .delta-minus { color: var(--danger); font-weight: 600; }
.history .who { color: var(--muted); }

/* --- Katalog --- */
.hint { color: var(--muted); font-size: 0.85rem; }
.category-title { font-size: 0.85rem; color: var(--muted); margin: 16px 0 6px; text-transform: uppercase; letter-spacing: 0.04em; }
.chore-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px 12px; margin-bottom: 6px; cursor: pointer;
}
.chore-row.inactive { opacity: 0.5; }
.chore-row .chore-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 3px; }

/* --- Tab-Bar --- */
.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; background: var(--card); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-btn {
  flex: 1; background: none; border: none; padding: 8px 0 6px;
  font-size: 1.2rem; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab-btn span { font-size: 0.7rem; }
.tab-btn.active { color: var(--primary); font-weight: 600; }

/* --- Overlay / Sheet --- */
.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
}
.overlay[hidden] { display: none; }
.sheet {
  background: var(--card); border-radius: 16px 16px 0 0;
  width: 100%; max-width: 720px; padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  max-height: 85vh; overflow-y: auto;
}
.sheet h3 { margin: 0 0 4px; }
.sheet .sheet-sub { color: var(--muted); font-size: 0.85rem; margin: 0 0 12px; }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; }
.sheet-actions button { width: 100%; text-align: center; }
.sheet form { display: flex; flex-direction: column; gap: 8px; }
.sheet label { font-size: 0.82rem; color: var(--muted); }
.sheet input, .sheet select, .sheet textarea {
  padding: 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 1rem; width: 100%; background: #fff;
}
.form-row { display: flex; gap: 8px; }
.form-row > div { flex: 1; }
.sheet .form-buttons { display: flex; gap: 8px; margin-top: 8px; }
.sheet .form-buttons button { flex: 1; }

@media (min-width: 720px) {
  .balances { max-width: 480px; }
}

/* Handy: ein Tag füllt den Schirm, Wischen springt zum nächsten Tag */
@media (max-width: 700px) {
  .board {
    scroll-snap-type: x mandatory;
    scroll-padding-left: 48px; /* Platz der fixen Zeitskala */
  }
  .day-col {
    flex: 0 0 calc(100% - 48px);
    min-width: 0;
    scroll-snap-align: start;
  }
}
