/* ---------------------------------------------------------------------
   ChatSim design system "Blau Expressive" (student tablet + admin).
   Material 3 Expressive, used sparingly: tonal surfaces instead of
   shadows, pill buttons, one emphasized element per screen and the
   expressive shapes (cookie, sunny) only at key moments.
   All text colours are checked against WCAG AA (>= 4.5:1).
--------------------------------------------------------------------- */

@font-face {
  font-family: 'Roboto Flex';
  src: url('/fonts/roboto-flex.woff2') format('woff2');
  font-weight: 100 1000;
  font-style: normal;
  font-display: swap;
}

:root {
  --blue: #2155F5;            /* actions, 5.7:1 with white */
  --blue-hover: #1A47D6;
  --blue-container: #DCE5FF;  /* tonal buttons, chips */
  --on-blue-container: #00174B;
  --surface: #FFFFFF;
  --surface-low: #F7F9FF;
  --surface-mid: #EEF2FF;
  --surface-high: #E4E9F8;
  --bubble: #F1F3FA;
  --text: #191C23;
  --text-2: #44474F;          /* secondary text, 9.3:1 */
  --outline: #C4C6D0;
  --outline-strong: #74777F;
  --line: #E1E2EC;
  --danger: #B3261E;
  --warn-bg: #FFF4E0;
  --warn-text: #8A5A00;
  --ink: #191C23;             /* floating toolbar */

  --r-taeter-bg: #FFDAD6;      --r-taeter-fg: #410002;      --r-taeter-name: #B3261E;
  --r-betroffene-bg: #EADDFF;  --r-betroffene-fg: #21005D;  --r-betroffene-name: #6B4FB3;
  --r-mitlaeufer-bg: #FFDEA6;  --r-mitlaeufer-fg: #271900;  --r-mitlaeufer-name: #7A5900;
  --r-verteidiger-bg: #B6F2BE; --r-verteidiger-fg: #00210B; --r-verteidiger-name: #1E6B35;
  --r-beobachter-bg: #E1E2EC;  --r-beobachter-fg: #44474F;  --r-beobachter-name: #44474F;

  --spring: cubic-bezier(.34, 1.32, .64, 1);
  --emphasized: cubic-bezier(.2, .9, .3, 1);
  --font: 'Roboto Flex', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Type ---------------------------------------------------------- */
.display { margin: 0; font-weight: 800; font-size: clamp(36px, 4.4vw, 56px); line-height: 1.04; letter-spacing: -0.035em; }
.title { margin: 0; font-weight: 800; font-size: clamp(26px, 2.6vw, 32px); line-height: 1.1; letter-spacing: -0.025em; }
.lead { margin: 0; font-size: clamp(17px, 1.7vw, 20px); line-height: 1.5; color: var(--text-2); }
.label { margin: 0; font-size: 15px; font-weight: 600; color: var(--text-2); }
.muted { color: var(--text-2); }
.error { margin: 0; color: var(--danger); font-weight: 600; font-size: 16px; }

/* ---- Buttons -------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  height: 56px; padding: 0 28px; border: 0; border-radius: 999px;
  font-size: 17px; font-weight: 600; white-space: nowrap;
  transition: background-color .15s ease, transform .15s var(--spring), border-radius .25s var(--spring);
  text-decoration: none;
}
.btn:active:not(:disabled) { transform: scale(.97); border-radius: 18px; }
.btn-lg { height: 72px; padding: 0 36px; font-size: 21px; font-weight: 700; }
.btn-xl { height: 96px; padding: 0 40px; font-size: 22px; font-weight: 700; border-radius: 28px; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blue-hover); }
.btn-tonal { background: var(--blue-container); color: var(--on-blue-container); }
.btn-tonal:hover:not(:disabled) { background: #CDD9FF; }
.btn-text { background: transparent; color: var(--blue); padding: 0 16px; }
.btn-text:hover:not(:disabled) { background: var(--surface-mid); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-soft-danger { background: var(--bubble); color: var(--danger); height: 44px; padding: 0 16px; font-size: 14px; }
.btn:disabled { background: var(--surface-high); color: var(--text-2); }
.btn svg { flex-shrink: 0; }
.link { background: none; border: 0; padding: 8px 4px; color: var(--blue); font-weight: 600; font-size: 16px; text-decoration: underline; text-underline-offset: 5px; }

/* ---- Chips & status ------------------------------------------------- */
.chip {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 16px;
  border-radius: 999px; font-size: 15px; font-weight: 600; white-space: nowrap;
  background: var(--surface-mid); color: var(--blue);
}
.chip-ink { background: var(--ink); color: #fff; }
.chip-tonal { background: var(--blue-container); color: var(--on-blue-container); }
.chip-warn { background: var(--warn-bg); color: var(--warn-text); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.role-chip { display: inline-flex; align-items: center; height: 30px; padding: 0 12px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.role-chip.lg { height: 64px; padding: 0 28px; font-size: 32px; font-weight: 800; letter-spacing: -0.02em; }
.role-chip.md { height: 48px; padding: 0 20px; font-size: 22px; font-weight: 800; }

/* role colour helpers: background container + matching name colour */
.r-taeter { --role-bg: var(--r-taeter-bg); --role-fg: var(--r-taeter-fg); --role-name: var(--r-taeter-name); }
.r-betroffene { --role-bg: var(--r-betroffene-bg); --role-fg: var(--r-betroffene-fg); --role-name: var(--r-betroffene-name); }
.r-mitlaeufer { --role-bg: var(--r-mitlaeufer-bg); --role-fg: var(--r-mitlaeufer-fg); --role-name: var(--r-mitlaeufer-name); }
.r-verteidiger { --role-bg: var(--r-verteidiger-bg); --role-fg: var(--r-verteidiger-fg); --role-name: var(--r-verteidiger-name); }
.r-beobachter, .r-none { --role-bg: var(--r-beobachter-bg); --role-fg: var(--r-beobachter-fg); --role-name: var(--r-beobachter-name); }
.role-chip, .role-fill { background: var(--role-bg); color: var(--role-fg); }

/* ---- Shapes --------------------------------------------------------- */
.cookie, .sunny {
  -webkit-mask: url('/shapes/cookie.svg') center / contain no-repeat;
  mask: url('/shapes/cookie.svg') center / contain no-repeat;
  background: var(--blue);
}
.sunny { -webkit-mask-image: url('/shapes/sunny.svg'); mask-image: url('/shapes/sunny.svg'); }

/* Animated wavy progress line (M3 Expressive). */
.wave {
  height: 12px; flex: 1; min-width: 60px;
  background: var(--blue);
  -webkit-mask: url('/shapes/wave.svg') 0 0 / 20px 12px repeat-x;
  mask: url('/shapes/wave.svg') 0 0 / 20px 12px repeat-x;
  animation: wave-move .9s linear infinite;
}
@keyframes wave-move { to { -webkit-mask-position: 20px 0; mask-position: 20px 0; } }

/* Spinning sunny shape used as loading indicator inside buttons. */
.loader { width: 26px; height: 26px; animation: spin 1.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Surfaces -------------------------------------------------------- */
.card { background: var(--surface-low); border-radius: 28px; padding: 22px 26px; }
.card-mid { background: var(--surface-mid); }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 24px 32px 0;
}
.brand { font-weight: 700; font-size: 18px; }

/* ---- Numbered task list --------------------------------------------- */
.tasks { display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 0; list-style: none; }
.tasks li { display: flex; gap: 14px; align-items: flex-start; font-size: 19px; line-height: 1.45; }
.tasks li::before {
  counter-increment: task; content: counter(task);
  flex-shrink: 0; width: 32px; height: 32px; margin-top: -2px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  background: var(--role-bg, var(--blue-container)); color: var(--role-fg, var(--on-blue-container));
  font-weight: 700; font-size: 15px;
}
.tasks { counter-reset: task; }
.tasks.sm li { font-size: 16px; gap: 10px; }
.tasks.sm li::before { width: 26px; height: 26px; font-size: 13px; margin-top: -1px; }

/* ---- Chat ----------------------------------------------------------- */
.chat-log { display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.msg { display: flex; gap: 10px; align-items: flex-end; max-width: 78%; animation: msg-in .22s var(--emphasized); }
.msg.me { align-self: flex-end; flex-direction: column; align-items: flex-end; gap: 4px; }
.msg .avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px;
  background: var(--role-bg); color: var(--role-fg);
}
.bubble { background: var(--bubble); border-radius: 24px 24px 24px 8px; padding: 12px 18px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.bubble .name { font-weight: 600; font-size: 14px; color: var(--role-name); }
.bubble .text { font-size: 18px; line-height: 1.4; overflow-wrap: anywhere; }
.msg.me .bubble { background: var(--blue); color: #fff; border-radius: 24px 24px 8px 24px; }
.msg-note { font-size: 13px; font-weight: 500; color: var(--text-2); }
.situation-note {
  align-self: center; max-width: 640px; text-align: center; font-size: 15px; line-height: 1.5;
  color: var(--text-2); background: var(--surface-low); border-radius: 20px; padding: 12px 18px;
}
@keyframes msg-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---- Overlays --------------------------------------------------------- */
.overlay {
  position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px; text-align: center; padding: 24px;
  background: rgba(25, 28, 35, .92); color: #fff;
}
.overlay .big { font-weight: 800; font-size: clamp(44px, 6vw, 72px); letter-spacing: -0.035em; margin: 0; }
.overlay p { margin: 0; font-size: 22px; color: #D9DCE6; }

/* ---- Settings (admin) ------------------------------------------------- */
.sec { background: var(--surface-low); border-radius: 32px; padding: 24px 28px; display: flex; flex-direction: column; }
.sec h2 { margin: 0 0 6px; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.set-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px;
  padding: 14px 0; border-top: 1px solid var(--surface-high);
}
.sec h2 + .set-row { border-top: 0; }
.set-text { display: flex; flex-direction: column; gap: 3px; flex: 1 1 260px; }
.set-row.stack { flex-direction: column; align-items: stretch; }
.set-row.stack .set-text { flex: none; }
.set-text b { font-size: 17px; font-weight: 600; }
.set-text span { font-size: 14px; line-height: 1.4; color: var(--text-2); }

.switch {
  position: relative; width: 52px; height: 32px; flex-shrink: 0; border: 0; padding: 0;
  border-radius: 999px; background: var(--surface-high); box-shadow: inset 0 0 0 2px var(--outline-strong);
  transition: background-color .2s ease;
}
.switch::after {
  content: ''; position: absolute; top: 8px; left: 8px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--outline-strong); transition: all .25s var(--spring);
}
.switch[aria-checked="true"] { background: var(--blue); box-shadow: none; }
.switch[aria-checked="true"]::after { top: 4px; left: 24px; width: 24px; height: 24px; background: #fff; }

.seg { display: flex; flex-wrap: wrap; gap: 3px; }
.seg button {
  height: 44px; padding: 0 16px; border: 0; border-radius: 10px; background: var(--surface-high);
  font-size: 14px; font-weight: 600; transition: background-color .15s ease, border-radius .25s var(--spring);
}
.seg button:first-child { border-radius: 999px 10px 10px 999px; }
.seg button:last-child { border-radius: 10px 999px 999px 10px; }
.seg button[aria-pressed="true"] { background: var(--blue); color: #fff; border-radius: 999px; }

.stepper { display: flex; align-items: center; gap: 14px; }
.stepper button { width: 56px; height: 56px; border: 0; border-radius: 999px; background: var(--blue-container); color: var(--on-blue-container); font-size: 28px; }
.stepper input { width: 96px; border: 0; background: transparent; text-align: center; font-size: 48px; font-weight: 800; color: var(--blue); padding: 0; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ---- Time ruler --------------------------------------------------------- */
.ruler { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.ruler-value { text-align: center; font-weight: 800; font-size: 44px; line-height: 1; letter-spacing: -0.02em; color: var(--blue); font-variant-numeric: tabular-nums; }
.ruler-window { position: relative; background: var(--surface-mid); border-radius: 28px; padding: 14px 0 10px; overflow: hidden; }
.ruler-track {
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none; touch-action: pan-x; cursor: grab;
  padding: 0 calc(50% - var(--step) / 2);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 16%, #000 84%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 16%, #000 84%, transparent);
}
.ruler-track::-webkit-scrollbar { display: none; }
.ruler-track.grabbing { cursor: grabbing; }
.ruler-track:focus-visible { outline: none; }
.ruler-window:has(.ruler-track:focus-visible) { box-shadow: inset 0 0 0 3px var(--blue); }
.ruler-inner { display: flex; width: max-content; }
.ruler-tick { width: var(--step); flex-shrink: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; border: 0; background: none; padding: 0; }
.ruler-tick i { display: block; width: 3px; height: 16px; margin-top: 16px; border-radius: 3px; background: var(--outline); }
.ruler-tick.major i { height: 32px; margin-top: 0; background: var(--outline-strong); }
.ruler-tick span { height: 18px; font-size: 14px; font-weight: 600; color: var(--text-2); }
.ruler-needle { position: absolute; left: 50%; top: 8px; width: 6px; height: 44px; margin-left: -3px; border-radius: 6px; background: var(--blue); pointer-events: none; }

dialog.sheet {
  border: 0; padding: 0; border-radius: 32px; width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  background: var(--surface); color: var(--text);
}
dialog.sheet::backdrop { background: rgba(25, 28, 35, .5); }
.sheet-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 24px; background: var(--surface); }
.sheet-body { display: flex; flex-direction: column; gap: 16px; padding: 0 24px 24px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
