:root {
  --accent: #6D5FE0;
  --accent-dark: #5647c9;
  --accent-light: #ede9ff;
  --danger: #e0405f;
  --text: #26243a;
  --muted: #7a7791;
  --bg: #f6f5fb;
  --card-bg: #ffffff;
  --border: #e4e1f2;
  --radius: 14px;
  color-scheme: light;
}

* { 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;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 14px) 18px 14px;
  background: var(--accent);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { font-size: 1.15rem; margin: 0; font-weight: 600; }

.btn-icon {
  background: rgba(255,255,255,.15);
  border: none;
  color: #fff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 14px 40px;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 18px 16px 22px;
  box-shadow: 0 1px 3px rgba(30, 20, 60, .06);
  margin-bottom: 22px;
}

/* ── Tabs ── */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab-btn {
  flex: 1;
  padding: 11px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-weight: 600;
  font-size: .88rem;
  cursor: pointer;
}
.tab-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Kalender ── */
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.calendar-month-label { font-weight: 700; font-size: 1rem; }
.btn-icon-small {
  background: var(--accent-light);
  border: none;
  color: var(--accent-dark);
  width: 34px;
  height: 34px;
  border-radius: 9px;
  font-size: 1.2rem;
  cursor: pointer;
}
.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  font-size: .72rem;
  color: var(--muted);
  text-align: center;
  margin-bottom: 6px;
}
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.calendar-day {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .82rem;
  font-weight: 600;
  background: var(--bg);
  color: var(--text);
}
.calendar-day.empty { visibility: hidden; }
.calendar-day.neutral { background: var(--bg); color: var(--muted); font-weight: 400; }
.calendar-day.clickable { cursor: pointer; }
.calendar-day .migraine-mark {
  position: absolute;
  top: 1px;
  right: 3px;
  font-size: .58rem;
  font-weight: 900;
  line-height: 1;
  color: #fff;
  text-shadow: 0 0 2px rgba(0, 0, 0, .5);
}
.calendar-day.today { box-shadow: 0 0 0 2px var(--accent-dark) inset; }
.calendar-legend {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 12px;
  font-size: .75rem;
  color: var(--muted);
}
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.legend-free { background: #4ade80; }
.legend-mild { background: hsl(80, 65%, 50%); }
.legend-strong { background: hsl(0, 65%, 50%); }
.calendar-day-detail {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: .85rem;
}
.calendar-day-entry { padding: 6px 0; display: flex; align-items: center; gap: 8px; }
.calendar-day-entry .badge-inline {
  min-width: 26px;
  height: 26px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: .78rem;
  flex-shrink: 0;
}

/* ── Dashboard ── */
.dashboard-title { margin-top: 0; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.stat-tile { background: var(--bg); border-radius: 10px; padding: 14px 10px; text-align: center; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--accent-dark); line-height: 1.1; }
.stat-label { font-size: .74rem; color: var(--muted); margin-top: 4px; line-height: 1.3; }
.breakdown-block { margin-top: 18px; }
.breakdown-block h3 { font-size: .88rem; margin: 0 0 8px; color: var(--text); }
.breakdown-row { display: flex; justify-content: space-between; font-size: .84rem; padding: 5px 0 2px; }
.breakdown-bar-wrap { background: var(--border); border-radius: 4px; height: 6px; overflow: hidden; margin-bottom: 8px; }
.breakdown-bar { height: 100%; background: var(--accent); width: 0; }

.motivation {
  background: linear-gradient(135deg, var(--accent-light), #fdf2ff);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 18px;
  text-align: center;
  color: var(--accent-dark);
  font-size: .88rem;
  line-height: 1.5;
}
.motivation-streak {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  margin-bottom: 4px;
}

label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--muted);
  margin: 16px 0 6px;
}
label:first-child { margin-top: 0; }
.big-label { font-size: 1rem; color: var(--text); margin-top: 20px; }
.optional { font-weight: 400; text-transform: none; color: var(--muted); }

input[type="date"], input[type="time"], input[type="number"], input[type="text"],
input[type="password"], textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Farbverlauf 1..10 identisch zur heatColor()-Formel im Kalender/Verlauf
   (hue 100=Gelbgrün bei 1 bis hue 0=Rot bei 10, 65% Sättigung, 50% Helligkeit) */
.intensity-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 40px;
  background: transparent;
  --thumb-color: #6D5FE0;
}
.intensity-slider::-webkit-slider-runnable-track {
  height: 10px;
  border-radius: 6px;
  background: linear-gradient(to right,
    hsl(100, 65%, 50%), hsl(88.9, 65%, 50%), hsl(77.8, 65%, 50%), hsl(66.7, 65%, 50%), hsl(55.6, 65%, 50%),
    hsl(44.4, 65%, 50%), hsl(33.3, 65%, 50%), hsl(22.2, 65%, 50%), hsl(11.1, 65%, 50%), hsl(0, 65%, 50%));
}
.intensity-slider::-moz-range-track {
  height: 10px;
  border-radius: 6px;
  background: linear-gradient(to right,
    hsl(100, 65%, 50%), hsl(88.9, 65%, 50%), hsl(77.8, 65%, 50%), hsl(66.7, 65%, 50%), hsl(55.6, 65%, 50%),
    hsl(44.4, 65%, 50%), hsl(33.3, 65%, 50%), hsl(22.2, 65%, 50%), hsl(11.1, 65%, 50%), hsl(0, 65%, 50%));
}
.intensity-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -9px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--thumb-color);
  box-shadow: 0 1px 4px rgba(30, 20, 60, .3);
}
.intensity-slider::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--thumb-color);
  box-shadow: 0 1px 4px rgba(30, 20, 60, .3);
}
#intensity-value { font-weight: 700; }

.migraine-toggle {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
}
.migraine-toggle[aria-pressed="true"] {
  background: #6D28D9;
  border-color: #6D28D9;
  color: #fff;
}

.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.choice {
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 10px 14px;
  border-radius: 999px;
  font-size: .92rem;
  cursor: pointer;
  min-height: 40px;
  transition: background .12s, border-color .12s, color .12s;
}
.choice.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.choices.scale-5 .choice { flex: 1 1 auto; text-align: center; padding: 10px 6px; font-size: .82rem; }

fieldset {
  border: none;
  padding: 0;
  margin: 0 0 4px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
fieldset:first-of-type { border-top: none; padding-top: 0; }
legend {
  font-weight: 700;
  color: var(--text);
  padding: 0;
  font-size: .95rem;
}

.more-details {
  margin-top: 18px;
  border-top: 1px solid var(--border);
  padding-top: 4px;
}
.more-details summary {
  cursor: pointer;
  padding: 10px 0;
  font-weight: 600;
  color: var(--accent-dark);
  list-style: none;
}
.more-details summary::-webkit-details-marker { display: none; }
.more-details summary::before { content: "▸ "; }
.more-details[open] summary::before { content: "▾ "; }

.weather-preview {
  background: var(--accent-light);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: .85rem;
  color: var(--accent-dark);
  margin: 14px 0 4px;
  line-height: 1.5;
}

.btn {
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  padding: 14px;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-dark); }
.btn-block { width: 100%; }
.btn-save { margin-top: 22px; }

.save-status {
  text-align: center;
  margin-top: 10px;
  font-size: .88rem;
  color: var(--accent-dark);
}
.error { color: var(--danger); font-size: .88rem; margin-top: 10px; }

.history h2 { font-size: 1.05rem; margin: 0 0 12px 4px; }
.history-list { display: flex; flex-direction: column; gap: 10px; }
.muted { color: var(--muted); padding: 4px; }

.entry-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 1px 2px rgba(30,20,60,.05);
}
.entry-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}
.entry-date { font-weight: 600; font-size: .92rem; }
.entry-sub { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.entry-badge {
  min-width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  font-size: .95rem;
}
.entry-detail {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: .85rem;
  color: var(--text);
  display: none;
}
.entry-detail.open { display: block; }
.entry-detail dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; }
.entry-detail dt { color: var(--muted); }
.entry-detail dd { margin: 0; }
.entry-actions { margin-top: 10px; display: flex; gap: 8px; }
.btn-small {
  border: 1.5px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: .82rem;
  cursor: pointer;
  color: var(--text);
}
.btn-small.danger { color: var(--danger); border-color: var(--danger); }

/* ── Login ── */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 32px 26px;
  box-shadow: 0 4px 18px rgba(30,20,60,.1);
  max-width: 340px;
  width: 100%;
  text-align: center;
}
.login-icon { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 14px; }
.login-card h1 { font-size: 1.2rem; margin: 0 0 22px; }
.login-card label { text-align: left; }
.login-card .btn { margin-top: 18px; }
