/* Shell: Leitschiene (Seitenleiste), Kopfleiste, Arbeitsblatt, Tab-Leiste mobil, Tabs für geöffnete Seiten.
   Layout aus dem Prototyp: schmale Leitschiene auf neutralem Grund, die Arbeitsfläche liegt als Blatt darauf.
   Unter 1180 px nur noch eine Icon-Leiste, unter 760 px keine Leitschiene, dafür eine Tab-Leiste unten. */

/* ---------- Grundgerüst ---------- */
.app { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: 100dvh; }

/* ---------- Leitschiene ---------- */
.rail { position: sticky; top: 0; align-self: start; height: 100dvh; display: flex; flex-direction: column; gap: 12px; padding: 16px 10px 14px 14px; overflow-y: auto; scrollbar-width: none; }

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 6px; text-decoration: none; color: var(--ink); }
.brand-mark { display: block; width: 30px; height: 30px; flex: none; }
.brand-name { font-family: var(--f-display); font-stretch: 66%; font-weight: 800; font-size: 21px; letter-spacing: .01em; text-transform: uppercase; line-height: 1; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-group { margin: 14px 10px 5px; font-family: var(--f-mono); font-stretch: 80%; font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-2); }
.nav-group.sep { height: 1px; margin: 12px 10px; background: var(--line); }
.nav-item { display: flex; align-items: center; gap: 11px; height: 36px; padding: 0 10px; border-radius: 7px; color: var(--ink-2); text-decoration: none; font-weight: 500; font-size: 14px; position: relative; transition: background .12s, color .12s; }
.nav-item:hover { background: var(--hover); color: var(--ink); }
.nav-item[aria-current="page"] { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.nav-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-count { margin-left: auto; font-family: var(--f-mono); font-stretch: 80%; font-size: 11px; color: var(--ink-2); }
.nav-item[aria-current="page"] .nav-count { color: inherit; opacity: .65; }
.nav-alert { margin-left: auto; width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--bad-fill); }
.nav-live { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-family: var(--f-mono); font-stretch: 80%; font-size: 11px; color: var(--live-text); }
.nav-item[aria-current="page"] .nav-live { color: inherit; }
.nav-live::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: blink 1.4s infinite; }
.nav-live.is-hang { color: var(--bad); }
.nav-live.is-hang::before { animation: blink .6s infinite; }
.nav-item[aria-current="page"] .nav-live.is-hang { color: inherit; }

.rail-foot { display: flex; flex-direction: column; gap: 10px; }
.me { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px; border: 0; border-radius: 9px; background: none; text-align: left; }
.me:hover { background: var(--hover); }
.me-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.me-text b { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-text small { color: var(--ink-3); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 32px; height: 32px; flex: none; border-radius: var(--radius); display: grid; place-items: center; background: var(--accent); color: var(--on-accent); font-family: var(--f-display); font-stretch: 66%; font-weight: 800; font-size: 15px; }
.avatar.sm { width: 28px; height: 28px; border-radius: 7px; font-size: 12.5px; }
/* Benutzermenü: Die volle Leitschiene scrollt (overflow-y: auto) und schneidet alles ab, was rechts
   übersteht. Das Menü ist deshalb so breit wie der Benutzer-Knopf; in der schmalen Icon-Leiste
   (unter 1180 px, overflow: visible) bekommt es wieder seine volle Breite. */
.rail-foot .menu { left: 0; right: 0; min-width: 0; }
/* Die Farbschema-Knöpfe stehen in einer Gruppe (role="group"); ohne eigene Flex-Spalte wären sie
   nur so breit wie ihre Beschriftung, und das Häkchen (.spacer) rückte nicht an den rechten Rand. */
.rail-foot .menu [role="group"] { display: flex; flex-direction: column; }

/* ---------- Bühne und Kopfleiste ---------- */
.stage { display: flex; flex-direction: column; min-width: 0; padding: 0 12px 12px 0; }
.topbar { --tb: var(--ground); position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; height: 60px; background: var(--tb); padding: 0 2px 0 6px; }

.crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1; font-size: 13px; color: var(--ink-3); }
.crumbs b { color: var(--ink); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs .i { width: 14px; height: 14px; color: var(--line); }
.cr-root { white-space: nowrap; }
.cr-link { border: 0; background: none; padding: 0; color: var(--ink-3); white-space: nowrap; }
.cr-link:hover { color: var(--ink); }
.cr-mark { display: none; }

.search-trigger { display: flex; align-items: center; gap: 10px; height: 36px; width: min(320px, 34vw); padding: 0 8px 0 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--raised); color: var(--ink-3); font-size: 13px; text-align: left; }
.search-trigger:hover { border-color: var(--ink-3); }
/* Beschriftung; :not([data-icon]) lässt eine Icon-Hülle wie im Prototyp (<span data-icon>) außen vor */
.search-trigger > span:not([data-icon]) { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Live-Anzeige der Robot-Verbindung. Zustand über data-st (core/bus.js status()):
   open = verbunden (grüner, pulsierender Punkt), connecting/reconnecting = Verbindung wird aufgebaut
   (gelb, blinkend, Text bleibt auch mobil sichtbar), off = keine Verbindung (rot, ruhig).
   Ohne data-st sieht die Anzeige aus wie „open“. Auf .topbar begrenzt, weil .live sonst auch
   als Modifikator (.pill.live, .lg.live) vorkommt und dort Höhe und Rahmen erben würde. */
.topbar .live { display: inline-flex; align-items: center; gap: 7px; height: 28px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; flex: none; }
.topbar .live i { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--good-fill); animation: ping 2s infinite; }
.topbar .live[data-st="connecting"] i, .topbar .live[data-st="reconnecting"] i { background: var(--warn-fill); animation: blink 1s infinite; }
.topbar .live[data-st="connecting"], .topbar .live[data-st="reconnecting"] { color: var(--warn); border-color: color-mix(in oklab, var(--warn-fill) 55%, var(--line)); }
.topbar .live[data-st="off"] i { background: var(--bad-fill); animation: none; }
.topbar .live[data-st="off"] { color: var(--ink-3); }

.icon-btn { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: var(--radius); border: 1px solid transparent; background: none; color: var(--ink-2); position: relative; }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn.sm .i { width: 15px; height: 15px; }
.icon-btn .i { transition: transform .15s; }
.icon-btn.armed, .icon-btn.armed:hover { background: var(--bad); color: var(--on-bad); }
.icon-btn:disabled { opacity: .5; }
/* Aufklapp-Knöpfe (z. B. Zeile ausklappen) drehen ihr Icon. Nicht bei Menü-/Popover-Auslösern
   (aria-haspopup) und nicht in der Kopfleiste – sonst kippt die Glocke beim Öffnen der Meldungen. */
.icon-btn[aria-expanded="true"]:not([aria-haspopup]):not(.topbar .icon-btn) .i { transform: rotate(90deg); }

.badge { position: absolute; top: 3px; right: 2px; min-width: 17px; height: 17px; border-radius: 9px; background: var(--accent); color: var(--on-accent); font-size: 10px; font-weight: 700; display: grid; place-items: center; padding: 0 4px; border: 2px solid var(--tb, var(--ground)); line-height: 1; }

/* ---------- Arbeitsblatt ---------- */
.sheet { container: sheet / inline-size; flex: 1; background: var(--sheet); border: 1px solid var(--line); box-shadow: var(--shadow-sheet); border-radius: var(--radius-xl); padding-block: 30px 64px; padding-inline: clamp(16px, 3vw, 36px); min-width: 0; }
.sheet:focus { outline: none; }

/* ---------- Tab-Leiste mobil ---------- */
.tabbar { display: none; }
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 2px 0; border: 0; background: none; color: var(--ink-3); font-size: 11px; font-weight: 600; text-decoration: none; position: relative; min-width: 0; }
.tab-ic { width: 48px; height: 28px; display: grid; place-items: center; border-radius: 14px; transition: background .15s; }
.tab[aria-current="page"] { color: var(--ink); }
.tab[aria-current="page"] .tab-ic { background: var(--accent-soft); color: var(--accent-text); }
.tab .nav-alert { position: absolute; top: 2px; right: calc(50% - 20px); margin: 0; }
/* Windows-Kontrastmodus ersetzt die Hintergründe – aktuelle Seite (Leitschiene und Tab-Leiste) per
   Rahmen in Systemfarbe kennzeichnen. Beim Navigationspunkt hat der Fokusrahmen Vorrang. */
@media (forced-colors: active) {
  .nav-item[aria-current="page"]:not(:focus-visible), .tab[aria-current="page"] .tab-ic { outline: 2px solid Highlight; outline-offset: -2px; }
}

/* ---------- Tabs für geöffnete Seiten (nur Desktop) ----------
   Ein fester Start-Tab (zuletzt genutzter Bereich) plus je geöffneter Aufgabe bzw. geöffnetem Projekt
   ein Tab (shell/topbar.js). Steht in der Kopfleiste eine sichtbare .apptabs-wrap vor den Brotkrumen,
   ersetzen die Tabs auf dem Desktop die Brotkrumen. Was nicht passt, landet im „+N“-Menü. */
.apptabs-wrap { align-self: stretch; display: flex; align-items: flex-end; flex: 1; min-width: 0; gap: 6px; padding-left: 14px; }
.apptabs { display: flex; align-items: flex-end; gap: 2px; min-width: 0; height: 100%; overflow: hidden; }
.apptab { position: relative; display: flex; align-items: center; gap: 8px; height: 40px; flex: 0 1 250px; min-width: 118px; padding: 0 6px 0 12px; border: 1px solid transparent; border-bottom: 0; border-radius: 10px 10px 0 0; background: transparent; color: var(--ink-2); font-size: 13px; font-weight: 550; white-space: nowrap; cursor: pointer; transition: background .12s, color .12s; }
.apptab.home { flex: 0 0 auto; min-width: 0; padding-right: 14px; }
.apptab:hover { background: var(--hover); color: var(--ink); }
.apptab:focus-visible { outline-offset: -2px; }   /* .apptabs schneidet ab (overflow: hidden) */
.apptab[aria-selected="true"] { z-index: 2; height: 42px; margin-bottom: -1px; background: var(--sheet); color: var(--ink); border-color: var(--line); font-weight: 650; }
.apptab:not([aria-selected="true"]):not(:hover) + .apptab:not([aria-selected="true"]):not(:hover)::before { content: ""; position: absolute; left: -2px; top: 12px; bottom: 12px; width: 1px; background: var(--line); }
.apptab .i { width: 15px; height: 15px; flex: none; color: var(--ink-3); }
.apptab[aria-selected="true"] > .i { color: var(--accent-text); }
.apptab-l { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; text-align: left; }
.apptab-x { width: 22px; height: 22px; flex: none; display: grid; place-items: center; border-radius: var(--radius-s); color: var(--ink-3); opacity: .7; }
.apptab-x .i { width: 12px; height: 12px; color: inherit; }
.apptab:hover .apptab-x, .apptab[aria-selected="true"] .apptab-x { opacity: 1; }
.apptab-x:hover { background: var(--hover); color: var(--ink); }
.tst { flex: none; width: 8px; height: 8px; border-radius: 50%; display: none; }
.tst[data-st="run"] { display: block; background: var(--live); animation: blink 1.2s infinite; }
.tst[data-st="done"] { display: block; background: var(--good-fill); }
.tst[data-st="warn"] { display: block; background: var(--bad-fill); }
.apptabs-more { align-self: center; height: 28px; padding: 0 9px; border-radius: 7px; border: 1px solid var(--line); background: var(--raised); font-size: 12px; font-weight: 650; color: var(--ink-2); }
.apptabs-more:hover, .apptabs-more[aria-expanded="true"] { color: var(--ink); border-color: var(--ink-3); }
.apptabs-wrap > .menu-wrap { align-self: center; }
/* Das Menü hängt an der klebenden Kopfleiste und scrollt nicht mit der Seite: Bei vielen Tabs
   (bis zu 30) bleibt es im Fenster und scrollt selbst. */
.apptabs-wrap .menu { left: 0; right: auto; max-width: 320px; max-height: calc(100dvh - 76px); overflow-y: auto; overscroll-behavior: contain; }
.apptabs-wrap .menu button { flex: none; }
.apptabs-wrap .menu button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.apptabs-wrap .menu button > span:not(.tst) { flex: 1; min-width: 0; }
.apptabs-wrap .menu button > .i { flex: none; color: var(--ink-3); }
/* Statuspunkt im Überlauf-Menü: ohne Status gar nicht im Markup, mit Status rechts außen. */
.apptabs-wrap .menu .tst { margin-left: auto; }
/* Windows-Kontrastmodus: Der Statuspunkt ist nur eine Fläche – in Systemfarbe zeichnen. Der aktive
   Tab hebt sich nur über den Hintergrund ab und bekommt wie die aktuelle Seite in der Leitschiene
   einen Rahmen in Systemfarbe (der Fokusrahmen hat Vorrang). */
@media (forced-colors: active) {
  .tst[data-st="run"], .tst[data-st="done"], .tst[data-st="warn"] { background: CanvasText; }
  .apptab[aria-selected="true"]:not(:focus-visible) { outline: 2px solid Highlight; outline-offset: -2px; }
}

/* Ohne :has(): Die Tab-Leiste steht im Markup vor .crumbs (Geschwister-Selektor). Der negative
   Außenabstand hebt den linken Innenabstand der Kopfleiste auf, wie padding-left: 0 im Prototyp. */
@media (min-width: 760px) {
  .topbar > .apptabs-wrap:not([hidden]) { margin-left: -6px; }
  .topbar > .apptabs-wrap:not([hidden]) ~ .crumbs { display: none; }
}

/* ---------- Schmale Icon-Leiste (unter 1180 px) ---------- */
@media (max-width: 1179px) {
  :root { --rail-w: 72px; }
  .rail { padding-inline: 10px; align-items: center; overflow: visible; }
  .brand { padding: 4px 0 6px; }
  .brand-name, .nav-label, .nav-count, .me-text { display: none; }
  .nav-group { height: 1px; margin: 10px 8px; background: var(--line); font-size: 0; color: transparent; }
  .nav-item { justify-content: center; width: 44px; padding: 0; }
  .nav-alert { position: absolute; top: 7px; right: 7px; margin: 0; }
  /* Live-Zähler (Aktivität) als blinkender Punkt wie .nav-alert, rot bei Hänger. Die Zahl bleibt
     als Text im Element (font-size: 0) und damit für Screenreader hörbar. */
  .nav-live, .nav-item[aria-current="page"] .nav-live { position: absolute; top: 7px; right: 7px; margin: 0; gap: 0; font-size: 0; color: var(--live); }
  .nav-live::before { width: 7px; height: 7px; box-shadow: 0 0 0 2px var(--ground); }
  .nav-live.is-hang, .nav-item[aria-current="page"] .nav-live.is-hang { color: var(--bad-fill); }
  .nav-item::after { content: attr(data-label); position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%); white-space: nowrap; background: var(--tip-bg); color: var(--tip-fg); font-size: 12px; font-weight: 600; padding: 5px 9px; border-radius: var(--radius-s); opacity: 0; pointer-events: none; transition: opacity .12s; z-index: 5; }
  .nav-item:hover::after, .nav-item:focus-visible::after { opacity: 1; }
  /* Escape blendet die Beschriftung aus (tooltip.js setzt .tips-off, bis Fokus oder Zeiger wechseln). */
  .nav.tips-off .nav-item::after { opacity: 0; }
  .me { justify-content: center; padding: 4px; }
  .rail-foot .menu { right: auto; min-width: 230px; }
}

/* ---------- Mobil (unter 760 px): keine Leitschiene, Tab-Leiste unten, Blatt randlos ---------- */
@media (max-width: 759px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail { display: none; }
  .stage { padding: 0; }
  .topbar { --tb: var(--sheet); height: 56px; padding: 0 10px 0 16px; top: env(safe-area-inset-top, 0px); border-bottom: 1px solid var(--line-soft); }
  .apptabs-wrap { display: none; }
  .crumbs { display: flex; }
  .cr-root, .crumbs .i, .cr-link { display: none; }
  .cr-mark { display: block; width: 26px; height: 26px; flex: none; }
  .crumbs b { font-family: var(--f-display); font-stretch: 66%; font-weight: 800; font-size: 19px; text-transform: uppercase; letter-spacing: .01em; }
  .search-trigger { width: 36px; padding: 0; justify-content: center; border-color: transparent; background: none; color: var(--ink-2); }
  .search-trigger > span:not([data-icon]), .search-trigger kbd { display: none; }
  .topbar .live { border: 0; padding: 0 6px; }
  /* Nur „Live“ zeigt mobil allein den Punkt; der Text bleibt wie .sr-only für Screenreader
     erhalten. „Offline“ und „Verbinde …“ bleiben sichtbar, sonst trüge nur die Farbe den Zustand. */
  .topbar .live[data-st="open"] span { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
  .sheet { border: 0; border-radius: 0; padding-block: 20px 112px; padding-inline: 16px; }
  .tabbar { display: grid; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; grid-template-columns: repeat(5, minmax(0, 1fr)); background: var(--raised); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px)); }
  input, textarea, select { font-size: 16px !important; }
}
