/* ==========================================================================
   Zack KI — Buehne und App-Einbettung
   Enthaelt: den skalierten Rahmen um das echte App-Fenster, die drei
   Fremdfenster (Mail, Explorer, Desktop), Alt+1-Keycap, Mauszeiger und
   Auswahlrechtecke. Die App selbst wird hier nicht gestaltet — dafuer ist
   appshot.css zustaendig, erzeugt aus der echten App-CSS.
   ========================================================================== */

/* --- App-Einbettung ------------------------------------------------------ */

/* Das Fenster bleibt 420x640 und wird als Ganzes skaliert. So stimmen
   Schriftgroessen, Radien und Abstaende relativ zueinander exakt wie in der App. */
.appframe {
  width: calc(420px * var(--app-scale, 1));
  height: calc(var(--app-h, 640px) * var(--app-scale, 1));
  flex: none;
}
.appframe > .appshot {
  width: 420px;
  height: var(--app-h, 640px);
  transform: scale(var(--app-scale, 1));
  transform-origin: top left;
}
/* Fensteroptik nur fuer echte Fenster — .appshot dient sonst auch als
   reiner Traeger der App-Tokens (etwa fuer die Quick/Deep-Pille). */
.appframe > .appshot,
.stage-app .appshot {
  border-radius: var(--ca-r-window, 10px);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--edge);
}
.appshot .app-shell { height: 100%; }
/* Nichts in der Nachbildung ist anklickbar. */
.appshot, .appshot * { pointer-events: none; user-select: none; }
.appshot .chat-scroll { overflow: hidden; }
.appshot .composer-chips { flex-wrap: nowrap; }
.appshot .composer-chip { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appshot .composer-chip.is-active {
  color: rgb(var(--ca-accent-text));
  background: rgb(var(--ca-accent) / 0.2);
  box-shadow: inset 0 0 0 1px rgb(var(--ca-accent) / 0.4);
}

/* Schreibpunkte und Antwort-Einblendung (reine Website-Zutat). */
.appshot-typing { display: none; gap: 4px; padding: 4px 0; }
.appshot-typing.is-visible { display: inline-flex; }
.appshot-typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: rgb(var(--ca-fg-subtle));
  animation: appshot-dot 1.2s infinite ease-in-out;
}
.appshot-typing i:nth-child(2) { animation-delay: .15s; }
.appshot-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes appshot-dot { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }

.appshot-answer-text, .appshot .code-block-row { transition: opacity .4s ease; }
/* Der Pfeil im Einsetzen-Icon ist in seinem ViewBox nach oben gezeichnet
   (Glyphenmitte y=8 von 20) und schwebt deshalb optisch ueber dem Label. */
.appshot .md .code-apply-button svg { transform: translateY(10%); }
.appshot-bullets { display: grid; gap: 6px; margin: 0; padding-left: 1.1rem; }
.appshot-bullet { list-style: disc; transition: opacity .3s ease; }
.appshot-bullet::marker { color: rgb(var(--ca-fg-subtle)); }

/* Auswahl-Text im App-Nachbau: muss wie in der echten App sauber umbrechen */
.appshot .context-card pre,
.appshot .context-text {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* Code-Zeilen: kein kuenstlicher haengender Einzug, damit mehrzeiliger Text buendig bleibt. */
.appshot .md .code-line { display: block; padding-left: 0 !important; text-indent: 0 !important; }

/* Thinking Trace / Thought Summary */
.activity-summary {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 6px; margin-bottom: 6px; border-radius: 6px;
  font-size: 0.74rem; color: rgb(var(--ca-fg-muted));
  cursor: default; user-select: none;
}
.activity-caret {
  width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

/* Kleinigkeiten, die die App ueber Utilities loest und die im Nachbau
   sonst fehlen wuerden. */
.appshot .pb-1 { padding-bottom: .25rem; }
.appshot .context-preview { display: grid; }
.appshot .context-image-card { height: 5rem; max-width: 46%; }
.appshot .context-image-img { height: 100%; width: auto; object-fit: cover; border-radius: inherit; }
/* Der Leerzustand soll sich im freien Raum zentrieren — dafuer muss der
   Nachrichtenbereich eine Flex-Spalte sein. */
.appshot-messages { display: flex; flex-direction: column; min-height: 0; }
.appshot .empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1 1 auto; min-height: 0; width: 100%; max-width: 100% !important; margin: auto 0;
  text-align: center;
  transition: opacity .25s ease;
}
.appshot .empty-state-mark {
  width: 8.5rem; height: 8.5rem; margin: 0 auto 1rem auto;
  display: flex; align-items: center; justify-content: center;
}
.appshot .empty-state-mark svg {
  display: block; margin: 0 auto; width: 100%; height: 100%;
}
.ctx-stage-col { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.stage-restart-wrap { display: flex; justify-content: flex-start; width: 100%; margin-top: 1.5rem; }

/* Explorer-Spalten und Pfadtrenner. */
.explorer-col { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.explorer-col--name { font-weight: 600; color: var(--fg-muted); }
.explorer-rows { display: block; }
.explorer-crumb-sep { color: var(--fg-subtle); }
.explorer-nav-icon--pc { background: var(--edge-strong); }

/* --- Buehnengeruest ------------------------------------------------------ */

.context-stage { min-width: 0; }

/* Ein Umschalter mit drei Stellungen, kein Feld aus drei Knoepfen. */
.stage-tabs {
  display: flex; width: max-content; gap: 3px; padding: 4px;
  margin: 0 auto var(--sp-5);
  background: var(--surface-2); border: 1px solid var(--edge); border-radius: var(--r-pill);
}
.stage-tabs-wrap { display: flex; justify-content: center; }
.stage-tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 18px; border: 0; border-radius: var(--r-pill);
  background: transparent; color: var(--fg-muted);
  font-weight: 600; font-size: 0.93rem; cursor: pointer; white-space: nowrap;
  transition: background-color .16s var(--ease), color .16s var(--ease);
}
.stage-tab .icon { width: 17px; height: 17px; }
.stage-tab:hover { color: var(--fg); }
.stage-tab[aria-pressed="true"] {
  background: var(--surface); color: var(--fg); box-shadow: var(--shadow-sm);
}

.stage-viewport {
  position: relative; overflow: hidden;
  padding: clamp(10px, 2vw, 18px) clamp(10px, 2vw, 18px) 20px;
  border: 1px solid var(--edge); border-radius: var(--r-lg);
  background:
    radial-gradient(420px 200px at 12% 0%, var(--accent-soft), transparent 70%),
    linear-gradient(180deg, var(--surface), var(--bg));
}
.stage-frame {
  position: relative; width: 100%;
  aspect-ratio: var(--stage-w, 880px) / var(--stage-h, 680px);
}
.stage-canvas {
  position: absolute; left: 0; top: 0;
  width: var(--stage-w, 880px); height: var(--stage-h, 680px);
  transform-origin: 0 0;
  transform: scale(var(--stage-scale, 1));
}
/* Ohne JavaScript trotzdem massstabsgerecht. */
@media (max-width: 1180px) { .stage-canvas { --stage-scale: .82; } }
@media (max-width: 1000px) { .stage-canvas { --stage-scale: .74; } }

.stage-panel { display: none; position: absolute; inset: 0; }
.stage-panel.is-active { display: block; animation: stage-in .28s ease-out; }
@keyframes stage-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.stage-sources { position: relative; display: block; width: 100%; height: 100%; }

.stage-playhead {
  position: absolute; left: 0; right: 0; bottom: 0; height: 3px; display: block;
  background: color-mix(in srgb, var(--surface-3) 70%, transparent);
}
.stage-playhead i { display: block; width: 0; height: 100%; background: var(--accent); transition: width .15s linear; }

.stage-bar {
  display: flex; align-items: center; justify-content: flex-start;
  margin-top: 10px;
}
.stage-restart {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--edge); background: var(--surface);
  color: var(--fg-muted); cursor: pointer; box-shadow: var(--shadow-xs);
  transition: color .15s ease, background-color .15s ease, border-color .15s ease, transform .15s ease;
}
.stage-restart:hover {
  color: var(--fg); background: var(--surface-2); border-color: var(--edge-strong);
  transform: scale(1.05);
}
.stage-restart:active {
  transform: scale(.95);
}
.stage-restart .icon {
  width: 16px; height: 16px;
}



/* --- Fremdfenster -------------------------------------------------------- */

.stage-window {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  border: 1px solid var(--edge-strong); border-radius: 12px;
  background: var(--bg); box-shadow: var(--shadow-md);
}
.stage-titlebar {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center; min-height: 34px; padding: 0 6px;
  border-bottom: 1px solid var(--edge); background: var(--surface-2);
}
.stage-titlebar-title { grid-column: 2; text-align: center; font-size: .78rem; color: var(--fg-muted); }
.stage-frame-controls { grid-column: 3; justify-self: end; display: inline-flex; gap: 0; }
.stage-frame-controls i {
  display: grid; place-items: center; width: 30px; height: 22px;
  color: var(--fg-muted); font-size: .62rem; font-style: normal;
}
.stage-frame-controls i[data-frame-btn="min"]::before { content: "\2014"; }
.stage-frame-controls i[data-frame-btn="max"]::before { content: "\25A2"; }
.stage-frame-controls i[data-frame-btn="close"]::before { content: "\2715"; }
.stage-frame-side { display: none; }

:root[data-host="mac"] .stage-frame-controls { grid-column: 1; justify-self: start; gap: 5px; padding-left: 4px; }
:root[data-host="mac"] .stage-frame-controls i { width: 11px; height: 11px; border-radius: 50%; }
:root[data-host="mac"] .stage-frame-controls i::before { content: ""; }
:root[data-host="mac"] .stage-frame-controls i[data-frame-btn="min"] { background: #f28b82; }
:root[data-host="mac"] .stage-frame-controls i[data-frame-btn="max"] { background: #fdd663; }
:root[data-host="mac"] .stage-frame-controls i[data-frame-btn="close"] { background: #81c995; }
:root[data-host="linux"] .stage-frame-controls i[data-frame-btn="min"],
:root[data-host="linux"] .stage-frame-controls i[data-frame-btn="max"] { display: none; }

/* --- Szene 1: Mail ------------------------------------------------------- */

.stage-panel[data-stage-panel="text"] .stage-mail { left: 48%; right: 0; top: 16px; bottom: 30px; }
.stage-mail-body {
  position: relative; flex: 1;
  display: flex; flex-direction: column; gap: 7px;
  padding: 16px 20px; font-size: .84rem; line-height: 1.55; color: var(--fg);
}
.mail-line { position: relative; z-index: 1; padding: 4px 7px; border-radius: 6px; }
.mail-line.is-target { font-weight: 600; }
.mail-line .mail-line-text { padding: 1px 3px; margin: -1px -3px; border-radius: 2px; box-decoration-break: clone; }
.stage-selection {
  position: absolute; z-index: 0; left: 0; top: 0; width: 0; height: 0;
  border-radius: 3px; background: rgb(0 120 215 / .34);
  box-shadow: inset 0 0 0 1px rgb(0 120 215 / .18);
}
.mail-line.is-replaced {
  background: color-mix(in srgb, var(--ok) 16%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ok) 35%, transparent);
}
.mail-line.is-flash { animation: mail-flash .7s ease; }
@keyframes mail-flash {
  0%, 100% { background-color: color-mix(in srgb, var(--ok) 16%, transparent); }
  50% { background-color: color-mix(in srgb, var(--ok) 34%, transparent); }
}

/* --- Szene 2: Explorer --------------------------------------------------- */

.stage-explorer { background: var(--bg); }
.explorer-breadcrumb {
  display: flex; align-items: center; gap: 6px;
  min-height: 32px; padding: 0 14px; font-size: .72rem; color: var(--fg-muted);
  border-bottom: 1px solid var(--edge);
}
.explorer-crumb.is-current { color: var(--fg); font-weight: 600; }
.explorer-body { flex: 1; display: flex; min-height: 0; }
.explorer-sidebar {
  flex: 0 0 168px; padding: 8px; border-right: 1px solid var(--edge); background: var(--surface);
}
.explorer-sidebar-item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px; border-radius: 6px; font-size: .74rem; color: var(--fg-muted);
}
.explorer-sidebar-item.is-active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.explorer-nav-icon { width: 13px; height: 11px; border-radius: 2px; background: var(--edge-strong); flex: none; }
.explorer-nav-icon--blue { background: #7cadf0; }
.explorer-nav-icon--green { background: #7fc79a; }
.explorer-list { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.explorer-cols, .explorer-row {
  display: grid; grid-template-columns: 18px minmax(0, 2.4fr) .7fr .7fr;
  align-items: center; gap: 8px; padding: 0 12px;
}
.explorer-cols {
  grid-template-columns: minmax(0, 2.4fr) .7fr .7fr;
  height: 30px; border-bottom: 1px solid var(--edge);
  font-size: .68rem; color: var(--fg-subtle);
}
.explorer-row { height: 28px; font-size: .72rem; color: var(--fg); }
.explorer-file-icon { color: var(--file-color, var(--fg-muted)); }
.explorer-file-icon svg { width: 16px; height: 16px; }
.explorer-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.explorer-date, .explorer-type, .explorer-size { color: var(--fg-muted); }
.explorer-row.is-selected { background: #0067c0; color: #fff; }
.explorer-row.is-selected .explorer-file-icon,
.explorer-row.is-selected .explorer-date,
.explorer-row.is-selected .explorer-type,
.explorer-row.is-selected .explorer-size { color: #fff; }

/* --- Szene 3: Desktop ---------------------------------------------------- */

.stage-desktop {
  border-color: var(--edge-strong);
  background:
    radial-gradient(520px 260px at 82% 10%, rgba(255, 255, 255, .75), transparent 70%),
    linear-gradient(135deg, #f2f3f6, #e3e6eb 55%, #d8dbe1);
}
.desktop-sky { position: absolute; inset: 0 0 auto; height: 40%; background: linear-gradient(180deg, rgba(255,255,255,.6), transparent); }
.desktop-window {
  position: absolute; overflow: hidden;
  border: 1px solid #c4c8cf; border-radius: 10px; background: #e9ebef;
  box-shadow: 0 14px 34px rgba(31, 35, 41, .16);
}
.desktop-window-bar {
  display: flex; align-items: center; gap: 5px; height: 26px; padding: 0 10px;
  background: #d9dce2; color: #5f6368; font-size: .66rem;
}
.desktop-window-bar i { width: 8px; height: 8px; border-radius: 50%; background: #c2c6cc; }
.desktop-window-bar span { margin-left: 6px; }
.desktop-window--note { right: 7%; top: 9%; width: 27%; height: 22%; z-index: 1; }
.desktop-note-lines { display: grid; gap: 7px; padding: 12px; }
.desktop-note-lines i { height: 7px; border-radius: 4px; background: #cfd3d9; }
.desktop-note-lines i:last-child { width: 60%; }
.desktop-window--error { left: 9%; top: 14%; width: 48%; height: 50%; z-index: 2; background: #f4f5f7; }
.desktop-window--error::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 4px;
  background: repeating-linear-gradient(90deg, #d93025 0 10px, rgba(217, 48, 37, .28) 10px 20px);
}
.desktop-window-body { display: grid; gap: 10px; justify-items: center; padding: 18px 16px; text-align: center; }
.desktop-error-badge {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
  background: #d93025; color: #fff; font-size: 1.3rem; font-weight: 700;
}
.desktop-error-copy { display: grid; gap: 7px; width: 100%; justify-items: center; }
.desktop-error-line { height: 9px; border-radius: 4px; background: #cfd3d9; }
.desktop-error-line--a { width: 82%; }
.desktop-error-line--b { width: 60%; }
.desktop-error-line--c { width: 40%; background: #e5a39e; }
.desktop-error-code { font-family: var(--mono); font-size: .74rem; color: #c5221f; }
.desktop-taskbar { position: absolute; left: 0; right: 0; bottom: 0; height: 32px; background: #e2e4e9; }
.desktop-taskbar-pill { position: absolute; left: 12px; top: 9px; width: 54px; height: 14px; border-radius: 7px; background: #cfd3d9; }

.desktop-overlay {
  position: absolute; inset: 0; z-index: 3;
  background: rgba(10, 12, 14, .5); opacity: 0; transition: opacity .15s ease;
}
.stage-desktop.is-selecting .desktop-overlay { opacity: 1; }
.desktop-selection {
  position: absolute; left: 5%; top: 6%; width: 0; height: 0; z-index: 4;
  border: 2px solid var(--accent); border-radius: 3px; opacity: 0;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .38);
}
.stage-desktop.is-selecting .desktop-selection { opacity: 1; }
.desktop-selection-size {
  position: absolute; left: 50%; top: -24px; transform: translateX(-50%);
  padding: 2px 7px; border-radius: 5px; background: #0067c0; color: #fff;
  font-size: .66rem; font-weight: 600; white-space: nowrap;
}

/* --- App im Panel -------------------------------------------------------- */

/* Das Fenster hat auf der Buehne exakt seine echten Masse (420x640) und
   wird nur zusammen mit der Leinwand skaliert. */
.stage-app {
  position: absolute; left: 50%; top: 50%; z-index: 5;
  width: 420px;
  transform: translate(-50%, -50%);
  opacity: 0;
}
.stage-app .appshot { height: 640px; }
.stage-app.is-open { opacity: 1; }
.stage-app .appshot { box-shadow: var(--shadow-lg); }
.stage-panel[data-stage-panel="text"] .stage-app { left: 25%; }
/* 640px Fensterhoehe zentriert: ab ca. 52.9% Top ragt das Fenster unten
   aus der 680px-Leinwand — deshalb hier 52%, damit es ganz innen bleibt. */
.stage-panel[data-stage-panel="none"] .stage-app { left: 66%; top: 52%; }

/* --- Alt+1-Keycap -------------------------------------------------------- */

.stage-keys {
  position: absolute; left: 50%; top: 50%; z-index: 6;
  transform-origin: 50% 50%;
  transform: translate(-50%, -50%) translateY(-8px) scale(.94);
  opacity: 0;
  transition: opacity .3s ease, transform .24s cubic-bezier(.33, 1, .68, 1);
}
.stage-keys.is-visible { opacity: 1; transform: translate(-50%, -50%) scale(1.16); }
/* Druecken schrumpft symmetrisch um die Mitte — kein Versatz nach unten. */
.stage-keys.is-pressed { transform: translate(-50%, -50%) scale(.94); }
/* Szene 1: ausserhalb der Kunden-Mail, leicht ueber der Fenstermitte. */
.stage-panel[data-stage-panel="text"] .stage-keys { left: 40%; top: 42%; }
.keycaps {
  display: inline-flex; align-items: center; gap: 7px; padding: 10px 14px;
  border: 1px solid var(--edge-strong); border-radius: 14px;
  background: var(--bg); box-shadow: 0 10px 28px rgba(0, 0, 0, .22);
}
.keycaps kbd {
  display: inline-grid; place-items: center; min-width: 2.4em; min-height: 2.4em;
  padding: 3px 10px; border: 1px solid var(--edge-strong); border-bottom-width: 3px;
  border-radius: 9px; background: var(--surface); color: var(--fg);
  font-family: var(--font); font-size: .92rem; font-weight: 600;
  transition: transform .08s ease, border-bottom-width .08s ease;
}
.stage-keys.is-pressed kbd { transform: translateY(2px); border-bottom-width: 1px; }

/* --- Mauszeiger ---------------------------------------------------------- */

.stage-cursor {
  position: absolute; left: 0; top: 0; z-index: 12;
  width: 24px; height: 24px; opacity: 0;
  color: var(--fg); will-change: transform;
}
.stage-cursor.is-visible { opacity: 1; }
.stage-cursor svg { width: 24px; height: 24px; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .35)); }
.stage-cursor-arrow { transform-origin: 4px 2px; }
.stage-cursor-cross { display: none; color: #fff; }
.stage-cursor.is-crosshair .stage-cursor-arrow { display: none; }
.stage-cursor.is-crosshair .stage-cursor-cross { display: block; }
.stage-cursor-ring {
  position: absolute; left: -9px; top: -11px; width: 26px; height: 26px;
  border: 2px solid var(--accent); border-radius: 50%; opacity: 0;
}
.stage-cursor.is-clicking .stage-cursor-arrow,
.stage-cursor.is-clicking .stage-cursor-cross { animation: cursor-press .28s ease; }
.stage-cursor.is-clicking .stage-cursor-ring { animation: cursor-ring .64s ease-out; }
@keyframes cursor-press { 0%, 100% { transform: scale(1); } 50% { transform: scale(.85); } }
@keyframes cursor-ring { 0% { opacity: .7; transform: scale(.4); } 100% { opacity: 0; transform: scale(1.9); } }

/* --- Ohne Bewegung ------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .stage-panel.is-active,
  .stage-cursor.is-clicking .stage-cursor-arrow,
  .stage-cursor.is-clicking .stage-cursor-cross,
  .stage-cursor.is-clicking .stage-cursor-ring,
  .appshot-typing i { animation: none !important; }
  .stage-playhead i { width: 100% !important; }
  .stage-app { opacity: 1 !important; }
  .stage-selection, .desktop-selection, .desktop-overlay { transition: none !important; }
  .stage-cursor { display: none; }
  .stage-keys { opacity: 1 !important; transform: translate(-50%, -50%) !important; }
}

/* --- Schmale Schirme ----------------------------------------------------- */

/* Auf schmalen Schirmen waere die ganze Buehne eine unleserliche Miniatur.
   Dort zeigen wir nur das App-Fenster — gross genug zum Lesen. */
@media (max-width: 760px) {
  .stage-frame { aspect-ratio: 420 / 640; }
  .stage-canvas { width: 420px; height: 640px; --stage-scale: 1; }
  .stage-window, .stage-cursor, .stage-keys, .stage-playhead, .stage-restart { display: none; }
  .stage-panel[data-stage-panel] .stage-app { left: 50%; top: 50%; opacity: 1; }
  .stage-viewport { padding: 0; border: 0; background: none; }
}

