:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --text: #2b2b28;
  --text-muted: #6b6b64;
  --border: #e6e1d6;
  --green: #4c9a72;
  --green-bg: #e4f2ea;
  --blue: #4d76c9;
  --blue-bg: #e6edfb;
  --red: #c0564d;
  --red-bg: #f8e7e5;
  --accent: #3f6f5e;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1b18;
    --surface: #262521;
    --text: #efece5;
    --text-muted: #a8a49a;
    --border: #3a3833;
    --green: #6fbd93;
    --green-bg: #1f3329;
    --blue: #7fa2e6;
    --blue-bg: #1f2b3f;
    --red: #d98077;
    --red-bg: #3a2320;
    --accent: #7fbfa6;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior-y: none;
}

body {
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

.topbar {
  padding: env(safe-area-inset-top) 20px 12px 20px;
  text-align: center;
}
.topbar h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent);
  margin: 10px 0 0 0;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  padding: 0 16px 24px 16px;
}

h2 { font-size: 1.1rem; margin: 8px 0 12px; }
h3 { font-size: 0.95rem; margin: 20px 0 8px; color: var(--text-muted); }

.identity-main {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0 0 8px 0;
  line-height: 1.35;
  text-align: center;
}

.banner {
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 0.88rem;
  margin: 10px 0;
  line-height: 1.4;
}
.banner-danger { background: var(--red-bg); color: var(--text); border: 1px solid var(--red); font-weight: 600; }
.hidden { display: none !important; }

.big-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 10px 0 16px;
}
.big-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 16px 18px;
  border-radius: var(--radius);
  border: 2px solid transparent;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 56px;
  color: var(--text);
  transition: transform 0.05s ease;
}
.big-btn:active { transform: scale(0.98); }
.btn-green { background: var(--green-bg); }
.btn-blue { background: var(--blue-bg); }
.btn-red { background: var(--red-bg); }
.big-btn.selected { border-color: currentColor; }
.big-btn.btn-green.selected { border-color: var(--green); }
.big-btn.btn-blue.selected { border-color: var(--blue); }
.big-btn.btn-red.selected { border-color: var(--red); }
.big-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.cal-nav {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 32px;
  height: 32px;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text);
  flex-shrink: 0;
}

/* Forms */
form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--text-muted); }
input[type="text"], input[type="date"], input[type="time"] {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--text);
}
.primary-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

/* Stats */
.stat-bars {
  display: flex;
  height: 28px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}
.stat-bars > div { height: 100%; }
.stat-bar-green { background: var(--green); }
.stat-bar-blue { background: var(--blue); }
.stat-bar-red { background: var(--red); }
.stat-legend { list-style: none; padding: 0; margin: 0 0 16px; font-size: 0.85rem; }
.stat-legend li { display: flex; justify-content: space-between; padding: 4px 0; align-items: center; }
.stat-legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot-green { background: var(--green); }
.dot-blue { background: var(--blue); }
.dot-red { background: var(--red); }

/* Day editor modal */
.day-editor {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
}
.day-editor.hidden { display: none; }
.day-editor-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}
.day-editor-card {
  position: relative;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 18px 18px calc(24px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.2);
}
.day-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-weight: 700;
  font-size: 1rem;
}
.day-editor-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
}
.day-editor-planned {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0 0 12px;
}
.day-editor-plan {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.text-btn {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--red);
  font-size: 0.85rem;
  padding: 10px 0 0;
  text-align: center;
  cursor: pointer;
}

/* Loading overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.loading-overlay.hidden { display: none; }
.loading-spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-error {
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.loading-error.hidden { display: none; }
.loading-error .primary-btn { width: auto; padding: 10px 20px; }

/* Weeks strip (rolling 4-week overview) */
.weeks-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 16px 0;
}
.weeks-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.weeks-range {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
  text-align: center;
  flex: 1;
}
.weeks-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 0.62rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.weeks-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}
.ws-cell {
  aspect-ratio: 1;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.ws-cell.state-green { background: var(--green); }
.ws-cell.state-blue { background: var(--blue); }
.ws-cell.state-red { background: var(--red); }
.ws-cell.planned-only {
  background: var(--blue-bg);
  border-style: dashed;
  border-width: 2px;
  border-color: var(--blue);
}
.ws-cell.future { opacity: 0.55; }
.ws-cell.future.planned-only { opacity: 1; }
.ws-cell.is-today {
  box-shadow: 0 0 0 2px var(--accent);
}
.ws-cell.double-red::before {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 1px var(--surface);
}

/* Collapsible sections (Kalender, Planung, Statistik, Einstellungen) */
.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 16px 0;
  overflow: hidden;
}
.section-card summary {
  list-style: none;
  cursor: pointer;
  padding: 16px 18px;
  font-weight: 700;
  font-size: 0.98rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  -webkit-tap-highlight-color: transparent;
}
.section-card summary::-webkit-details-marker { display: none; }
.section-card summary::after {
  content: '\203A';
  transform: rotate(90deg);
  color: var(--text-muted);
  font-size: 1.1rem;
  transition: transform 0.15s ease;
}
.section-card[open] summary::after { transform: rotate(-90deg); }
.section-card[open] summary {
  border-bottom: 1px solid var(--border);
}

/* Identity + Statistik merged card: identity sentence is the tap target,
   no separate "Statistik" label — chevron sits centered below the text. */
.identity-details summary {
  flex-direction: column;
  justify-content: flex-start;
  gap: 8px;
  padding: 18px 18px 14px;
}
.section-card .section-body {
  padding: 16px 18px 18px;
}
.section-card .section-body h2:first-child,
.section-card .section-body h3:first-child { margin-top: 0; }
