:root {
  --bg: #f2f4f8;
  --bg-soft: #e7eaf1;
  --card: #fff;
  --fg: #171a21;
  --muted: #6a7382;
  --line: #e1e5ec;
  --line-strong: #ccd3de;
  --accent: #3b6fd4;
  --accent-fg: #fff;
  --accent-soft: #e8effc;
  --shared: #17916a;
  --danger: #c0392b;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px #0f172a0f, 0 6px 20px #0f172a0d;
  --shadow-lg: 0 10px 40px #0f172a26;
  --tint-l: 46%;
  --tint-a: .13;
  --code-l: 30%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --bg-soft: #151a22;
    --card: #191e27;
    --fg: #e6e9ef;
    --muted: #949dad;
    --line: #262d39;
    --line-strong: #333c4b;
    --accent: #6d9bf1;
    --accent-fg: #0f1218;
    --accent-soft: #1d2839;
    --shared: #3fc294;
    --danger: #e2695c;
    --shadow: 0 1px 2px #0006, 0 6px 20px #0000004d;
    --shadow-lg: 0 10px 40px #000000a6;
    --tint-l: 62%;
    --tint-a: .2;
    --code-l: 74%;
  }
}

* { box-sizing: border-box; }

/* [hidden] steht nur im Browser-Stylesheet und verliert gegen jede eigene display-Regel
   (z.B. .field { display: grid }) - deshalb hier explizit durchsetzen. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.45rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: .95rem; letter-spacing: .01em; }
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* --- Controls ------------------------------------------------------------ */

button, input, select {
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: .45rem .7rem;
}
input, select { min-width: 0; }
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button { cursor: pointer; font-weight: 550; transition: background .12s, border-color .12s; }
button:hover { background: var(--bg-soft); }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--muted); }
button.ghost:hover { background: var(--bg-soft); color: var(--fg); }
button.tiny { padding: .18rem .5rem; font-size: .82rem; font-weight: 500; }
input[type="color"] { padding: .15rem; width: 3rem; height: 2.1rem; }

.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.stack { display: grid; gap: .55rem; }
.stack.tight { gap: .35rem; align-content: start; }
.field { display: grid; gap: .2rem; font-size: .82rem; color: var(--muted); }
.check { display: flex; gap: .35rem; align-items: center; font-size: .85rem; color: var(--muted); }
.check input { width: 1rem; height: 1rem; }

/* --- Shell --------------------------------------------------------------- */

.brand { display: flex; gap: .5rem; align-items: center; }
.brand h1, .brand strong { margin: 0; }
.brand-mark { font-size: 1.2rem; }

header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: .75rem;
  align-items: center;
  flex-wrap: wrap;
  padding: .55rem 1rem;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

header nav {
  display: flex;
  gap: .15rem;
  padding: .2rem;
  background: var(--bg-soft);
  border-radius: 999px;
  overflow-x: auto;
}
header nav button {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: .35rem .8rem;
  white-space: nowrap;
}
header nav button.active { background: var(--card); color: var(--fg); box-shadow: var(--shadow); }

.chip {
  margin-left: auto;
  display: flex;
  gap: .45rem;
  align-items: center;
  padding: .25rem .7rem .25rem .25rem;
  border-radius: 999px;
  border-color: var(--line);
  font-weight: 550;
}

section[data-panel] { padding: 1.1rem; max-width: 1180px; margin: 0 auto; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}
.card.narrow { max-width: 34rem; }
.cards { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); align-items: start; }
.cards .card.wide { grid-column: 1 / -1; }

.empty {
  padding: 2.5rem 1rem;
  text-align: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}
.empty p { margin: .2rem 0; }

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

#login { display: grid; place-items: center; min-height: 100dvh; padding: 1rem; }
.login-card { width: min(23rem, 100%); padding: 1.6rem; }
.login-card .muted { margin: 0 0 1.1rem; }
.login-card form { margin-top: .3rem; }
#regHint { margin: .8rem 0 0; }

/* --- Avatare ------------------------------------------------------------- */

.avatar {
  flex: 0 0 auto;      /* nie stauchen, nie strecken - der Kreis muss ein Kreis bleiben */
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 50%;
  overflow: hidden;
  color: #fff;
  font-size: .8rem;
  font-weight: 650;
  line-height: 1;
  text-shadow: 0 1px 1px #0003;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.big { width: 5rem; height: 5rem; font-size: 2rem; }
.avatar.big-sm { width: 2.6rem; height: 2.6rem; font-size: 1.05rem; box-shadow: 0 0 0 2px #ffffff59; }
.profile-head { display: flex; gap: 1rem; align-items: center; margin: 1rem 0; }

/* --- Banner -------------------------------------------------------------- */

.banner {
  position: relative;
  height: 7.5rem;
  margin-bottom: .9rem;
  border-radius: var(--radius);
  overflow: hidden;
  background-size: cover;
  background-position: center;
  box-shadow: var(--shadow);
}
.banner::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(transparent 35%, #0000008c);
}
.banner .who {
  position: absolute;
  z-index: 1;
  left: 1rem;
  bottom: .8rem;
  display: flex;
  gap: .65rem;
  align-items: center;
  color: #fff;
  text-shadow: 0 1px 3px #000000a6;
}
.banner .who strong { display: block; font-size: 1.05rem; }
.banner .who small { opacity: .85; font-size: .8rem; }

/* --- Stundenplan --------------------------------------------------------- */

.bar { display: flex; gap: .6rem; align-items: center; margin-bottom: .9rem; flex-wrap: wrap; }
.weeknav { display: flex; align-items: center; gap: .2rem; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: .15rem; box-shadow: var(--shadow); }
.weeknav button { border: 0; background: transparent; border-radius: 999px; padding: .3rem .6rem; }
#weekLabel { min-width: 10.5rem; text-align: center; color: var(--muted); font-size: .9rem; }
#whosePlan { margin-left: auto; }

#grid { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow); }
table { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 42rem; background: var(--card); }
th, td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 0; text-align: left; }
tr > *:last-child { border-right: 0; }
tbody tr:last-child > * { border-bottom: 0; }

thead th {
  position: sticky;
  top: 0;
  padding: .55rem .7rem;
  background: var(--bg-soft);
  font-weight: 600;
  font-size: .9rem;
}
thead th small, th.time small { display: block; color: var(--muted); font-weight: 400; font-size: .78rem; }
thead th.today { color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
thead th.off { color: var(--danger); }
th.time { width: 5.5rem; padding: .5rem .7rem; color: var(--muted); font-weight: 550; background: var(--card); }

td.slot { height: 4.9rem; }
td.slot button {
  width: 100%;
  height: 100%;
  min-height: 4.9rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: left;
  padding: .4rem .55rem;
  display: block;
  font-weight: 400;
}
td.slot button:hover { background: var(--accent-soft); }
td.slot .code { font-weight: 650; font-size: .92rem; }
td.slot .sub {
  display: block;
  color: var(--muted);
  font-size: .76rem;
  margin-top: .12rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;   /* lange Lehrernamen sprengen die Spalte sonst */
}
td.slot .sub.nr { font-size: .68rem; opacity: .7; letter-spacing: .02em; }
td.slot .plus { color: var(--line-strong); font-size: 1.1rem; }

td.slot.filled button {
  background: hsl(var(--hue) 65% var(--tint-l) / var(--tint-a));
  box-shadow: inset 3px 0 0 hsl(var(--hue) 55% var(--tint-l));
}
td.slot.filled button:hover { background: hsl(var(--hue) 65% var(--tint-l) / calc(var(--tint-a) * 2)); }
td.slot.filled .code { color: hsl(var(--hue) 60% var(--code-l)); }
td.absent { opacity: .4; }

.badge {
  float: right;
  background: var(--shared);
  color: #fff;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 650;
  padding: .05rem .4rem;
  line-height: 1.35;
}

/* --- Listen -------------------------------------------------------------- */

.list { list-style: none; padding: 0; margin: .6rem 0 0; display: grid; gap: .4rem; }
.list li {
  display: flex;
  gap: .6rem;
  align-items: center;
  padding: .45rem .7rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
/* An die Klasse gebunden, nicht an die Position: der Avatar ist selbst ein <span> und wurde von
   einem :first-of-type-Selektor erwischt - dann zieht ihn flex:1 zu einer Ellipse auseinander. */
.list li .grow { flex: 1; min-width: 0; }
.list li .sub { display: block; color: var(--muted); font-size: .78rem; }
.list li.gone .grow { text-decoration: line-through; color: var(--muted); }
.list li.editing { border-color: var(--accent); background: var(--accent-soft); }
.list li em { color: var(--danger); font-size: .8rem; font-style: normal; }
#friendLists h3 { margin: 1.2rem 0 0; }
#absenceList, #friendLists .list { max-width: 38rem; }

.tag {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: .08rem .5rem;
  font-size: .74rem;
  font-weight: 650;
}

/* --- Dialog & Toast ------------------------------------------------------ */

dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--fg);
  box-shadow: var(--shadow-lg);
  padding: 1.3rem;
  width: min(26rem, calc(100vw - 2rem));
}
dialog::backdrop { background: #0b1020a8; backdrop-filter: blur(2px); }
dialog h2 { margin-bottom: .15rem; }
dialog .meta { color: var(--muted); font-size: .87rem; margin: 0 0 1rem; }
dialog dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .25rem .9rem;
  margin: 0 0 1rem;
  padding: .7rem .85rem;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  font-size: .9rem;
}
dialog dt { color: var(--muted); }
dialog dd { margin: 0; }
dialog .row { margin-top: 1rem; }
dialog select { flex: 1; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  translate: -50% 0;
  padding: .6rem 1.1rem;
  border-radius: 999px;
  color: #fff;
  background: var(--danger);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, translate .2s;
  z-index: 10;
}
#toast.show { opacity: 1; translate: -50% -.3rem; }
#toast.ok { background: var(--shared); }

@media (max-width: 640px) {
  section[data-panel] { padding: .8rem; }
  header { gap: .5rem; padding: .5rem .7rem; }
  .chip span:last-child { display: none; }
  #whosePlan { margin-left: 0; width: 100%; }
}
