/* Komponenten des EST-Design-Systems (Makros unter app/templates/components/). Besitzer: S4.
   Alle Werte aus tokens.css. Klassen-Konvention: docs/ui-contract.md §4. */

/* --- Buttons (Primär Navy/weiß, Ghost weiß mit Rand, Radius 6 px, min. 44 px auf allen Geräten) ------------ */
.est-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch-min);
  padding: 0 var(--space-4);
  border: var(--hairline) solid var(--field);
  border-radius: var(--radius-btn);
  background: var(--white);
  color: var(--navy);
  font-family: var(--sans);
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  line-height: var(--lh-snug);
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.est-btn:hover { border-color: var(--navy); color: var(--navy); background: var(--navy-tint); }
.est-btn:active { box-shadow: none; }
.est-btn--primary { background: var(--navy); border-color: var(--navy); color: var(--white); }
.est-btn--primary:hover { background: var(--navy-3); border-color: var(--navy-3); color: var(--white); }
.est-btn--ghost { background: var(--white); border-color: var(--field); color: var(--navy); }
.est-btn--danger { background: var(--white); border-color: var(--bad-line); color: var(--bad-text); }
.est-btn--danger:hover { background: var(--bad); border-color: var(--bad); color: var(--white); }
.est-btn--primary.est-btn--danger { background: var(--bad); border-color: var(--bad); color: var(--white); }
.est-btn--primary.est-btn--danger:hover { background: var(--bad-text); border-color: var(--bad-text); }
.est-btn--on-navy { background: transparent; border-color: var(--navy-line); color: var(--on-navy); }
.est-btn--on-navy:hover { background: var(--navy-hover); border-color: var(--on-navy-2); color: var(--white); }
/* Klein heißt: kleinere Schrift und weniger Innenabstand – die Mindesthöhe bleibt 44 px (SPEC §10). */
.est-btn--sm { min-height: var(--touch-min); padding: 0 var(--space-3); font-size: var(--fs-sm); }
.est-btn:disabled,
.est-btn[aria-disabled="true"] { opacity: var(--opacity-disabled); cursor: not-allowed; pointer-events: none; }
.est-btn.is-loading { pointer-events: none; }
.est-btn.is-loading > * { opacity: 0; }
.est-btn.is-loading::after {
  content: "";
  position: absolute;
  width: var(--space-4);
  height: var(--space-4);
  border: var(--border-strong) solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: est-spin var(--dur-spin) linear infinite;
}

/* --- Karte ------------------------------------------------------------------------------ */
.est-card {
  min-width: 0;
  padding: var(--space-5);
  background: var(--white);
  border: var(--hairline) solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}
.est-card__title {
  margin-bottom: var(--space-4);
  font-family: var(--serif);
  font-weight: var(--fw-regular);
  font-size: var(--fs-2xl);
  line-height: var(--lh-tight);
  color: var(--navy);
}
.est-card__body > * + * { margin-top: var(--space-4); }

/* --- Kennzahlen-Kachel -------------------------------------------------------------------- */
.est-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
  padding: var(--space-4) var(--space-4) var(--space-4) var(--space-5);
  overflow: hidden;
  background: var(--white);
  border: var(--hairline) solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  color: var(--ink);
  text-decoration: none;
  transition: border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.est-tile::before {
  content: "";
  position: absolute;
  inset: var(--space-4) auto var(--space-4) 0;
  width: var(--space-1);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--line);
}
.est-tile--ok::before { background: var(--ok); }
.est-tile--warn::before { background: var(--orange); }
.est-tile--bad::before { background: var(--bad); }
.est-tile--info::before { background: var(--info); }
.est-tile--muted::before { background: var(--field); }
a.est-tile:hover { border-color: var(--navy); color: var(--ink); transform: translateY(calc(var(--space-0) * -1)); }
.est-tile__value {
  font-family: var(--serif);
  font-size: var(--tile-value-size);
  line-height: 1;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
}
.est-tile__label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-snug);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* --- Projektkarte ------------------------------------------------------------------------- */
.est-project-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
  padding: var(--space-3) var(--space-4) var(--space-4);
  background: var(--white);
  border: var(--hairline) solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-soft);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
/* Freistehend im Raster (Übersicht) trägt die Karte den Karten-Schatten; im Board bleibt er flach. */
.est-grid > .est-project-card { box-shadow: var(--shadow-card); }
.est-project-card:hover { border-color: var(--field); box-shadow: var(--shadow-raised); }
.est-project-card:focus-within { border-color: var(--navy); }
/* Verworfen: gedämpfte Fläche und gestrichelter Rand statt Deckkraft – der Text behält seinen Kontrast. */
.est-project-card[data-status="verworfen"] { background: var(--bg); border-style: dashed; border-color: var(--field); box-shadow: none; }
.est-project-card__head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--space-5);
  font-size: var(--fs-xs);
  color: var(--muted);
}
.est-project-card__area { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.est-project-card__handle {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-min);
  height: var(--touch-min);
  margin: calc(var(--space-2) * -1) calc(var(--space-3) * -1) calc(var(--space-2) * -1) 0;
  border: 0;
  border-radius: var(--radius-btn);
  background: none;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
}
.est-project-card__handle:hover,
.est-project-card__handle[aria-pressed="true"] { color: var(--navy); background: var(--navy-tint); }
.est-project-card__link { color: var(--navy); text-decoration: none; border-radius: var(--radius-sm); }
.est-project-card__link::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius-card); }
.est-project-card__link:focus-visible { outline: none; }
.est-project-card__link:focus-visible::after { outline: var(--focus-ring); outline-offset: var(--focus-offset); }
.est-project-card__name {
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-snug);
  color: var(--navy);
  overflow-wrap: anywhere;
}
.est-project-card__step {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  color: var(--muted);
}
.est-project-card__step:empty { display: none; }
.est-project-card__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-1);
}
.est-project-card__time { font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; }

/* --- Fortschrittsbalken (Navy-Füllung, Spitze mit Orange-Akzent) ----------------------------- */
.est-progress { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.est-progress__track {
  flex: 1;
  min-width: 0;
  height: var(--progress-md);
  overflow: hidden;
  border-radius: var(--radius-chip);
  background: var(--track);
}
.est-progress__fill {
  position: relative;
  height: 100%;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  border-radius: var(--radius-chip);
  background: var(--navy);
  transition: width var(--dur-slow) var(--ease);
}
.est-progress__fill::after {
  content: "";
  position: absolute;
  inset: 0 0 0 auto;
  width: var(--progress-tip);
  background: var(--orange);
}
.est-progress__value {
  flex-shrink: 0;
  min-width: var(--progress-value);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--navy);
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
/* 100 %: fertig – reine Navy-Füllung ohne Spitze. 0 %: dezenter Startpunkt statt eines leeren Balkens. */
.est-progress[aria-valuenow="100"] .est-progress__fill::after,
.est-progress[aria-valuenow="0"] .est-progress__fill::after { display: none; }
.est-progress[aria-valuenow="0"] .est-progress__fill { min-width: var(--progress-md); background: var(--field); }
.est-progress--sm[aria-valuenow="0"] .est-progress__fill { min-width: var(--progress-sm); }
.est-progress--lg[aria-valuenow="0"] .est-progress__fill { min-width: var(--progress-lg); }
.est-progress--sm .est-progress__track { height: var(--progress-sm); }
.est-progress--sm .est-progress__value { font-size: var(--fs-xs); min-width: calc(var(--progress-value) - var(--space-2)); }
.est-progress--lg .est-progress__track { height: var(--progress-lg); }
.est-progress--lg .est-progress__fill::after { width: calc(var(--progress-tip) * 1.5); }
.est-progress--lg .est-progress__value { font-family: var(--serif); font-weight: var(--fw-regular); font-size: var(--fs-2xl); min-width: calc(var(--progress-value) * 1.5); }

/* --- Status-Chip ---------------------------------------------------------------------------- */
.est-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 100%;
  min-height: var(--space-5);
  padding: var(--space-0) var(--space-3) var(--space-0) var(--space-2);
  border: var(--hairline) solid var(--line);
  border-radius: var(--radius-chip);
  background: var(--muted-bg);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-snug);
  white-space: nowrap;
}
.est-chip::before {
  content: "";
  width: var(--dot-sm);
  height: var(--dot-sm);
  flex-shrink: 0;
  border-radius: 50%;
  background: currentColor;
}
.est-chip--ok { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok-text); }
.est-chip--warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-text); }
.est-chip--warn::before { background: var(--orange); }
.est-chip--bad { background: var(--bad-bg); border-color: var(--bad-line); color: var(--bad-text); }
.est-chip--info { background: var(--info-bg); border-color: var(--info-line); color: var(--info-text); }
.est-chip--muted { background: var(--muted-bg); border-color: var(--line); color: var(--muted); }
.est-chip--phase { padding-left: var(--space-3); background: var(--white); border-color: var(--field); color: var(--navy); }
.est-chip--phase::before { display: none; }
[data-status="laeuft"] .est-chip--ok[data-status-chip]::before,
.est-chip--ok[data-run-status-chip][data-live="1"]::before { animation: est-pulse var(--dur-pulse) ease-in-out infinite; }

.est-area-dot {
  display: inline-block;
  width: var(--dot);
  height: var(--dot);
  flex-shrink: 0;
  border-radius: 50%;
  background-color: var(--muted);
  box-shadow: 0 0 0 var(--border-strong) var(--white), 0 0 0 calc(var(--border-strong) + var(--hairline)) var(--line);
}

/* --- Tabs ----------------------------------------------------------------------------------- */
.est-tabs {
  display: flex;
  gap: var(--space-1);
  margin-bottom: var(--space-5);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  border-bottom: var(--hairline) solid var(--line);
}
.est-tabs::-webkit-scrollbar { display: none; }
.est-tabs__tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
  min-height: var(--touch-min);
  padding: 0 var(--space-4);
  border: 0;
  border-radius: var(--radius-btn) var(--radius-btn) 0 0;
  background: none;
  color: var(--muted);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.est-tabs__tab::after {
  content: "";
  position: absolute;
  inset: auto var(--space-3) 0 var(--space-3);
  height: var(--border-strong);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: var(--orange);
  transform: scaleX(0);
  transition: transform var(--dur-mid) var(--ease);
}
.est-tabs__tab:hover { color: var(--navy); background: var(--navy-tint); }
.est-tabs__tab.is-active { color: var(--navy); font-weight: var(--fw-semibold); }
.est-tabs__tab.is-active::after { transform: none; }
.est-tabs__tab:focus-visible { outline-offset: calc(var(--focus-offset) * -1); }
.est-tab-panel { animation: est-fade var(--dur-mid) var(--ease); }
.est-tab-panel:focus-visible { outline-offset: var(--space-1); }

/* --- Modal und Bestätigungsdialog -------------------------------------------------------------- */
.est-modal,
.est-sheet {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--space-4) + var(--safe-top)) calc(var(--space-4) + var(--safe-right))
    calc(var(--space-4) + var(--safe-bottom)) calc(var(--space-4) + var(--safe-left));
}
.est-modal__backdrop,
.est-sheet__backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
  animation: est-fade var(--dur-mid) var(--ease);
}
.est-modal__dialog,
.est-sheet__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--modal-md);
  max-height: 100%;
  background: var(--white);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-overlay);
  animation: est-rise var(--dur-slow) var(--ease);
}
#est-confirm { z-index: var(--z-confirm); }
.est-modal--sm .est-modal__dialog { max-width: var(--modal-sm); }
.est-modal--lg .est-modal__dialog { max-width: var(--modal-lg); }
.est-modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) 0;
}
.est-modal__title,
.est-sheet__title {
  font-family: var(--serif);
  font-weight: var(--fw-regular);
  font-size: var(--fs-2xl);
  line-height: var(--lh-tight);
  color: var(--navy);
  overflow-wrap: anywhere;
}
.est-modal__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-min);
  height: var(--touch-min);
  flex-shrink: 0;
  margin: calc(var(--space-3) * -1) calc(var(--space-3) * -1) 0 0;
  border: 0;
  border-radius: var(--radius-btn);
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.est-modal__close:hover { background: var(--navy-tint); color: var(--navy); }
.est-modal__body { padding: var(--space-4) var(--space-5) var(--space-5); overflow-y: auto; overscroll-behavior: contain; }
.est-modal__body > * + * { margin-top: var(--space-4); }
.est-modal__text { color: var(--ink); white-space: pre-line; overflow-wrap: anywhere; }
.est-modal__footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-5);
}

/* --- Bottom-Sheet (Handy: von unten; ab Tablet: zentrierter Dialog) ------------------------------- */
.est-sheet__panel { max-width: var(--modal-sm); padding: var(--space-5); gap: var(--space-4); }
.est-sheet__header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.est-sheet__grip { display: none; }
.est-sheet__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: calc(var(--space-1) * -1);
  padding: var(--space-1);  /* Platz für den Fokusrahmen trotz overflow */
  overflow-y: auto;
  overscroll-behavior: contain;
}
.est-sheet__body .est-btn { width: 100%; justify-content: flex-start; }

/* --- Toast --------------------------------------------------------------------------------------- */
.est-toasts {
  position: fixed;
  right: calc(var(--space-5) + var(--safe-right));
  bottom: calc(var(--space-5) + var(--safe-bottom));
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(var(--toast-width), calc(100vw - var(--space-6)));
  pointer-events: none;
}
/* Bei offenem Dialog oder Sheet nach oben ausweichen: Toasts liegen nie über dessen Aktionsknöpfen. */
body.has-overlay .est-toasts { top: calc(var(--space-4) + var(--safe-top)); bottom: auto; }
.est-toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-2) var(--space-3) var(--space-4);
  background: var(--white);
  border: var(--hairline) solid var(--line);
  border-left: var(--space-1) solid var(--info);
  border-radius: var(--radius-btn);
  box-shadow: var(--shadow-raised);
  color: var(--ink);
  font-size: var(--fs-sm);
  pointer-events: auto;
  animation: est-rise var(--dur-slow) var(--ease);
  transition: opacity var(--dur-mid) var(--ease), transform var(--dur-mid) var(--ease);
}
.est-toast.is-leaving { opacity: 0; transform: translateY(var(--space-2)); }
.est-toast__icon { margin-top: var(--space-0); color: var(--info); }
.est-toast__text { flex: 1; min-width: 0; padding: var(--space-0) 0; overflow-wrap: anywhere; }
.est-toast__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-min);
  height: var(--touch-min);
  flex-shrink: 0;
  margin: calc(var(--space-3) * -1) 0;
  border: 0;
  border-radius: var(--radius-btn);
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.est-toast__close:hover { color: var(--navy); }
.est-toast--ok { border-left-color: var(--ok); }
.est-toast--ok .est-toast__icon { color: var(--ok); }
.est-toast--warn { border-left-color: var(--orange); }
.est-toast--warn .est-toast__icon { color: var(--orange-text); }
.est-toast--bad { border-left-color: var(--bad); }
.est-toast--bad .est-toast__icon { color: var(--bad); }

/* --- Leerzustand ------------------------------------------------------------------------------------ */
.est-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-7) var(--space-5);
  background: var(--white);
  border: var(--hairline) dashed var(--field);
  border-radius: var(--radius-card);
  text-align: center;
}
.est-empty__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--empty-icon);
  height: var(--empty-icon);
  border-radius: 50%;
  background: var(--navy-tint);
  color: var(--navy);
}
.est-empty__title {
  font-family: var(--serif);
  font-weight: var(--fw-regular);
  font-size: var(--fs-2xl);
  line-height: var(--lh-tight);
  color: var(--navy);
}
.est-empty__text { max-width: var(--measure-short); color: var(--muted); }
.est-empty .est-btn { margin-top: var(--space-2); }

/* --- Hinweis ------------------------------------------------------------------------------------------ */
.est-alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: var(--hairline) solid var(--info-line);
  border-radius: var(--radius-btn);
  background: var(--info-bg);
  color: var(--info-text);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}
.est-alert .est-icon { margin-top: var(--space-0); }
.est-alert--ok { border-color: var(--ok-line); background: var(--ok-bg); color: var(--ok-text); }
.est-alert--warn { border-color: var(--warn-line); background: var(--warn-bg); color: var(--warn-text); }
.est-alert--bad { border-color: var(--bad-line); background: var(--bad-bg); color: var(--bad-text); }
.est-alert--info { border-color: var(--info-line); background: var(--info-bg); color: var(--info-text); }

/* --- Limit-Status ---------------------------------------------------------------------------------------- */
.est-limit {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 100%;
  min-height: var(--space-6);
  padding: 0 var(--space-3);
  border: var(--hairline) solid var(--line);
  border-radius: var(--radius-chip);
  background: var(--white);
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  white-space: nowrap;
}
.est-limit::before {
  content: "";
  width: var(--dot-sm);
  height: var(--dot-sm);
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--ok);
}
.est-limit > [data-limit-text] { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.est-limit.is-active,
.est-limit[data-active="1"] { border-color: var(--warn-line); background: var(--warn-bg); color: var(--warn-text); }
.est-limit.is-active::before,
.est-limit[data-active="1"]::before { background: var(--orange); animation: est-pulse var(--dur-pulse) ease-in-out infinite; }

/* --- Markdown-Ansicht -------------------------------------------------------------------------------------- */
.est-markdown { max-width: var(--measure); color: var(--ink); overflow-wrap: anywhere; }
.est-markdown > * + * { margin-top: var(--space-4); }
.est-markdown h1,
.est-markdown h2,
.est-markdown h3 { font-family: var(--serif); font-weight: var(--fw-regular); line-height: var(--lh-tight); color: var(--navy); }
.est-markdown h1 { font-size: var(--fs-3xl); }
.est-markdown h2 { font-size: var(--fs-2xl); margin-top: var(--space-6); padding-bottom: var(--space-2); border-bottom: var(--hairline) solid var(--line); }
.est-markdown h3 { font-size: var(--fs-xl); margin-top: var(--space-5); }
.est-markdown h4,
.est-markdown h5,
.est-markdown h6 { font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--navy); margin-top: var(--space-5); }
.est-markdown > :first-child { margin-top: 0; }
.est-markdown ul,
.est-markdown ol { padding-left: var(--space-5); }
.est-markdown li + li { margin-top: var(--space-1); }
.est-markdown li > ul,
.est-markdown li > ol { margin-top: var(--space-1); }
.est-markdown a { color: var(--navy); text-decoration: underline; }
.est-markdown strong { font-weight: var(--fw-semibold); }
.est-markdown code {
  padding: var(--space-0) var(--space-1);
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  font-family: var(--mono);
  font-size: var(--fs-code);
}
.est-markdown pre {
  padding: var(--space-4);
  overflow-x: auto;
  border: var(--hairline) solid var(--line);
  border-radius: var(--radius-btn);
  background: var(--code-bg);
  font-size: var(--fs-sm);
  line-height: var(--lh-body);
}
.est-markdown pre code { padding: 0; background: none; font-size: inherit; }
.est-markdown blockquote { margin-left: 0; margin-right: 0; padding: var(--space-1) var(--space-4); border-left: var(--space-1) solid var(--field); color: var(--muted); }
.est-markdown hr { height: var(--hairline); border: 0; background: var(--line); margin: var(--space-5) 0; }
.est-markdown table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: var(--fs-sm); }
.est-markdown th,
.est-markdown td { padding: var(--space-2) var(--space-3); border: var(--hairline) solid var(--line); text-align: left; vertical-align: top; }
.est-markdown th { background: var(--bg); color: var(--navy); font-weight: var(--fw-semibold); }
.est-markdown img { height: auto; border-radius: var(--radius-btn); }
.est-markdown:empty::before { content: attr(data-empty-text); color: var(--muted); }

/* --- Log ---------------------------------------------------------------------------------------------------- */
.est-log {
  max-height: var(--log-height);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-2) 0;
  background: var(--white);
  border: var(--hairline) solid var(--line);
  border-radius: var(--radius-card);
  font-size: var(--fs-sm);
  line-height: var(--lh-body);
}
.est-log-wrap { position: relative; min-width: 0; }
.est-log-jump {
  position: absolute;
  bottom: var(--space-3);
  left: 50%;
  z-index: 1;
  transform: translateX(-50%);
  box-shadow: var(--shadow-raised);
}
.est-log-jump .est-icon { transform: rotate(90deg); }
.est-log:empty::before { content: attr(data-empty-text); display: block; padding: var(--space-5); color: var(--muted); text-align: center; }
.est-log__line {
  display: grid;
  grid-template-columns: var(--log-time) var(--icon-box) minmax(0, 1fr);
  align-items: start;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-left: var(--border-strong) solid transparent;
}
.est-log__line + .est-log__line { border-top: var(--hairline) solid var(--bg); }
.est-log__line.is-new { animation: est-fade var(--dur-slow) var(--ease); }
.est-log__line.is-subagent { border-left-color: var(--navy-line); background: var(--navy-tint); }
.est-log__time { padding-top: var(--space-0); font-family: var(--mono); font-size: var(--fs-xs); color: var(--muted); font-variant-numeric: tabular-nums; }
.est-log__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--icon-box);
  height: var(--icon-box);
  margin-top: calc(var(--space-1) * -1);
  border-radius: var(--radius-btn);
  background: var(--muted-bg);
  color: var(--muted);
}
.est-log__main { min-width: 0; }
.est-log__kind {
  margin-right: var(--space-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-kind);
  color: var(--muted);
}
.est-log__text { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink); }
.est-log__meta { display: block; margin-top: var(--space-1); font-size: var(--fs-xs); color: var(--muted); }
.est-log__details { display: inline; }
.est-log__details > summary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  max-width: 100%;
  min-height: var(--space-5);
  border-radius: var(--radius-sm);
  color: var(--ink);
  cursor: pointer;
  list-style: none;
}
.est-log__details > summary::-webkit-details-marker { display: none; }
/* Touch, Handy und Tablet: Der Aufklapper ist 44 px hoch; der negative Außenabstand hält die Zeilenhöhe. */
@media (any-pointer: coarse), (max-width: 1099px) {
  .est-log__details > summary {
    min-height: var(--touch-min);
    margin-block: calc((var(--space-5) - var(--touch-min)) / 2);
  }
}
.est-log__details > summary::before {
  content: "";
  width: var(--space-2);
  height: var(--space-2);
  flex-shrink: 0;
  margin: 0 var(--space-1);
  border-right: var(--border-strong) solid var(--muted);
  border-bottom: var(--border-strong) solid var(--muted);
  transform: rotate(-45deg);
  transition: transform var(--dur-fast) var(--ease);
}
.est-log__details[open] > summary::before { transform: rotate(45deg); }
.est-log__summary { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); }
.est-log__pre {
  margin-top: var(--space-2);
  padding: var(--space-3);
  max-height: var(--pre-max);
  overflow: auto;
  border: var(--hairline) solid var(--line);
  border-radius: var(--radius-btn);
  background: var(--code-bg);
  font-family: var(--mono);
  font-size: var(--fs-xs);
  line-height: var(--lh-body);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.est-log__line--text .est-log__icon { background: var(--navy-tint); color: var(--navy); }
.est-log__line--text .est-log__kind,
.est-log__line--tool_use .est-log__kind { color: var(--navy); }
.est-log__line--tool_use .est-log__icon { background: var(--navy); color: var(--white); }
.est-log__line--tool_result .est-log__icon,
.est-log__line--result .est-log__icon { background: var(--ok-bg); color: var(--ok-text); }
.est-log__line--rate_limit .est-log__icon { background: var(--warn-bg); color: var(--warn-text); }
.est-log__line--manager .est-log__icon { background: var(--info-bg); color: var(--info-text); }
.est-log__line--manager .est-log__text { color: var(--muted); }
.est-log__line--system .est-log__text { color: var(--muted); }
.est-log__line--error .est-log__icon,
.est-log__line--stderr .est-log__icon,
.est-log__line.is-error .est-log__icon { background: var(--bad-bg); color: var(--bad-text); }
.est-log__line--error .est-log__text,
.est-log__line--error .est-log__kind,
.est-log__line.is-error .est-log__kind { color: var(--bad-text); }
.est-log__line--stderr .est-log__text { font-family: var(--mono); font-size: var(--fs-xs); color: var(--muted); }
.est-log__line--result { background: var(--bg); }

/* --- Formulare ------------------------------------------------------------------------------------------------ */
.est-field { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.est-field__label { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--navy); }
.est-field__hint { font-size: var(--fs-sm); color: var(--muted); }
.est-field__error { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--bad-text); }
.est-input {
  display: block;
  width: 100%;
  min-height: var(--touch-min);
  padding: var(--space-2) var(--space-3);
  border: var(--hairline) solid var(--field);
  border-radius: var(--radius-btn);
  background: var(--white);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--fs-md);
  line-height: var(--lh-snug);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.est-input::placeholder { color: var(--muted); opacity: 1; }
.est-input:hover { border-color: var(--muted); }
.est-input:focus-visible { border-color: var(--navy); outline: var(--focus-ring); outline-offset: 0; }
.est-input:disabled,
.est-input[readonly] { background: var(--bg); color: var(--muted); }
.est-input--area { min-height: var(--textarea-min); line-height: var(--lh-body); resize: vertical; }
.est-input--area.u-mono { font-family: var(--mono); font-size: var(--fs-sm); }
.est-input--select {
  padding-right: var(--space-6);
  appearance: none;
  -webkit-appearance: none;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  background-size: var(--space-3);
  cursor: pointer;
}
.est-input--file { padding: var(--space-1); cursor: pointer; }
.est-input--file::file-selector-button {
  min-height: var(--control-sm);
  margin-right: var(--space-3);
  padding: 0 var(--space-3);
  border: var(--hairline) solid var(--field);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--navy);
  font: inherit;
  font-weight: var(--fw-medium);
  cursor: pointer;
}
.est-field.has-error .est-input,
.est-input[aria-invalid="true"] { border-color: var(--bad); }
.est-field.has-error .est-field__label { color: var(--bad-text); }

.est-check {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--touch-min);
  padding: 0 var(--space-1);
  border-radius: var(--radius-btn);
  cursor: pointer;
}
.est-check input {
  width: var(--check-size);
  height: var(--check-size);
  flex-shrink: 0;
  margin: 0;
  accent-color: var(--navy);
  cursor: pointer;
}
.est-check__label { min-width: 0; overflow-wrap: anywhere; }
.est-check-group {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile-min), 1fr));
  gap: 0 var(--space-4);
  padding: var(--space-1) var(--space-3);
  border: var(--hairline) solid var(--field);
  border-radius: var(--radius-btn);
  background: var(--white);
}
.est-field.has-error .est-check-group { border-color: var(--bad); }

/* --- Drag & Drop ------------------------------------------------------------------------------------------------- */
.is-dragging { opacity: var(--opacity-dragging); outline: var(--border-strong) dashed var(--navy-line); outline-offset: calc(var(--border-strong) * -1); box-shadow: none; }
.is-grabbed { outline: var(--focus-ring); outline-offset: var(--focus-offset); box-shadow: var(--shadow-raised); }
.est-drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: var(--z-drag);
  margin: 0;
  pointer-events: none;
  opacity: .96;
  box-shadow: var(--shadow-overlay);
  transform-origin: center;
  will-change: transform;
}
body.is-sorting { cursor: grabbing; user-select: none; -webkit-user-select: none; }
body.is-sorting * { cursor: grabbing !important; }

/* --- Handy --------------------------------------------------------------------------------------------------------- */
@media (max-width: 767px) {
  .est-card { padding: var(--space-4); }
  .est-card__title { font-size: var(--fs-xl); }
  .est-tile { padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4); }
  .est-tile__value { font-size: var(--fs-3xl); }
  .est-tile__label { font-size: var(--fs-2xs); }

  .est-tabs { margin-left: calc(var(--space-4) * -1); margin-right: calc(var(--space-4) * -1); padding: 0 var(--space-4); }
  .est-tabs__tab { padding: 0 var(--space-3); }

  .est-modal { align-items: flex-end; padding-left: var(--space-2); padding-right: var(--space-2); padding-bottom: calc(var(--space-2) + var(--safe-bottom)); }
  .est-modal__footer { flex-direction: column-reverse; }
  .est-modal__footer .est-btn { width: 100%; }

  .est-sheet { align-items: flex-end; padding: var(--safe-top) 0 0; }
  .est-sheet__panel {
    max-width: none;
    max-height: var(--sheet-height);
    padding: var(--space-2) calc(var(--space-4) + var(--safe-right)) calc(var(--space-5) + var(--safe-bottom)) calc(var(--space-4) + var(--safe-left));
    border-radius: var(--radius-card) var(--radius-card) 0 0;
    animation-name: est-sheet-up;
  }
  .est-sheet__grip {
    display: block;
    width: var(--grip);
    height: var(--grip-height);
    margin: 0 auto var(--space-2);
    border-radius: var(--radius-chip);
    background: var(--field);
  }

  /* Oben unter der Kopfzeile: unten liegen Bottom-Bar, Aktionsleiste und die Knöpfe der Dialoge. */
  .est-toasts {
    top: calc(var(--topbar-height) + var(--safe-top) + var(--space-2));
    right: calc(var(--space-3) + var(--safe-right));
    bottom: auto;
    left: calc(var(--space-3) + var(--safe-left));
    width: auto;
  }
  .est-toast.is-leaving { transform: translateY(calc(var(--space-2) * -1)); }

  .est-empty { padding: var(--space-6) var(--space-4); }
  .est-limit { font-size: var(--fs-xs); }
  .est-topbar .est-limit { padding: 0 var(--space-2); font-size: var(--fs-2xs); }

  .est-log { border-radius: var(--radius-btn); }
  .est-log__line { grid-template-columns: var(--icon-box) minmax(0, 1fr); padding: var(--space-2) var(--space-3); }
  .est-log__time { grid-column: 2; grid-row: 2; padding-top: 0; }
  .est-log__icon { grid-row: 1 / span 2; }
  .est-check-group { grid-template-columns: 1fr; }
}
