:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --text: #1c2430;
  --muted: #6b7686;
  --line: #e3e8ee;
  --accent: #3b7ddd;
  --today: #fff4d6;
  --other-month: #f7f9fb;
  --radius: 16px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b;
    --panel: #1a2029;
    --text: #e8edf3;
    --muted: #8a95a5;
    --line: #2a323e;
    --accent: #6ea4f4;
    --today: #3a3220;
    --other-month: #151a22;
  }
}

* { box-sizing: border-box; }

html {
  height: 100%;
  margin: 0;
  /* Schrift wächst mit dem Bildschirm: Wandtablet wird aus Distanz gelesen */
  font-size: clamp(15px, 1.15vw + 4px, 24px);
}

body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Touch-Betrieb: kein Markieren, kein Pull-to-Refresh, kein Doppeltipp-Zoom */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}
input, textarea { -webkit-user-select: text; user-select: text; }

.dashboard {
  height: 100%;
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  padding: 16px;
}

.side {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 16px;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

h1, h2, h3 { margin: 0; font-weight: 650; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }

button { font: inherit; color: inherit; cursor: pointer; }

.icon-btn, .text-btn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 14px;
  min-height: 44px; /* Fingerfreundlich */
}
.icon-btn { width: 48px; font-size: 1.6rem; line-height: 1; padding: 0; }
.icon-btn:hover, .text-btn:hover { background: var(--bg); }
.text-btn { font-size: .9rem; }

.status { font-size: .8rem; color: var(--muted); }
.status.err { color: #d64545; }

/* ---------- Kalender ---------- */
.cal-head, .panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.cal-nav { display: flex; gap: 8px; }
.clock { text-align: center; line-height: 1.1; flex: 1; }
.clock-time { font-size: 2rem; font-weight: 300; font-variant-numeric: tabular-nums; }
.clock-date { font-size: .9rem; color: var(--muted); }

.weekdays, .grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}
.weekdays div {
  text-align: center;
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  padding-bottom: 6px;
}

.grid {
  flex: 1;
  min-height: 0;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.day {
  background: var(--panel);
  padding: 4px 5px;
  min-height: 0;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.day.other { background: var(--other-month); }
.day.other .num { color: var(--muted); opacity: .6; }
.day.today { background: var(--today); }
.day.today .num { background: var(--accent); color: #fff; }

.num {
  align-self: flex-start;
  font-size: .85rem;
  font-weight: 600;
  min-width: 1.6em;
  height: 1.6em;
  line-height: 1.6em;
  text-align: center;
  border-radius: 1em;
  padding: 0 4px;
  flex: none;
}

.ev {
  font-size: .78rem;
  line-height: 1.5;
  height: 1.5em;
  padding: 0 5px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: none;
  border-left: 3px solid var(--c);
  background: color-mix(in srgb, var(--c) 16%, transparent);
}
.ev.allday {
  background: var(--c);
  border-left-color: transparent;
  color: #fff;
}
.ev .t { opacity: .7; margin-right: 4px; }
.more { font-size: .72rem; color: var(--muted); padding-left: 3px; flex: none; }

.cal-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  min-height: 20px;
}
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .85rem; color: var(--muted); }
.legend span::before {
  content: "";
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--c);
  margin-right: 6px;
}

/* ---------- Einkaufsliste ---------- */
.add-form { display: flex; gap: 8px; margin-bottom: 10px; }
.add-form input, .notes textarea {
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 12px;
  min-width: 0;
}
.add-form input { flex: 1; }
.add-form input:focus, .notes textarea:focus { outline: none; border-color: var(--accent); }
.add-btn {
  width: 42px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 4px;
  border-bottom: 1px solid var(--line);
}
.list input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.list .txt { flex: 1; overflow-wrap: anywhere; }
.list li.done .txt { text-decoration: line-through; color: var(--muted); }
.list .del {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.3rem;
  padding: 0 6px;
}
.list .del:hover { color: #d64545; }
.empty { color: var(--muted); font-size: .9rem; padding: 8px 4px; border: none !important; }

/* ---------- Notizen ---------- */
.notes textarea {
  flex: 1;
  min-height: 0;
  resize: none;
  line-height: 1.5;
}

/* ---------- Tages-Dialog ---------- */
dialog {
  border: none;
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 18px 20px;
  width: min(440px, 92vw);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.day-events { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.day-events li {
  border-left: 4px solid var(--c);
  background: color-mix(in srgb, var(--c) 12%, transparent);
  border-radius: 6px;
  padding: 6px 10px;
}
.day-events .when { font-size: .85rem; color: var(--muted); }
.day-events .where { font-size: .85rem; color: var(--muted); }

/* ---------- Anmeldung ---------- */
.login {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.login[hidden] { display: none; }
.login-box {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
  padding: 28px;
  width: min(360px, 100%);
  display: grid;
  gap: 14px;
}
.login-box input {
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px 14px;
}
.login-box input:focus { outline: none; border-color: var(--accent); }
.login-btn {
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  padding: 12px;
  min-height: 48px;
  font-weight: 600;
}

/* ---------- Schmale Bildschirme ---------- */
@media (max-width: 900px) {
  html, body { height: auto; }
  .dashboard { height: auto; grid-template-columns: 1fr; }
  .calendar { height: 80vh; }
  .side { grid-template-rows: auto; }
  .shopping, .notes { height: 50vh; }
}
