/* Cool-Lernen – freundlich, verspielt, aufgeräumt. Mobile first. */

:root {
  --primary: #7c3aed;
  --primary-2: #a855f7;
  --on-primary: #ffffff;
  --accent: var(--primary);
  --on-accent: var(--on-primary);

  --bg: #f6f3ff;
  --bg-2: #efe9ff;
  --surface: #ffffff;
  --surface-2: #f8f7fc;
  --text: #1f1d2b;
  --muted: #6b6880;
  --border: #e4e0f0;
  --shadow: 0 2px 10px rgba(76, 29, 149, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 40px rgba(76, 29, 149, 0.18);

  --danger: #e11d48;
  --danger-soft: #ffe4ea;
  --ok: #059669;
  --ok-soft: #d1fae5;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --info-soft: #ede9fe;

  --radius: 18px;
  --radius-sm: 12px;
  --tap: 48px;
  --header-h: 60px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, "Liberation Mono", monospace;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #a78bfa;
    --primary-2: #c084fc;
    --on-primary: #1a1430;
    --bg: #15131f;
    --bg-2: #1c1929;
    --surface: #221f31;
    --surface-2: #2a2640;
    --text: #f1eefb;
    --muted: #a7a2bf;
    --border: #3a3552;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
    --danger: #fb7185;
    --danger-soft: #3f1d2a;
    --ok: #34d399;
    --ok-soft: #133229;
    --warn: #fbbf24;
    --warn-soft: #3a2e12;
    --info-soft: #2b2545;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 110% -10%, rgba(168, 85, 247, 0.12), transparent 60%),
    radial-gradient(900px 400px at -10% 110%, rgba(59, 130, 246, 0.08), transparent 60%),
    var(--bg);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

a {
  color: var(--primary);
}

h1,
h2,
h3 {
  line-height: 1.25;
  margin: 0 0 0.5em;
}

h1 {
  font-size: 1.6rem;
}

h2 {
  font-size: 1.25rem;
}

h3 {
  font-size: 1.05rem;
}

p {
  margin: 0 0 0.75em;
}

code,
.mono {
  font-family: var(--mono);
  font-size: 0.92em;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.875rem;
}

.break {
  word-break: break-all;
}

.pad {
  padding: 12px;
}

.big-emoji {
  font-size: 3.2rem;
  line-height: 1.1;
  margin-bottom: 0.25em;
}

:focus-visible {
  outline: 3px solid var(--primary-2);
  outline-offset: 2px;
  border-radius: 6px;
}

.view:focus {
  outline: none;
}

/* ------------------------------------------------------------------ */
/* Kopfzeile                                                          */
/* ------------------------------------------------------------------ */

.app-header {
  flex: 0 0 auto;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  color: var(--on-primary);
  box-shadow: var(--shadow);
  padding-top: env(safe-area-inset-top);
  position: relative;
  z-index: 30;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: var(--header-h);
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
}

.logo {
  color: inherit;
  text-decoration: none;
  font-weight: 800;
  font-size: 1.3rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.hdr-link,
.user-btn {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  min-width: 44px;
  justify-content: center;
  padding: 0 10px;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  background: transparent;
  border: 0;
  cursor: pointer;
}

.hdr-link:hover,
.user-btn:hover,
.user-btn[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.18);
}

.hdr-label,
.user-name {
  display: none;
}

.menu-wrap {
  position: relative;
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 230px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 40;
}

.menu-who {
  padding: 8px 12px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.menu-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: var(--tap);
  padding: 0 12px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  background: none;
  border: 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.menu-item:hover {
  background: var(--surface-2);
}

/* ------------------------------------------------------------------ */
/* Hauptbereich                                                       */
/* ------------------------------------------------------------------ */

.view {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: env(safe-area-inset-bottom);
}

.view.view-fill {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: 0;
}

.page {
  max-width: 1000px;
  margin: 0 auto;
  padding: 16px max(14px, env(safe-area-inset-left)) 32px;
}

.page.narrow {
  max-width: 720px;
}

.boot {
  text-align: center;
  padding: 80px 20px;
  color: var(--muted);
}

.loading {
  color: var(--muted);
  padding: 20px;
  text-align: center;
}

.loading::before {
  content: "⏳ ";
}

.noscript {
  padding: 20px;
  text-align: center;
}

.hero {
  padding: 8px 0 12px;
}

.hero h1 {
  font-size: 1.7rem;
  margin-bottom: 0.2em;
}

/* Karten */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.card-head h2 {
  margin: 0;
}

.empty-state {
  text-align: center;
  padding: 28px 18px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.row.center {
  justify-content: center;
}

.toolbar-row {
  margin-bottom: 14px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.grid-2,
.grid-3 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 14px;
}

/* ------------------------------------------------------------------ */
/* Buttons                                                            */
/* ------------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: 999px;
  border: 2px solid transparent;
  font: inherit;
  font-weight: 650;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s ease, filter 0.15s ease, background-color 0.15s ease;
  white-space: nowrap;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.12);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.07);
}

.btn-soft {
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}

.btn-soft:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 22%, var(--surface));
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger-soft {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-big {
  min-height: 56px;
  font-size: 1.1rem;
}

.btn-block {
  width: 100%;
}

.btn-small {
  min-height: 40px;
  padding: 0 14px;
  font-size: 0.92rem;
}

.btn.is-busy {
  cursor: progress;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border: 0;
  background: transparent;
  border-radius: 999px;
  cursor: pointer;
  font-size: 1rem;
  color: inherit;
}

.icon-btn:hover {
  background: var(--surface-2);
}

/* ------------------------------------------------------------------ */
/* Formulare                                                          */
/* ------------------------------------------------------------------ */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field-label {
  font-weight: 650;
  font-size: 0.95rem;
}

.field-hint {
  font-size: 0.85rem;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="url"],
input[type="number"],
input[type="file"],
select,
textarea {
  font: inherit;
  font-size: 16px; /* verhindert Zoom auf iOS */
  color: var(--text);
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  min-height: var(--tap);
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent);
}

input[type="color"] {
  width: 72px;
  height: var(--tap);
  padding: 4px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

.doc-textarea,
.instr-textarea {
  min-height: 320px;
  font-family: var(--mono);
  font-size: 15px;
}

.instr-textarea {
  min-height: 50vh;
}

.icon-input {
  font-size: 1.6rem !important;
  max-width: 120px;
  text-align: center;
}

.icon-ideas {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.icon-idea {
  min-width: 44px;
  min-height: 44px;
  font-size: 1.35rem;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  cursor: pointer;
}

.icon-idea:hover {
  background: var(--surface-2);
}

.form-error {
  color: var(--danger);
  font-weight: 600;
}

.username-display {
  font-weight: 700;
  font-size: 1.15rem;
  padding: 10px 14px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 2px dashed var(--border);
}

.model-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.model-row select {
  flex: 1 1 auto;
  min-width: 0;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
  margin: 12px 0;
}

.inline-form .field {
  flex: 1 1 220px;
  margin-bottom: 0;
}

/* Schalter */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  min-height: var(--tap);
  position: relative;
}

.switch.is-disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.switch-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch-track {
  flex: 0 0 auto;
  width: 58px;
  height: 32px;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  transition: background-color 0.2s ease;
}

.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease;
}

.switch-input:checked + .switch-track {
  background: var(--accent);
}

.switch-input:checked + .switch-track .switch-thumb {
  transform: translateX(26px);
}

.switch-input:focus-visible + .switch-track {
  outline: 3px solid var(--primary-2);
  outline-offset: 2px;
}

.switch-label {
  font-weight: 600;
}

.mode-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding: 12px;
  margin: 8px 0 14px;
  background: var(--surface-2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  text-align: center;
}

.mode-label {
  font-weight: 600;
  color: var(--muted);
  flex: 1 1 120px;
}

.mode-label.active {
  color: var(--text);
}

.mode-toggle.is-disabled .mode-label {
  opacity: 0.6;
}

.key-state {
  font-weight: 500;
  font-size: 0.85rem;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.key-state.is-set {
  background: var(--ok-soft);
  color: var(--ok);
}

.key-state.is-unset {
  background: var(--surface-2);
  color: var(--muted);
}

.info-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
}

.test-result {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
}

.test-result.ok {
  background: var(--ok-soft);
}

.test-result.fail {
  background: var(--danger-soft);
}

.test-reply {
  margin-top: 4px;
  font-style: italic;
}

/* Kopierfeld */
.copy-box {
  margin: 10px 0;
}

.copy-label {
  font-weight: 650;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.copy-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.copy-field {
  flex: 1 1 auto;
  min-width: 0;
}

.copy-box-multi .copy-row {
  flex-direction: column;
}

.copy-box-multi .copy-row .btn {
  align-self: flex-start;
}

/* Banner */
.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 0.95rem;
}

.banner-info {
  background: var(--info-soft);
}

.banner-warn {
  background: var(--warn-soft);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
}

.banner-text {
  flex: 1 1 220px;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-official {
  background: color-mix(in srgb, var(--accent) 18%, var(--surface));
  color: var(--text);
}

.badge-own {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge-ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge-wait {
  background: var(--warn-soft);
  color: var(--warn);
}

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

.auth-page {
  display: flex;
  justify-content: center;
  padding-top: 28px;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  text-align: center;
  padding: 26px 22px;
}

.auth-card .field {
  text-align: left;
}

.auth-card h1 {
  font-size: 1.5rem;
}

/* ------------------------------------------------------------------ */
/* Fächer-Kacheln                                                     */
/* ------------------------------------------------------------------ */

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

.subject-tile {
  --accent: var(--primary);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 2px;
  min-height: 140px;
  padding: 16px;
  border-radius: 22px;
  text-decoration: none;
  color: var(--text);
  background:
    linear-gradient(160deg, color-mix(in srgb, var(--accent) 26%, var(--surface)) 0%, var(--surface) 75%);
  border: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.subject-tile::after {
  content: "";
  position: absolute;
  right: -30px;
  top: -30px;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

.subject-tile:hover {
  transform: translateY(-3px) rotate(-0.5deg);
  box-shadow: var(--shadow-lg);
}

.subject-tile:active {
  transform: scale(0.98);
}

.subject-icon {
  font-size: 2.6rem;
  line-height: 1;
  margin-bottom: auto;
  position: relative;
  z-index: 1;
}

.subject-name {
  font-weight: 800;
  font-size: 1.2rem;
  position: relative;
  z-index: 1;
}

.subject-meta {
  font-size: 0.85rem;
  color: var(--muted);
  position: relative;
  z-index: 1;
}

.skeleton {
  background: var(--surface-2);
  border-color: var(--border);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.5;
  }
}

/* ------------------------------------------------------------------ */
/* Fach-Seite                                                         */
/* ------------------------------------------------------------------ */

.subject-top {
  flex: 0 0 auto;
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 16%, var(--bg)) 0%, transparent 100%);
  border-bottom: 1px solid var(--border);
}

.subject-head {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 12px 0;
}

.subject-head h1 {
  margin: 0;
  font-size: 1.35rem;
}

.subject-head-icon {
  font-size: 1.8rem;
}

.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--text);
  font-size: 1.3rem;
  font-weight: 700;
}

.back-link:hover {
  background: var(--surface-2);
}

.tabs {
  display: flex;
  gap: 4px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 6px 10px 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: 1 1 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: var(--tap);
  padding: 0 14px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 700;
  border-bottom: 4px solid transparent;
  border-radius: 12px 12px 0 0;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.tabs-inline {
  padding: 0;
  margin: 0 0 16px;
  border-bottom: 1px solid var(--border);
}

.tabs-inline .tab {
  flex: 0 1 auto;
}

.subject-panel {
  flex: 1 1 auto;
  min-height: 0;
}

/* ------------------------------------------------------------------ */
/* Chat                                                               */
/* ------------------------------------------------------------------ */

.chat-layout {
  display: flex;
  position: relative;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  flex: 1 1 auto;
  min-height: 0;
}

.chat-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(86vw, 320px);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  transform: translateX(-105%);
  transition: transform 0.22s ease;
  display: flex;
  flex-direction: column;
  padding: calc(10px + env(safe-area-inset-top)) 10px calc(10px + env(safe-area-inset-bottom));
  gap: 10px;
}

.chat-drawer.open {
  transform: translateX(0);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 5, 30, 0.45);
  z-index: 45;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 6px;
}

.chat-list {
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 56px;
  padding: 6px 4px 6px 12px;
  border-radius: 14px;
  color: var(--text);
  text-decoration: none;
}

.chat-item:hover {
  background: var(--surface-2);
}

.chat-item.active {
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
}

.chat-item-text {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.chat-item-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-date {
  font-size: 0.78rem;
  color: var(--muted);
}

.chat-del {
  opacity: 0.6;
  flex: 0 0 auto;
}

.chat-item:hover .chat-del,
.chat-item.active .chat-del {
  opacity: 1;
}

.chat-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
}

.chat-toolbar .btn {
  min-height: 44px;
  padding: 0 14px;
}

.chat-title {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
}

.btn-label-long {
  display: none;
}

.chat-main > .banner {
  margin: 0 10px 8px;
}

.messages-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 6px 10px 14px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 820px;
  margin: 0 auto;
}

.msg {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: pop 0.18s ease-out;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.msg-user {
  justify-content: flex-end;
}

.msg-avatar {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  background: color-mix(in srgb, var(--accent) 18%, var(--surface));
  border-radius: 50%;
}

.msg-bubble {
  max-width: min(88%, 700px);
  padding: 10px 14px;
  border-radius: 20px;
  overflow-wrap: anywhere;
  min-width: 0;
}

.msg-user .msg-bubble {
  background: var(--accent);
  color: var(--on-accent);
  border-bottom-right-radius: 6px;
  white-space: pre-wrap;
}

.msg-assistant .msg-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow);
}

.msg-failed .msg-bubble {
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
}

.msg-error {
  color: var(--danger);
  font-weight: 600;
  margin-top: 6px;
}

.msg-note {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 6px;
}

.typing-dots {
  display: none;
  gap: 5px;
  padding: 6px 2px;
}

.msg.typing .typing-dots {
  display: inline-flex;
}

.msg.typing .msg-body:empty {
  display: none;
}

.typing-dots span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  40% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

.chat-empty {
  text-align: center;
  padding: 18px 4px;
}

.chat-empty h2 {
  font-size: 1.25rem;
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px auto;
  max-width: 560px;
}

.quick-btn {
  min-height: 64px;
  padding: 10px 12px;
  border-radius: 18px;
  border: 2px solid color-mix(in srgb, var(--accent) 35%, transparent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 3px 0 color-mix(in srgb, var(--accent) 25%, transparent);
  transition: transform 0.1s ease, background-color 0.15s ease;
}

.quick-btn:hover {
  background: color-mix(in srgb, var(--accent) 20%, var(--surface));
}

.quick-btn:active {
  transform: translateY(2px);
  box-shadow: none;
}

.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px max(10px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background: var(--bg-2);
  border-top: 1px solid var(--border);
}

.composer-input {
  flex: 1 1 auto;
  resize: none;
  max-height: 38vh;
  min-height: 52px;
  border-radius: 24px;
  padding: 13px 18px;
  background: var(--surface);
  overflow-y: hidden;
}

.send-btn {
  flex: 0 0 auto;
  width: 54px;
  height: 54px;
  min-height: 54px;
  padding: 0;
  font-size: 1.4rem;
  border-radius: 50%;
}

/* Markdown */
.md {
  overflow-wrap: anywhere;
}

.md > :first-child {
  margin-top: 0;
}

.md > :last-child {
  margin-bottom: 0;
}

.md p,
.md ul,
.md ol,
.md pre,
.md blockquote,
.md table {
  margin: 0 0 0.7em;
}

.md ul,
.md ol {
  padding-left: 1.4em;
}

.md li + li {
  margin-top: 0.2em;
}

.md h1,
.md h2,
.md h3,
.md h4 {
  margin: 0.9em 0 0.4em;
}

.md h1 {
  font-size: 1.35rem;
}

.md h2 {
  font-size: 1.2rem;
}

.md h3 {
  font-size: 1.05rem;
}

.md code {
  background: var(--surface-2);
  padding: 0.1em 0.35em;
  border-radius: 6px;
}

.md pre {
  background: var(--surface-2);
  padding: 12px;
  border-radius: 12px;
  overflow-x: auto;
}

.md pre code {
  background: none;
  padding: 0;
}

.md blockquote {
  border-left: 4px solid var(--accent);
  padding: 4px 12px;
  margin-left: 0;
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  border-radius: 0 10px 10px 0;
}

.md table {
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
  max-width: 100%;
}

.md th,
.md td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}

.md th {
  background: var(--surface-2);
}

.md img {
  max-width: 100%;
  height: auto;
}

.md hr {
  border: 0;
  border-top: 2px dashed var(--border);
  margin: 1em 0;
}

.msg-user .md code {
  background: rgba(255, 255, 255, 0.2);
}

/* ------------------------------------------------------------------ */
/* Inhalte                                                            */
/* ------------------------------------------------------------------ */

.doc-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.doc-item {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
  padding: 14px 16px;
  margin-bottom: 10px;
  transition: transform 0.12s ease;
}

.doc-item:hover {
  transform: translateX(3px);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}

.doc-item-icon {
  font-size: 1.6rem;
}

.doc-item-text {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.doc-item-title {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-item-meta {
  font-size: 0.82rem;
  color: var(--muted);
}

.back-row {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  text-decoration: none;
  font-weight: 700;
  margin-bottom: 6px;
}

.doc-head {
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.doc-head h2 {
  margin: 0;
  font-size: 1.4rem;
}

.doc-head-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.doc-preview {
  margin-top: 14px;
}

.form-card h2 {
  margin-bottom: 14px;
}

.progress-preview {
  max-height: 55vh;
  overflow-y: auto;
  padding: 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}

/* ------------------------------------------------------------------ */
/* Admin                                                              */
/* ------------------------------------------------------------------ */

.user-list,
.admin-subject-list {
  display: flex;
  flex-direction: column;
}

.user-card.is-inactive {
  opacity: 0.6;
}

.user-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.user-emoji {
  font-size: 1.6rem;
}

.user-names {
  flex: 1 1 160px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.mini-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 650;
  color: var(--muted);
}

.mini-field select,
.mini-field input {
  color: var(--text);
  font-weight: 400;
}

.invite-result {
  margin-top: 12px;
  padding: 14px;
  background: var(--ok-soft);
  border-radius: var(--radius-sm);
}

.subject-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  border-left: 6px solid var(--accent);
}

.subject-row-icon {
  font-size: 2rem;
}

.subject-row-text {
  flex: 1 1 140px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.color-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border);
}

/* Tokens */
.token-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.token-item {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}

.token-info {
  flex: 1 1 200px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.new-token {
  background: var(--warn-soft);
  border-color: color-mix(in srgb, var(--warn) 35%, transparent);
}

.mcp-example summary {
  cursor: pointer;
  font-weight: 650;
  min-height: var(--tap);
  display: flex;
  align-items: center;
}

/* ------------------------------------------------------------------ */
/* Dialoge & Toasts                                                   */
/* ------------------------------------------------------------------ */

.modal {
  border: 0;
  padding: 0;
  border-radius: 22px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  width: min(94vw, 480px);
  max-height: 90dvh;
}

.modal[open] {
  display: flex;
  flex-direction: column;
  animation: pop 0.18s ease-out;
}

.modal-wide {
  width: min(96vw, 860px);
}

.modal::backdrop {
  background: rgba(10, 5, 30, 0.5);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 10px 6px 20px;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.2rem;
}

.modal-body {
  padding: 6px 20px 16px;
  overflow-y: auto;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 20px 18px;
  border-top: 1px solid var(--border);
}

.confirm-text {
  font-size: 1.05rem;
}

#toasts {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  top: calc(var(--header-h) + 10px + env(safe-area-inset-top));
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(94vw, 460px);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  border-left: 6px solid var(--primary);
  cursor: pointer;
  animation: toast-in 0.2s ease-out;
  font-weight: 550;
}

.toast-error {
  border-left-color: var(--danger);
}

.toast-success {
  border-left-color: var(--ok);
}

.toast-out {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
}

/* ------------------------------------------------------------------ */
/* Größere Bildschirme                                                */
/* ------------------------------------------------------------------ */

@media (min-width: 560px) {
  .subject-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
  }

  .hdr-label,
  .user-name {
    display: inline;
  }

  .btn-label-long {
    display: inline;
  }

  .btn-label-short {
    display: none;
  }

  .grid-2 {
    grid-template-columns: 1fr 1fr;
  }

  .grid-3 {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .user-controls {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .quick-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }
}

@media (min-width: 860px) {
  h1 {
    font-size: 1.9rem;
  }

  .page {
    padding-top: 24px;
  }

  .chat-layout {
    padding: 12px;
    gap: 12px;
  }

  .chat-drawer {
    position: static;
    transform: none;
    width: 280px;
    flex: 0 0 280px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    z-index: auto;
    transition: none;
  }

  .drawer-close,
  .drawer-toggle,
  .drawer-backdrop {
    display: none !important;
  }

  .chat-main {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  .messages-scroll {
    background: var(--bg-2);
  }

  .composer {
    background: var(--surface);
  }

  .doc-head {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .doc-head h2 {
    flex: 1 1 100%;
  }
}

@media (max-width: 359px) {
  .logo {
    font-size: 1.1rem;
  }

  /* Einstellungen/Admin sind auch im Benutzer-Menü */
  .hdr-link {
    display: none;
  }
}

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