:root {
  color-scheme: dark;
  --bg: #0b1020;
  --bg-elevated: #0f172a;
  --panel: #121a2b;
  --panel-alt: #182235;
  --panel-soft: #1c2940;
  --line: #283247;
  --line-strong: #35425d;
  --text: #e6edf7;
  --text-muted: #94a3b8;
  --text-dim: #7b8aa5;
  --accent: #4fd1c5;
  --accent-strong: #3b82f6;
  --accent-ink: #06111f;
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.16);
  --success: #22c55e;
  --shadow: 0 24px 70px rgba(2, 6, 23, 0.36);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "Berkeley Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  /* Hoehe der unteren Navigationsleiste am Handy. */
  --tabbar-height: 64px;
}

* {
  box-sizing: border-box;
}

/*
 * Eigene display-Regeln (etwa form { display: grid }) schlagen sonst das
 * hidden-Attribut, weil die Regel des Browsers schwaecher ist.
 */
[hidden] {
  display: none !important;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at top left, rgba(59, 130, 246, 0.16), transparent 28%),
    radial-gradient(circle at top right, rgba(79, 209, 197, 0.1), transparent 24%),
    linear-gradient(180deg, #0b1020 0%, #0a0f1d 100%);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.5;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
.button-link {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: linear-gradient(180deg, var(--accent) 0%, #34b8c5 100%);
  color: var(--accent-ink);
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background-color 140ms ease-out,
    border-color 140ms ease-out,
    color 140ms ease-out,
    transform 120ms ease-out,
    box-shadow 140ms ease-out,
    opacity 140ms ease-out;
}

button:hover,
.button-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 28px rgba(79, 209, 197, 0.18);
}

button:active,
.button-link:active {
  transform: translateY(0);
}

button.ghost,
.button-link {
  background: rgba(79, 209, 197, 0.06);
  border-color: rgba(79, 209, 197, 0.28);
  color: var(--accent);
  box-shadow: none;
}

button.danger {
  background: linear-gradient(180deg, #f45a5a 0%, #ef4444 100%);
  color: #fff5f5;
}

button:disabled,
input:disabled,
textarea:disabled,
select:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
.button-link:focus-visible,
.tab:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

a {
  color: #8ab4ff;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0;
  color: var(--text);
  text-wrap: balance;
}

h1 {
  font-size: clamp(2rem, 2.8vw, 3rem);
  line-height: 1;
  letter-spacing: -0.03em;
}

h2 {
  font-size: clamp(1.2rem, 1.6vw, 1.65rem);
  line-height: 1.08;
  letter-spacing: -0.02em;
}

h3 {
  font-size: 1rem;
  line-height: 1.2;
}

p {
  margin: 0;
  color: var(--text-muted);
  text-wrap: pretty;
}

code,
pre,
.code-block,
.markdown-block code,
.issues-list code {
  font-family: var(--font-mono);
}

.shell {
  width: 100%;
  padding: 20px;
}

.shell.auth-locked {
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: 32px 20px;
  display: grid;
  align-content: center;
  gap: 24px;
}

.shell.auth-locked .topbar {
  margin-bottom: 0;
}

.shell.auth-locked .workspace-topbar,
.shell.auth-locked .workspace-scrim,
.shell.auth-locked .workspace,
.shell.auth-locked .workspace-nav,
.shell.auth-locked .workspace-main {
  display: none !important;
}

.shell.auth-locked #appPanel,
#appPanel[hidden],
#loginPanel[hidden],
#logoutButton[hidden],
.workspace-scrim[hidden] {
  display: none !important;
}

/*
 * Nach dem Login traegt die Seitenspalte Marke, Verbindungszustand und Logout.
 * Die grosse Kopfleiste waere eine zweite Kopie davon - und kostet genau die
 * Hoehe, die dem Chatfenster fehlt.
 */
.shell:not(.auth-locked) > .topbar {
  display: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  margin-bottom: 20px;
  border: 1px solid rgba(53, 66, 93, 0.72);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, rgba(24, 34, 53, 0.92) 0%, rgba(18, 26, 43, 0.96) 100%);
  box-shadow: var(--shadow);
}

.topbar p {
  margin-top: 10px;
  color: var(--text-dim);
}

.panel,
.workspace,
.composer,
.metrics,
.notice,
.auth-flow,
.run,
.session-panel,
.session-status,
.session-record,
.file-card,
.tool-call {
  border: 1px solid rgba(53, 66, 93, 0.72);
  background: linear-gradient(180deg, rgba(24, 34, 53, 0.96) 0%, rgba(18, 26, 43, 0.98) 100%);
  box-shadow: var(--shadow);
}

.panel {
  padding: 22px;
  border-radius: var(--radius-lg);
}

.narrow {
  max-width: 520px;
  margin-inline: auto;
}

.login-panel {
  width: 100%;
}

.workspace-shell {
  display: grid;
  gap: 20px;
}

.workspace-topbar {
  display: none;
}

.workspace-topbar-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.workspace-topbar-copy p[data-state="offline"] {
  color: #fcd9a4;
}

.workspace-topbar-copy p {
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.workspace-topbar-copy h2 {
  font-size: 1rem;
  line-height: 1.1;
}

.workspace-icon-button {
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.workspace-icon-button svg {
  width: 20px;
  height: 20px;
}

.login-hint {
  color: var(--text-muted);
}

.login-hint[data-tone="error"] {
  color: #fecaca;
}

.login-hint[data-tone="success"] {
  color: #bbf7d0;
}

.workspace {
  position: relative;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: calc(100dvh - 40px);
  border-radius: 28px;
  overflow: hidden;
}

.workspace-nav {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 24px;
  padding: 24px 18px;
  border-right: 1px solid rgba(53, 66, 93, 0.72);
  background:
    linear-gradient(180deg, rgba(15, 23, 42, 0.98) 0%, rgba(11, 16, 32, 0.98) 100%);
}

.workspace-nav-head {
  display: grid;
  gap: 12px;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(53, 66, 93, 0.58);
}

.workspace-nav-brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.workspace-nav-kicker {
  font-size: 0.76rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.workspace-nav-head p {
  color: var(--text-dim);
  font-size: 0.92rem;
}

.tabs {
  display: grid;
  gap: 10px;
  align-content: start;
}

/*
 * Der Claude-Tab wird ausgeblendet, wenn kein Schluessel hinterlegt ist. Sowohl
 * .tab als auch .tabbar-item setzen display selbst - ohne diese Regel bliebe
 * [hidden] wirkungslos.
 */
.tab[hidden],
.tabbar-item[hidden] {
  display: none !important;
}

.tab {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  width: 100%;
  min-height: 52px;
  padding: 0 14px 0 12px;
  border: 1px solid rgba(53, 66, 93, 0.5);
  background: rgba(24, 34, 53, 0.62);
  color: var(--text-muted);
  box-shadow: none;
}

.tab-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.tab-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 1px solid rgba(53, 66, 93, 0.56);
  background: rgba(11, 16, 32, 0.44);
  color: currentColor;
  flex: 0 0 auto;
}

.tab-icon svg {
  width: 18px;
  height: 18px;
}

.tab-label {
  min-width: 0;
  font-size: 0.94rem;
  text-align: left;
}

.tab-state {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  flex: 0 0 auto;
}

.tab:hover {
  border-color: rgba(79, 209, 197, 0.28);
  color: var(--text);
}

.tab:hover .tab-icon {
  border-color: rgba(79, 209, 197, 0.28);
}

.tab.active {
  background:
    linear-gradient(90deg, rgba(79, 209, 197, 0.16) 0%, rgba(24, 34, 53, 0.96) 22%),
    linear-gradient(180deg, rgba(29, 43, 67, 1) 0%, rgba(19, 29, 47, 1) 100%);
  border-color: rgba(79, 209, 197, 0.42);
  color: var(--text);
}

.tab.active .tab-icon {
  border-color: rgba(79, 209, 197, 0.36);
  background: rgba(79, 209, 197, 0.12);
}

.tab.active .tab-state {
  border-color: rgba(79, 209, 197, 0.48);
  background: var(--accent);
}

.workspace-nav-footer {
  padding-top: 20px;
  border-top: 1px solid rgba(53, 66, 93, 0.58);
}

.workspace-nav-footer button {
  width: 100%;
}

.workspace-main {
  min-width: 0;
  padding: 24px;
  background: linear-gradient(180deg, rgba(10, 15, 29, 0.72) 0%, rgba(11, 16, 32, 0.82) 100%);
}

.view {
  display: none;
  min-width: 0;
}

.view.active {
  display: block;
}

.view-grid {
  display: grid;
  gap: 24px;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  align-items: start;
}

.projects-grid {
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
}

.view-sidebar,
.view-stage {
  display: grid;
  gap: 18px;
  min-width: 0;
}

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

.composer {
  display: grid;
  gap: 16px;
  padding: 20px;
  border-radius: var(--radius-lg);
}

label {
  display: grid;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.94rem;
}

input,
textarea,
select {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(53, 66, 93, 0.88);
  border-radius: 12px;
  background: rgba(11, 16, 32, 0.92);
  color: var(--text);
  padding: 12px 14px;
  box-shadow: inset 0 1px 0 rgba(148, 163, 184, 0.06);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-dim);
}

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 42px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 2px),
    calc(100% - 12px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

form {
  display: grid;
  gap: 16px;
}

.advanced-panel {
  border: 1px solid rgba(53, 66, 93, 0.64);
  border-radius: 16px;
  background: rgba(13, 19, 34, 0.72);
  overflow: hidden;
}

.advanced-panel summary {
  cursor: pointer;
  padding: 14px 16px;
  color: var(--text);
  font-weight: 600;
  list-style: none;
}

.advanced-panel summary::-webkit-details-marker {
  display: none;
}

.advanced-panel summary::after {
  content: "+";
  float: right;
  color: var(--text-dim);
}

.advanced-panel[open] summary::after {
  content: "−";
}

.advanced-panel-body {
  display: grid;
  gap: 14px;
  padding: 0 16px 16px;
  /*
   * Ohne das bestimmt der laengste ununterbrochene Text (Repo-URL, Deploy-Key)
   * die Mindestbreite der Spalte - am Handy schiebt das den ganzen Bereich
   * ueber den Rand hinaus.
   */
  min-width: 0;
}

.advanced-panel-body > *,
.notice,
.session-empty,
.code-block {
  min-width: 0;
  overflow-wrap: anywhere;
}

.mobile-sticky-actions {
  position: static;
  bottom: auto;
  z-index: auto;
  padding-top: 4px;
  background: transparent;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Chat-Bausteine (Agent + Loop teilen sich diese) ---- */

.chat-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 3px 6px 3px 14px;
  border: 1px solid rgba(53, 66, 93, 0.72);
  border-radius: 999px;
  background: rgba(11, 16, 32, 0.55);
  color: var(--text-muted);
}

.chat-pill > span {
  font-size: 0.74rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-dim);
  white-space: nowrap;
}

.chat-pill select,
.chat-pill input {
  flex: 1 1 auto;
  min-height: 38px;
  width: auto;
  max-width: 15rem;
  padding: 6px 10px;
  border: 0;
  border-radius: 999px;
  background-color: transparent;
  box-shadow: none;
  color: var(--text);
}

.chat-pill select {
  padding-right: 30px;
  background-position:
    calc(100% - 14px) calc(50% - 2px),
    calc(100% - 8px) calc(50% - 2px);
}

.chat-pill input {
  max-width: 5rem;
}

.chat-circle-button {
  width: 48px;
  min-width: 48px;
  height: 48px;
  min-height: 48px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-circle-button svg {
  width: 20px;
  height: 20px;
}

.grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/*
 * Raster-Kinder haben von sich aus die Mindestbreite ihres Inhalts. Auf
 * schmalen Schirmen zieht das die Spalte breiter als das Formular, und der
 * ganze Bereich laeuft nach rechts aus dem Bild. Felder duerfen schrumpfen.
 */
.grid > *,
.composer > *,
.channel-fields-grid > *,
.check-grid > *,
.loop-advanced-grid > *,
.metrics > * {
  min-width: 0;
}

input,
select,
textarea {
  min-width: 0;
}

.full {
  grid-column: 1 / -1;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.metrics {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 16px;
  border-radius: var(--radius-lg);
}

.metrics span {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid rgba(53, 66, 93, 0.62);
  border-radius: 12px;
  background: rgba(11, 16, 32, 0.7);
  color: var(--text-dim);
  font-size: 0.86rem;
}

.metrics strong {
  color: var(--text);
  font-size: 0.98rem;
  line-height: 1.2;
}

.notice,
.auth-flow {
  display: grid;
  gap: 10px;
  padding: 16px 18px;
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, rgba(59, 130, 246, 0.1) 0%, rgba(24, 34, 53, 0.96) 100%);
}

.session-pane {
  display: grid;
  gap: 16px;
}

.session-status {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(28, 41, 64, 0.98) 0%, rgba(17, 25, 41, 0.98) 100%);
}

.session-spinner {
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(79, 209, 197, 0.32);
  animation: pulse 1.2s infinite;
}

.session-status-meta {
  color: var(--text-dim);
  font-size: 0.88rem;
}

.session-pane-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.95fr);
}

.session-panel {
  display: grid;
  gap: 14px;
  padding: 18px;
  border-radius: var(--radius-lg);
}

.session-stream,
.session-files,
.runs {
  display: grid;
  gap: 12px;
}

.session-record,
.run,
.file-card,
.tool-call {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: 16px;
}

.run.is-selected {
  border-color: rgba(79, 209, 197, 0.54);
  background:
    linear-gradient(180deg, rgba(79, 209, 197, 0.12) 0%, rgba(18, 26, 43, 0.98) 100%);
}

.session-error {
  border-color: rgba(239, 68, 68, 0.42);
  background:
    linear-gradient(180deg, rgba(239, 68, 68, 0.12) 0%, rgba(18, 26, 43, 0.98) 100%);
}

.session-user {
  border-color: rgba(79, 209, 197, 0.42);
  background:
    linear-gradient(180deg, rgba(79, 209, 197, 0.12) 0%, rgba(18, 26, 43, 0.98) 100%);
}

.session-record-head,
.file-card-head,
.session-files-head,
.provider-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.session-record-meta,
.file-card-meta {
  color: var(--text-dim);
  font-size: 0.86rem;
}

.session-record-body {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.session-empty {
  color: var(--text-dim);
}

.markdown-block {
  display: grid;
  gap: 10px;
  color: var(--text-muted);
  line-height: 1.6;
}

.markdown-block h3,
.markdown-block h4 {
  margin: 0;
  color: var(--text);
  font-size: 0.98rem;
}

.markdown-block p,
.issue-recommendation,
.issues-list p {
  margin: 0;
}

.markdown-block ul,
.issues-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 8px;
  color: var(--text-muted);
}

.markdown-block code,
.issues-list code {
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(79, 209, 197, 0.08);
  color: #bfeee9;
}

.code-artifact {
  display: grid;
  gap: 10px;
  min-width: 0;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid rgba(53, 66, 93, 0.84);
  border-radius: 14px;
  background: rgba(8, 12, 24, 0.92);
}

.code-artifact-header,
.code-artifact-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
}

.code-artifact-summary {
  cursor: pointer;
}

.code-artifact-summary::-webkit-details-marker {
  color: var(--text-dim);
}

.code-artifact-meta {
  color: var(--text-dim);
  font-size: 0.84rem;
  flex-shrink: 0;
}

.code-block {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid rgba(53, 66, 93, 0.84);
  border-radius: 14px;
  background: rgba(8, 12, 24, 0.92);
  color: #dbe7fb;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.9rem;
  line-height: 1.55;
  max-width: 100%;
}

.code-artifact .code-block {
  padding: 0;
  border: 0;
  background: transparent;
}

.code-block.is-collapsed-artifact {
  max-height: 28rem;
}

.code-block.is-error {
  padding: 12px 14px;
  border: 1px solid rgba(239, 68, 68, 0.42);
  background: rgba(50, 17, 23, 0.72);
  color: #fecaca;
}

.tool-call {
  background:
    linear-gradient(180deg, rgba(28, 41, 64, 0.9) 0%, rgba(18, 26, 43, 0.98) 100%);
}

.tool-call summary {
  cursor: pointer;
  color: var(--text);
}

/*
 * Denkschritte sind Beiwerk: eine leise Zeile, die man aufklappen kann,
 * keine eigene Karte im Verlauf.
 */
.thinking-block {
  border: 0;
  background: transparent;
  box-shadow: none;
}

.thinking-block > summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  cursor: pointer;
  list-style: none;
  color: var(--text-dim);
  font-size: 0.82rem;
}

.thinking-block > summary::-webkit-details-marker {
  display: none;
}

.thinking-block > summary::before {
  content: "›";
  display: inline-block;
  transition: transform 120ms ease-out;
}

.thinking-block[open] > summary::before {
  transform: rotate(90deg);
}

.thinking-block .thinking-body {
  margin-top: 6px;
  padding-left: 12px;
  border-left: 2px solid rgba(53, 66, 93, 0.72);
}

.thinking-block .markdown-block {
  color: var(--text-dim);
  font-size: 0.9rem;
}

.thinking-body,
.tool-call-body {
  margin-top: 12px;
  display: grid;
  gap: 12px;
}

.tool-call-summary {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr) auto;
  align-items: baseline;
}

.tool-call-target,
.tool-call-state {
  min-width: 0;
  color: var(--text-dim);
  font-size: 0.88rem;
}

.tool-call-target {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-card-actions,
.provider-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.file-preview {
  display: grid;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid rgba(53, 66, 93, 0.5);
}

.file-preview-body {
  min-height: 260px;
  padding: 14px;
  border: 1px dashed rgba(79, 209, 197, 0.2);
  border-radius: 16px;
  background: rgba(8, 12, 24, 0.6);
}

.sandbox-preview,
.image-preview {
  width: 100%;
  min-height: 340px;
  border: 0;
  border-radius: 12px;
  background: #fff;
}

.image-preview {
  object-fit: contain;
  background: rgba(8, 12, 24, 0.96);
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
}

.checkbox input {
  width: auto;
  margin: 0;
}

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

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

#notifyHint[data-tone="error"] {
  color: #fecaca;
}

#notifyHint[data-tone="success"] {
  color: #bbf7d0;
}

#runSummary[data-tone="error"] {
  color: #fecaca;
}

#runSummary[data-tone="info"] {
  color: var(--text-muted);
}

.compare-card {
  align-content: start;
}

/* ---- Untere Navigationsleiste (nur Handy) ---- */

.mobile-tabbar {
  display: none;
}

/* ---- Karten-Sprache fuer Projekte, Runs und Dateien ---- */

/*
 * Nur die aktive Ansicht ist sichtbar. Die Regel muss die .active-Regel
 * ueberbieten, sonst zeigt der Tab-Wechsel gar keine Wirkung.
 */
.view.active.view-stack {
  display: grid;
  gap: 16px;
  align-content: start;
}

.panel {
  display: grid;
  gap: 14px;
  align-content: start;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-head h2 {
  font-size: 1.1rem;
}

.panel-head button {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 0.86rem;
}

.panel-head-meta {
  min-width: 0;
  color: var(--text-dim);
  font-size: 0.86rem;
}

.panel-head-meta[data-tone="error"] {
  color: #fecaca;
}

.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid rgba(53, 66, 93, 0.72);
  border-radius: 999px;
  background: rgba(11, 16, 32, 0.55);
  align-self: start;
}

.segment {
  min-height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  box-shadow: none;
  color: var(--text-dim);
  font-size: 0.88rem;
}

.segment:hover {
  transform: none;
  box-shadow: none;
  color: var(--text-muted);
}

.segment.active {
  background: rgba(79, 209, 197, 0.14);
  color: var(--accent);
}

.filter-bar {
  display: grid;
  gap: 10px;
}

.card-list {
  display: grid;
  gap: 10px;
}

.card {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  border: 1px solid rgba(53, 66, 93, 0.72);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(24, 34, 53, 0.94) 0%, rgba(18, 26, 43, 0.98) 100%);
}

.card.is-selected {
  border-color: rgba(79, 209, 197, 0.54);
  background: linear-gradient(180deg, rgba(79, 209, 197, 0.12) 0%, rgba(18, 26, 43, 0.98) 100%);
}

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

.card-title {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--text);
}

.card-badge {
  padding: 2px 10px;
  border: 1px solid rgba(53, 66, 93, 0.72);
  border-radius: 999px;
  background: rgba(11, 16, 32, 0.7);
  color: var(--text-muted);
  font-size: 0.76rem;
  white-space: nowrap;
}

.card-badge[data-tone="ok"] {
  border-color: rgba(74, 222, 128, 0.4);
  background: rgba(74, 222, 128, 0.1);
  color: #bbf7d0;
}

.card-badge[data-tone="warn"] {
  border-color: rgba(251, 191, 36, 0.4);
  background: rgba(251, 191, 36, 0.1);
  color: #fde68a;
}

.card-badge[data-tone="error"] {
  border-color: rgba(239, 68, 68, 0.42);
  background: rgba(239, 68, 68, 0.12);
  color: #fecaca;
}

.card-badge[data-tone="git"] {
  border-color: rgba(79, 209, 197, 0.4);
  background: rgba(79, 209, 197, 0.1);
  color: #bfeee9;
}

.card-meta {
  color: var(--text-dim);
  font-size: 0.84rem;
}

.card-text {
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.card-actions button,
.card-actions .button-link {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 0.86rem;
}

/* Loeschen bleibt erkennbar, draengt sich in einer Liste aber nicht auf. */
.card-actions .danger {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.42);
  color: #fecaca;
}

.chat-root-compact {
  height: auto;
  min-height: 0;
}

.chat-root-compact .chat-panel {
  height: auto;
  max-height: calc(100dvh - 180px);
}

.chat-run-meta {
  color: var(--text-dim);
  font-size: 0.84rem;
}

/* ---- Modelle-Tab: Pi Auto und Anbieter-Schluessel ---- */

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

.auto-chain {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid rgba(53, 66, 93, 0.72);
  border-radius: 18px;
  background: rgba(11, 16, 32, 0.55);
  align-content: start;
}

.auto-chain-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.auto-chain-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
  color: var(--text-muted);
}

.auto-chain-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px 10px;
}

.auto-chain-model {
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  color: var(--text);
}

.auto-chain-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.auto-chain-actions button {
  min-height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.78rem;
}

.chain-icon-button {
  width: 36px;
  min-width: 36px;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
}

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

.provider-card {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid rgba(53, 66, 93, 0.72);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(24, 34, 53, 0.96) 0%, rgba(18, 26, 43, 0.98) 100%);
  align-content: start;
}

.provider-card-form {
  display: grid;
  gap: 10px;
}

.provider-status {
  padding: 2px 10px;
  border: 1px solid rgba(53, 66, 93, 0.72);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 0.78rem;
  white-space: nowrap;
}

.provider-status[data-state="stored"] {
  border-color: rgba(74, 222, 128, 0.4);
  background: rgba(74, 222, 128, 0.1);
  color: #bbf7d0;
}

.provider-status[data-state="external"] {
  border-color: rgba(79, 209, 197, 0.4);
  background: rgba(79, 209, 197, 0.08);
  color: #bfeee9;
}

.provider-card-message[data-tone="success"] {
  color: #bbf7d0;
}

.provider-card-message[data-tone="error"] {
  color: #fecaca;
}

#autoModelHint[data-tone="success"] {
  color: #bbf7d0;
}

#autoModelHint[data-tone="error"] {
  color: #fecaca;
}

/* ---- Chat-Oberflaeche: Agent-Tab und Writer/Reviewer-Loop ---- */

/*
 * Der Verlauf muss selbst scrollen, nicht die ganze Seite: nur dann bleiben
 * Eingabeleiste und Kopfzeile stehen, das Nachrutschen bei neuen Nachrichten
 * funktioniert und die Sprungmarken haben einen Bezug.
 */
.chat-root {
  /* Schirmhoehe minus Rahmen der Huelle (2x20) und Innenabstand (2x24). */
  height: calc(100dvh - 88px);
  min-height: 480px;
}

.chat-shell {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
  height: 100%;
  min-height: 0;
}

.chat-panel {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  border: 1px solid rgba(53, 66, 93, 0.72);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(24, 34, 53, 0.96) 0%, rgba(18, 26, 43, 0.99) 100%);
  box-shadow: var(--shadow);
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(53, 66, 93, 0.5);
}

.chat-status {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 12rem;
}

.chat-status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 999px;
  background: var(--text-dim);
}

.chat-status-dot[data-busy="true"] {
  background: var(--accent);
  animation: pulse 1.2s infinite;
}

.chat-status-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.chat-status-facts {
  display: flex;
  align-items: center;
  gap: 6px 14px;
  flex-wrap: wrap;
  color: var(--text-dim);
  font-size: 0.84rem;
}

.chat-status-facts strong {
  color: var(--text-muted);
  font-weight: 600;
}

/*
 * Kurzform der Kosten: am Schreibtisch ueberfluessig, am Handy die einzige
 * Stelle, an der der Preis noch hinpasst. Gegenstueck zu .chat-fact-wide.
 */
.chat-fact-compact {
  display: none;
}

/*
 * Ein Unteragent wird eingerueckt und bekommt eine Kante an der linken Seite.
 * Die Einrueckung ist bewusst klein: sie soll die Zugehoerigkeit zeigen, ohne
 * am Handy die halbe Zeilenbreite zu kosten.
 */
.chat-subagent {
  margin-left: 18px;
  padding-left: 12px;
  border-left: 2px solid rgba(79, 209, 197, 0.35);
}

/* Kostenpflichtige Anbieter im Katalog kennzeichnen. */
.provider-status[data-state="paid"] {
  color: var(--text-dim);
  border-color: rgba(148, 163, 184, 0.35);
}

/* Kurzbeschreibung des gewaehlten Agenten unter der Auswahl. */
.chat-agent-hint {
  display: grid;
  gap: 6px;
  margin: 10px 0 0;
  color: var(--text-dim);
  font-size: 0.86rem;
  line-height: 1.45;
}

.chat-agent-warning {
  color: var(--danger);
}

/* Nahe an der Ausgabengrenze faellt die Zahl auf, ohne zu blinken. */
.chat-status-facts[data-budget="warn"] strong {
  color: var(--danger);
}

.chat-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.chat-actions button {
  min-height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 0.88rem;
}

.chat-viewport > * {
  min-width: 0;
  max-width: 100%;
  /*
   * Der Verlauf ist eine Spalte aus Flex-Elementen. Ohne dieses flex-shrink: 0
   * quetscht der Browser jeden Block zusammen, sobald der Verlauf laenger als
   * das Fenster ist - eingeklappte Runden werden dann niedriger als ihr
   * eigener Text und der Inhalt laeuft ueber den naechsten Block.
   */
  flex-shrink: 0;
}

.chat-viewport {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  scroll-padding-bottom: 160px;
}

.chat-empty {
  display: grid;
  gap: 6px;
  padding: 18px;
  border: 1px dashed rgba(79, 209, 197, 0.22);
  border-radius: 18px;
  background: rgba(8, 12, 24, 0.5);
}

.chat-empty p {
  color: var(--text-dim);
}

.chat-message {
  display: flex;
  width: 100%;
}

.chat-message-user {
  justify-content: flex-end;
}

.chat-message-assistant {
  justify-content: flex-start;
}

.chat-bubble {
  width: min(100%, 920px);
  padding: 14px 16px;
  border: 1px solid rgba(53, 66, 93, 0.76);
  border-radius: 20px;
  box-shadow: 0 18px 48px rgba(2, 6, 23, 0.22);
}

.chat-bubble-user {
  width: min(100%, 720px);
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.16) 0%, rgba(24, 34, 53, 0.98) 100%);
  border-color: rgba(59, 130, 246, 0.34);
}

.chat-bubble-assistant {
  background: linear-gradient(180deg, rgba(24, 34, 53, 0.98) 0%, rgba(15, 23, 42, 0.98) 100%);
}

.chat-message-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.chat-message-meta {
  color: var(--text-dim);
  font-size: 0.8rem;
}

.chat-tool-group,
.chat-tool-group-body {
  display: grid;
  gap: 8px;
}

.chat-tool-group > summary {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.chat-bubble .markdown-block h1,
.chat-bubble .markdown-block h2,
.chat-bubble .markdown-block h3,
.chat-bubble .markdown-block h4 {
  font-size: 1rem;
  line-height: 1.3;
  letter-spacing: 0;
}

.chat-bubble .markdown-block h1 {
  font-size: 1.08rem;
}

.chat-bubble .markdown-block > :first-child {
  margin-top: 0;
}

.chat-bubble .markdown-block > :last-child {
  margin-bottom: 0;
}

.chat-composer {
  position: sticky;
  bottom: 0;
  z-index: 4;
  display: grid;
  gap: 10px;
  padding: 10px 14px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(53, 66, 93, 0.5);
  background:
    linear-gradient(180deg, rgba(18, 26, 43, 0) 0%, rgba(18, 26, 43, 0.9) 22%, rgba(18, 26, 43, 0.99) 52%);
}

.chat-composer-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "input send"
    "controls controls";
  gap: 10px;
  align-items: end;
  padding: 10px 12px;
  border: 1px solid rgba(53, 66, 93, 0.72);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(24, 34, 53, 0.96) 0%, rgba(18, 26, 43, 0.99) 100%);
  box-shadow: 0 24px 60px rgba(2, 6, 23, 0.34);
}

.chat-composer-bar.is-simple {
  grid-template-areas: "input send";
}

.chat-composer-input {
  display: block;
  grid-area: input;
  min-width: 0;
  margin: 0;
}

.chat-composer-input textarea {
  min-height: 46px;
  max-height: 200px;
  padding: 8px 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  resize: none;
}

.chat-composer-input textarea:focus-visible {
  outline: none;
}

.chat-settings-line {
  grid-area: controls;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 36px;
  padding: 4px 12px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: rgba(11, 16, 32, 0.5);
  box-shadow: none;
  color: var(--text-dim);
  font-size: 0.84rem;
  font-weight: 500;
  white-space: normal;
}

.chat-settings-line:hover {
  transform: none;
  box-shadow: none;
  border-color: rgba(79, 209, 197, 0.28);
  color: var(--text-muted);
}

.chat-settings-summary {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.chat-settings-toggle {
  flex: 0 0 auto;
  color: var(--accent);
}

.chat-jump {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.chat-jump-chip {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid rgba(53, 66, 93, 0.82);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(28, 41, 64, 0.96) 0%, rgba(18, 26, 43, 0.98) 100%);
  color: var(--text-muted);
  font-size: 0.82rem;
  box-shadow: 0 12px 30px rgba(2, 6, 23, 0.42);
}

.chat-jump-chip:hover {
  color: var(--text);
  border-color: rgba(79, 209, 197, 0.42);
}

.loop-advanced-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.loop-advanced-head h3 {
  font-size: 0.86rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.loop-advanced-head button {
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 0.82rem;
}

.chat-send {
  grid-area: send;
}

.chat-files {
  border: 1px solid rgba(53, 66, 93, 0.72);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(24, 34, 53, 0.96) 0%, rgba(18, 26, 43, 0.99) 100%);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-files-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 50px;
  padding: 12px 16px;
  cursor: pointer;
  list-style: none;
  color: var(--text);
  font-weight: 600;
  font-size: 0.94rem;
}

.chat-files-summary::-webkit-details-marker {
  display: none;
}

.chat-files-summary::after {
  content: "+";
  color: var(--accent);
  font-size: 1.15rem;
}

.chat-files[open] .chat-files-summary::after {
  content: "\2212";
}

.chat-files-count {
  color: var(--text-dim);
  font-weight: 400;
  font-size: 0.86rem;
  margin-left: auto;
}

.chat-files-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  padding: 0 16px 16px;
}

.chat-files-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

/* ---- Writer/Reviewer-Loop ---- */

.loop-round {
  border: 1px solid rgba(53, 66, 93, 0.72);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(24, 34, 53, 0.92) 0%, rgba(18, 26, 43, 0.98) 100%);
  overflow: hidden;
}

.loop-round[data-state="running"] {
  border-color: rgba(79, 209, 197, 0.4);
}

.loop-round-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-height: 52px;
  padding: 10px 16px;
  cursor: pointer;
  list-style: none;
  color: var(--text);
}

.loop-round-summary::-webkit-details-marker {
  display: none;
}

.loop-round-summary::after {
  content: "+";
  margin-left: auto;
  padding-left: 8px;
  color: var(--text-dim);
}

.loop-round[open] > .loop-round-summary::after {
  content: "\2212";
}

.loop-round-title {
  font-weight: 600;
}

.loop-round-meta {
  color: var(--text-dim);
  font-size: 0.84rem;
}

.loop-badge {
  padding: 3px 10px;
  border: 1px solid rgba(53, 66, 93, 0.72);
  border-radius: 999px;
  background: rgba(11, 16, 32, 0.7);
  color: var(--text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.loop-badge[data-tone="approved"] {
  border-color: rgba(74, 222, 128, 0.4);
  background: rgba(74, 222, 128, 0.1);
  color: #bbf7d0;
}

.loop-badge[data-tone="revise"] {
  border-color: rgba(251, 191, 36, 0.4);
  background: rgba(251, 191, 36, 0.1);
  color: #fde68a;
}

.loop-badge[data-tone="running"] {
  border-color: rgba(79, 209, 197, 0.4);
  background: rgba(79, 209, 197, 0.1);
  color: #bfeee9;
}

.loop-round-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  padding: 0 14px 14px;
}

.loop-round-body .chat-bubble {
  width: 100%;
  box-shadow: none;
}

.loop-role {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(79, 209, 197, 0.1);
  color: #bfeee9;
  font-size: 0.76rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.loop-role[data-role="reviewer"] {
  background: rgba(139, 148, 255, 0.12);
  color: #c7cbff;
}

/* Vorschlag und Probelauf der Pruefbefehle im Projekt-Bereich. */
.advisor-card {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid rgba(79, 209, 197, 0.28);
  border-radius: 16px;
  background: rgba(8, 12, 24, 0.55);
}

.advisor-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.advisor-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.advisor-list li {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.advisor-list code {
  overflow-wrap: anywhere;
  color: var(--text);
}

.advisor-result[data-passed="false"] p {
  color: #fecaca;
}

.advisor-result .code-block {
  margin-top: 6px;
  max-height: 220px;
  overflow: auto;
  font-size: 0.82rem;
}

.session-empty[data-tone="warn"] {
  color: #fcd9a4;
}

.session-empty[data-tone="error"] {
  color: #fecaca;
}

.check-advisor-model select {
  min-width: 160px;
}

/*
 * Pruefergebnisse. Gruen ist eine Zeile, rot bekommt seine Ausgabe - die ist
 * das Wertvollste in der ganzen Runde, weil daran die naechste arbeitet.
 */
.loop-checks {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid rgba(53, 66, 93, 0.6);
  border-left: 3px solid var(--success);
  border-radius: 16px;
  background: rgba(8, 12, 24, 0.55);
}

.loop-checks[data-tone="failed"] {
  border-left-color: var(--danger);
}

.loop-checks-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.loop-check-command {
  margin: 0;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.loop-check[data-passed="false"] .loop-check-command {
  color: #fecaca;
}

.loop-check .code-block {
  margin-top: 6px;
  max-height: 260px;
  overflow: auto;
  font-size: 0.82rem;
}

.loop-criteria {
  display: grid;
  gap: 6px;
}

.loop-criteria-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.loop-criteria-list li {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  gap: 8px;
  color: var(--text-muted);
}

.loop-criteria-list li[data-state="met"] {
  color: #bbf7d0;
}

.loop-criteria-list li[data-state="open"] {
  color: #fecaca;
}

/* Das Tor sagt, warum eine Freigabe nicht angenommen wurde. */
.loop-gate {
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  border: 1px solid rgba(251, 191, 36, 0.42);
  border-radius: 16px;
  background: rgba(120, 82, 15, 0.16);
}

.loop-gate-head {
  color: #fcd9a4;
  font-weight: 600;
}

.loop-review {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid rgba(53, 66, 93, 0.6);
  border-radius: 18px;
  background: rgba(8, 12, 24, 0.55);
}

.loop-review-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.loop-review-head strong {
  font-size: 0.94rem;
}

.loop-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0;
  padding: 8px 14px;
  border: 1px solid rgba(251, 191, 36, 0.32);
  border-radius: 999px;
  background: rgba(251, 191, 36, 0.08);
  color: var(--text-muted);
  font-size: 0.86rem;
}

.loop-switch strong {
  color: var(--text);
  font-weight: 600;
}

.loop-switch-badge {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(251, 191, 36, 0.16);
  color: #fde68a;
  font-size: 0.74rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}

.loop-round-models {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.84rem;
}

.loop-round-models strong {
  color: var(--text-muted);
  font-weight: 600;
}

.loop-final {
  border-color: rgba(79, 209, 197, 0.45);
  background: linear-gradient(180deg, rgba(79, 209, 197, 0.1) 0%, rgba(18, 26, 43, 0.98) 100%);
}

.loop-final-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.loop-final-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.loop-final-actions button {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 0.88rem;
}

.loop-status-more {
  position: relative;
  margin-left: auto;
}

.loop-status-more > summary {
  cursor: pointer;
  list-style: none;
  padding: 4px 10px;
  border: 1px solid rgba(53, 66, 93, 0.72);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 0.8rem;
}

.loop-status-more > summary::-webkit-details-marker {
  display: none;
}

.loop-status-sheet {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 6;
  display: grid;
  gap: 6px;
  min-width: 260px;
  padding: 12px 14px;
  border: 1px solid rgba(53, 66, 93, 0.72);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(24, 34, 53, 0.99) 0%, rgba(18, 26, 43, 1) 100%);
  box-shadow: var(--shadow);
  color: var(--text-dim);
  font-size: 0.84rem;
}

.loop-status-sheet div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.loop-status-sheet strong {
  color: var(--text-muted);
  font-weight: 600;
  text-align: right;
}

.loop-advanced {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid rgba(53, 66, 93, 0.72);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(24, 34, 53, 0.96) 0%, rgba(18, 26, 43, 0.99) 100%);
  box-shadow: var(--shadow);
}

.loop-advanced-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

.loop-advanced h3 {
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.loop-base-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 8px 8px 14px;
  border: 1px solid rgba(79, 209, 197, 0.45);
  border-radius: 999px;
  background: rgba(79, 209, 197, 0.08);
  color: var(--text-muted);
  font-size: 0.86rem;
}

.loop-base-chip button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 0.82rem;
}

.loop-chain-tasks {
  display: grid;
  gap: 10px;
}

.loop-chain-task {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  padding: 10px;
  border: 1px solid rgba(53, 66, 93, 0.62);
  border-radius: 14px;
  background: rgba(11, 16, 32, 0.55);
}

.loop-chain-task-label {
  grid-column: 1 / -1;
  color: var(--text-dim);
  font-size: 0.82rem;
}

.loop-chain-task textarea {
  min-height: 72px;
}

.loop-error {
  margin: 0;
  padding: 10px 14px;
  border: 1px solid rgba(239, 68, 68, 0.42);
  border-radius: 14px;
  background: rgba(239, 68, 68, 0.1);
  color: #fecaca;
  font-size: 0.9rem;
}

.loop-clarify {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-content: start;
}

.loop-clarify > *,
.loop-clarify-grid > *,
.loop-advanced > * {
  min-width: 0;
}

.loop-clarify-head {
  display: grid;
  gap: 4px;
}

.loop-clarify-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

.loop-clarify-card {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid rgba(53, 66, 93, 0.72);
  border-radius: 18px;
  background: rgba(8, 12, 24, 0.55);
  align-content: start;
}

.loop-clarify-card h3 {
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.loop-clarify-card pre {
  max-height: 22rem;
}

.loop-clarify-card textarea {
  min-height: 16rem;
  font-size: 1rem;
  line-height: 1.6;
}

.loop-clarify-question {
  display: grid;
  gap: 8px;
}

.loop-clarify-question p {
  color: var(--text);
}

.loop-clarify-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

@media (max-width: 1120px) {
  .view-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 920px) {
  .session-pane-grid,
  .grid,
  .metrics,
  .check-grid,
  .compare-grid,
  .channel-fields-grid,
  .project-inline-grid,
  .loop-clarify-grid,
  .loop-advanced-grid,
  .auto-chains,
  .provider-cards {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .shell {
    padding: 10px;
  }

  .shell:not(.auth-locked) > .topbar {
    display: none;
  }

  .topbar {
    padding: 14px 16px;
    align-items: flex-start;
  }

  .workspace-shell {
    gap: 12px;
  }

  /*
   * Die obere Leiste wiederholte nur, was die untere Leiste schon zeigt, und
   * schwebte beim Scrollen ueber den Karten. Sie erscheint jetzt nur noch,
   * wenn die Verbindung weg ist - dann als durchgehender Streifen, der
   * Inhalt schiebt statt ihn zu ueberdecken.
   */
  .workspace-topbar {
    display: none;
  }

  body.is-offline .workspace-topbar {
    position: sticky;
    top: 0;
    z-index: 42;
    display: flex;
    align-items: center;
    gap: 12px;
    margin: -10px -10px 0;
    padding: 8px 12px calc(8px + env(safe-area-inset-top));
    border: 0;
    border-bottom: 1px solid rgba(252, 217, 164, 0.34);
    border-radius: 0;
    background: linear-gradient(180deg, #3a2f1c 0%, #2a2314 100%);
    box-shadow: none;
  }

  body.is-offline .workspace-topbar h2 {
    display: none;
  }

  .workspace {
    display: block;
    min-height: 0;
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  /* Die Seitenspalte ist am Handy durch die untere Leiste ersetzt. */
  .workspace-nav,
  .workspace-scrim {
    display: none;
  }

  .workspace-main {
    padding: 0 0 calc(var(--tabbar-height) + env(safe-area-inset-bottom));
  }

  .mobile-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 44;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 2px;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(53, 66, 93, 0.72);
    background: linear-gradient(180deg, rgba(18, 26, 43, 0.94) 0%, rgba(11, 16, 32, 0.99) 100%);
    backdrop-filter: blur(12px);
  }

  .tabbar-item {
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 3px;
    min-height: 52px;
    padding: 4px 2px;
    border: 0;
    border-radius: 14px;
    background: transparent;
    box-shadow: none;
    color: var(--text-dim);
    font-size: 0.68rem;
    font-weight: 500;
    letter-spacing: 0.01em;
  }

  .tabbar-item svg {
    width: 22px;
    height: 22px;
  }

  .tabbar-item:hover {
    transform: none;
    box-shadow: none;
  }

  .tabbar-item.active {
    background: rgba(79, 209, 197, 0.12);
    color: var(--accent);
  }

  .tabs {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .panel,
  .composer,
  .session-panel,
  .session-record,
  .file-card,
  .run {
    padding: 14px;
  }

  .view-stage,
  .view-sidebar {
    gap: 12px;
  }

  .composer,
  form,
  .grid,
  .metrics,
  .runs,
  .session-stream,
  .session-files {
    gap: 12px;
  }

  label {
    gap: 6px;
    font-size: 0.88rem;
  }

  input,
  textarea,
  select {
    min-height: 44px;
    padding: 10px 12px;
    /* Unter 16px zoomt iOS beim Fokus automatisch in die Seite hinein. */
    font-size: 16px;
  }

  textarea {
    min-height: 96px;
  }

  .notice,
  .metrics {
    padding: 12px 14px;
  }

  .advanced-panel summary {
    padding: 12px 14px;
    font-size: 0.92rem;
  }

  .advanced-panel-body {
    gap: 12px;
    padding: 0 14px 14px;
  }

  /*
   * Frueher klebte diese Leiste ueber dem Formular - ohne Hintergrund, also
   * lagen Knopf und Text uebereinander. In einem Einstellungs-Formular scrollt
   * man ohnehin bis zum Ende; der Knopf steht jetzt einfach dort.
   */
  .mobile-sticky-actions {
    position: static;
    bottom: auto;
    margin: 0;
    padding-top: 8px;
  }

  .mobile-sticky-actions button,
  .mobile-sticky-actions .button-link {
    min-height: 48px;
  }

  .actions {
    width: 100%;
  }

  /*
   * Lange Beschriftungen duerfen am Handy umbrechen. Sonst bestimmt der
   * breiteste Knopf die Mindestbreite des Formulars und schiebt den Bereich
   * ueber den rechten Rand.
   */
  .actions button,
  .actions .button-link {
    min-width: 0;
    white-space: normal;
  }

  .actions button,
  .actions .button-link {
    flex: 1 1 100%;
  }

  .sandbox-preview,
  .image-preview {
    min-height: 260px;
  }

  .chat-root {
    /* Schirmhoehe minus Huellen-Rand (2x10) und untere Leiste. */
    height: calc(100dvh - 20px - var(--tabbar-height) - env(safe-area-inset-bottom));
    min-height: 360px;
  }

  .chat-composer {
    bottom: 0;
  }



  /*
   * Die Kopfzeile darf am Handy nicht ein Drittel des Schirms fressen:
   * Zustand in Zeile eins, Kennzahlen und Bedienung teilen sich Zeile zwei.
   */
  .chat-head {
    align-items: center;
    flex-wrap: nowrap;
    gap: 8px 10px;
    padding: 6px 12px;
  }

  /*
   * Jeder Pixel um den Verlauf herum fehlt dem Verlauf. Am Handy sind
   * Eingabeleiste und Dateiliste deshalb enger gesetzt als am Desktop.
   */
  .chat-composer {
    gap: 8px;
    padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  }

  .chat-composer-bar {
    gap: 8px;
    padding: 6px 12px;
  }

  .chat-composer-input textarea {
    min-height: 40px;
    padding: 6px 0;
  }

  .chat-settings-line {
    min-height: 32px;
  }

  .chat-files-summary {
    min-height: 42px;
    padding: 8px 12px;
    font-size: 0.9rem;
  }

  .chat-status {
    /* Der Zustandstext gibt Platz ab, damit Kennzahlen und Details danebenpassen. */
    flex: 1 1 auto;
    max-width: 60%;
  }

  /* Eine Zeile: der Zustandstext gibt nach, Kennzahlen und Knoepfe bleiben. */
  .chat-status-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /*
   * Am Handy bleibt in dieser Zeile nur der Details-Knopf stehen. Er darf
   * nicht schrumpfen, sonst rutscht er aus der sichtbaren Zeile heraus -
   * nachgeben soll der Zustandstext.
   */
  .chat-status-facts {
    flex: 0 0 auto;
    min-width: 0;
    flex-wrap: nowrap;
    gap: 4px 12px;
  }

  .chat-status-facts > span {
    white-space: nowrap;
  }

  /* Lange Werte stehen am Handy in den Details statt in der Kopfzeile. */
  .chat-fact-wide {
    display: none;
  }

  .chat-fact-compact {
    display: inline;
    white-space: nowrap;
  }

  .chat-subagent {
    margin-left: 8px;
    padding-left: 8px;
  }

  /* Im Claude-Tab hat der Preis Vorrang vor dem Statuswort. */
  .chat-head-claude .chat-status-text {
    display: none;
  }

  .chat-actions {
    flex: 0 1 auto;
    justify-content: flex-end;
    gap: 6px;
  }

  .chat-actions button {
    min-height: 34px;
    padding: 0 10px;
    font-size: 0.82rem;
  }

  .chat-pill {
    padding: 2px 4px 2px 8px;
  }

  /* Die Auswahl nennt den Wert selbst - die Beschriftung kostet nur Platz. */
  .chat-actions .chat-pill > span {
    display: none;
  }

  .chat-pill > span {
    font-size: 0.66rem;
  }

  .chat-pill select {
    min-height: 32px;
    max-width: 8rem;
  }

  .loop-status-more > summary {
    padding: 3px 10px;
  }

  .chat-actions {
    justify-content: space-between;
  }

  .chat-pill select {
    max-width: 10rem;
  }

  .chat-viewport {
    padding: 12px;
    gap: 10px;
    scroll-padding-bottom: calc(180px + env(safe-area-inset-bottom));
  }

  .chat-message-assistant .chat-bubble {
    margin-right: 10px;
  }

  .chat-message-user .chat-bubble {
    margin-left: 28px;
  }

  .chat-bubble {
    width: 100%;
    padding: 12px 14px;
    border-radius: 18px;
  }

  .chat-composer {
    padding: 8px 12px calc(12px + env(safe-area-inset-bottom));
  }

  .chat-composer-bar {
    gap: 8px;
    padding: 8px 10px;
    border-radius: 20px;
  }

  .loop-chain-task {
    grid-template-columns: minmax(0, 1fr);
  }

  .chat-files-body {
    padding: 0 12px 12px;
  }

  .loop-round-summary {
    padding: 10px 12px;
  }

  .loop-round-body {
    padding: 0 10px 12px;
  }

  .loop-advanced {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(var(--tabbar-height) + 8px);
    z-index: 45;
    max-height: 70dvh;
    overflow-y: auto;
    box-shadow: 0 -18px 60px rgba(2, 6, 23, 0.6);
  }

  /*
   * Am Handy steht der Modellname in einer eigenen Zeile: nebeneinander
   * bestimmen die drei Knoepfe die Breite und der Name bleibt als
   * Buchstabenkolonne uebrig.
   */
  .auto-chain-list li {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Gross genug zum Tippen, schmal genug fuer eine Zeile zu dritt. */
  .auto-chain-actions button {
    min-height: 40px;
    padding: 0 10px;
    font-size: 0.8rem;
  }

  .chain-icon-button {
    width: 40px;
    min-width: 40px;
    padding: 0;
    font-size: 1.05rem;
  }

  .card-actions button,
  .card-actions .button-link {
    flex: 1 1 auto;
    min-height: 44px;
  }

  .panel-head {
    gap: 8px;
  }

  .segmented {
    width: 100%;
  }

  .segment {
    flex: 1 1 0;
    min-height: 40px;
    padding: 0 10px;
  }

  .chat-root-compact .chat-panel {
    max-height: calc(100dvh - 160px - var(--tabbar-height));
  }

  .loop-final-actions button,
  .loop-clarify-actions button {
    flex: 1 1 100%;
    min-height: 44px;
    /* Lange Beschriftungen duerfen umbrechen statt aus der Karte zu laufen. */
    white-space: normal;
  }

  .loop-status-more {
    margin-left: 0;
  }

  /*
   * Die Kennzahlen-Zeile scrollt am Handy waagerecht - ein absolut
   * positioniertes Blatt landete darin ausserhalb des Schirms. Deshalb
   * erscheinen die Details wie die Einstellungen als Blatt ueber der Leiste.
   */
  .loop-status-sheet {
    position: fixed;
    left: 8px;
    right: 8px;
    top: auto;
    bottom: calc(var(--tabbar-height) + 8px);
    z-index: 46;
    min-width: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@keyframes pulse {
  0% {
    transform: scale(0.92);
    box-shadow: 0 0 0 0 rgba(79, 209, 197, 0.28);
  }

  70% {
    transform: scale(1);
    box-shadow: 0 0 0 8px rgba(79, 209, 197, 0);
  }

  100% {
    transform: scale(0.92);
    box-shadow: 0 0 0 0 rgba(79, 209, 197, 0);
  }
}
