/* ============================================================================
 * Chat-App Komponenten — komplett neu geschrieben (2026-07-20).
 * Die Vorgängerdatei war eine 1:1-Kopie des health-pwa-Dashboard-CSS und
 * enthielt keine einzige Regel für die hier gerenderten Klassen. Hier stehen
 * nur noch Komponenten, die die Chat-App wirklich nutzt (Login, Sidebar,
 * Chat, Composer, Dialoge).
 * Farben ausschließlich über --md-sys-color-*-Tokens (Dark/Light läuft
 * automatisch mit). Glass-Varianten am Dateiende, gekapselt unter
 * html[data-glass="on"] — "?glass=0" fällt auf die flachen Regeln zurück.
 * ========================================================================== */

/* --- Native Formularelemente ---------------------------------------------
 * Eine Basis-Regel statt pro-ID-Styling: deckt Login-Passwort, Modellwahl,
 * Composer-Textarea und alle Settings-Felder gleichzeitig ab. */
input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface-container-highest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-small);
  padding: 10px 12px;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: -1px;
}
select { cursor: pointer; }

/* --- Karten ----------------------------------------------------------------
 * .glass-card = Chat-App-Name der health-pwa-Karte. Flache Basis hier;
 * Frosted-Override unten im Glass-Block. Padding setzen die Komponenten
 * selbst (Login braucht 32px, Composer nur 8px). */
.glass-card {
  background-color: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-sys-shape-corner-large);
  box-shadow: var(--md-sys-elevation-1);
}

/* .modal.card aus makeDialog() (chat.js/settings.js): flache Basis wie bisher
 * aus health-pwa; der Glass-Override dafür liegt fertig in glass.css. */
.card {
  background-color: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 16px;
  box-shadow: var(--md-sys-elevation-1);
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--md-sys-color-on-surface);
}

/* --- Buttons -------------------------------------------------------------- */
.md-filled-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 24px;
  border: none;
  border-radius: 20px;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: filter .2s, box-shadow .2s;
}
.md-filled-button:hover { filter: brightness(1.08); box-shadow: var(--md-sys-elevation-1); }
.md-filled-button:active { filter: brightness(.95); }

.md-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color .2s, color .2s;
}
.md-icon-button:hover {
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
}

.md-text-button {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border: none;
  border-radius: 20px;
  background: transparent;
  color: var(--md-sys-color-primary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .2s;
}
.md-text-button:hover {
  background: color-mix(in srgb, var(--md-sys-color-primary) 10%, transparent);
}

.spacer { flex: 1; }
.error-text { color: var(--md-sys-color-error); font-size: 13px; }

/* --- Login ----------------------------------------------------------------- */
#login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(360px, 100%);
  padding: 32px;
}
#login-form h2 {
  font-size: 28px;
  font-weight: 600;
  text-align: center;
  color: var(--md-sys-color-on-surface);
}

/* .chip: Brain-Projekt-Tag auf Themen-Karten (chat.js) — von der alten
   Sidebar übernommen, weiterhin in Gebrauch. */
.chip {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  font-size: 12px;
  white-space: nowrap;
}

/* --- Dialoge (Speichern-Diff, Einstellungen) --------------------------------- */
.dlg-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.modal h3 { font-size: 18px; font-weight: 500; }
.modal label {
  display: block;
  font-size: 13px;
  color: var(--md-sys-color-on-surface-variant);
}
.modal label input:not([type="checkbox"]),
.modal label textarea,
.modal label select {
  display: block;
  width: 100%;
  margin-top: 4px;
  font-size: 14px;
}
.modal details { margin: 4px 0; }
.modal summary { cursor: pointer; font-size: 14px; }
/* Checkbox-Label im Speichern-Dialog (<summary><label><input …) ist Fließtext,
   kein Settings-Formularfeld — inline lassen, Textfarbe erben. */
.modal summary label {
  display: inline;
  font-size: inherit;
  color: inherit;
}
/* .diff-view/-add/-del stehen inline in index.html; nur der Kontext fehlte. */
.diff-ctx { color: var(--md-sys-color-on-surface-variant); }

/* ============================================================================
 * Glass-Varianten — dasselbe Frosted-Rezept wie health-pwa (glass.css stylt
 * dort nur .card/.m3-button; hier die Chat-App-Klassen). Variablen
 * (--glass-blur/-sat/-grad/-sheen/-card-base) kommen aus glass.css.
 * ========================================================================== */
html[data-glass="on"] .glass-card {
  background:
    linear-gradient(180deg, var(--glass-grad), transparent 55%),
    color-mix(in srgb, var(--md-sys-color-surface-container-low) var(--glass-card-base), transparent);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
  border: 1px solid color-mix(in srgb, var(--md-sys-color-outline-variant) 45%, transparent);
  box-shadow:
    inset 0 1px 0 var(--glass-sheen),
    0 1px 2px rgba(0, 0, 0, .10),
    0 8px 28px rgba(0, 0, 0, .16);
}

/* Primär-Button glossy — identisches Rezept wie .m3-button-filled in glass.css. */
html[data-glass="on"] .md-filled-button {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .30), rgba(255, 255, 255, 0) 58%),
    linear-gradient(135deg,
      color-mix(in srgb, var(--md-sys-color-primary) 84%, #fff),
      var(--md-sys-color-primary));
  border: 1px solid color-mix(in srgb, var(--md-sys-color-primary) 55%, transparent);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .40),
    0 1px 2px rgba(0, 0, 0, .18),
    0 8px 22px color-mix(in srgb, var(--md-sys-color-primary) 42%, transparent);
}
/* Lightmode: getönter Glow trägt auf hellen Flächen stärker auf → abschwächen
   (gleiche Korrektur wie in glass.css für .m3-button). */
html[data-glass="on"]:not([data-theme="dark"]) .md-filled-button {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .40),
    0 1px 2px rgba(0, 0, 0, .10),
    0 3px 10px color-mix(in srgb, var(--md-sys-color-primary) 20%, transparent);
}
html[data-glass="on"] .md-filled-button:active {
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, .26),
    0 1px 2px rgba(0, 0, 0, .20);
}

/* Icon-Buttons: weicher durchscheinender Hover statt solider Surface-Blob. */
html[data-glass="on"] .md-icon-button:hover {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 10%, transparent);
}

/* --- Health-PWA-Kompatibilitätsklassen für die 1:1 übernommenen Chat-Templates --- */
.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    vertical-align: middle;
    user-select: none;
}
.m3-button-icon-small {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--md-sys-color-on-surface-variant);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    flex: none;
}
.m3-button-icon-small:hover { background: color-mix(in srgb, var(--md-sys-color-on-surface) 10%, transparent); }
.m3-button-icon-small .material-symbols-outlined { font-size: 20px; }
.m3-button-filled {
    min-height: 44px;
    border: 0;
    border-radius: 20px;
    padding: 0 18px;
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    cursor: pointer;
    font: inherit;
    font-weight: 500;
}
.app-dialog-cancel, .app-dialog-ok {
    min-height: 44px;
    border-radius: 999px;
    padding: 0 18px;
    font: inherit;
    font-weight: 600;
}
.app-dialog-cancel {
    border: 1px solid var(--md-sys-color-outline);
    background: transparent;
    color: var(--md-sys-color-primary);
    cursor: pointer;
}
.app-toast {
    position: fixed;
    z-index: 9600;
    left: 50%;
    bottom: max(20px, env(safe-area-inset-bottom));
    max-width: calc(100vw - 32px);
    padding: 12px 18px;
    border: 1px solid color-mix(in srgb, var(--md-sys-color-outline-variant) 60%, transparent);
    border-radius: 999px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, .22);
    transform: translate(-50%, 16px);
    opacity: 0;
    transition: transform .18s ease, opacity .18s ease;
    color: var(--md-sys-color-on-primary-container);
    background: var(--md-sys-color-primary-container);
}
.app-toast-error { color: var(--md-sys-color-on-error-container); background: var(--md-sys-color-error-container); }
.app-toast.visible { transform: translate(-50%, 0); opacity: 1; }
@media (prefers-reduced-motion: reduce) { .app-toast { transition: none; } }
.md-typescale-label-small { font-size: 11px; font-weight: 500; letter-spacing: .03em; }
.md-typescale-label-medium { font-size: 12px; font-weight: 500; }
.md-typescale-label-large { font-size: 14px; font-weight: 500; }
.md-typescale-body-small { font-size: 12px; line-height: 1.45; }
.md-typescale-body-medium { font-size: 14px; line-height: 1.5; }
.md-typescale-body-large { font-size: 16px; line-height: 1.55; }
.md-typescale-title-small { font-size: 14px; font-weight: 600; }
.md-typescale-title-medium { font-size: 16px; font-weight: 600; }

/* --- Startseite: schwebende Aktionen, Kontextmenü, Sortierung ------------- */
.glass-fab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 48px;
  border: 1px solid color-mix(in srgb, var(--md-sys-color-outline-variant) 45%, transparent);
  border-radius: 999px;
  padding: 0 15px;
  background:
    linear-gradient(180deg, var(--glass-grad, rgba(255,255,255,.28)), transparent 55%),
    color-mix(in srgb, var(--md-sys-color-surface-container-low) 58%, transparent);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  backdrop-filter: blur(20px) saturate(170%);
  box-shadow: inset 0 1px 0 var(--glass-sheen, rgba(255,255,255,.55)), 0 6px 24px rgba(0,0,0,.18);
  color: var(--md-sys-color-on-surface);
  font: inherit;
  font-weight: 500;
}
.home-settings-fab { position: static; width: 44px; min-height: 44px; padding: 0; border-radius: 50%; opacity: .76; background: color-mix(in srgb, var(--md-sys-color-surface) 52%, transparent); }
.home-reorder-done { position: static; min-height: 44px; margin-right: auto; }
.tile-context-menu { width: min(100%, 360px); padding: 10px; }
.tile-context-title { padding: 8px 10px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; font-weight: 600; }
.tile-context-action { width: 100%; min-height: 48px; display: flex; align-items: center; gap: 12px; border: 0; border-radius: 14px; padding: 0 12px; background: transparent; color: var(--md-sys-color-on-surface); font: inherit; text-align: left; }
.tile-context-action:hover { background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent); }
.tile-context-action .material-symbols-outlined { color: var(--md-sys-color-on-surface-variant); }
.tile-context-action.danger, .tile-context-action.danger .material-symbols-outlined { color: var(--md-sys-color-error); }
.tile-reorder-active [data-home-key] { cursor: grab; touch-action: none; animation: tileWiggle .22s ease-in-out infinite alternate; }
.tile-reorder-active [data-home-key]:active { cursor: grabbing; }
.tile-reorder-active[data-tile-container] > [data-home-key], .tile-drop-placeholder { transition: transform .18s ease, opacity .18s ease, box-shadow .18s ease, background .18s ease; }
.tile-dragging { opacity: .92; z-index: 1000; animation: none !important; filter: drop-shadow(0 12px 22px rgba(0,0,0,.38)); }
.tile-drop-placeholder {
  box-sizing: border-box;
  min-height: 124px;
  border: 1px dashed color-mix(in srgb, var(--md-sys-color-primary) 72%, transparent);
  border-radius: 24%;
  background: color-mix(in srgb, var(--md-sys-color-primary-container) 34%, transparent);
  box-shadow: inset 0 1px 0 var(--glass-sheen, rgba(255,255,255,.55)), 0 0 0 3px color-mix(in srgb, var(--md-sys-color-primary) 12%, transparent);
  animation: tileDropPulse .72s ease-in-out infinite alternate;
}
.project-rail .tile-drop-placeholder { flex: 0 0 78px; min-height: 82px; border-radius: 18px; }
.tile-drop-target .topic-card-icon, .tile-drop-target .project-card-icon { box-shadow: inset 0 1px 0 var(--glass-sheen, rgba(255,255,255,.55)), 0 0 0 3px color-mix(in srgb, var(--md-sys-color-primary) 28%, transparent), 0 8px 24px color-mix(in srgb, var(--md-sys-color-primary) 22%, transparent); }
@keyframes tileWiggle { from { transform: rotate(-.7deg); } to { transform: rotate(.7deg); } }
@keyframes tileDropPulse { from { opacity: .62; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) {
  .tile-reorder-active [data-home-key], .tile-drop-placeholder { animation: none; transition: none; }
  .tile-drop-target .topic-card-icon, .tile-drop-target .project-card-icon { transition: none; }
}

/* --- Modell-Konfigurator -------------------------------------------------- */
.model-config-overlay { align-items: stretch; padding: 0; }
.model-config-sheet {
  width: min(100%, 760px);
  max-height: none;
  height: 100dvh;
  border-radius: 0;
  padding: max(16px, env(safe-area-inset-top, 0px)) clamp(16px, 4vw, 28px) calc(18px + env(safe-area-inset-bottom, 0px));
  gap: 16px;
  overflow-y: auto;
}
.model-config-header { display: flex; justify-content: flex-start; }
.model-catalog-section { display: flex; flex-direction: column; gap: 16px; }
.model-catalog-heading { display: grid; grid-template-columns: minmax(0, 1fr) 40px; align-items: start; gap: 10px; }
.model-catalog-heading h3 { margin: 4px 0 2px; font-size: clamp(20px, 4vw, 26px); }
.model-catalog-heading p, .model-config-note { margin: 0; color: var(--md-sys-color-on-surface-variant); line-height: 1.4; }
.theme-preference { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 12px; border-radius: 16px; background: color-mix(in srgb, var(--md-sys-color-surface-container-high) 58%, transparent); border: 1px solid color-mix(in srgb, var(--md-sys-color-outline-variant) 42%, transparent); }
.theme-preference-label { font-size: 13px; font-weight: 600; color: var(--md-sys-color-on-surface-variant); }
.theme-choice-row, .model-filter-row { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.theme-choice-row::-webkit-scrollbar, .model-filter-row::-webkit-scrollbar { display: none; }
.theme-choice, .model-filter-chip { flex: none; min-height: 36px; border: 1px solid color-mix(in srgb, var(--md-sys-color-outline-variant) 58%, transparent); border-radius: 999px; padding: 0 13px; background: color-mix(in srgb, var(--md-sys-color-surface-container-high) 46%, transparent); color: var(--md-sys-color-on-surface); font: inherit; font-size: 13px; }
.theme-choice[aria-pressed="true"], .model-filter-chip.active { border-color: transparent; background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); font-weight: 600; }
.model-card-list { display: flex; flex-direction: column; gap: 18px; }
.model-tier-group { display: flex; flex-direction: column; gap: 8px; }
.model-tier-heading { display: flex; justify-content: space-between; align-items: baseline; padding: 0 2px; color: var(--md-sys-color-on-surface-variant); font-size: 12px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
.model-tier-heading span { font-weight: 500; letter-spacing: normal; text-transform: none; }
.model-card { width: 100%; display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 10px; align-items: start; border: 1px solid color-mix(in srgb, var(--md-sys-color-outline-variant) 52%, transparent); border-radius: 20px; padding: 16px; background: color-mix(in srgb, var(--md-sys-color-surface-container-low) 70%, transparent); color: var(--md-sys-color-on-surface); text-align: left; box-shadow: 0 4px 16px rgba(0,0,0,.10); transition: transform .16s ease, border-color .16s ease, background .16s ease; }
.model-card:hover { transform: translateY(-1px); border-color: var(--md-sys-color-primary); }
.model-card.selected { border-color: var(--md-sys-color-primary); background: linear-gradient(135deg, color-mix(in srgb, var(--md-sys-color-primary-container) 72%, transparent), color-mix(in srgb, var(--md-sys-color-surface-container-low) 72%, transparent)); }
.model-card-check { margin-top: 2px; color: var(--md-sys-color-primary); }
.model-card-copy { display: flex; min-width: 0; flex-direction: column; gap: 3px; }
.model-card-name { font-size: 18px; font-weight: 600; }
.model-card-id, .model-card-price { overflow-wrap: anywhere; color: var(--md-sys-color-on-surface-variant); font-size: 13px; line-height: 1.35; }
.model-config-footer { position: sticky; bottom: calc(-18px - env(safe-area-inset-bottom, 0px)); margin: 0 -2px; padding: 12px 2px calc(12px + env(safe-area-inset-bottom, 0px)); background: linear-gradient(0deg, var(--md-sys-color-surface-container-high) 68%, transparent); color: var(--md-sys-color-on-surface-variant); font-size: 12px; line-height: 1.4; }
.model-config-loading { display: grid; place-items: center; min-height: 160px; color: var(--md-sys-color-on-surface-variant); }
@media (min-width: 720px) {
  .model-config-overlay { align-items: center; padding: 24px; }
  .model-config-sheet { height: min(88dvh, 900px); border-radius: 28px; }
}
