:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #12151a;
  --muted: #667085;
  --line: #e1e6ea;
  --line-soft: #eef1f4;
  --accent: #b86e0d;
  --accent-ink: #ffffff;
  --today: #fdf3e2;
  --closed: #eef1f4;
  --red: #c33b2c;
  --radius: 12px;
  --hour-min: 40px;
  --top-h: 56px;
  --c-RU: #dbeafe; --b-RU: #2563eb;
  --c-LO: #dcfce7; --b-LO: #16a34a;
  --c-BO: #fef3c7; --b-BO: #b45309;
  --c-FR: #ede9fe; --b-FR: #7c3aed;
  --c-LE: #fce7f3; --b-LE: #db2777;
  --c-SP: #ffedd5; --b-SP: #ea580c;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1116; --card: #171a21; --ink: #e7eaef; --muted: #98a1b0;
    --line: #262b36; --line-soft: #1f242e; --accent: #ef9f27; --accent-ink: #1a1206;
    --today: #2a2214; --closed: #181b22; --red: #f0806f;
    --c-RU: #1e2a44; --b-RU: #60a5fa;
    --c-LO: #15301f; --b-LO: #4ade80;
    --c-BO: #33290f; --b-BO: #fbbf24;
    --c-FR: #2a2342; --b-FR: #a78bfa;
    --c-LE: #3a1d2c; --b-LE: #f472b6;
    --c-SP: #3a2414; --b-SP: #fb923c;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
button, input, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--card); border-radius: 8px;
  padding: 0.45rem 0.8rem; cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { color: var(--red); }
button[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: -2px; font-weight: 600; }
input, select { width: 100%; padding: 0.5rem 0.6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
label { display: grid; gap: 0.25rem; font-size: 0.9rem; color: var(--muted); }
.error { color: var(--red); min-height: 1.2em; margin: 0; }
.muted { color: var(--muted); }
.fatal { padding: 2rem; text-align: center; color: var(--muted); }

.auth { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: min(360px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; }
.auth-card form { display: grid; gap: 0.8rem; }
.auth-logo { width: 56px; height: 56px; }
.auth h1 { margin: 0.5rem 0 1rem; font-size: 1.4rem; }

/* Seite fuellt das Fenster; der Kalender nimmt den Rest der Hoehe. */
.page { min-height: 100dvh; display: flex; flex-direction: column; }
.top {
  position: sticky; top: 0; z-index: 3; height: var(--top-h);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 0.5rem;
  padding: 0 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.top img { width: 32px; height: 32px; }
.top h1 { font-size: 1.15rem; margin: 0; }
.nav { display: flex; align-items: center; gap: 0.4rem; }
.nav .range { min-width: 11rem; text-align: center; font-weight: 600; font-size: 1.05rem; white-space: nowrap; }
.top .menu { position: relative; justify-self: end; }
.who { max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-list { position: absolute; right: 0; top: 110%; display: grid; min-width: 180px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 0.25rem; }
.menu-list button { border: 0; text-align: left; }
.menu-list[hidden] { display: none; }

.strip { display: none; }
.cal {
  flex: 1; display: grid; padding: 0 16px 1.2rem; row-gap: 0.8rem;
  grid-template-columns: 3.4rem repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: auto minmax(calc(14 * var(--hour-min)), 1fr);
}
.head { position: sticky; top: var(--top-h); z-index: 2; background: var(--bg); text-align: center; padding: 0.5rem 0; font-size: 1rem; border-bottom: 1px solid var(--line); }
.head.today span { background: var(--accent); color: var(--accent-ink); font-weight: 700; padding: 0.15rem 0.6rem; border-radius: 999px; }
.times { position: relative; }
.times span { position: absolute; right: 0.5rem; transform: translateY(-50%); font-size: 0.9rem; color: var(--muted); }

/* Stundenlinien in Prozent: die Spalte ist so hoch wie das Fenster erlaubt. */
.col {
  position: relative; border-left: 1px solid var(--line); cursor: pointer;
  background-image: linear-gradient(to bottom, var(--line-soft) 0 1px, transparent 1px);
  background-size: 100% calc(100% / 14);
}
.col.closed { background-color: var(--closed); cursor: not-allowed; }
.col.today { background-color: var(--today); }
.now { position: absolute; left: 0; right: 0; height: 2px; background: var(--red); z-index: 1; pointer-events: none; }
.block {
  position: absolute; left: 3px; right: 3px; border-radius: 6px; padding: 0 6px; overflow: hidden;
  display: flex; align-items: center; white-space: nowrap;
  font-size: 0.85rem; line-height: 1.25; border: 1px solid transparent; cursor: pointer;
}
.block.mine { border-width: 2px; font-weight: 600; }
.block .code { font-weight: 700; margin-right: 0.3rem; }
.block .time { margin-left: 0.4rem; color: var(--muted); font-weight: 400; overflow: hidden; text-overflow: ellipsis; }
.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 0.6rem 1rem; border-radius: 8px; z-index: 10; }

/* Oben verankert: waechst der Inhalt (Wiederholen), dehnt er sich nur nach unten. */
dialog.sheet { margin: 8vh auto auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink); width: min(420px, calc(100vw - 32px)); padding: 1.25rem; }
dialog.sheet::backdrop { background: rgb(0 0 0 / 0.4); }
dialog.sheet form { display: grid; gap: 0.8rem; }
dialog.sheet h2 { margin: 0; font-size: 1.15rem; }
dialog.sheet p { margin: 0; }
.choices { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.choices button { flex: 1 1 auto; }
.cat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.4rem; }
.cat-grid button[aria-pressed="true"] { outline: none; border-width: 2px; padding: calc(0.45rem - 1px) calc(0.8rem - 1px); }
.inline { display: flex; align-items: center; gap: 0.5rem; color: var(--ink); }
.inline input { width: auto; }
.actions { display: flex; gap: 0.5rem; justify-content: flex-end; flex-wrap: wrap; }
.actions .danger { margin-right: auto; }

@media (max-width: 767px) {
  .top { padding: 0 8px; gap: 0.25rem; }
  .top h1 { display: none; }
  .nav { gap: 0.2rem; }
  .nav button { padding: 0.4rem 0.55rem; }
  .nav .range { min-width: 6.5rem; font-size: 0.95rem; }
  .who { max-width: 5.5rem; padding: 0.4rem 0.5rem; }
  .strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding: 0.4rem 8px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: var(--top-h); z-index: 2; }
  .strip button { padding: 0.3rem 0; font-size: 0.9rem; display: grid; }
  .strip button.today { color: var(--accent); font-weight: 700; }
  .strip button[aria-current="date"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
  /* Tagesköpfe sind hier ausgeblendet und belegen keine Grid-Zeile. */
  .cal { padding: 0.8rem 8px 1rem; grid-template-columns: 3rem minmax(0, 1fr); grid-template-rows: minmax(calc(14 * var(--hour-min)), 1fr); }
  .head { display: none; }
  .cat-grid { grid-template-columns: repeat(2, 1fr); }
}
