:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #17201d;
  --muted: #6b7773;
  --line: #e3e8e6;
  --input: #f1f4f3;
  --accent: #1f7a63;
  --accent-text: #ffffff;
  --accent-soft: #e2f1ec;
  --warn: #b26a00;
  --warn-soft: #fdf1dc;
  --danger: #c0392b;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .04);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615;
    --card: #1b2120;
    --text: #e8eeec;
    --muted: #93a09b;
    --line: #2a3331;
    --input: #242c2a;
    --accent: #3fb592;
    --accent-text: #0d1513;
    --accent-soft: #1f3530;
    --warn: #f0b350;
    --warn-soft: #3a2f1c;
    --danger: #ef6b5d;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
h1 { font-size: 1.35rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0; }
h3.section { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 24px 4px 8px; }
p { margin: 8px 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
button, input, select { font: inherit; color: inherit; }

/* Tabs */
.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  border-bottom: 1px solid var(--line);
}
.tabs { display: grid; grid-template-columns: 1fr 1fr 1fr .8fr; gap: 6px; max-width: 720px; margin: 0 auto; }
.tab {
  border: 0; border-radius: 12px; padding: 8px 4px; background: var(--card); box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 1px; cursor: pointer; min-height: 52px;
}
.tab-num { font-weight: 700; font-size: 1.1rem; }
.tab-day { font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tab.active { background: var(--accent); color: var(--accent-text); }
.tab.active .tab-day { color: inherit; opacity: .85; }

main { max-width: 720px; margin: 0 auto; padding: 16px 12px; }
.unit-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 4px 4px 12px; }
.unit-sub { display: flex; gap: 8px; align-items: center; margin-top: 4px; font-size: .85rem; }

.pill { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--input); color: var(--muted); font-weight: 600; }
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

.date-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 4px 12px; }
.discard { margin: -6px 4px 8px; }
.discard[hidden] { display: none; }
input[type="date"] { min-height: 44px; }

/* Karten */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 2px 12px; margin-bottom: 10px; }
.last { font-size: .82rem; }

.sets { display: grid; gap: 6px; }
.set-row { display: grid; grid-template-columns: 2.2rem minmax(0, 1.2fr) 1fr 1fr; gap: 8px; align-items: center; }
.set-row.three { grid-template-columns: 2.2rem 1fr 1fr; }
.set-head { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.set-head span:nth-child(n+3) { text-align: center; }
.set-row.three.set-head span:nth-child(n+2) { text-align: center; }
.set-no { font-weight: 700; color: var(--muted); text-align: center; }
.prev { font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

input {
  width: 100%; min-height: 48px; border: 1.5px solid transparent; border-radius: 12px;
  background: var(--input); padding: 8px 12px; font-size: 16px; /* 16px verhindert Zoom auf dem iPhone */
  outline: none; transition: border-color .15s;
}
input:focus { border-color: var(--accent); background: var(--card); }
input.num { text-align: center; font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; padding: 8px 4px; }
input::placeholder { color: var(--muted); opacity: .55; font-weight: 400; }
.date-row input { width: auto; flex: 0 1 auto; font-weight: 600; }

.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* Buttons */
.btn {
  border: 0; border-radius: 12px; padding: 10px 16px; min-height: 44px; cursor: pointer; font-weight: 600;
  background: var(--input); -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn.small { padding: 6px 12px; min-height: 38px; font-size: .88rem; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); }
.btn.link { background: none; padding: 6px 0; min-height: 36px; color: var(--accent); font-weight: 600; }
.btn.link.danger { color: var(--danger); }
.btn.danger-fill { background: var(--danger); color: #fff; }
.btn.big { width: 100%; min-height: 56px; font-size: 1.1rem; border-radius: 16px; }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.icon {
  border: 0; background: var(--input); border-radius: 10px; width: 40px; height: 40px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; font-size: 1rem; flex: none;
}
.icon:disabled { opacity: .3; }
.icon.danger { color: var(--danger); }

.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.savebar .btn { display: block; max-width: 696px; margin: 0 auto; }

/* Historie */
.history { margin-top: 6px; border-top: 1px solid var(--line); padding-top: 4px; }
.history-list { list-style: none; padding: 0; margin: 4px 0 0; display: grid; gap: 8px; }
.history-list li { background: var(--input); border-radius: 12px; padding: 8px 10px; }
.hist-head { display: flex; gap: 8px; align-items: center; font-size: .9rem; }
.hist-actions { margin-left: auto; display: flex; gap: 6px; }
.hist-actions .icon { width: 34px; height: 34px; background: var(--card); }
.hist-sets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { font-size: .82rem; padding: 4px 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }
.chip.add { cursor: pointer; font: inherit; font-size: .9rem; padding: 8px 12px; background: var(--accent-soft); color: var(--accent); border: 0; font-weight: 600; }

/* Bearbeiten */
.edit-list { list-style: none; padding: 4px 14px; }
.edit-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.edit-list li:last-child { border-bottom: 0; }
.edit-name { display: flex; flex-direction: column; gap: 2px; flex: 1 1 140px; min-width: 0; }
.edit-name > span:first-child { font-weight: 600; }
.edit-name.row { flex-direction: row; align-items: center; gap: 6px; }
.edit-name .icon { width: 32px; height: 32px; background: none; color: var(--muted); }
.edit-actions { display: flex; gap: 6px; align-items: center; }
select.move { min-height: 40px; border-radius: 10px; border: 0; background: var(--input); padding: 0 8px; max-width: 130px; }
.field { display: grid; gap: 4px; margin-bottom: 10px; }
.field label { font-size: .85rem; color: var(--muted); font-weight: 600; }
.add-row { display: flex; gap: 8px; }
.add-row .btn { flex: none; }

.note { background: var(--warn-soft); color: var(--text); border-radius: 12px; padding: 10px 12px; font-size: .88rem; margin: 12px 0; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }

/* Dialog */
.dialog {
  border: 0; border-radius: 20px; padding: 20px; width: min(92vw, 420px);
  background: var(--card); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dialog h2 { margin-bottom: 8px; }
.dialog .sets { margin-top: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .92rem; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); z-index: 30; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

@media (min-width: 640px) {
  main { padding: 24px 16px; }
  .card { padding: 18px 20px; }
}

/* Login */
.login { max-width: 360px; margin: 0 auto; padding: calc(48px + env(safe-area-inset-top)) 16px 24px; text-align: center; }
.login img { border-radius: 18px; }
.login h1 { margin: 12px 0 24px; }
.login form { text-align: left; display: grid; gap: 10px; }
.field-label { font-size: .85rem; color: var(--muted); font-weight: 600; }
.login-error { color: var(--danger); margin: 0; font-weight: 600; }
.login-error[hidden] { display: none; }
body.login-page { padding-bottom: 24px; }
.center-row { justify-content: center; }
