:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --border: #e2dfd8;
  --text: #1f1d1a;
  --muted: #6b665d;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #e2f0eb;
  --ok: #2f8a4a;
  --ok-soft: #e4f3e8;
  --warn: #b26a00;
  --warn-soft: #fdf1dc;
  --err: #c0362c;
  --err-soft: #fbe5e2;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .05);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151614;
    --surface: #1e201d;
    --surface-2: #262924;
    --border: #353832;
    --text: #ecebe6;
    --muted: #a39f95;
    --accent: #4fb89a;
    --accent-ink: #0b1f19;
    --accent-soft: #1d3a31;
    --ok: #5cc27a;
    --ok-soft: #1c3324;
    --warn: #e8a33b;
    --warn-soft: #3a2c13;
    --err: #ef6f64;
    --err-soft: #3d1d1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.15rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pre { white-space: pre-line; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.right { margin-left: auto; }

/* ---------- Buttons & Formulare ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled, .btn.primary:disabled { opacity: .45; filter: grayscale(1); cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: .85rem; }
.btn.block { width: 100%; justify-content: center; }
.icon-btn {
  border: 0; background: transparent; color: var(--muted);
  font-size: 1.1rem; cursor: pointer; padding: 6px 8px; border-radius: 6px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

label { display: block; font-size: .85rem; font-weight: 550; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 40px;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type="checkbox"] { width: auto; min-height: 0; }
.check { display: flex; gap: 8px; align-items: flex-start; color: var(--text); font-weight: 400; font-size: .92rem; }
.check input { margin-top: 3px; }
.field { margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 12px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.actions .left { margin-right: auto; }

/* ---------- Karten, Badges ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.badge {
  display: inline-block; font-size: .75rem; font-weight: 650;
  padding: 1px 8px; border-radius: 99px;
  background: var(--surface-2); color: var(--muted);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.over, .badge.err { background: var(--err-soft); color: var(--err); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.count {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 99px; background: var(--err); color: #fff; font-size: .72rem; font-weight: 700;
}

.issues { list-style: none; padding: 0; margin: 8px 0 0; font-size: .87rem; }
.issues li { padding: 6px 10px; border-radius: 6px; margin-bottom: 4px; }
.issues li.warn { background: var(--warn-soft); color: var(--warn); }
.issues li.error { background: var(--err-soft); color: var(--err); }

.meter { min-width: 140px; }
.meter-bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.meter-bar span { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.meter.warn .meter-bar span { background: var(--warn); }
.meter.over .meter-bar span { background: var(--err); }
.meter-text { font-size: .8rem; color: var(--muted); margin-top: 3px; white-space: nowrap; }
.meter.over .meter-text strong { color: var(--err); }
.meter.warn .meter-text strong { color: var(--warn); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .4);
  display: grid; place-items: center; z-index: 50; padding: 16px;
}
.modal {
  background: var(--surface); border-radius: 14px; width: min(560px, 100%);
  max-height: calc(100dvh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 6px; position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.modal-body { padding: 8px 16px 16px; }
@media (max-width: 600px) {
  .modal-backdrop { place-items: end stretch; padding: 0; }
  .modal { border-radius: 16px 16px 0 0; max-height: 92dvh; width: 100%; }
}

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 30px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  opacity: 0; transition: .2s; z-index: 100; pointer-events: none; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--err); color: #fff; }

/* ---------- Planer-Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand img { width: 26px; height: 26px; }
.tabs { display: flex; gap: 2px; }
.tab {
  border: 0; background: transparent; font: inherit; color: var(--muted); font-weight: 600;
  padding: 8px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center;
  white-space: nowrap; flex: none;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar h2 { margin: 0 8px; min-width: 220px; }

.plan { display: grid; grid-template-columns: 1fr 280px; gap: 16px; align-items: start; }
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.day { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-height: 200px; display: flex; flex-direction: column; }
.day.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.day-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.day-head .d { font-weight: 700; }
.day-body { padding: 6px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.shift {
  text-align: left; width: 100%; font: inherit; color: inherit; cursor: pointer;
  border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 8px;
  background: var(--surface); padding: 6px 8px;
}
.shift:hover { background: var(--surface-2); }
.shift.unassigned { border-left-color: var(--muted); border-style: dashed; border-left-style: solid; }
.shift.warn { border-left-color: var(--warn); }
.shift.error { border-left-color: var(--err); background: var(--err-soft); }
.shift .t { font-weight: 650; font-size: .88rem; }
.shift .n { font-size: .88rem; }
.shift .l { font-size: .78rem; color: var(--muted); }
.shift .flag { float: right; font-size: .8rem; }
.add-shift { border: 1px dashed var(--border); background: transparent; color: var(--muted); border-radius: 8px; padding: 6px; cursor: pointer; font: inherit; }
.add-shift:hover { color: var(--accent); border-color: var(--accent); }
.side { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 72px; }
.side .card h3 { margin-bottom: 10px; }
.amp-row { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 6px 0; border-top: 1px solid var(--border); }
.amp-row:first-of-type { border-top: 0; }
.amp-row .name { font-size: .9rem; font-weight: 600; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr.inactive td { opacity: .5; }
.table-wrap { overflow-x: auto; }

.list { display: flex; flex-direction: column; gap: 10px; }
.section-title { display: flex; align-items: center; gap: 8px; margin: 24px 0 10px; }
.section-title:first-child { margin-top: 0; }
.empty { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }

.presets { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 99px; padding: 4px 10px; font: inherit; font-size: .82rem; cursor: pointer; }
.chip:hover { border-color: var(--accent); }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 24px; }
.login h1 { margin-bottom: 4px; }
.login p { margin: 0 0 18px; }

@media (max-width: 1100px) {
  .plan { grid-template-columns: 1fr; }
  .side { position: static; }
}
/* ---------- Gruppen ---------- */
.gpill {
  display: inline-block; font-size: .72rem; font-weight: 650; line-height: 1.5;
  padding: 0 8px; border-radius: 99px; color: #fff; background: var(--c, var(--muted));
  white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.gpill.none { background: var(--surface-2); color: var(--muted); }
.shift .gpill { margin: 2px 0 1px; }
.group-chip { display: inline-flex; gap: 6px; align-items: center; }
.needs { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.need .gpill { max-width: none; }
.need {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0;
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 6px 6px 10px; color: var(--text);
}
.need input { width: 64px; min-height: 34px; padding: 4px 8px; text-align: center; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; background: var(--c); margin: 0; cursor: pointer;
  display: grid; place-items: center; border: 2px solid transparent;
}
.swatch input { opacity: 0; width: 0; height: 0; position: absolute; }
.swatch:has(input:checked) { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--surface); }
.swatch:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
label.check.chip { margin: 0; display: inline-flex; align-items: center; }

/* Nur fürs Handy gedachte Elemente sind am Desktop ausgeblendet */
.daystrip, .tl-short, .tab .ico, .break { display: none; }
.row-actions { text-align: right; white-space: nowrap; }

/* ---------- Handy (Planer-Ansicht wie eine App) ---------- */
@media (max-width: 800px) {
  body { font-size: 16px; }
  /* 16px verhindert das automatische Hineinzoomen auf dem iPhone */
  input, select, textarea { font-size: 16px; min-height: 46px; }
  .btn { min-height: 44px; }
  .btn.small { min-height: 38px; }
  .grid3 { grid-template-columns: 1fr 1fr; }

  /* Kopfzeile schlank, Navigation unten */
  .topbar { position: static; padding: 12px 16px; gap: 8px; }
  .brand { font-size: 1.05rem; min-width: 0; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 0;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tab {
    flex-direction: column; gap: 3px; padding: 4px 2px; border-radius: 0;
    font-size: .74rem; position: relative; justify-content: center;
  }
  .tab:hover { background: transparent; }
  .tab .ico {
    display: block; width: 54px; height: 30px; padding: 4px 16px; border-radius: 99px;
    fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
  }
  .tab[aria-selected="true"] { background: transparent; color: var(--accent); }
  .tab[aria-selected="true"] .ico { background: var(--accent-soft); }
  .tl-long { display: none; }
  .tl-short { display: inline; }
  .tab .count { position: absolute; top: 0; left: calc(50% + 8px); }
  main { padding: 12px 16px calc(100px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(92px + env(safe-area-inset-bottom)); }

  /* Werkzeugleiste */
  .toolbar { gap: 8px; margin-bottom: 12px; }
  .toolbar h2 { min-width: 0; width: 100%; order: -1; margin: 0 0 2px; font-size: 1.15rem; }
  .toolbar .right { display: none; }
  .toolbar > .btn:not(.fab) { flex: 1; justify-content: center; padding: 8px 10px; }
  .toolbar > .btn[data-week="-1"], .toolbar > .btn[data-week="1"],
  .toolbar > .btn[data-month] { flex: 0 0 48px; }
  .toolbar > #today-btn { flex: 0 0 auto; }
  .toolbar > #copy-week { white-space: nowrap; font-size: .92rem; }
  .toolbar label.check { flex: 1; margin-left: 6px !important; }
  .toolbar .break { display: block; flex-basis: 100%; height: 0; }
  .toolbar > a.btn { flex: 1 1 calc(50% - 4px); white-space: nowrap; font-size: .9rem; padding: 8px 6px; }
  .toolbar > .wide-m { flex: 1 1 100% !important; }

  /* "+ Schicht" als runder Button unten rechts */
  .fab {
    position: fixed; right: 16px; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 25;
    width: 60px; height: 60px; border-radius: 50%; padding: 0; justify-content: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .28);
  }
  .fab-text { display: none; }
  .fab-plus { font-size: 2rem; line-height: 1; font-weight: 400; }

  /* Tagesleiste: immer nur ein Tag sichtbar */
  .daystrip {
    display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px;
    position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 0; margin: -4px 0 8px;
  }
  .daychip {
    border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 14px;
    padding: 7px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 2px;
    font: inherit; cursor: pointer; min-width: 0;
  }
  .daychip .wd { font-size: .7rem; font-weight: 700; color: var(--muted); text-transform: uppercase; }
  .daychip .dn { font-size: 1.15rem; font-weight: 800; line-height: 1.1; }
  .daychip .dot { width: 6px; height: 6px; border-radius: 50%; }
  .daychip .dot.ok { background: var(--ok); }
  .daychip .dot.warn { background: var(--warn); }
  .daychip.today .dn { color: var(--accent); }
  .daychip.sel { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
  .daychip.sel .wd, .daychip.sel .dn { color: inherit; }
  .daychip.sel .dot.ok, .daychip.sel .dot.warn { background: var(--accent-ink); }

  .week { grid-template-columns: 1fr; }
  .week .day:not(.sel) { display: none; }
  .day { min-height: 0; border-radius: 16px; }
  .day.today { box-shadow: none; border-color: var(--border); }
  .day-head { padding: 12px 14px; }
  .day-head .d { font-size: 1.05rem; }
  .day-body { padding: 10px; gap: 10px; }
  .shift { padding: 12px 14px; border-radius: 12px; border-left-width: 5px; }
  .shift .t { font-size: 1.05rem; }
  .shift .n { font-size: 1rem; margin-top: 2px; }
  .shift .l { font-size: .85rem; }
  .shift .flag { font-size: 1rem; }
  .shift .gpill { font-size: .78rem; margin: 4px 0 2px; }
  .add-shift { padding: 14px; font-size: 1.2rem; border-radius: 12px; }
  .plan { gap: 14px; }
  .side { gap: 14px; }

  /* Team: Karten statt Tabelle */
  .table-wrap { overflow: visible; background: transparent; border: 0; box-shadow: none; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr {
    background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
    padding: 6px 16px 14px; margin-bottom: 12px; box-shadow: var(--shadow);
  }
  .table-wrap td { border: 0; padding: 8px 0; }
  .table-wrap td:first-child { font-size: 1.1rem; padding: 10px 0; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
  .table-wrap td[data-label] { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
  .table-wrap td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .85rem; font-weight: 600; padding-top: 2px; flex: none; }
  .table-wrap td .cell { text-align: right; min-width: 0; }
  .table-wrap td .meter { min-width: 150px; }
  .table-wrap td.row-actions { display: flex; gap: 8px; padding-top: 12px; white-space: normal; }
  .row-actions .btn { flex: 1; justify-content: center; }

  /* Karten-Aktionen und Dialoge */
  .card .actions .btn { flex: 1; justify-content: center; }
  .modal-body .actions {
    position: sticky; bottom: 0; background: var(--surface); z-index: 1;
    margin: 16px -16px -16px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
  }
  .modal-head { padding: 16px 16px 8px; }
  .needs { grid-template-columns: 1fr; }
  .presets { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px 12px; padding: 0 16px 4px; scrollbar-width: none; }
  .presets::-webkit-scrollbar { display: none; }
  #set-form th, #s-years td { padding: 6px 4px; }
  #s-years input { padding: 8px 6px; }
  #s-years [data-year] { width: 76px; }
  .chip { flex: none; padding: 7px 12px; }
  .section-title { margin-top: 22px; }
  .list { gap: 12px; }
}

/* Handy-Ansicht der Aushilfen: etwas luftiger */
@media (max-width: 800px) {
  .m-wrap { padding: 16px 16px 48px; }
  .m-card-actions .btn { min-height: 48px; }
  .m-wrap .card { padding: 16px; border-radius: 16px; }
}

/* ---------- Handy-Ansicht ---------- */
.m-wrap { max-width: 560px; margin: 0 auto; padding: 16px 16px 40px; }
.m-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 16px; }
.m-head .hi { font-size: 1.3rem; font-weight: 700; }
.m-shift { display: flex; gap: 12px; align-items: center; }
.m-date { width: 52px; text-align: center; flex: none; background: var(--accent-soft); color: var(--accent); border-radius: 10px; padding: 6px 0; }
.m-date .wd { font-size: .75rem; font-weight: 700; text-transform: uppercase; }
.m-date .dd { font-size: 1.25rem; font-weight: 800; line-height: 1; }
.m-date .mm { font-size: .7rem; }
.m-info { flex: 1; min-width: 0; }
.m-info .time { font-weight: 700; }
.m-card-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.m-card-actions .btn { flex: 1; justify-content: center; }
.stat-big { font-size: 1.6rem; font-weight: 800; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
