@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;700&family=Inter:wght@400;500;600&display=swap');

:root {
  --bg: #F1EEFB;
  --ink: #2B2540;
  --ink-soft: #6B6480;
  --card: #FFFFFF;
  --highlight: #FFD166;
  --success: #4CAF7D;
  --skip: #9B8FC7;
  --danger: #D1667A;
  --radius-lg: 24px;
  --radius-md: 18px;
}

* { box-sizing: border-box; }

html {
  overscroll-behavior-y: none;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', sans-serif;
  padding: 20px;
  overscroll-behavior-y: none;
}

h1, .display {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  margin: 0;
}

.app {
  max-width: 420px;
  margin: 0 auto;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-bottom: 10px;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--card);
  color: var(--ink);
  font-size: 18px;
  flex-shrink: 0;
  text-decoration: none;
  transition: background 0.15s ease, transform 0.1s ease;
}

.icon-btn:hover {
  background: var(--highlight);
}

.icon-btn:active {
  transform: scale(0.94);
}

/* ---------- Settings page ---------- */

.settings-page {
  max-width: 420px;
  margin: 0 auto;
}

.settings-header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 44px;
  margin-bottom: 20px;
}

.settings-title {
  font-size: 28px;
  margin: 0 4px 0 4px;
  flex: 1;
}

.settings-header-logout {
  margin-left: auto;
}

.totp-qr-wrap {
  display: flex;
  justify-content: center;
  background: #fff;
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 14px;
}

.totp-qr {
  width: 160px;
  height: 160px;
  display: block;
}

.totp-secret-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.totp-copy-btn {
  flex-shrink: 0;
  padding: 10px 12px;
}

input.totp-secret-input {
  flex: 1;
  min-width: 0;
  font-family: 'Baloo 2', sans-serif;
  font-size: 13px;
  letter-spacing: 0.02em;
  text-align: center;
  cursor: text;
  margin-bottom: 0;
  padding-left: 6px;
  padding-right: 6px;
}

.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.settings-col {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.settings-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.settings-card .section-label {
  margin-left: 0;
}

.settings-card-desc {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0 0 14px;
}

.settings-field-gap {
  margin-top: 14px;
}

.weekday-select {
  cursor: pointer;
  margin-bottom: 0;
}

select.weekday-select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-color: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23837a99' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 10px 6px;
  padding-right: 36px;
}

.settings-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  list-style: none;
}

.settings-summary::-webkit-details-marker {
  display: none;
}

.settings-summary .section-label {
  margin: 0;
}

.settings-chevron {
  font-size: 16px;
  color: var(--ink-soft);
  transition: transform 0.15s ease;
}

.settings-collapsible[open] .settings-chevron {
  transform: rotate(180deg);
}

.settings-collapsible-body {
  margin-top: 14px;
}

.settings-disclaimer {
  font-size: 12px;
  color: var(--ink-soft);
  text-align: center;
  margin: 24px 0 0;
  line-height: 1.5;
}

.settings-card-danger {
  border: 1.5px dashed var(--danger);
}

.member-list {
  margin-bottom: 16px;
}

.member-row {
  background: var(--bg);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  touch-action: none;
}

.member-row.dragging {
  z-index: 10;
  box-shadow: 0 0 0 2px var(--highlight);
  position: relative;
}

.member-drag-handle {
  color: var(--ink-soft);
  font-size: 18px;
  cursor: grab;
  padding: 4px;
  flex-shrink: 0;
}

.member-row.dragging .member-drag-handle {
  cursor: grabbing;
}

.member-name {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.member-delete-btn {
  flex-shrink: 0;
  padding: 6px 8px;
  color: var(--ink-soft);
}

.member-delete-btn:hover {
  background: var(--bg);
  color: var(--danger);
}

.member-row-new {
  background: transparent;
  border: 1.5px dashed var(--ink-soft);
  opacity: 0.85;
}

.member-row-new-icon {
  color: var(--ink-soft);
  font-size: 18px;
  padding: 4px;
  flex-shrink: 0;
}

.member-name-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  padding: 0;
}

.member-name-input:focus {
  outline: none;
}

.settings-save-row {
  margin-bottom: 0;
}

.settings-rebuild-btn {
  width: 100%;
  justify-content: center;
}

.save-btn {
  background: var(--bg);
  color: var(--ink-soft);
  opacity: 0.55;
  cursor: not-allowed;
  transition: background 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.save-btn:disabled {
  pointer-events: none;
}

.save-btn.is-dirty {
  background: var(--danger);
  color: #fff;
  opacity: 1;
  cursor: pointer;
}

.save-btn.is-loading {
  background: var(--danger);
  color: #fff;
  opacity: 1;
  cursor: default;
}

.save-btn.is-success {
  background: var(--success);
  color: #fff;
  opacity: 1;
  cursor: default;
}

.btn-spinner {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  display: inline-block;
  animation: btn-spin 0.6s linear infinite;
}

@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

.avatar-editable {
  cursor: pointer;
}

.avatar-editable:hover {
  box-shadow: 0 0 0 2px var(--highlight);
}

.color-wheel {
  display: flex;
  justify-content: center;
  margin: 14px 0;
}

.color-hex-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.color-preview {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  flex-shrink: 0;
  border: 1px solid rgba(43, 37, 64, 0.12);
}

.color-hex-input-full {
  flex: 1;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0;
}

@media (min-width: 860px) {
  .settings-page {
    width: min(94vw, 1400px);
    max-width: none;
    margin: 0 auto;
  }

  .settings-grid {
    flex-direction: row;
    align-items: start;
  }

  .settings-grid > .settings-card,
  .settings-col {
    flex: 1;
    min-width: 0;
  }

  .settings-col .settings-card {
    flex: 0 0 auto;
  }
}

.hero {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 22px;
  position: sticky;
  top: 20px;
  z-index: 5;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 24px;
  cursor: pointer;
}

.hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.hero-text {
  flex: 1;
  min-width: 0;
}

.hero .row-actions {
  margin-top: 0;
}

.hero .row-actions button:not(.btn-primary) {
  flex: 0 0 auto;
  padding-left: 10px;
  padding-right: 10px;
}

.hero .row-actions button:not(.btn-primary) span {
  display: none;
}

.hero::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 90px; height: 90px;
  background: var(--highlight);
  border-radius: 0 0 90px 0;
  opacity: 0.9;
}

.hero-date {
  font-family: 'Baloo 2', sans-serif;
  font-size: 26px;
  font-weight: 700;
  position: relative;
  z-index: 1;
  container-type: inline-size;
}

.hero-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-top: 4px;
  position: relative;
  z-index: 1;
}

.hero-notes {
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 4px;
  position: relative;
  z-index: 1;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  text-transform: uppercase;
  color: #fff;
  flex-shrink: 0;
  border: 3px solid var(--card);
  background: var(--avatar-color);
}

.avatar.empty {
  background: var(--bg);
  color: var(--ink-soft);
  border-color: var(--bg);
}

.avatar.sm { width: 48px; height: 48px; font-size: 18px; border-width: 2px; }
.avatar.lg { width: 64px; height: 64px; font-size: 26px; }

.section-label {
  font-size: 12px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 10px 4px;
}

/* ---------- Buttons ---------- */

button {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  padding: 9px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  line-height: 1.2;
  background: var(--bg);
  color: var(--ink);
  transition: transform 0.1s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}

button i {
  font-size: 15px;
  line-height: 1;
}

button:active {
  transform: scale(0.96);
}

button:hover {
  opacity: 0.9;
}

.btn-primary {
  background: var(--success);
  color: #fff;
}

.btn-outline {
  background: var(--bg);
  color: var(--ink);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  padding-left: 8px;
  padding-right: 8px;
}

.btn-ghost:hover {
  background: var(--bg);
}

.btn-danger.btn-primary {
  background: var(--danger);
}

.btn-danger.btn-ghost {
  color: var(--danger);
}

.row-actions {
  container-type: inline-size;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  width: 100%;
  margin-top: 10px;
}

.row-actions button {
  flex: 1 1 0;
  min-width: 0;
  justify-content: center;
}

.row-actions button span {
  overflow: hidden;
  text-overflow: ellipsis;
}

@container (max-width: 300px) {
  .row-actions button span {
    display: none;
  }
  .row-actions button {
    flex: 0 0 auto;
    padding-left: 10px;
    padding-right: 10px;
  }
  .row-actions button i {
    font-size: 16px;
  }
}

.entry-row .row-actions {
  flex: 1 0 100%;
  margin-top: 4px;
}

.entry-row {
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
  flex-wrap: wrap;
  cursor: pointer;
}

.entry-row.done { opacity: 0.5; }
.entry-row.skipped { opacity: 0.5; text-decoration: line-through; }

.entry-row.swap-target,
.hero.swap-target {
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--skip);
}

.entry-row.swap-source,
.hero.swap-source {
  box-shadow: 0 0 0 3px var(--success);
}

.entry-info { flex: 1; min-width: 0; }
.entry-info p { margin: 0; }
.entry-name {
  font-size: 16px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.entry-meta { font-size: 13px; color: var(--ink-soft); margin-top: 3px; container-type: inline-size; }

.entry-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.status-badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.status-badge.open { background: rgba(255, 209, 102, 0.4); color: #8A5B00; }
.status-badge.completed { background: rgba(76, 175, 125, 0.16); color: var(--success); }
.status-badge.skipped { background: rgba(155, 143, 199, 0.2); color: var(--skip); }

.calendar {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-top: 24px;
  transition: box-shadow 0.15s ease;
}

.calendar.selecting {
  box-shadow: 0 0 0 3px var(--highlight);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  text-align: center;
  font-size: 12px;
  margin-top: 12px;
}

#undo-bar {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 14px;
  box-sizing: border-box;
  margin-bottom: 0;
}

#undo-bar span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cal-label { color: var(--ink-soft); padding: 4px 0; }

.cal-day {
  padding: 6px 0;
  border-radius: 10px;
  position: relative;
}

.cal-day-done::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: repeating-linear-gradient(
    45deg,
    rgba(0, 0, 0, 0.08),
    rgba(0, 0, 0, 0.08) 3px,
    transparent 3px,
    transparent 8px
  );
  pointer-events: none;
}

.cal-day.clickable {
  cursor: pointer;
}
.cal-day.clickable:hover {
  outline: 2px solid var(--highlight);
}

.cal-day.range-valid {
  background: rgba(255, 209, 102, 0.35);
  font-weight: 600;
}

.cal-day.today {
  outline: 2px solid var(--ink);
  font-weight: 700;
}

.action-banner {
  background: var(--highlight);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin-bottom: 10px;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  flex-wrap: wrap;
}

.action-banner button {
  flex-shrink: 0;
}

.action-banner .row-actions {
  margin-top: 0;
}

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(43, 37, 64, 0.45);
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 20px;
  max-width: 320px;
  width: 100%;
}

.modal-title {
  font-family: 'Baloo 2', sans-serif;
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
}

.modal-sub {
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 14px;
  container-type: inline-size;
}

.wd-short {
  display: none;
}

@container (max-width: 230px) {
  .hero-date .wd-long { display: none; }
  .hero-date .wd-short { display: inline; }
}

@container (max-width: 140px) {
  .entry-meta .wd-long,
  .modal-sub .wd-long {
    display: none;
  }
  .entry-meta .wd-short,
  .modal-sub .wd-short {
    display: inline;
  }
}

.modal-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.notes-label {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 4px 0 6px;
}

.notes-input {
  width: 100%;
  resize: vertical;
  border: none;
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  padding: 10px 12px;
  margin-bottom: 4px;
}

.notes-input:focus {
  outline: 2px solid var(--highlight);
}

.modal-save-row {
  margin-top: 14px;
}

.move-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 14px 0;
}

.move-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: var(--radius-md);
  text-align: left;
  justify-content: flex-start;
}

.move-option:hover {
  background: rgba(255, 209, 102, 0.35);
}

.move-option-info {
  flex: 1;
  min-width: 0;
}

.move-option-name {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
}

.list-toggle {
  display: none;
  width: 100%;
  justify-content: center;
  background: transparent;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 500;
  padding: 8px 0;
  border-radius: 10px;
}

.list-toggle:hover {
  background: var(--bg);
}

@media (max-width: 859px) {
  #entry-list .entry-row.extra-row {
    display: none;
  }
  #entry-list.expanded .entry-row.extra-row {
    display: flex;
  }
  .list-toggle.visible {
    display: flex;
  }
}

@media (max-width: 380px) {
  button {
    font-size: 12px;
    padding: 7px 11px;
  }
  .entry-row {
    padding: 12px;
    gap: 10px;
  }
  .avatar.sm { width: 42px; height: 42px; font-size: 16px; }
}

@media (min-width: 860px) {
  .app {
    width: min(94vw, 1400px);
    max-width: none;
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
    grid-template-rows: 44px auto;
    grid-template-areas:
      "topbar topbar"
      "list calendar";
    gap: 24px;
    align-items: start;
  }

  .top-bar {
    grid-area: topbar;
    height: 44px;
    margin-bottom: 0;
    justify-content: flex-end;
    position: sticky;
    top: 20px;
    z-index: 10;
  }

  .app-list {
    grid-area: list;
    max-width: 460px;
    width: 100%;
    margin: 0 auto;
  }

  /* Deckt die Lücke oberhalb der stationären Hero-Karte blickdicht ab, damit
     durchscrollende Listeneinträge dort nicht kurz sichtbar aufblitzen. */
  .app-list::before {
    content: '';
    display: block;
    position: sticky;
    top: 0;
    height: calc(88px + var(--radius-lg));
    margin-bottom: calc(-88px - var(--radius-lg));
    background: var(--bg);
    z-index: 4;
    pointer-events: none;
  }

  .hero {
    top: 88px;
  }

  .calendar {
    grid-area: calendar;
    width: 100%;
    margin-top: 0;
    position: sticky;
    top: 88px;
    align-self: start;
    height: calc(100vh - 108px);
    display: flex;
    flex-direction: column;
  }

  .calendar-grid {
    flex: 1;
    min-height: 0;
    grid-template-rows: auto;
    grid-auto-rows: 1fr;
  }

  .cal-day {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* ---------- Login-Seite ---------- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-page {
  width: 100%;
  max-width: 340px;
}

.login-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  text-align: center;
}

.login-icon {
  font-size: 32px;
  color: var(--ink-soft);
  margin-bottom: 10px;
  display: block;
}

.login-title {
  font-size: 22px;
  margin-bottom: 10px;
}

.login-sub {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0 0 22px;
  line-height: 1.5;
}

.login-input {
  width: 100%;
  border: none;
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--ink);
  font-family: 'Baloo 2', sans-serif;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-align: center;
  padding: 14px 12px 14px 18px;
  box-sizing: border-box;
}

.login-input:focus {
  outline: 2px solid var(--highlight);
}

.login-error {
  min-height: 18px;
  font-size: 13px;
  color: var(--danger);
  margin: 10px 0 0;
}

.login-submit-btn {
  width: 100%;
  justify-content: center;
  margin-top: 14px;
  padding: 12px 14px;
  font-size: 14px;
}