/* ===== Dateibaum ===== */
.tree-row {
  display: flex; align-items: center; gap: 5px; padding: 3px 6px;
  border-radius: 7px; cursor: pointer; font-size: 13.5px; user-select: none;
  white-space: nowrap; min-height: 26px;
}
.tree-row:hover { background: var(--panel2); }
.tree-row.selected { background: var(--accent-dim); }
.tree-row.focused { outline: 1px solid var(--accent); outline-offset: -1px; }
.tree-row.current .tr-name { color: var(--accent); font-weight: 600; }
.tree-row.cut { opacity: .45; }
/* Versteckte Ordner (über das Auge eingeblendet): ausgegraut */
.tree-row.tree-hidden { opacity: .5; }
.tree-row.tree-hidden .tr-name { font-style: italic; }
#btn-show-hidden.on { color: var(--accent); background: var(--accent-dim); }
.tree-row.drop-target { background: var(--accent-dim); outline: 1.5px dashed var(--accent); outline-offset: -2px; }
.tree-row.flash { animation: tree-flash .9s ease; }
@keyframes tree-flash {
  0%, 60% { background: var(--accent-dim); }
  100% { background: transparent; }
}

.tr-arrow { width: 13px; text-align: center; color: var(--muted); font-size: 10px; flex-shrink: 0; }
/* Auf-/Zuklappen: kleines Zeichen, GROSSE Trefferfläche. Die Fläche wächst über
   ein ::after seitlich in die Zeilenpolsterung und über die volle Zeilenhöhe —
   das Layout (Einrückung, Icon-Spalte) bleibt dadurch exakt wie vorher. Höhe
   fest = Zeilenhöhe, damit die Nachbarzeilen keine Klicks verlieren. */
.tr-arrow { position: relative; }
.tr-arrow::after {
  content: ''; position: absolute; left: -9px; right: -7px;
  top: 50%; height: 26px; transform: translateY(-50%);
}
.tr-ico { flex-shrink: 0; font-size: 14px; }
.tr-colordot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; margin-left: -2px; }
.tr-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.tr-tagdot { color: var(--accent); font-size: 11px; font-weight: 700; }
.tr-pin { color: var(--warn); font-size: 11px; }

/* Offline-Bearbeitet-Marke: Datei wurde offline geändert und überschreibt beim
   Reconnect den Server (Quelle: Upload-Warteschlange). */
.tr-offline-edit { display: inline-flex; align-items: center; flex-shrink: 0; color: #0ea5e9; }
.tr-offline-edit svg.ico { width: 13px; height: 13px; }
.tr-offline-edit.rollup { opacity: .55; }   /* Ordner-Sammelmarke (zugeklappt) */
/* Im Offline-Modus sanft pulsieren, damit die ausstehenden Edits auffallen. */
body.so-offline .tr-offline-edit:not(.rollup) { animation: tr-oe-pulse 2.2s ease-in-out infinite; }
@keyframes tr-oe-pulse {
  0%, 100% { opacity: 1; filter: drop-shadow(0 0 0 transparent); }
  50% { opacity: .5; filter: drop-shadow(0 0 3px #0ea5e9); }
}
@media (prefers-reduced-motion: reduce) {
  body.so-offline .tr-offline-edit:not(.rollup) { animation: none; }
}

/* ⋯-Knopf pro Zeile: IMMER sichtbar (ganz rechts), nur dezent gedimmt — bei
   Hover/Auswahl voll. So springt rechts nichts mehr, wenn die Maus über eine
   Zeile fährt. */
.tr-more {
  display: inline-flex; align-items: center; flex-shrink: 0; border: 0;
  background: none; cursor: pointer; color: var(--muted); border-radius: 5px;
  padding: 1px 4px; line-height: 1; opacity: .5;
}
.tr-more svg.ico { width: 14px; height: 14px; }
.tree-row:hover .tr-more, .tree-row.selected .tr-more { opacity: 1; }
.tr-more:focus-visible { opacity: 1; }
@media (hover: hover) {
  .tr-more:hover { background: var(--panel); color: var(--text); opacity: 1; }
}
@media (pointer: coarse) {
  .tree-row { min-height: 36px; }
  .tr-more { padding: 6px 8px; opacity: .6; }
  .tr-arrow::after { left: -11px; right: -9px; height: 36px; }
}

/* Fokus-Pill über dem Baum */
#focus-pill {
  display: flex; align-items: center; gap: 6px; margin: 4px 8px;
  background: var(--accent-dim); border: 1px solid var(--accent);
  border-radius: 20px; padding: 3px 6px 3px 12px; font-size: 12.5px;
}
#focus-pill .fp-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
#focus-pill .fp-x {
  border: 0; background: none; color: var(--text); cursor: pointer;
  border-radius: 50%; padding: 0 5px; font-size: 14px;
}
#focus-pill .fp-x:hover { background: var(--panel); }
#focus-pill .fp-up {
  border: 0; background: none; color: var(--text); cursor: pointer;
  border-radius: 50%; padding: 2px 4px; display: flex; align-items: center;
}
#focus-pill .fp-up:hover { background: var(--panel); }
#focus-pill .fp-up svg.ico { width: 14px; height: 14px; }

/* ===== Sidebar-Sektionen (Favoriten/Recents/Tags) ===== */
.sb-row {
  display: flex; align-items: center; gap: 7px; padding: 3px 12px;
  cursor: pointer; font-size: 13px; border-radius: 6px; margin: 0 4px;
  white-space: nowrap;
}
/* Hover-Optik NUR auf Zeigegeräten: auf Touch würde der erste Tap sonst bloß
   den Hover-Zustand setzen und erst der zweite öffnen (iOS/iPadOS-Verhalten). */
@media (hover: hover) {
  .sb-row:hover { background: var(--panel2); }
}
.sb-row-ico { flex-shrink: 0; font-size: 13px; width: 16px; text-align: center; color: var(--accent); }
.sb-row-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.sb-row-sub { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; max-width: 40%; }
.sb-tag-count {
  background: var(--panel2); border-radius: 9px; padding: 0 7px;
  font-size: 11px; color: var(--muted);
}
.sb-row-x {
  flex-shrink: 0; width: 18px; height: 18px; line-height: 1; padding: 0;
  border: 0; border-radius: 5px; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 15px; opacity: 0; transition: opacity .12s;
}
.sb-row-x:focus-visible { opacity: 1; }
@media (hover: hover) {
  .sb-row:hover .sb-row-x { opacity: 1; }
  .sb-row-x:hover { background: var(--panel); color: var(--err); }
}
.sb-empty { color: var(--muted); font-size: 12px; padding: 2px 14px 8px; }

/* Touch-Geräte haben kein Hover → ×-Entfernen-Knöpfe dauerhaft (dezent) zeigen */
@media (hover: none) {
  .hc-x, .sb-row-x { opacity: .55; }
}

#pinned-list, #recents-list, #tag-browser { padding-bottom: 6px; max-height: 30vh; overflow-y: auto; }

/* Kontextmenü-Erweiterungen */
/* Deckel: .ctx-item ist nowrap, ein langer Eintrag (Sprungliste „Zuletzt")
   schöbe das Menü sonst am Handy über den Bildschirmrand hinaus. */
.ctx-menu { max-width: min(92vw, 460px); }
.ctx-ico { width: 18px; text-align: center; flex-shrink: 0; }
.ctx-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.ctx-hint { color: var(--muted); font-size: 11px; margin-left: 14px; flex-shrink: 0; }
.ctx-aside { margin: -4px -6px -4px 8px; padding: 4px 6px; border: 0; border-radius: 6px; background: none;
  color: var(--muted); display: inline-flex; align-items: center; cursor: pointer; flex-shrink: 0; }
.ctx-aside:hover { background: var(--hover, rgba(127,127,127,.18)); color: inherit; }
.ctx-aside svg.ico { width: 15px; height: 15px; }
.ctx-more { color: var(--muted); margin-left: 10px; display: inline-flex; align-items: center; }
.ctx-more svg.ico { width: 13px; height: 13px; }
.color-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; }

/* SVG-Icons im Baum */
.tr-arrow { display: inline-flex; align-items: center; justify-content: center; }
.tr-arrow svg.ico { width: 12px; height: 12px; }
.tr-arrow:hover svg.ico { color: var(--text); }
.tr-ico { display: inline-flex; align-items: center; color: var(--muted); }
.tr-ico svg.ico { width: 15px; height: 15px; }
.tree-row.dir .tr-ico { color: #3b82f6; }
.tree-row.dir .tr-ico[style*="color"] svg { color: inherit; }
.tr-pin svg.ico { width: 11px; height: 11px; color: var(--warn); }
#focus-pill .fp-ico svg.ico { width: 13px; height: 13px; color: var(--accent); }
.sb-row-ico svg.ico { width: 14px; height: 14px; }

/* Custom-Reihenfolge: Einfüge-Linie beim Drag zwischen Zeilen */
.tree-row.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.tree-row.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }

/* Swipe-Gesten (Touch): links = trash/, rechts = Favorit */
.tree-row { touch-action: pan-y; }
.tree-row.swiping { transition: none; position: relative; z-index: 2; }
.tree-row:not(.swiping) { transition: transform .18s ease, background .18s ease; }
.tree-row.swipe-del { background: color-mix(in srgb, var(--err) 28%, transparent); }
.tree-row.swipe-pin { background: color-mix(in srgb, var(--warn) 30%, transparent); }

/* Offline-Wolke (sync/sync-rules.js): ganz RECHTS in der Zeile, vor dem ⋯-Knopf.
   Anklickbar — schaltet den Ordner (bzw. die Datei) zwischen „offline
   gespeichert" und „nicht offline" um. Ordner tragen sie immer, Dateien erst,
   sobald überhaupt eine Regel gesetzt ist. */
/* Höhe = Zeilenhöhe MINUS Polsterung (26 − 2×3), sonst zöge der Knopf die
   Zeile auseinander; die Trefferfläche wächst darum nur in die Breite. */
.tr-sync {
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0; width: 22px; height: 20px; padding: 0;
  border: 0; background: none; border-radius: 6px; cursor: pointer;
}
.tr-sync svg.ico { width: 13px; height: 13px; }
.tr-sync.inherit { color: var(--muted); opacity: .45; }
.tr-sync.on { color: var(--accent); }
.tr-sync.off { color: var(--warn); }
@media (hover: hover) {
  .tr-sync:hover { background: var(--panel); opacity: 1; }
}
.tr-sync:focus-visible { outline: 1px solid var(--accent); outline-offset: -1px; opacity: 1; }
@media (pointer: coarse) {
  .tr-sync { width: 30px; height: 30px; }
  .tr-sync svg.ico { width: 15px; height: 15px; }
}

/* ===== Touch-Mehrfachauswahl (tree/touch-select.js) ===== */
/* Langdruck darf kein iOS-Vorschau-/Kopiermenü aufmachen. */
.tree-row { -webkit-touch-callout: none; }
/* Schwebt UNTEN über dem Baum statt ihn zu verschieben: eine Leiste im Fluss
   schob die Zeilen beim Langdruck unter dem Finger weg, das Loslassen traf
   dann „Alle". Unten liegt sie außerdem am Daumen. */
#sec-tree { position: relative; }
#tree-selbar {
  display: flex; align-items: center; gap: 6px;
  position: absolute; left: 6px; right: 6px; bottom: 6px; z-index: 5;
  padding: 4px 4px 4px 10px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--accent);
  box-shadow: 0 4px 16px rgba(0,0,0,.25); font-size: 13.5px;
}
body.tree-touch-select #tree { padding-bottom: 56px; }
#tree-selbar.hidden { display: none; }
#tree-selbar .ts-count { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Handy-Seitenleiste ist ~280 px breit: dann nur ⋯ statt „⋯ Aktionen". */
#tree-selbar { container-type: inline-size; }
@container (max-width: 320px) { #tree-selbar .ts-menu span { display: none; } }
#tree-selbar button {
  display: inline-flex; align-items: center; gap: 4px; min-height: 32px;
  flex: none; padding: 0 10px; border-radius: 7px; border: 0; background: var(--panel2);
  color: inherit; font: inherit; cursor: pointer;
}
#tree-selbar button:disabled { opacity: .45; }
#tree-selbar .ts-x { font-size: 18px; padding: 0 12px; }
#tree-selbar svg { width: 15px; height: 15px; }
/* Im Auswahlmodus: Haken-Kreis vor jeder Zeile, damit klar ist, dass Tippen auswählt. */
body.tree-touch-select #tree .tree-row::before {
  content: ''; flex: none; width: 15px; height: 15px; border-radius: 50%;
  border: 1.5px solid var(--muted, #888); box-sizing: border-box; margin-right: 2px;
}
body.tree-touch-select #tree .tree-row.selected::before {
  border-color: var(--accent);
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 8.5l2.5 2.5L12 5.5' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/100% no-repeat;
}

/* ===== Galerie-Modus der Sidebar (Schalter #btn-tree-gallery) ===== */
#btn-tree-gallery.on { color: var(--accent); background: var(--accent-dim); }
#tree.tree-gallery {
  display: grid; grid-template-columns: repeat(var(--tg-cols, 2), minmax(0, 1fr)); gap: 8px;
  padding: 6px 6px 10px; align-content: start; touch-action: pan-x pan-y;
}
#tree.tree-gallery .tree-card {
  display: flex; flex-direction: column; align-items: stretch; gap: 0;
  padding: 0; min-height: 0; white-space: normal; overflow: hidden;
  border: 1px solid var(--line); border-radius: 9px; background: var(--panel);
}
#tree.tree-gallery .tree-card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--panel); }
#tree.tree-gallery .tree-card.selected { border-color: var(--accent); background: var(--accent-dim); }
#tree.tree-gallery .tree-card.focused { outline: 2px solid var(--accent); outline-offset: -2px; }
#tree.tree-gallery .tree-card.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
#tree.tree-gallery .tc-cover {
  height: auto; aspect-ratio: 4 / 3; background: var(--bg); position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
#tree.tree-gallery .tc-cover img { width: 100%; height: 100%; object-fit: cover; }
#tree.tree-gallery .tc-cover video, #tree.tree-gallery .tc-cover canvas { width: 100%; height: 100%; object-fit: cover; }
#tree.tree-gallery .tc-cover .ico { width: 34px; height: 34px; }
#tree.tree-gallery .tc-foot { display: flex; align-items: center; gap: 2px; padding: 4px 4px 4px 7px; min-width: 0; }
#tree.tree-gallery .tc-name {
  flex: 1; min-width: 0; font-size: 12px; line-height: 1.25;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#tree.tree-gallery .tree-card.current .tc-name { color: var(--accent); font-weight: 600; }
#tree.tree-gallery .tr-more { flex-shrink: 0; }
#tree.tree-gallery .tc-empty { grid-column: 1 / -1; padding: 18px 8px; text-align: center; color: var(--muted); font-size: 13px; }
/* Download aufs Gerät läuft (sync/download-track.js) */
.tr-dl { display: inline-flex; align-items: center; flex-shrink: 0; color: var(--accent); cursor: pointer; }
.tr-dl svg.ico { width: 13px; height: 13px; animation: tr-dl-hop 1.1s ease-in-out infinite; }
@keyframes tr-dl-hop { 0%, 100% { transform: translateY(-1px); } 50% { transform: translateY(2px); } }
@media (prefers-reduced-motion: reduce) { .tr-dl svg.ico { animation: none; } }
