:root {
  --green: #3a7d34;
  --green-dark: #2c5e28;
  --blue: #2f6fb0;
  --bg: #f5f7f3;
  --card: #ffffff;
  --ink: #243024;
  --muted: #6b766b;
  --line: #e2e7df;
  --radius: 12px;
  --shadow: 0 8px 28px rgba(0, 0, 0, .16);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3, h4 { font-weight: 600; line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
a { color: var(--green-dark); }

/* ---------- Login ---------- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: linear-gradient(160deg, #e8f0e4, #d3e3cc);
}
.login-card {
  background: var(--card); padding: 2.2rem 2rem; border-radius: var(--radius);
  box-shadow: var(--shadow); width: min(360px, 92vw); text-align: center;
}
.login-card h1 { margin: .2rem 0 0; }
.login-logo { font-size: 2.6rem; }
#login-form { display: flex; flex-direction: column; gap: .9rem; margin-top: 1.4rem; text-align: left; }
#login-form label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; color: var(--muted); }
input, select {
  padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 8px;
  font-size: 1rem; background: #fff;
}
input:focus { outline: 2px solid var(--green); border-color: var(--green); }
.btn-primary {
  background: var(--green); color: #fff; border: none; padding: .7rem;
  border-radius: 8px; font-size: 1rem; cursor: pointer; margin-top: .4rem;
}
.btn-primary:hover { background: var(--green-dark); }
.error { color: #b3261e; font-size: .9rem; margin: 0; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: .8rem; padding: .6rem 1rem;
  background: var(--green); color: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
  position: sticky; top: 0; z-index: 20; flex-wrap: wrap; row-gap: .4rem;
}
.brand { font-size: 1.15rem; margin: 0; }
.scenario-badge { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.burger { background: none; border: none; color: #fff; font-size: 1.5rem; cursor: pointer; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .7rem; }
.year-select { padding: .3rem .5rem; border-radius: 6px; border: none; }
.scenario-badge { background: rgba(255, 255, 255, .22); padding: .15rem .55rem; border-radius: 20px; font-size: .8rem; }
.btn-link { background: none; border: 1px solid rgba(255, 255, 255, .6); color: #fff; padding: .25rem .6rem; border-radius: 6px; cursor: pointer; }
.topbar .muted { color: #e6f0e2; font-size: .85rem; }

/* ---------- Page / Schema ---------- */
.page { max-width: 900px; margin: 0 auto; padding: 1rem; }
.legend { display: flex; flex-wrap: wrap; gap: 1rem; margin: .6rem 0; font-size: .85rem; color: var(--muted); }
.lg { display: inline-flex; align-items: center; gap: .35rem; }
.lg i { width: 14px; height: 14px; border-radius: 3px; display: inline-block; border: 1px solid rgba(0,0,0,.15); }
.schema-wrap { background: var(--card); border-radius: var(--radius); padding: .5rem; box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.schema-svg { display: block; }
.bed { cursor: pointer; }
.bed:hover rect { filter: brightness(.94); }
.bed:focus { outline: none; }
.bed:focus rect { stroke-dasharray: 4 2; }
.svg-num { font-size: 14px; font-weight: 600; font-family: system-ui, sans-serif; }
.svg-badge { fill: #fff; font-size: 10px; font-weight: 700; font-family: system-ui, sans-serif; }
.svg-dim { fill: #9098a0; font-size: 12px; font-family: system-ui, sans-serif; }
.today-note { color: var(--muted); font-size: .9rem; text-align: center; }

/* ---------- Overlays ---------- */
.overlay, .menu-overlay {
  position: fixed; inset: 0; background: rgba(20, 30, 20, .45);
  display: flex; z-index: 40; padding: 1rem;
}
/* hidden-Attribut muss die display-Regel oben schlagen */
.overlay[hidden], .menu-overlay[hidden] { display: none; }
.overlay { align-items: flex-start; justify-content: center; overflow-y: auto; }
.overlay-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  width: min(560px, 96vw); margin: 3vh auto; padding: 1.4rem 1.5rem; position: relative;
}
.overlay-card.wide { width: min(820px, 96vw); }
.overlay-close {
  position: absolute; top: .6rem; right: .7rem; background: none; border: none;
  font-size: 1.2rem; cursor: pointer; color: var(--muted);
}
.overlay-card h2 { margin-top: 0; }

/* ---------- Tasks ---------- */
.task { border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; margin: .5rem 0; background: #fcfdfb; }
.task.overdue { border-left: 4px solid #b3261e; }
.task.due { border-left: 4px solid #e08a00; }
.task.coming { border-left: 4px solid #cdd8cd; }
.task.done { opacity: .6; }
.task-head { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.task-title { font-weight: 500; }
.kw { background: #eef2ec; color: var(--green-dark); font-size: .75rem; padding: .1rem .4rem; border-radius: 5px; font-weight: 600; }
.chip { font-size: .72rem; padding: .1rem .45rem; border-radius: 20px; color: #fff; }
.cat-prep { background: #8d6e63; } .cat-sow { background: #7cb342; }
.cat-plant { background: #43a047; } .cat-feed { background: #6d4c41; }
.cat-water { background: #2f6fb0; } .cat-care { background: #78909c; }
.cat-harvest { background: #e08a00; }
.task-note { margin: .35rem 0 .2rem; font-size: .85rem; color: var(--muted); }
.task-actions { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .35rem; }
.btn-mini { font-size: .78rem; padding: .25rem .55rem; border: 1px solid var(--line); background: #fff; border-radius: 6px; cursor: pointer; }
.btn-mini:hover { background: #f0f3ee; }
.btn-mini.done { border-color: var(--green); color: var(--green-dark); }
.btn-mini.undo { border-color: #e08a00; color: #9a5b00; }
.btn-mini.apply { border-color: var(--green); color: var(--green-dark); }
details summary { cursor: pointer; color: var(--muted); margin: .6rem 0; }

/* ---------- Wochenkalender ---------- */
.week-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .5rem; margin: .8rem 0; }
.week-chip { text-align: left; border: 1px solid var(--line); border-radius: 8px; padding: .4rem .5rem; cursor: pointer; display: flex; flex-direction: column; gap: .1rem; background: #fff; }
.week-chip .wk { font-weight: 600; font-size: .85rem; }
.week-chip .wd { font-size: .72rem; color: var(--muted); }
.week-chip .wo { font-size: .72rem; }
.week-chip.lvl0 { background: #f3f6f1; }
.week-chip.lvl1 { background: #fbe3e3; }
.week-chip.lvl2 { background: #f3b4b4; }
.week-chip.lvl3 { background: #e58a8a; }
.week-chip.current { outline: 2px solid var(--green); }
.week-bed { border-top: 1px solid var(--line); padding-top: .4rem; margin-top: .6rem; }
.week-bed h4 { margin: .2rem 0; }
#week-detail { margin-top: .8rem; }

/* ---------- Pläne / Szenarien ---------- */
.plan-year { margin-bottom: 1rem; }
.scen-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .6rem; }
.scen-card { border: 1px solid var(--line); border-radius: 10px; padding: .7rem .8rem; background: #fcfdfb; }
.scen-card.active { border-color: var(--green); background: #eef6ea; }
.scen-title { font-weight: 600; }
.scen-desc { font-size: .82rem; color: var(--muted); margin: .35rem 0 .5rem; }
.scen-active { color: var(--green-dark); font-size: .82rem; font-weight: 600; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.rot { border-collapse: collapse; width: 100%; font-size: .82rem; margin-top: .4rem; }
table.rot th, table.rot td { border: 1px solid var(--line); padding: .35rem .5rem; text-align: left; }
table.rot th { background: #eef2ec; }
.cell-select { width: 100%; min-width: 150px; padding: .3rem; border: 1px solid var(--line); border-radius: 6px; font-size: .8rem; background: #fff; }
ul.links { padding-left: 1.1rem; }
ul.links li { margin: .25rem 0; }

/* ---------- Menü ---------- */
.menu-overlay { justify-content: flex-start; }
.menu-panel { background: var(--card); width: min(300px, 86vw); height: 100%; padding: 1.2rem; box-shadow: var(--shadow); position: relative; overflow-y: auto; }
.menu-list { list-style: none; padding: 0; margin: 1rem 0 0; }
.menu-list li { margin: .15rem 0; }
.menu-list button { width: 100%; text-align: left; background: none; border: none; padding: .6rem .5rem; border-radius: 8px; font-size: .95rem; cursor: pointer; color: var(--ink); }
.menu-list button:hover { background: #eef2ec; }
.menu-sep { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; margin: .8rem .5rem .2rem; }

/* ---------- Mobile / responsive ---------- */
@media (max-width: 640px) {
  .topbar { gap: .5rem; padding: .5rem .6rem; }
  .brand { font-size: 1rem; }
  #user-label { display: none; }
  .topbar-right { gap: .45rem; margin-left: auto; }
  .year-select { padding: .25rem .35rem; font-size: .9rem; }
  .scenario-badge { font-size: .7rem; max-width: 34vw; padding: .12rem .45rem; }
  .btn-link { padding: .3rem .55rem; font-size: .85rem; }

  .page { padding: .7rem; }
  .legend { gap: .45rem .9rem; font-size: .78rem; margin: .5rem 0; }

  /* Overlays als Vollbild, Schließen-Button fix sichtbar */
  .overlay { padding: 0; display: block; }
  .overlay-card, .overlay-card.wide {
    width: 100%; margin: 0; border-radius: 0; min-height: 100vh; padding: 1rem .9rem 2.5rem;
  }
  .overlay-close {
    position: fixed; top: .5rem; right: .6rem; z-index: 3;
    width: 2.2rem; height: 2.2rem; border-radius: 50%;
    background: var(--card); box-shadow: 0 1px 6px rgba(0,0,0,.2);
    display: flex; align-items: center; justify-content: center;
  }
  .overlay-card h2 { padding-right: 2.4rem; }

  .menu-panel { width: 88vw; padding: 1rem; }
  .menu-list button { padding: .8rem .55rem; font-size: 1rem; }

  /* Größere Tap-Targets bei Aufgaben */
  .task { padding: .65rem .7rem; }
  .task-actions { gap: .4rem; }
  .task-actions .btn-mini { flex: 1 1 30%; text-align: center; padding: .55rem .4rem; font-size: .82rem; }

  .week-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: .4rem; }
  .week-chip { padding: .45rem .5rem; }

  .scen-grid { grid-template-columns: 1fr; }
  table.rot th, table.rot td { padding: .35rem .4rem; font-size: .8rem; }
  .cell-select { min-width: 118px; font-size: .8rem; padding: .4rem .3rem; }
}

@media (max-width: 380px) {
  .scenario-badge { display: none; }
  .brand { font-size: .95rem; }
  .task-actions .btn-mini { flex: 1 1 100%; }
}
