/* SPEC-013 P2: self-hosted brand typography (ADR-044).
 *
 * Cinzel (Roman inscriptional serif, OFL) is the Custos wordmark/heading face.
 * Vendored UNMODIFIED + lossless-woff2 under /public/fonts/ (same-origin — no
 * external font origin, no CSP relaxation). Applied to HEADINGS ONLY; the body
 * and code deliberately stay on the system sans/mono stacks in theme.json for
 * legibility of dense answers (SPEC-013 narrowed B4: body-serif deferred). */
@font-face {
  font-family: "Cinzel";
  src: url("/public/fonts/Cinzel-variable.woff2") format("woff2");
  font-weight: 400 900; /* variable weight axis (browser auto-detects) */
  font-style: normal;
  font-display: swap; /* system serif renders first; no render-blocking fetch */
}

/* Headings rendered from message markdown. Chainlit wraps markdown in a
 * Tailwind `.prose-sm` container (no `#message-list`/`.markdown-body` exists in
 * the v2 build); scoping to `.prose-sm` retints headings without touching body
 * paragraphs or code. */
.prose-sm :is(h1, h2, h3, h4, h5, h6) {
  font-family: "Cinzel", Georgia, "Times New Roman", serif;
  letter-spacing: 0.01em;
}

/* SPEC-013 P3: restrained brand motion — opacity/transform only, <=200ms,
 * disabled under prefers-reduced-motion. A gentle one-time entrance on each
 * message bubble (Chainlit renders every message/step as `.step`) as it mounts. */
@keyframes aise-bubble-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.step {
  animation: aise-bubble-in 180ms ease-out both;
}

/* SPEC-013 P4: interaction feedback — input-bar states + governance-tier badge.
 * The animated properties are paint/composite-only (opacity/transform/box-shadow
 * — no reflow), keeping the composer usable while it animates. The badge's
 * one-off show/hide uses a `display` toggle, but on a `position:fixed` chip
 * (out of normal flow), so it recalcs only that element and never reflows the
 * page. Every rule is disabled under prefers-reduced-motion below; state classes
 * are toggled by public/custom.js. */
@keyframes aise-sent-pop {
  0%   { box-shadow: 0 0 0 0 hsl(var(--ring) / 0); }
  30%  { box-shadow: 0 0 0 3px hsl(var(--ring) / 0.35); }
  100% { box-shadow: 0 0 0 0 hsl(var(--ring) / 0); }
}
@keyframes aise-classify-scan {
  0%   { box-shadow: 0 0 0 1px hsl(var(--ring) / 0.15); }
  50%  { box-shadow: 0 0 12px 1px hsl(var(--ring) / 0.5); }
  100% { box-shadow: 0 0 0 1px hsl(var(--ring) / 0.15); }
}
@keyframes aise-respond-pulse {
  0%, 100% { box-shadow: 0 0 6px 0 hsl(var(--primary) / 0.25); }
  50%      { box-shadow: 0 0 14px 1px hsl(var(--primary) / 0.5); }
}
@keyframes aise-tier-badge-in {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes aise-welcome-intro {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.aise-composer {
  border-radius: var(--radius);
}
.aise-composer.aise-state-sent {
  animation: aise-sent-pop 320ms ease-out;
}
.aise-composer.aise-state-classifying {
  animation: aise-classify-scan 500ms ease-in-out;
}
.aise-composer.aise-state-responding {
  animation: aise-respond-pulse 1.8s ease-in-out infinite;
}
.aise-welcome-intro {
  animation: aise-welcome-intro 200ms ease-out both;
}

/* Governance-tier checkpoint badge: a small transient chip just above the
 * composer. Hidden by default; JS reveals it during the classification phase. */
#aise-tier-badge {
  /* Anchored inside the composer's relative wrapper (custom.js), so it always
   * floats just above the input — never over it — whatever the composer's
   * height. The --fixed variant is the body-append fallback only. */
  position: absolute;
  left: 50%;
  bottom: 100%;
  margin-bottom: 0.875rem;
  z-index: 40;
  display: none;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.875rem 0.375rem 0.75rem;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  color: hsl(var(--aise-tier-standard-fg));
  background-color: hsl(var(--aise-tier-standard-bg));
  border: 1px solid hsl(var(--aise-tier-standard-border));
  border-radius: 9999px;
  box-shadow: 0 1px 2px hsl(var(--foreground) / 0.06),
    0 4px 12px hsl(var(--foreground) / 0.08);
  transform: translateX(-50%);
  pointer-events: none;
  /* lucide "shield" — masks are alpha-only, so the stroke color is irrelevant;
   * the icon paints in currentColor and follows the tier text color. */
  --aise-tier-icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z'/></svg>");
}
#aise-tier-badge.aise-badge-show {
  display: inline-flex;
  animation: aise-tier-badge-in 220ms cubic-bezier(0.2, 0, 0, 1);
}
#aise-tier-badge.aise-tier-badge--fixed {
  position: fixed;
  bottom: 6.25rem;
}
/* The icon span is a currentColor square shaped by the per-tier SVG mask, so
 * it always matches the tier text color without any JS involvement. */
.aise-tier-icon {
  flex: none;
  width: 0.875rem;
  height: 0.875rem;
  background-color: currentColor;
  -webkit-mask: var(--aise-tier-icon) center / contain no-repeat;
  mask: var(--aise-tier-icon) center / contain no-repeat;
}
/* Graceful fallback: engines without mask support keep a plain dot. */
@supports not ((mask-repeat: no-repeat) or (-webkit-mask-repeat: no-repeat)) {
  .aise-tier-icon {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 9999px;
  }
}
.aise-tier-text {
  display: inline-flex;
  align-items: baseline;
  gap: 0.375rem;
}
.aise-tier-caption {
  color: hsl(var(--muted-foreground));
  font-weight: 500;
}
.aise-tier-caption::after {
  content: "·";
  margin-left: 0.375rem;
  opacity: 0.6;
}
.aise-tier-name {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: inherit; /* the badge root carries the tier fg */
}

/* Per-tier "governance seal" (offen < intern < vertraulich < geheim; the
 * neutral base above covers data-tier "default"/unknown — there is no
 * "standard" attribute value). Colors come from the --aise-tier-* tokens
 * theme.json injects per theme (light AND dark — no media queries needed);
 * contrast of every fg/bg pair is ≥ 4.5:1 (checked arithmetically). Icon
 * ladder: shield-check (offen, ok) → shield-half (intern) → shield-alert
 * (vertraulich, Vorsicht) → closed lock (geheim — deliberately breaks the
 * shield family to mark the top tier). */
#aise-tier-badge[data-tier="offen"] {
  color: hsl(var(--aise-tier-offen-fg));
  background-color: hsl(var(--aise-tier-offen-bg));
  border-color: hsl(var(--aise-tier-offen-border));
  --aise-tier-icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z'/><path d='m9 12 2 2 4-4'/></svg>");
}
#aise-tier-badge[data-tier="intern"] {
  color: hsl(var(--aise-tier-intern-fg));
  background-color: hsl(var(--aise-tier-intern-bg));
  border-color: hsl(var(--aise-tier-intern-border));
  --aise-tier-icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z'/><path d='M12 22V2'/></svg>");
}
#aise-tier-badge[data-tier="vertraulich"] {
  font-weight: 600;
  color: hsl(var(--aise-tier-vertraulich-fg));
  background-color: hsl(var(--aise-tier-vertraulich-bg));
  border-color: hsl(var(--aise-tier-vertraulich-border));
  --aise-tier-icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z'/><path d='M12 8v4'/><path d='M12 16h.01'/></svg>");
}
#aise-tier-badge[data-tier="geheim"] {
  font-weight: 600;
  color: hsl(var(--aise-tier-geheim-fg));
  background-color: hsl(var(--aise-tier-geheim-bg));
  border-color: hsl(var(--aise-tier-geheim-border));
  /* quiet outer ring: the highest tier gets one extra visual step */
  box-shadow: 0 1px 2px hsl(var(--foreground) / 0.06),
    0 4px 12px hsl(var(--foreground) / 0.08),
    0 0 0 3px hsl(var(--aise-tier-geheim-fg) / 0.12);
  --aise-tier-icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><rect width='18' height='11' x='3' y='11' rx='2' ry='2'/><path d='M7 11V7a5 5 0 0 1 10 0v4'/></svg>");
}

/* @/# autocomplete dropdown (custom.js): pixel-matched to Chainlit's native
 * "/" command popover (same 18rem box, offset, surface, item anatomy and
 * motion) so the three trigger families read as ONE component. Tier chips and
 * the badge share the --aise-tier-* tokens injected from theme.json. */
/* Anchoring: custom.js makes the textarea's parent a containing block
 * (position: relative when static) before appending the box — deterministic
 * across browsers, no :has() dependency. */
@keyframes aise-ac-in {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}
#aise-autocomplete {
  position: absolute;
  left: 0; /* = native align: "start" */
  bottom: calc(100% + 12px); /* = native Radix sideOffset: 12 */
  z-index: 50; /* above the tier badge (z-40) */
  width: 18rem; /* = native w-72 — identical box for / @ # */
  padding: 0.5rem; /* p-2 */
  display: none;
  font-size: 0.875rem;
  color: hsl(var(--foreground));
  background-color: hsl(var(--background)); /* native uses bg-background */
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 4px 6px -1px hsl(var(--foreground) / 0.1),
    0 2px 4px -2px hsl(var(--foreground) / 0.1);
}
#aise-autocomplete.aise-ac-show {
  display: block;
  transform-origin: bottom left;
  animation: aise-ac-in 200ms ease-out; /* = native fade-in + zoom-in-95 */
}
.aise-ac-header {
  padding: 0.375rem 0.5rem; /* native group heading px-2 py-1.5 text-xs */
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1rem;
  color: hsl(var(--muted-foreground));
}
.aise-ac-list {
  max-height: 300px; /* native max-h-[300px] — ~5 items, then scroll */
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: hsl(var(--muted-foreground) / 0.3) transparent;
}
.aise-ac-list::-webkit-scrollbar {
  width: 8px;
}
.aise-ac-list::-webkit-scrollbar-thumb {
  border-radius: 9999px;
  background: hsl(var(--muted-foreground) / 0.3);
}
.aise-ac-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem; /* native px-2 py-2 */
  border-radius: calc(var(--radius) - 2px);
  line-height: 1.25rem;
  cursor: pointer;
  user-select: none;
  transition: transform 150ms ease, background-color 150ms ease,
    color 150ms ease;
}
/* Selection tracks the mouse in JS, so this is also the hover state. */
.aise-ac-item.aise-ac-selected {
  background-color: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
  transform: scale(1.02); /* native hover/selected scale */
}
.aise-ac-icon {
  display: inline-flex;
  flex: none;
  color: hsl(var(--muted-foreground)); /* native: muted even when selected */
}
.aise-ac-icon svg {
  width: 1.25rem; /* native !size-5 */
  height: 1.25rem;
  transition: transform 150ms ease;
}
.aise-ac-selected .aise-ac-icon svg {
  transform: scale(1.1); /* native selected icon pop */
}
.aise-ac-main {
  display: flex;
  flex-direction: column;
  min-width: 0; /* lets titles/descs truncate in the 18rem box */
  flex: 1 1 auto;
}
.aise-ac-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Match highlight: bold + soft ring-tinted mark. Deliberately NOT --primary
 * text — primary-on-background is 3.62:1 in dark mode (fails AA); bold +
 * inherit passes everywhere. Background override also kills the UA yellow
 * <mark> default. */
mark.aise-ac-match {
  background-color: hsl(var(--ring) / 0.2);
  color: inherit;
  font-weight: 700;
  border-radius: 3px;
  padding: 0 1px;
}
.aise-ac-selected mark.aise-ac-match {
  background-color: transparent; /* bg-accent already carries the emphasis */
}
.aise-ac-desc {
  font-size: 0.875rem; /* native desc is also text-sm */
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Classification chip on #-items — same tier tokens as the badge below. */
.aise-ac-chip {
  flex: none; /* the chip never truncates; the title does */
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  height: 1.125rem;
  padding: 0 0.375rem;
  border-radius: 9999px;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.01em;
  text-transform: capitalize; /* JS emits the raw lowercase tier key */
  color: hsl(var(--aise-tier-standard-fg));
  background-color: hsl(var(--aise-tier-standard-bg));
  border: 1px solid hsl(var(--aise-tier-standard-border));
}
.aise-ac-chip[data-tier="offen"] {
  color: hsl(var(--aise-tier-offen-fg));
  background-color: hsl(var(--aise-tier-offen-bg));
  border-color: hsl(var(--aise-tier-offen-border));
}
.aise-ac-chip[data-tier="intern"] {
  color: hsl(var(--aise-tier-intern-fg));
  background-color: hsl(var(--aise-tier-intern-bg));
  border-color: hsl(var(--aise-tier-intern-border));
}
.aise-ac-chip[data-tier="vertraulich"] {
  color: hsl(var(--aise-tier-vertraulich-fg));
  background-color: hsl(var(--aise-tier-vertraulich-bg));
  border-color: hsl(var(--aise-tier-vertraulich-border));
}
.aise-ac-chip[data-tier="geheim"] {
  color: hsl(var(--aise-tier-geheim-fg));
  background-color: hsl(var(--aise-tier-geheim-bg));
  border-color: hsl(var(--aise-tier-geheim-border));
}
.aise-ac-empty {
  padding: 1.5rem 0; /* native py-6, centered */
  text-align: center;
  color: hsl(var(--muted-foreground));
}
.aise-ac-hint {
  margin-top: 0.25rem;
  padding: 0.375rem 0.5rem 0.125rem;
  border-top: 1px solid hsl(var(--border));
  font-size: 0.6875rem;
  letter-spacing: 0.02em;
  text-align: right;
  color: hsl(var(--muted-foreground));
}

/* Header mute toggle is an icon-only ghost button — same box as #readme-button. */
.aise-header-btn--icon {
  width: 2.25rem;
  padding: 0;
}

@media (prefers-reduced-motion: reduce) {
  .step,
  .aise-header-btn,
  .aise-composer,
  .aise-composer.aise-state-sent,
  .aise-composer.aise-state-classifying,
  .aise-composer.aise-state-responding,
  .aise-welcome-intro,
  #aise-tier-badge,
  #aise-tier-badge.aise-badge-show,
  #aise-autocomplete,
  #aise-autocomplete.aise-ac-show,
  .aise-ac-item,
  .aise-ac-icon svg {
    animation: none !important;
    transition: none !important;
  }
}

/* SPEC-011: chat-header consistency.
 *
 * The injected "Admin" affordance (public/custom.js, SPEC-008) used to render
 * as a bare text-link next to Chainlit's native header buttons (Readme, theme,
 * avatar) — different height, no hover surface, no focus ring (issue #150).
 * Here we style it as a proper *ghost* header button using Chainlit's own
 * shadcn design tokens, so it matches #readme-button in BOTH light and dark.
 * Tokens (HSL triplets, hsl(var(--x))): --foreground, --accent,
 * --accent-foreground, --radius, --ring — set on :root by Chainlit's bundle. */

.aise-header-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 2.25rem; /* h-9 — same box as the header's ghost icon buttons */
  margin: 0 0.25rem;
  padding: 0 0.75rem; /* px-3 */
  border-radius: calc(var(--radius) - 2px);
  font-family: inherit;
  font-size: 0.875rem; /* text-sm */
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  color: hsl(var(--foreground));
  background-color: transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.aise-header-btn:hover {
  /* Same hover surface shadcn/Chainlit gives its ghost buttons. */
  background-color: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
}

.aise-header-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px hsl(var(--ring));
}

/* Last-resort fixed fallback (custom.js only uses this if Chainlit's header row
 * can't be located): keep the button appearance, add pinned positioning. */
.aise-header-btn--fixed {
  position: fixed;
  top: 0.75rem;
  right: 8.75rem;
  z-index: 9999;
}

/* Read-only revisit banner (SPEC-025 Phase 5 / ADR-062): shown by custom.js on
 * a composer-less /thread/{id} view. Theme tokens for both schemes; text +
 * border carry the meaning (never colour alone, WCAG 2.2 AA). */
#aise-readonly-banner {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(44rem, calc(100vw - 2rem));
  padding: 0.625rem 1rem;
  border: 1px solid hsl(var(--border));
  border-left: 3px solid hsl(var(--primary));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  font-size: 0.875rem;
  line-height: 1.4;
  z-index: 9999;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.25);
}

/* ---------------------------------------------------------------------------
 * Layout hygiene — scrollbars (issue: "viele sichtbare Scrollbalken").
 *
 * Two independent defects produced the stray bars; both are fixed here because
 * both live in Chainlit's own markup, which we can only reach from this sheet.
 *
 * (1) REDUNDANT NESTED SCROLLER in the ElementSidebar. Chainlit renders
 *     <aside class="... overflow-y-auto"> and, inside it, an element card that
 *     is pinned to the aside's height AND is itself `overflow: auto`. The card
 *     therefore scrolls while the aside never can (its only child is
 *     height-locked), so the bar is painted *inset inside the card's border*
 *     instead of at the panel edge. Measured on main at 1100x720 with the
 *     SPEC-024 progress panel open: aside client/scroll 644/644 (idle) vs card
 *     642/1070 (scrolls) — a scrollbar in the middle of the UI.
 *
 * (2) IMPLICIT HORIZONTAL SCROLLER. Chainlit sets only `overflow-y: auto` on
 *     its scroll surfaces. Per CSS Overflow 3 §3.1, when one axis is `visible`
 *     and the other is not, the `visible` value computes to `auto` — so every
 *     such surface silently becomes a horizontal scroll container too and
 *     paints a bar on any 1px overshoot. Verified in-page: the <aside> carries
 *     only `overflow-y-auto`, yet its computed `overflow-x` is `auto`.
 *
 * Selectors anchor on the stable Chainlit IDs (#side-view-content,
 * #side-view-title) and never on the card's utility classes — those are
 * minified and renamed between Chainlit releases (see the ConsoleGuard
 * allow-list rot in e2e/quality.py).
 *
 * Deliberately NOT applied to the message list: wide code blocks and tables
 * inside answers must keep their own horizontal scroller. */

/* (1) The <aside> becomes the single scroller; the card sizes to its content. */
aside:has(#side-view-content) {
  overflow-y: auto;
  overflow-x: clip;
}
aside:has(#side-view-content) > :has(> #side-view-content) {
  height: auto;
  max-height: none;
  overflow: visible;
}
/* Flex children default to `min-height: auto`, which refuses to shrink below
 * content and is what pushed the panel past the card in the first place. */
#side-view-content {
  min-height: 0;
}
/* The panel title stays put while the steps scroll under it. */
#side-view-title {
  position: sticky;
  top: 0;
  z-index: 1;
  background: hsl(var(--card));
}

/* (2) House scrollbar style — thin, tokenised, and identical in both themes.
 * This is the same treatment `.aise-ac-list` already used; promoting it to the
 * default means every scroll surface in the app reads as one component instead
 * of falling back to the platform's chunky default bar. */
* {
  scrollbar-width: thin;
  scrollbar-color: hsl(var(--muted-foreground) / 0.28) transparent;
}
*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
*::-webkit-scrollbar-track,
*::-webkit-scrollbar-corner {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: hsl(var(--muted-foreground) / 0.28);
  border-radius: 9999px;
}
*::-webkit-scrollbar-thumb:hover {
  background: hsl(var(--muted-foreground) / 0.45);
}
