/* Claude-Terminal (features/terminal.js, Ansicht '::term[/<ordner>]').
   Eine UNTERHALTUNG, keine Konsole: links die Sitzungen, rechts Verlauf und
   Eingabe. Alles über App-Tokens (--bg/--panel/--panel2/--line/--text/--muted/
   --accent) — dadurch stimmen helles Design, dunkles Design und html.modern
   ohne eine einzige Sonderregel. Keine festen Farbwerte in dieser Datei.

   Performance: keine Schatten/Blur/Transitions auf dem Verlauf (er wird beim
   Streamen hunderte Male pro Sekunde angefasst), nur auf der Chrome drumherum. */

.tm { position: absolute; inset: 0; display: flex; flex-direction: column; min-height: 0; background: var(--bg); }

/* ---- Kopf --------------------------------------------------------------- */
.tm-head {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-bottom: 1px solid var(--line);
  background: var(--panel); flex: 0 0 auto;
}
.tm-burger { display: none; }
.tm-ico { display: flex; color: var(--accent); flex: 0 0 auto; }
.tm-ico .ico { width: 20px; height: 20px; }
.tm-title { display: flex; flex-direction: column; gap: 0; min-width: 0; }
.tm-title h1 { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.2; }
.tm-cwd {
  background: none; border: 0; padding: 0; text-align: left; cursor: pointer;
  font: 11px/1.35 ui-monospace, 'Cascadia Code', 'SF Mono', Consolas, monospace;
  color: var(--muted); max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tm-cwd:hover { color: var(--accent); }
.tm-spacer { flex: 1 1 auto; }
.tm-head .tm-new { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

/* ---- Rumpf & Sitzungs-Spalte -------------------------------------------- */
.tm-body { flex: 1 1 auto; display: flex; min-height: 0; position: relative; }

/* min-width:0 ist Pflicht: ein langer Sitzungstitel ist ein Flex-Kind mit
   min-width:auto und würde die Spalte sonst weit über ihre Breite aufziehen. */
.tm-side {
  flex: 0 0 250px; min-width: 0; display: flex; flex-direction: column; min-height: 0;
  border-right: 1px solid var(--line); background: var(--panel);
}
.tm-side-h {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 8px 9px 14px; font-size: 11px; letter-spacing: .05em;
  text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--line);
}
.tm-side-h > span { flex: 1 1 auto; }
.tm-side-x { display: none; }
.tm-sessions { flex: 1 1 auto; min-width: 0; overflow-y: auto; padding: 6px; }
.tm-side-empty { margin: 12px 14px; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.tm-scrim { display: none; }

.tm-sess {
  position: relative; padding: 8px 10px; border-radius: var(--radius, 8px);
  cursor: pointer; border: 1px solid transparent;
}
.tm-sess:hover { background: var(--panel2); }
.tm-sess.active { background: var(--accent-dim); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.tm-sess-title {
  font-size: 13px; line-height: 1.35; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tm-sess-meta {
  display: flex; align-items: center; gap: 5px; flex-wrap: wrap;
  font-size: 11px; color: var(--muted); margin-top: 3px;
}
.tm-sess-dot { opacity: .5; }
/* Kontextgroesse der Sitzung — dieselbe Zahl, die unter jedem Zug steht. */
.tm-sess-ctx { font-variant-numeric: tabular-nums; }
.tm-sess-ctx.heavy { color: var(--warn, #f5a524); }
/* Marke für Sitzungen, die in der Server-Shell entstanden sind — sie stehen
   gleichberechtigt in der Liste, man soll ihre Herkunft aber sehen. */
.tm-sess-src {
  padding: 0 5px; border-radius: 4px; font-size: 10px; line-height: 15px;
  background: var(--panel2); border: 1px solid var(--line); color: var(--muted);
}
.tm-sess.active .tm-sess-src { background: var(--panel); }
/* „läuft" — die Sitzung arbeitet gerade, auch wenn niemand zusieht. */
.tm-sess-run {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 0 6px 0 5px; border-radius: 4px; font-size: 10px; line-height: 15px;
  background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent);
}
.tm-sess-run::before {
  content: ''; width: 5px; height: 5px; border-radius: 50%;
  background: currentColor; animation: tm-pulse 1.4s ease-in-out infinite;
}
@keyframes tm-pulse { 0%, 100% { opacity: 1 } 50% { opacity: .25 } }
@media (prefers-reduced-motion: reduce) { .tm-sess-run::before { animation: none } }
.tm-sess-act { position: absolute; top: 5px; right: 5px; display: none; gap: 2px; }
.tm-sess:hover .tm-sess-act, .tm-sess.active .tm-sess-act { display: flex; }
/* Die Knöpfe liegen ÜBER dem Titel — er muss ihnen ausweichen. */
.tm-sess:hover .tm-sess-title, .tm-sess.active .tm-sess-title { padding-right: 44px; }
.tm-sess-act .icon-btn { padding: 3px; }
.tm-sess-act .ico { width: 14px; height: 14px; }

/* ---- Verlauf ------------------------------------------------------------ */
.tm-main { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
/* Eigener Rahmen um den Verlauf: die Springmarke hängt an SEINER Unterkante.
   Läge sie im .tm-main, müsste ihr Abstand die Höhe der Eingabe raten — und
   die wächst mit dem Prompt. */
.tm-chatwrap { flex: 1 1 auto; position: relative; display: flex; min-height: 0; }
.tm-chat {
  flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain;
  padding: 18px clamp(14px, 5vw, 40px) 8px;
  display: flex; flex-direction: column; gap: 4px;
  font-size: 14px; line-height: 1.6;
}

/* Leerer Zustand / Ladehinweis */
.tm-hint {
  margin: auto; padding: 24px; max-width: 420px; text-align: center; color: var(--muted);
}
.tm-hint-ico { display: block; color: var(--accent); margin-bottom: 10px; }
.tm-hint-ico .ico { width: 30px; height: 30px; }
.tm-hint strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 5px; }
.tm-hint p { margin: 0; font-size: 13px; line-height: 1.6; word-break: break-word; }

.tm-more {
  align-self: center; margin-bottom: 10px; padding: 5px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  font-size: 12px; cursor: pointer;
}
.tm-more:hover { color: var(--text); border-color: var(--muted); }

/* Eigener Prompt: Blase rechts — man findet im langen Verlauf sofort wieder,
   wo ein Zug anfing. */
.tm-msg { max-width: 100%; }
.tm-me { align-self: flex-end; max-width: min(680px, 88%); margin: 14px 0 6px; text-align: right; }
.tm-bubble {
  display: inline-block; text-align: left; padding: 9px 13px;
  border-radius: 16px 16px 4px 16px;
  background: var(--accent); color: #fff;
  white-space: pre-wrap; word-break: break-word;
}
.tm-me-files {
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 10px;
  margin-top: 5px; font-size: 11.5px; color: var(--muted);
}
.tm-me-files .ico { width: 12px; height: 12px; vertical-align: -2px; margin-right: 3px; }
.tm-me-time { font-size: 10.5px; color: var(--muted); margin-top: 3px; }

/* Claudes Antwort: volle Breite, keine Blase — das ist der Lesetext. */
.tm-ai { align-self: stretch; margin: 2px 0 16px; min-width: 0; }
.tm-prose { color: var(--text); word-break: break-word; white-space: pre-wrap; }
/* Ausgezeichnetes Markdown schaltet pre-wrap ab (sonst doppelte Leerzeilen). */
.tm-text { white-space: pre-wrap; }
.tm-md { white-space: normal; }
.tm-md > :first-child { margin-top: 0; }
.tm-md > :last-child { margin-bottom: 0; }
.tm-md p { margin: 0 0 .7em; }
.tm-md h1, .tm-md h2, .tm-md h3, .tm-md h4 { margin: 1.1em 0 .45em; line-height: 1.3; font-weight: 600; }
.tm-md h1 { font-size: 1.3em; } .tm-md h2 { font-size: 1.18em; }
.tm-md h3 { font-size: 1.06em; } .tm-md h4 { font-size: 1em; }
.tm-md ul, .tm-md ol { margin: 0 0 .7em; padding-left: 1.4em; }
.tm-md li { margin: .15em 0; }
.tm-md blockquote {
  margin: 0 0 .7em; padding: 2px 0 2px 12px;
  border-left: 3px solid var(--line); color: var(--muted);
}
.tm-md code {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 5px;
  padding: 1px 5px; font: 12.5px/1.5 ui-monospace, 'Cascadia Code', 'SF Mono', Consolas, monospace;
}
.tm-md pre {
  margin: 0 0 .7em; padding: 10px 12px; border-radius: 10px; overflow-x: auto;
  background: var(--panel2); border: 1px solid var(--line);
}
.tm-md pre code { background: none; border: 0; padding: 0; }
.tm-md hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.tm-md a { color: var(--accent); }
.tm-md table { border-collapse: collapse; margin: 0 0 .7em; }
.tm-md th, .tm-md td { border: 1px solid var(--line); padding: 4px 8px; }

.tm-think {
  color: var(--muted); font-size: 12.5px; font-style: italic;
  margin: 2px 0 8px; white-space: pre-wrap;
}

/* ---- Arbeitsschritte (das ehemals „Technische") ------------------------- */
.tm-steps { margin: 0 0 10px; }
.tm-steps-h {
  display: flex; align-items: center; gap: 7px; cursor: pointer; list-style: none;
  padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); color: var(--muted); font-size: 12px;
  width: fit-content; max-width: 100%;
}
.tm-steps-h::-webkit-details-marker { display: none; }
.tm-steps-h:hover { border-color: var(--muted); color: var(--text); }
.tm-steps-caret { display: inline-flex; flex: 0 0 auto; }
.tm-steps-caret .ico { width: 13px; height: 13px; }
.tm-steps[open] .tm-steps-caret { transform: rotate(90deg); }
.tm-steps-n { flex: 0 0 auto; font-weight: 500; }
.tm-steps-last { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .8; }
.tm-steps[open] .tm-steps-last { display: none; }
.tm-steps.has-err .tm-steps-h { border-color: color-mix(in srgb, var(--err, #e5484d) 45%, var(--line)); }

.tm-steps-list {
  margin: 6px 0 0; padding: 4px 0 4px 12px;
  border-left: 2px solid var(--line);
}
.tm-step {
  display: flex; align-items: center; gap: 7px; padding: 3px 6px; border-radius: 7px;
  font-size: 12.5px; color: var(--muted); cursor: pointer;
}
.tm-step:hover { background: var(--panel); }
.tm-step-ico { display: inline-flex; flex: 0 0 auto; opacity: .85; }
.tm-step-ico .ico { width: 14px; height: 14px; }
.tm-step-l { flex: 0 0 auto; color: var(--text); }
.tm-step-b {
  flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: ui-monospace, 'Cascadia Code', 'SF Mono', Consolas, monospace; font-size: 11.5px;
}
.tm-step-s { flex: 0 0 auto; font-size: 11px; opacity: .7; }
.tm-step.err .tm-step-s, .tm-step.err .tm-step-l { color: var(--err, #e5484d); }
.tm-step.open { background: var(--panel); }
.tm-step-d {
  margin: 0 0 6px; padding: 8px 10px; border-radius: 8px; max-height: 320px; overflow: auto;
  background: var(--panel2); border: 1px solid var(--line); color: var(--muted);
  font: 11.5px/1.5 ui-monospace, 'Cascadia Code', 'SF Mono', Consolas, monospace;
  white-space: pre-wrap; word-break: break-word;
}

/* Hinweiszeilen (Fehler, Warnungen, Systemmeldungen, Abschluss) */
.tm-note {
  padding: 5px 10px; border-radius: 8px; font-size: 12px; margin: 4px 0;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  white-space: pre-wrap; word-break: break-word;
}
.tm-note-ok { border: 0; background: none; padding: 2px 0; font-size: 11.5px; }
/* Kopfzeilen des Zugs (Arbeitsverzeichnis, Modell, Anhänge): da, aber leise. */
.tm-note-sys { border: 0; background: none; padding: 1px 0; font-size: 11.5px; opacity: .75; }
/* „Was gerade passiert" — eine Zeile, die sich selbst ersetzt und am Ende geht. */
.tm-act {
  display: flex; align-items: center; gap: 7px;
  margin: 4px 0 2px; font-size: 12px; color: var(--accent);
  white-space: pre-wrap; word-break: break-word;
}
.tm-act::before {
  content: ''; flex: 0 0 auto; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; animation: tm-pulse 1.4s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) { .tm-act::before { animation: none } }
.tm-note-load { border: 0; background: none; padding: 2px 0; opacity: .7; }
.tm-note-warn { border-color: color-mix(in srgb, var(--warn, #f5a524) 40%, var(--line)); }
.tm-note-err {
  border-color: color-mix(in srgb, var(--err, #e5484d) 45%, var(--line));
  color: var(--err, #e5484d);
}
.tm-foot:empty { display: none; }

/* Was ein Zug verbraucht hat. Steht unter der Antwort, nicht als Warnung:
   die Zahl soll begleiten, nicht mahnen — mahnen tut erst .tm-ctxwarn. */
.tm-usage {
  margin-top: 6px; font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.tm-usage.heavy { color: var(--warn, #f5a524); }

/* Der Kontext einer Sitzung waechst mit jedem Zug, und jeder weitere Zug
   bezahlt ihn komplett mit. Im Terminal macht man beilaeufig eine neue
   Sitzung auf; hier ist die Ordner-Sitzung der Standardweg, deshalb der
   ausdrueckliche Hinweis samt Ausweg. */
.tm-ctxwarn {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 8px; padding: 7px 10px; border-radius: 8px;
  font-size: 12px; line-height: 1.4;
  color: var(--muted); background: var(--panel2);
  border: 1px solid var(--line);
}
.tm-ctxwarn.heavy {
  color: var(--warn, #f5a524);
  border-color: color-mix(in srgb, var(--warn, #f5a524) 45%, var(--line));
  background: color-mix(in srgb, var(--warn, #f5a524) 8%, var(--panel2));
}
/* `display:flex` schlaegt die Standardregel des Browsers fuer [hidden] —
   ohne diese Zeile bliebe ein leerer Streifen stehen, wenn die Leiste geht. */
.tm-ctxwarn[hidden] { display: none; }
.tm-ctxwarn-t { flex: 1 1 220px; }
.tm-ctxwarn-new { flex: 0 0 auto; padding: 3px 10px; font-size: 12px; }

/* Springmarke „zum Ende" — nur sichtbar, wenn man weiter oben liest. */
.tm-jump {
  position: absolute; right: 18px; bottom: 14px; z-index: 3;
  width: 34px; height: 34px; border-radius: 50%; display: none;
  align-items: center; justify-content: center; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  box-shadow: var(--shadow, 0 4px 14px rgba(0, 0, 0, .3));
}
.tm-jump.on { display: flex; }
.tm-jump .ico { width: 16px; height: 16px; }

/* ---- Eingabe ------------------------------------------------------------ */
.tm-compose {
  flex: 0 0 auto; background: var(--panel); border-top: 1px solid var(--line);
  padding: 10px clamp(12px, 5vw, 40px) 12px; display: flex; flex-direction: column; gap: 8px;
}
.tm-compose.drop { outline: 2px dashed var(--accent); outline-offset: -4px; }
.tm-atts { display: flex; flex-wrap: wrap; gap: 6px; }
.tm-atts:empty { display: none; }
.tm-att {
  display: inline-flex; align-items: center; gap: 5px; max-width: 320px;
  padding: 3px 4px 3px 8px; border-radius: 999px; background: var(--panel2);
  border: 1px solid var(--line); font-size: 11.5px; color: var(--muted);
}
.tm-att > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tm-att .ico { width: 12px; height: 12px; flex: 0 0 auto; }
.tm-att-x {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  display: inline-flex; padding: 2px; border-radius: 50%;
}
.tm-att-x:hover { color: var(--err, #e5484d); background: var(--panel); }

.tm-inputrow {
  display: flex; gap: 8px; align-items: flex-end;
  border: 1px solid var(--line); border-radius: 18px; background: var(--bg);
  padding: 6px 6px 6px 14px;
}
.tm-inputrow:focus-within { border-color: var(--accent); }
.tm-prompt {
  flex: 1 1 auto; resize: none; border: 0; background: none; color: var(--text);
  padding: 7px 0; min-height: 24px; max-height: 40vh; overflow-y: auto;
  font: 14px/1.55 inherit; font-family: inherit;
}
.tm-prompt:focus { outline: none; }
.tm-prompt::placeholder { color: var(--muted); }
.tm-send, .tm-stop {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; border: 0;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  background: var(--accent); color: #fff;
}
.tm-send:hover, .tm-stop:hover { filter: brightness(1.08); }
.tm-send .ico, .tm-stop .ico { width: 16px; height: 16px; }
.tm-stop { background: var(--err, #e5484d); }
.tm-send.hidden, .tm-stop.hidden { display: none; }

.tm-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.tm-chip {
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--muted); font-size: 12px;
}
.tm-chip:hover { color: var(--text); border-color: var(--muted); }
.tm-chip .ico { width: 13px; height: 13px; }
.tm-readonly .tm-cfg { border-color: color-mix(in srgb, var(--warn, #f5a524) 50%, var(--line)); }
.tm-status { font-variant-numeric: tabular-nums; text-align: right; }
.tm-status.on { color: var(--accent); }
.tm-status.err { color: var(--err, #e5484d); }

/* ---- Handy -------------------------------------------------------------- */
@media (max-width: 860px) {
  .tm-burger { display: inline-flex; }
  .tm-head { padding: 8px 10px; gap: 8px; }
  .tm-head .tm-new span { display: none; }
  .tm-head .tm-new { padding: 7px 10px; }
  .tm-cwd { max-width: 52vw; }

  /* Die Sitzungen liegen ÜBER der Unterhaltung statt ein Drittel der Höhe zu
     fressen — auf dem Handy zählt jede Zeile Verlauf. */
  .tm-side {
    position: absolute; inset: 0 auto 0 0; z-index: 5;
    width: min(320px, 84vw); flex: 0 0 auto;
    transform: translateX(-101%); transition: transform .18s ease;
    box-shadow: var(--shadow, 0 10px 30px rgba(0, 0, 0, .4));
  }
  .tm-side-open .tm-side { transform: none; }
  .tm-side-x { display: inline-flex; }
  .tm-side-open .tm-scrim {
    display: block; position: absolute; inset: 0; z-index: 4;
    background: rgba(0, 0, 0, .45);
  }
  .tm-sess-act { display: flex; }              /* kein Hover auf Touch */
  .tm-sess .tm-sess-title { padding-right: 44px; }

  .tm-chat { padding: 12px 12px 6px; font-size: 14.5px; }
  .tm-me { max-width: 92%; }
  .tm-compose { padding: 8px 10px 10px; }
  .tm-jump { right: 12px; }
}

/* Wer „weniger Bewegung" eingestellt hat, bekommt die Schublade ohne Animation. */
@media (prefers-reduced-motion: reduce) {
  .tm-side { transition: none; }
}
