:root {
  --font: "Fira Sans Condensed", sans-serif;
  --bg: #dff0f5;
  --surface: #ffffff;
  --text: #1a4d28;
  --muted: #4a7a5a;
  --accent: #2d7a3a;
  --border: #b0d4bc;
  --brand: #d96a00;
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --text: #c9d1d9;
  --muted: #6e7681;
  --accent: #3fb950;
  --border: #30363d;
  --brand: #ff8a2a;
}

* { box-sizing: border-box; }

html, body { height: 100%; width: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.app-header[hidden] {
  display: none;
}

.menu-panel {
  position: absolute;
  top: 58px;
  right: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  min-width: 180px;
  z-index: 20;
  overflow: hidden;
}
#menu-panel { top: 44px; right: 0; }

.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  background: none;
  border: none;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}
.menu-item:hover { background: var(--bg); }
.menu-item.active { color: var(--accent); font-weight: 700; }

.icon-wrap { position: relative; display: inline-flex; flex: none; }
.view-panel { top: 44px; left: 0; right: auto; min-width: 140px; }

.calendar-panel { top: 44px; left: auto; right: 0; min-width: 200px; padding: 4px 0; }
.cal-item { display: flex; align-items: center; gap: 8px; padding: 8px 14px; cursor: pointer; font-size: 14px; color: var(--text); }
.cal-item:hover { background: var(--bg); }
.cal-item input { margin: 0; flex: none; cursor: pointer; accent-color: var(--accent); }
.cal-chip { min-width: 0; padding: 2px 10px; border-radius: 999px; color: #fff; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-item:has(input:not(:checked)) .cal-chip { opacity: 0.35; }
.cal-all { border-bottom: 1px solid var(--border); font-weight: 600; }

h1.app-title {
  font-size: 18px;
  font-weight: 800;
  margin: 0;
  color: var(--accent);
  text-align: center;
}
:root[data-theme="dark"] h1.app-title {
  color: var(--brand) !important;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 6px 4px 14px;
}

.search-bar input[type="search"] {
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  font-family: var(--font);
  font-size: 15px;
  color: var(--text);
  padding: 8px 4px;
}
.search-bar input[type="search"]:focus { outline: none; }
.search-bar input[type="search"]::-webkit-search-cancel-button { display: none; }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: none;
  color: var(--muted);
  padding: 0;
  cursor: pointer;
  flex: none;
}
.icon-btn:hover { background: var(--border); }
.search-bar .search-icon { color: var(--muted); cursor: default; }
.search-bar .search-icon:hover { background: none; }

.date-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
}
.date-nav[hidden] { display: none; }

.date-nav button {
  background: none;
  border: none;
  font-size: 22px;
  padding: 4px 12px;
  cursor: pointer;
  color: var(--accent);
}

#current-label {
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
  border-radius: 6px;
  padding: 4px 10px;
}
#current-label:hover {
  background: var(--bg);
}

#content-area {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#content-area[hidden] {
  display: none;
}

#view-root {
  flex: 1;
  width: 100%;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 12px 80px 12px;
}

#view-root.month-active {
  display: flex;
  flex-direction: column;
  width: 100%;
  overflow: hidden;
  padding-bottom: 12px;
}
#view-root.month-active .weekday-header { flex: none; width: 100%; }
#view-root.month-active .month-grid {
  flex: 1;
  width: 100%;
  min-height: 0;
  grid-template-rows: repeat(6, minmax(0, 1fr));
}

.event-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.event-card {
  background: var(--surface);
  border-left: 5px solid var(--accent);
  border-radius: 6px;
  padding: 10px 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  cursor: pointer;
  margin-bottom: 8px;
}
.event-card.today { border-right: 5px solid var(--accent); }
.event-card .time { font-size: 12px; color: var(--muted); font-weight: 600; }
.event-card .title { font-size: 15px; font-weight: 600; }
.event-card .event-link { margin-left: 6px; text-decoration: none; font-size: 13px; }
.event-card .location { font-size: 12px; color: var(--muted); }
.day-group-label { font-size: 13px; font-weight: 700; color: var(--muted); margin: 16px 0 6px; text-transform: uppercase; }

.day-timeline { display: flex; flex-direction: column; }
.muted { color: var(--muted); }

.week-grid { display: grid; gap: 4px; padding-bottom: 4px; }
.week-grid.horizontal { grid-template-columns: repeat(7, minmax(110px, 1fr)); overflow-x: auto; }
.week-grid.vertical { grid-template-columns: 1fr; }
.week-day { background: var(--surface); border-radius: 6px; padding: 6px; cursor: pointer; }
.week-grid.horizontal .week-day { min-height: 100px; }
.week-grid.vertical .week-day { min-height: 44px; }
.week-day .day-num { margin-bottom: 4px; }
.week-day .day-num-row { flex-direction: row; align-items: center; gap: 6px; margin-bottom: 4px; }
.week-chips { display: flex; flex-direction: column; }
.week-day .chip { font-size: 11px; background: var(--accent); color: #fff; border-radius: 4px; padding: 2px 4px; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.week-bar {
  color: #fff;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  z-index: 1;
}
.week-bar.horizontal {
  align-self: start;
  margin: 0 1px;
  height: 18px;
  line-height: 18px;
  font-size: 11px;
  padding: 0 6px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.week-bar.vertical {
  justify-self: start;
  width: 12px;
  margin: 2px 0;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 10px;
  line-height: 12px;
  padding: 6px 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.month-cell { background: var(--surface); border-radius: 4px; padding: 4px; font-size: 11px; cursor: pointer; min-width: 0; overflow: hidden; }
.month-cell.other-month { opacity: 0.35; }
.day-num { font-weight: 700; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.day-num span:last-child { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; }
.day-num.today span:last-child { background: var(--accent); color: #fff; }
.weekday-label { font-size: 11px; font-weight: 600; color: var(--muted); }
.pill-stack { display: flex; flex-direction: column; gap: 2px; margin-top: 3px; min-width: 0; }
.pill { display: block; font-size: 10px; line-height: 1.4; color: #fff; border-radius: 4px; padding: 1px 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.month-bar {
  align-self: start;
  margin-left: 1px;
  margin-right: 1px;
  height: 15px;
  font-size: 9px;
  line-height: 15px;
  color: #fff;
  padding: 0 4px;
  border-radius: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  z-index: 1;
}
.pill-more { background: var(--muted); }
.weekday-header { display: grid; grid-template-columns: repeat(7, 1fr); font-size: 11px; font-weight: 700; color: var(--muted); text-align: center; margin-bottom: 4px; }
.weekday-header span { min-width: 0; overflow: hidden; }

@media (max-width: 350px) {
  .month-cell { padding: 2px; font-size: 10px; min-height: 78px; }
  .pill { font-size: 9px; padding: 1px 2px; }
}

@media (max-width: 640px) {
  :root[data-theme="dark"] .month-cell { background: var(--bg); }
}

.header-top { position: relative; }

.fab {
  position: absolute;
  top: 50%;
  /* 48px = zentriert auf #btn-jump-now in der Suchleiste darunter:
     6px Suchleisten-Padding + 36px Menue-Icon + 4px Gap + 18px halbe
     Icon-Breite von btn-jump-now, minus 16px halbe FAB-Breite */
  right: 48px;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  border: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  cursor: pointer;
}

dialog { border: none; border-radius: 10px; padding: 0; width: min(420px, 92vw); font-family: var(--font); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,0.4); }
#event-form { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
#event-form h2 { margin: 0 0 4px; font-size: 18px; }
#event-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
#event-form input, #event-form select, #event-form textarea { font-family: var(--font); font-size: 15px; padding: 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); resize: vertical; }

.more-toggle { align-self: flex-start; background: none; border: none; padding: 4px 0; color: var(--accent); font-family: var(--font); font-size: 14px; font-weight: 600; cursor: pointer; }
.more-toggle[hidden] { display: none; }
#more-fields { display: flex; flex-direction: column; gap: 10px; }
#more-fields[hidden] { display: none; }

.cal-select { position: relative; }
.cal-select-btn { display: inline-flex; align-items: center; width: 100%; text-align: left; font-family: var(--font); font-size: 15px; padding: 7px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); cursor: pointer; }
.cal-select-panel { top: calc(100% + 4px); left: 0; right: auto; min-width: 200px; padding: 4px 0; }
.cal-select-item { display: block; width: 100%; text-align: left; background: none; border: none; padding: 6px 12px; cursor: pointer; }
.cal-select-item:hover { background: var(--bg); }

.date-field { display: flex; align-items: center; gap: 6px; }
.date-input { flex: 1; min-width: 0; }
.time-input { flex: 0 0 56px; min-width: 0; text-align: center; }
.date-pick-btn { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; flex: none; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--muted); cursor: pointer; }
.date-pick-btn:hover { background: var(--bg); color: var(--text); }
.date-pick-btn[hidden] { display: none; }

#event-form .allday-row { flex-direction: row; align-items: center; justify-content: space-between; font-size: 14px; color: var(--text); }
#event-form .allday-row input { width: 18px; height: 18px; padding: 0; accent-color: var(--accent); cursor: pointer; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.dialog-actions button { padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-family: var(--font); cursor: pointer; }
#event-save { background: var(--accent); color: #fff; border-color: var(--accent); }
.danger { color: #b3261e; border-color: #b3261e; margin-right: auto; }

.about-content { padding: 20px; text-align: center; }
.about-content h2 { margin: 0 0 4px; font-size: 20px; }
.about-version { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.about-stats { list-style: none; padding: 0; margin: 0 0 16px; display: flex; justify-content: center; gap: 22px; }
.about-stats li { font-size: 12px; color: var(--muted); }
.about-stats span { display: block; font-size: 20px; font-weight: 700; color: var(--text); }
.about-note { font-size: 12px; color: var(--muted); margin: 0 0 16px; }
.about-debug { font-size: 11px; font-family: monospace; color: var(--muted); margin: 0; }

@media (min-width: 720px) {
  #view-root { max-width: 900px; margin: 0 auto; padding: 20px; }
  .app-header { padding-left: max(16px, calc(50% - 450px)); padding-right: max(16px, calc(50% - 450px)); }
}

/* Emulator ist ein Desktop-Testwerkzeug, auf echten Touch-Geraeten sinnlos */
@media (hover: none) and (pointer: coarse) {
  .emu-control { display: none; }
}

.emu-control {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 1000;
}

.emu-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}
.emu-btn:hover { background: var(--bg); }

.emu-panel {
  position: absolute;
  top: 40px;
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  min-width: 160px;
  overflow: hidden;
}

.device-frame-wrap {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 28px;
  background: var(--bg);
  min-height: 100vh;
}
.device-frame-wrap[hidden] {
  display: none;
}
.device-frame-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  font-family: var(--font);
}

.device-screen {
  box-sizing: content-box;
  position: relative;
  overflow: hidden;
  background: #fff;
  border: 10px solid #1c1c1e;
  border-radius: 32px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.35);
}
.device-screen::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #1c1c1e;
  z-index: 2;
}

#device-frame {
  display: block;
  border: none;
  transform-origin: top left;
}

