:root {
  --red: #8b0000;
  --ink: #262626;
  --muted: #6f6b67;
  --line: #ded8d1;
  --paper: #fffdf9;
  --panel: #ffffff;
  --teal: #2f5d62;
  --soft: #f5f1ea;
  --ok: #2d7a46;
  --warn: #a65f00;
}

.calendar-toolbar { display:flex; justify-content:flex-end; margin:18px 0 10px; }
.calendar-toolbar label { max-width:260px; }
.private-calendar-list { display:grid; gap:10px; }
.private-calendar-event { display:grid; grid-template-columns:64px 1fr; gap:14px; align-items:start; padding:14px; border:1px solid #eadde2; border-radius:12px; background:#fff; }
.private-calendar-event p { margin:4px 0; color:#65565d; }
.private-calendar-event small { color:#786970; line-height:1.45; }
.calendar-date { display:flex; flex-direction:column; align-items:center; padding:8px 5px; border-radius:9px; background:#f5e6eb; color:#860a2e; text-transform:uppercase; }
.calendar-date strong { font-size:17px; }
.calendar-date span { font-size:11px; font-weight:700; }
.calendar-settings { margin-top:18px; border-top:1px solid #eadde2; padding-top:14px; }
.calendar-settings summary { cursor:pointer; color:#860a2e; font-weight:700; margin-bottom:14px; }
@media (max-width: 700px) {
  .private-calendar-event { grid-template-columns:54px 1fr; padding:12px; }
  .calendar-toolbar { justify-content:stretch; }
  .calendar-toolbar label { max-width:none; width:100%; }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--soft);
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  align-items: center;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 20px;
  justify-content: space-between;
  padding: 18px 24px;
  position: sticky;
  top: 0;
  z-index: 2;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: var(--red);
  font-size: 26px;
  letter-spacing: 0;
}

h2 {
  color: var(--teal);
  font-size: 18px;
}

.topbar p {
  color: var(--muted);
  margin-top: 4px;
}

.brand-heading {
  align-items: center;
  display: flex;
  gap: 13px;
}

.brand-logo {
  border-radius: 50%;
  box-shadow: 0 5px 16px rgba(74, 42, 35, .12);
  height: 58px;
  object-fit: cover;
  width: 58px;
}

.brand-wordmark {
  display: block;
  height: auto;
  max-width: min(340px, 54vw);
  width: 340px;
}

.mode-switch {
  background: var(--soft);
  border: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  padding: 3px;
}

button {
  background: var(--teal);
  border: 0;
  color: white;
  cursor: pointer;
  font: inherit;
  min-height: 38px;
  padding: 8px 14px;
}

.button-link {
  align-items: center;
  background: var(--teal);
  color: white;
  display: inline-flex;
  min-height: 38px;
  padding: 8px 14px;
  text-decoration: none;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.mode-switch button {
  background: transparent;
  color: var(--ink);
}

.mode-switch button.active {
  background: var(--red);
  color: white;
}

main {
  margin: 0 auto;
  max-width: 1180px;
  padding: 24px;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 18px;
}

.communication-intro {
  align-items: end;
  background: linear-gradient(135deg, #8b0000, #5e1830);
  color: white;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(220px, .8fr) minmax(280px, 1.2fr);
  padding: 24px;
}

.communication-intro h2 {
  color: white;
  font-size: 25px;
  margin-top: 5px;
}

.communication-intro p {
  line-height: 1.55;
  opacity: .92;
}

.eyebrow {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.summary {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
}

.metric {
  padding: 16px;
}

.metric strong {
  display: block;
  font-size: 28px;
}

.metric span {
  color: var(--muted);
  font-size: 14px;
}

.panel {
  padding: 16px;
}

.login-panel {
  background:
    radial-gradient(circle at 100% 0, rgba(139, 0, 0, .11), transparent 34%),
    linear-gradient(145deg, #fffdf9, #f8f1ec);
  border: 1px solid #e3d8d0;
  border-radius: 24px;
  box-shadow: 0 22px 60px rgba(74, 42, 35, .12);
  max-width: 900px;
  margin: 48px auto;
  overflow: hidden;
  padding: 30px;
}

.login-panel > .panel-title {
  display: block;
  margin-bottom: 24px;
  text-align: center;
}

.login-logo {
  border-radius: 50%;
  box-shadow: 0 8px 24px rgba(74, 42, 35, .14);
  display: block;
  height: 92px;
  margin: 0 auto 14px;
  object-fit: cover;
  width: 92px;
}

.login-panel > .panel-title h2 {
  color: var(--red);
  font-size: 27px;
  margin-bottom: 8px;
}

.login-panel > .panel-title::after {
  color: var(--muted);
  content: "Bitte wähle den passenden persönlichen Zugang.";
  display: block;
  font-size: 14px;
}

.login-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.login-box {
  background: rgba(255, 255, 255, .94);
  border: 1px solid #e4d9d2;
  border-radius: 18px;
  box-shadow: 0 9px 28px rgba(57, 44, 39, .07);
  display: grid;
  gap: 14px;
  padding: 24px;
  position: relative;
}

.login-box h3 {
  color: var(--red);
  font-size: 21px;
  margin: 0;
  padding-left: 44px;
}

.login-box h3::before {
  align-items: center;
  background: #f4e4e8;
  border-radius: 12px;
  content: "🔐";
  display: flex;
  font-size: 20px;
  height: 36px;
  justify-content: center;
  left: 24px;
  position: absolute;
  top: 20px;
  width: 36px;
}

#teacherLoginForm h3::before {
  background: #e5f0ee;
  content: "♫";
  color: var(--teal);
  font-weight: 800;
}

.login-box p {
  color: var(--muted);
  line-height: 1.5;
  min-height: 42px;
}

.login-box label {
  color: #554d49;
  font-size: 13px;
  font-weight: 700;
}

.login-box input {
  border: 1px solid #d7cac2;
  border-radius: 11px;
  font-size: 16px;
  min-height: 50px;
  padding: 12px 14px;
}

.login-box input:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(139, 0, 0, .10);
  outline: none;
}

.login-box button {
  border-radius: 11px;
  font-weight: 800;
  min-height: 50px;
  transition: transform .15s ease, box-shadow .15s ease;
}

#adminLoginForm button {
  background: var(--red);
}

.login-box button:hover {
  box-shadow: 0 8px 18px rgba(47, 93, 98, .18);
  transform: translateY(-1px);
}

.panel-title {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 14px;
}

.collapsible-panel > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  cursor: pointer;
  list-style: none;
  min-height: 58px;
}
.collapsible-panel > summary::-webkit-details-marker { display: none; }
.collapsible-panel > summary strong { display: block; font-size: 20px; color: var(--ink); }
.collapsible-panel > summary small { display: block; color: var(--muted); margin-top: 4px; line-height: 1.4; }
.collapsible-panel > summary::after { content: "Aufklappen"; color: var(--red); font-weight: 800; font-size: 13px; }
.collapsible-panel[open] > summary::after { content: "Zuklappen"; }
.collapsible-panel .count-badge { background: var(--soft); color: var(--red); border-radius: 999px; padding: 6px 10px; font-weight: 800; margin-left: auto; }
.collapsible-content { border-top: 1px solid #eadde2; margin-top: 14px; padding-top: 16px; }
.collapsible-content > .search { width: 100%; max-width: 420px; margin-bottom: 14px; }

.grid-form,
.attendance-form {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.import-form {
  display: grid;
  gap: 12px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  gap: 5px;
}

input,
select,
textarea {
  background: white;
  border: 1px solid var(--line);
  color: var(--ink);
  font: inherit;
  min-height: 38px;
  padding: 8px 10px;
  width: 100%;
}

textarea {
  resize: vertical;
}

.wide {
  grid-column: span 2;
}

form button {
  align-self: end;
}

.search {
  max-width: 260px;
}

.table-wrap {
  overflow: auto;
}

table {
  border-collapse: collapse;
  min-width: 720px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status {
  color: white;
  display: inline-block;
  font-size: 13px;
  padding: 4px 8px;
}

.status.aktiv {
  background: var(--ok);
}

.status.offen,
.status.abgelaufen,
.status.aufgebraucht {
  background: var(--warn);
}

.status.pausiert {
  background: var(--teal);
}

.course-info {
  color: var(--muted);
  margin-bottom: 10px;
}

.save-confirmation {
  background: #edf8f1;
  border: 1px solid #83b996;
  border-left: 5px solid var(--ok);
  border-radius: 8px;
  color: #245c38;
  font-size: 14px;
  font-weight: 700;
  margin: 10px 0;
  padding: 10px 12px;
}

.save-confirmation.pending {
  background: #fff8e8;
  border-color: #d4b56c;
  border-left-color: var(--warn);
  color: #735719;
}

.top-course-controls {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(220px, 2fr) minmax(140px, 1fr) minmax(180px, 1fr) minmax(110px, 0.7fr);
  margin-bottom: 12px;
}

.report-text {
  margin-top: 12px;
  width: 100%;
}

.helper {
  color: var(--muted);
  font-size: 14px;
  margin-top: 12px;
}

.form-error {
  background: #fff3f3;
  border: 1px solid #d89a9a;
  color: var(--red);
  font-size: 14px;
  margin-top: 14px;
  padding: 10px 12px;
}

.import-result {
  color: var(--muted);
  font-size: 14px;
  margin: 10px 0 14px;
}

.import-result strong {
  color: var(--ink);
}

.backup-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.backup-actions .helper {
  margin-top: 0;
}

.mark-buttons {
  display: flex;
  gap: 6px;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.row-actions button {
  min-height: 32px;
  padding: 5px 9px;
}

.row-actions .danger {
  background: var(--red);
}

.mark-buttons button {
  min-height: 32px;
  padding: 5px 10px;
}

.mark-buttons button.secondary {
  background: #77716b;
}

.mark-buttons button.active-yes {
  background: var(--ok);
}

.mark-buttons button.active-no {
  background: var(--warn);
}

.toast {
  background: var(--ink);
  bottom: 18px;
  color: white;
  left: 50%;
  padding: 11px 16px;
  position: fixed;
  transform: translateX(-50%);
}

.notification-layout { display:grid; grid-template-columns:minmax(0,1fr) 280px; gap:22px; align-items:start; }
.notification-actions { display:flex; align-items:end; gap:8px; }
.push-preview { min-height:300px; padding:48px 13px 18px; border:8px solid #242024; border-radius:32px; background:#242024; color:#fff; }
.push-preview>small { display:block; text-align:center; letter-spacing:2px; margin-bottom:22px; }
.push-preview>div { background:#fff; color:var(--ink); padding:15px; border-radius:16px; }
.push-preview p { margin:5px 0 0; }
.notification-list { display:grid; gap:8px; margin:14px 0 22px; }
.notification-item { display:flex; justify-content:space-between; gap:14px; padding:13px; border:1px solid var(--line); border-radius:10px; }
.notification-item p { margin:3px 0; }
.notification-badge { color:var(--burgundy); font-size:12px; font-weight:700; text-transform:uppercase; }
button:disabled { cursor:wait; opacity:.65; }
.chat-controls { display:grid; grid-template-columns:minmax(240px,2fr) minmax(220px,1fr) auto; gap:12px; align-items:end; margin-bottom:16px; }
.chat-messages { display:grid; gap:9px; max-height:520px; overflow:auto; padding:4px 0 12px; }
.chat-message { display:flex; justify-content:space-between; gap:14px; padding:13px; border:1px solid var(--line); border-radius:10px; background:#fff; }
.chat-message.staff { border-left:5px solid var(--burgundy); background:#fff8fa; }
.chat-message p { margin:5px 0; white-space:pre-wrap; }
.chat-message small { color:var(--muted); }
.chat-message button { align-self:start; min-height:32px; padding:5px 9px; }
.chat-compose { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:12px; align-items:end; border-top:1px solid var(--line); padding-top:15px; }
.poll-create { display:grid; grid-template-columns:180px minmax(260px,1fr) auto; gap:12px; align-items:end; padding:14px; margin-bottom:14px; border-radius:10px; background:#fff5f8; border:1px solid #ead6dd; }
.poll-list { display:grid; gap:8px; margin-bottom:16px; }
.poll-item { display:flex; justify-content:space-between; gap:14px; align-items:center; padding:13px; border:1px solid var(--line); border-radius:10px; background:#fff; }
.poll-item strong { display:block; margin:5px 0; }
.poll-item p { margin:0; color:var(--muted); }
.roster-prep-panel { border-left:5px solid var(--teal); }
.roster-prep-panel h2 { color:var(--red); }

@media (max-width: 800px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .summary,
  .communication-intro,
  .top-course-controls,
  .grid-form,
  .attendance-form,
  .login-grid {
    grid-template-columns: 1fr;
  }
  .notification-layout { grid-template-columns:1fr; }
  .chat-controls,
  .chat-compose,
  .poll-create { grid-template-columns:1fr; }

  .wide {
    grid-column: auto;
  }
}
.team-chat-layout { display:grid; grid-template-columns:minmax(220px, .8fr) minmax(320px, 2fr); gap:1rem; align-items:start; }
.team-chat-sidebar, .team-chat-main { display:grid; gap:.9rem; }
.team-conversation-create { display:grid; gap:.75rem; padding:1rem; border:1px solid var(--line); border-radius:16px; background:var(--soft); }
.team-conversation-create select[multiple] { min-height:11rem; }
.team-chat-main .chat-messages { min-height:19rem; max-height:32rem; overflow:auto; }
@media (max-width: 760px) { .team-chat-layout { grid-template-columns:1fr; } }

@media (max-width: 600px) {
  main { padding: 10px; }
  .topbar { gap: 12px; padding: 12px; }
  .topbar h1 { font-size: 22px; }
  .panel { padding: 14px 12px; }
  .login-panel { border-radius: 18px; margin: 16px auto; padding: 18px 12px; }
  .brand-logo { height: 46px; width: 46px; }
  .brand-wordmark { max-width: 230px; width: 52vw; }
  .login-logo { height: 78px; width: 78px; }
  .login-panel > .panel-title h2 { font-size: 24px; }
  .login-box { padding: 20px 16px; }
  .login-box h3 { padding-left: 42px; }
  .login-box h3::before { left: 16px; }
  .login-box p { min-height: 0; }
  .panel-title { align-items: stretch; flex-direction: column; }
  .panel-title > button { width: 100%; }
  input, select, textarea, button, .button-link { min-height: 48px; }

  #attendancePanel .top-course-controls {
    background: #fff9f4;
    border: 1px solid var(--line);
    border-radius: 12px;
    grid-template-columns: 1fr;
    padding: 12px;
  }
  #attendancePanel .top-course-controls .wide { grid-column: auto; }
  #attendancePanel #saveTeachingEntry { font-weight: 800; width: 100%; }
  #attendancePanel .course-info { font-size: 15px; font-weight: 700; }
  #attendancePanel .save-confirmation { line-height: 1.4; }

  #attendancePanel .table-wrap,
  #teachingReportDetails.table-wrap { overflow: visible; }
  #attendancePanel table,
  #teachingReportDetails table { min-width: 0; }
  #attendancePanel table,
  #attendancePanel tbody,
  #attendancePanel tr,
  #attendancePanel td,
  #teachingReportDetails table,
  #teachingReportDetails tbody,
  #teachingReportDetails tr,
  #teachingReportDetails td { display: block; width: 100%; }
  #attendancePanel thead,
  #teachingReportDetails thead { display: none; }
  #attendancePanel tbody tr,
  #teachingReportDetails tbody tr {
    background: white;
    border: 1px solid var(--line);
    border-left: 5px solid var(--teal);
    border-radius: 12px;
    margin: 12px 0;
    overflow: hidden;
    padding: 8px 12px;
  }
  #attendancePanel td,
  #teachingReportDetails td {
    align-items: center;
    border-bottom: 1px solid #eee8e1;
    display: flex;
    gap: 12px;
    justify-content: space-between;
    min-height: 44px;
    padding: 8px 0;
  }
  #attendancePanel td:last-child,
  #teachingReportDetails td:last-child { border-bottom: 0; }
  #attendancePanel td::before,
  #teachingReportDetails td::before {
    color: var(--muted);
    flex: 0 0 38%;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
  }
  #attendancePanel td:nth-child(1)::before { content: "Kundin"; }
  #attendancePanel td:nth-child(2)::before { content: "Abo"; }
  #attendancePanel td:nth-child(3)::before { content: "Anwesenheit"; }
  #attendancePanel td:nth-child(4)::before { content: "Rest"; }
  #attendancePanel td:nth-child(5)::before { content: "Bemerkung"; }
  #teachingReportDetails td:nth-child(1)::before { content: "Datum"; }
  #teachingReportDetails td:nth-child(2)::before { content: "Lehrperson"; }
  #teachingReportDetails td:nth-child(3)::before { content: "Tätigkeit / Kurs"; }
  #teachingReportDetails td:nth-child(4)::before { content: "Zeit"; }
  #teachingReportDetails td:nth-child(5)::before { content: "Stunden"; }
  #teachingReportDetails td:nth-child(6)::before { content: "Bemerkung"; }
  #attendancePanel .mark-buttons { flex: 1; }
  #attendancePanel .mark-buttons button { flex: 1; min-height: 46px; }
  #teachingReportForm button { width: 100%; }
}

/* Phone-only containment: keep long course names and forms inside the viewport. */
@media (max-width: 600px) {
  #teacherView { width:100%; min-width:0; max-width:100%; font-size:15px; }
  #teacherView .panel, #teacherView form, #teacherView label,
  #teacherView .grid-form > *, #teacherView .top-course-controls > *,
  #teacherView .private-calendar-event > * { min-width:0; max-width:100%; }
  #teacherView .grid-form, #teacherView .top-course-controls { grid-template-columns:minmax(0,1fr); gap:10px; }
  #teacherView h2 { font-size:20px; line-height:1.25; margin:0 0 8px; overflow-wrap:anywhere; }
  #teacherView h3 { font-size:17px; line-height:1.3; }
  #teacherView p, #teacherView summary, #teacherView td { overflow-wrap:anywhere; }
  #teacherView input, #teacherView select, #teacherView textarea {
    box-sizing:border-box; width:100%; min-width:0; max-width:100%;
    font-size:16px; min-height:44px;
  }
  #teacherView input[type=checkbox], #teacherView input[type=radio] { width:auto; }
  #teacherView button { min-height:44px; max-width:100%; white-space:normal; overflow-wrap:anywhere; font-size:15px; }
  #teacherView .helper { font-size:14px; line-height:1.4; }
  #teacherView .panel { padding:12px 10px; }
  #teacherView .table-wrap { max-width:100%; overflow-x:auto; }
  #teacherView #attendancePanel .table-wrap { overflow:visible; }
  #teacherView #attendancePanel td { gap:8px; flex-wrap:wrap; }
  #teacherView #attendancePanel td::before { flex-basis:30%; }
  #teacherView .mark-buttons { display:flex; flex-wrap:wrap; min-width:0; gap:6px; }
  #teacherView .calendar-toolbar { flex-wrap:wrap; gap:8px; }
}
