:root {
  --bg: #0f1721;
  --bg-elevated: #161f2c;
  --bg-card: #1b2632;
  --border: #2a3745;
  --text: #e7edf3;
  --text-dim: #8b9bab;
  --accent: #38bdf8;
  --accent-dim: #1c4a5e;
  --ok: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;
  --touch: 48px;
  font-size: 16px;
}

* { box-sizing: border-box; }

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

body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button {
  font: inherit;
  color: inherit;
}

input, textarea, select {
  font: inherit;
  color: inherit;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
}

#offline-banner {
  display: none;
  background: var(--warn);
  color: #1a1400;
  font-size: 0.85rem;
  text-align: center;
  padding: 6px 12px;
}
#offline-banner.show { display: block; }
#offline-banner .count { font-weight: 700; }

/* --- Login --- */

#login-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 16px;
}
#login-screen h1 { font-size: 1.4rem; margin: 0 0 8px; }
#login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}
#login-form input {
  padding: 14px;
  font-size: 1.4rem;
  text-align: center;
  letter-spacing: 0.3em;
  min-height: var(--touch);
}
#login-form button {
  padding: 14px;
  min-height: var(--touch);
  background: var(--accent);
  color: #05202b;
  border: none;
  border-radius: 8px;
  font-weight: 700;
}
#login-error {
  color: var(--danger);
  font-size: 0.9rem;
  min-height: 1.2em;
  text-align: center;
}

/* --- Waiting / Error states --- */

#waiting-screen, #error-screen {
  flex: 1;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 12px;
  text-align: center;
  color: var(--text-dim);
}
#waiting-screen.show, #error-screen.show { display: flex; }

/* --- App shell --- */

#app-screen {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 100vh;
}
#app-screen.show { display: flex; }

header.topbar {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
header.topbar .hebel-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
  padding: 0;
  background: none;
  border: none;
  text-align: left;
  font: inherit;
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
}
header.topbar .hebel-chevron { font-size: 0.9rem; color: var(--text-dim); }
header.topbar .hebel-value { font-size: 1.05rem; font-weight: 600; margin-top: 2px; }
header.topbar .hebel-value.collapsed { display: none; }
header.topbar .date-row { display: flex; justify-content: space-between; align-items: baseline; margin-top: 6px; }
header.topbar .date-row .date { color: var(--text-dim); font-size: 0.85rem; }
header.topbar .streak { color: var(--accent); font-size: 0.85rem; font-weight: 600; }

main { flex: 1; overflow-y: auto; padding: 12px 12px 90px; }

nav.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
nav.tabbar button {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 4px 8px;
  min-height: var(--touch);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--text-dim);
  font-size: 0.72rem;
}
nav.tabbar button .icon { font-size: 1.25rem; }
nav.tabbar button.active { color: var(--accent); }

section.tab-panel { display: none; }
section.tab-panel.active { display: block; }

/* --- Tasks --- */

.block-group { margin-bottom: 18px; }
.block-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 8px 2px;
}

.task-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.task-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: var(--touch);
}
.checkbox {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: 2px solid var(--border);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
  cursor: pointer;
}
.checkbox.done { background: var(--ok); border-color: var(--ok); }
.checkbox.done::after { content: "✓"; color: #06210f; font-weight: 800; }

.task-main { flex: 1; min-width: 0; }
.task-title { font-size: 0.98rem; line-height: 1.3; }
.task-title.done { text-decoration: line-through; color: var(--text-dim); }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; }
.badge {
  font-size: 0.68rem;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.badge.eisbrecher { color: var(--warn); border-color: var(--warn); }
.badge.micro { color: var(--accent); border-color: var(--accent); }
.badge.minutes::before { content: "⏱ "; }

.subtasks { margin-top: 8px; padding-left: 36px; display: flex; flex-direction: column; gap: 6px; }
.subtask-row { display: flex; align-items: center; gap: 8px; min-height: 36px; }
.subtask-row .checkbox { width: 20px; height: 20px; border-radius: 6px; }
.subtask-title { font-size: 0.88rem; }
.subtask-title.done { text-decoration: line-through; color: var(--text-dim); }

.empty-hint { color: var(--text-dim); text-align: center; padding: 32px 12px; font-size: 0.9rem; }

/* --- Habits --- */

.habit-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
}
.habit-header { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.habit-label { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.habit-progress { color: var(--text-dim); font-size: 0.85rem; }
.habit-boxes { display: flex; flex-wrap: wrap; gap: 8px; }
.habit-box {
  width: var(--touch);
  height: var(--touch);
  min-width: 44px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.habit-box.done { background: var(--accent); border-color: var(--accent); }
.habit-box.done::after { content: "✓"; color: #05202b; font-weight: 800; font-size: 1.15rem; }
.habit-box:active { background: var(--accent-dim); }
.info-dot {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 1px solid var(--text-dim);
  color: var(--text-dim);
  font-size: 0.72rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* --- KPIs --- */

.kategorie-title { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); margin: 16px 0 8px 2px; }
.kategorie-title:first-child { margin-top: 0; }
.kpi-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
}
.kpi-label { font-size: 0.92rem; }
.kpi-values { text-align: right; font-size: 0.85rem; }
.kpi-value { font-weight: 700; }
.kpi-value.missing { color: var(--text-dim); font-weight: 400; font-style: italic; }
.kpi-target { color: var(--text-dim); font-size: 0.78rem; }

/* --- Tagesende --- */

.day-picker { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.day-chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-size: 0.85rem;
  min-height: 36px;
}
.day-chip.active { color: #05202b; background: var(--accent); border-color: var(--accent); font-weight: 700; }

.form-field { margin-bottom: 16px; }
.form-field label { display: block; font-size: 0.85rem; color: var(--text-dim); margin-bottom: 6px; }
.form-field input[type="number"],
.form-field textarea {
  width: 100%;
  padding: 12px;
  min-height: var(--touch);
}
.form-field textarea { min-height: 80px; resize: vertical; }
.form-field .char-count { text-align: right; font-size: 0.72rem; color: var(--text-dim); margin-top: 4px; }

.scale-row { display: flex; align-items: center; gap: 10px; }
.scale-row input[type="range"] { flex: 1; height: var(--touch); }
.scale-value { min-width: 2.4ch; text-align: center; font-weight: 700; }

.toggle-row { display: flex; align-items: center; gap: 10px; }
.toggle-row input[type="checkbox"] { width: 26px; height: 26px; }

#tagesende-submit, #retry-btn {
  width: 100%;
  padding: 14px;
  min-height: var(--touch);
  background: var(--accent);
  color: #05202b;
  border: none;
  border-radius: 10px;
  font-weight: 700;
  font-size: 1rem;
  margin-top: 8px;
}
#tagesende-submit:disabled { opacity: 0.5; }
.retry-btn-narrow { max-width: 220px; }
#tagesende-status { text-align: center; margin-top: 10px; font-size: 0.88rem; min-height: 1.2em; }
#tagesende-status.ok { color: var(--ok); }
#tagesende-status.err { color: var(--danger); }

.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.logout-link {
  text-align: center;
  padding: 10px 0 4px;
}
.logout-link button {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.78rem;
  min-height: 32px;
}
