/* v360 Paket 2 – Sessionbibliothek (Dialog) und Bibliotheks-Seitenleiste.
   Links Suche + Vorlagen nach Trainingsart, rechts Ablauf-Vorschau, Hauptaktion "In Kalender einplanen".
   Nur Prep-Tokens; Grün nur als Akzent; keine Schatten/Verläufe. */

/* ---------- Dialog: Grundlayout (Desktop/Tablet) ---------- */
@media (min-width:761px) and (min-height:501px){
  #sessionLibraryDialog:not(.pl-v360-dialog) .session-library-filters {
    grid-template-columns:repeat(auto-fit,minmax(min(100%,160px),1fr));
  }
}
@media (min-width:768px) {
  html body dialog.pl-v360-dialog { height:min(860px,calc(100dvh - 32px)); max-height:calc(100dvh - 32px); }
  html body dialog.pl-v360-dialog > .session-library-shell {
    height:100%; box-sizing:border-box; overflow:hidden;
    display:grid; grid-template-columns:minmax(300px,380px) minmax(0,1fr);
    grid-template-rows:auto auto auto auto auto minmax(0,1fr) auto;
    grid-template-areas:"head head" "create detail" "filters detail" "tags detail" "folders detail" "items detail" "items footer";
  }
  html body dialog.pl-v360-dialog .session-library-shell > .dialog-heading { grid-area:head; }
  html body dialog.pl-v360-dialog .session-library-shell > p { grid-area:create; padding:16px 16px 0; }
  html body dialog.pl-v360-dialog .session-library-shell > :is(p, #sessionLibraryTagFilters) ,
  html body dialog.pl-v360-dialog .session-library-browser > details,
  html body dialog.pl-v360-dialog .pl-library-items { border-right:1px solid var(--prep-line); }
  html body dialog.pl-v360-dialog .session-library-shell > .session-library-filters { grid-area:filters; grid-template-columns:minmax(0,1fr) minmax(0,1fr); gap:8px; padding:12px 16px 0; margin:0; }
  html body dialog.pl-v360-dialog .session-library-filters > label:first-child,
  html body dialog.pl-v360-dialog .session-library-filters > .check-field { grid-column:1/-1; }
  html body dialog.pl-v360-dialog .session-library-filters .check-field { min-height:44px; padding:0; }
  html body dialog.pl-v360-dialog .session-library-shell > #sessionLibraryTagFilters { grid-area:tags; padding:0 16px; }
  html body dialog.pl-v360-dialog .session-library-browser { display:contents; }
  html body dialog.pl-v360-dialog .session-library-browser > details { grid-area:folders; margin:0; }
  html body dialog.pl-v360-dialog #sessionLibraryList.planiq-library-view { display:contents; }
  html body dialog.pl-v360-dialog .pl-library-items { grid-area:items; min-height:0; max-height:none; overflow:auto; }
  html body dialog.pl-v360-dialog .pl-library-detail { grid-area:detail; min-height:0; max-height:none; overflow:auto; }
  html body dialog.pl-v360-dialog .pl-library-footer { grid-area:footer; position:static; }
  html body dialog.pl-v360-dialog .pl-library-empty { grid-area:detail; padding:32px; }
  html:root:not(#_) #sessionLibraryDialog.pl-v360-dialog > .session-library-shell { padding:0!important; }
  html:root:not(#_) #sessionLibraryDialog.pl-v360-dialog .session-library-shell > .dialog-heading { margin:0!important; }
  html:root body #sessionLibraryDialog.pl-v360-dialog .session-library-browser > details { max-height:min(24dvh,240px); overflow:auto; }
  html:root:not(#_) #sessionLibraryDialog.pl-v360-dialog .session-library-shell > .dialog-actions {
    grid-row:footer; grid-column:1/-1; margin:0!important;
  }
  html:root:not(#_) #sessionLibraryDialog.pl-v360-dialog:has(.pl-library-footer) .session-library-shell > .dialog-actions { display:none!important; }
  html:root body #sessionLibraryDialog.pl-v360-dialog .pl-library-footer { justify-content:flex-end; }
  html:root body #sessionLibraryDialog.pl-v360-dialog .pl-library-more { margin-inline-start:0; }
}

/* ---------- Liste: nach Trainingsart gruppiert ---------- */
html body .pl-v360 .pl-library-count { margin:4px 0 12px; font-size:13px; font-weight:600; color:var(--prep-text2); }
html body .pl-v360 .pl-library-group + .pl-library-group { margin-top:16px; }
html body .pl-v360 .pl-library-group-title { display:flex; align-items:center; justify-content:space-between; gap:8px; margin:0 0 4px; padding:0 4px; font-size:13px; font-weight:600; color:var(--prep-text2); }
html body .pl-v360 .pl-library-group-count { font-variant-numeric:tabular-nums; color:var(--prep-text3); font-weight:500; }
html body .pl-v360 .pl-library-choices { display:grid; }
html body .pl-v360 .pl-library-choice { display:grid; width:100%; min-height:48px; border:1px solid transparent !important; border-left:3px solid transparent !important; color:var(--prep-text) !important; text-align:left; box-shadow:none !important; white-space:normal; cursor:pointer; }
html body .pl-v360 .pl-library-choice:hover { background:var(--prep-bg2) !important; }
html body .pl-v360 .pl-library-choice[aria-pressed=true] { background:var(--prep-raised) !important; border-color:var(--prep-line) !important; border-left-color:var(--prep-accent) !important; }
html body .pl-v360 .pl-library-choice strong { font-size:15px; font-weight:600; line-height:1.35; }
html body .pl-v360 .pl-library-choice-meta { display:flex; flex-wrap:wrap; gap:4px 12px; color:var(--prep-text2); font-size:13px; font-variant-numeric:tabular-nums; }
html body .pl-v360 .pl-library-state { display:inline-flex; align-items:center; gap:4px; color:var(--prep-text2); font-size:13px; font-weight:600; }
html body .pl-v360 .pl-library-state svg { width:14px; height:14px; }

/* ---------- Vorschau: Kopf, Eckdaten, Ablauf ---------- */
html body .pl-v360 .pl-library-heading { display:grid; margin:0 0 16px; }
html body .pl-v360 .pl-library-kicker { display:flex; flex-wrap:wrap; align-items:center; gap:12px; color:var(--prep-text2); font-size:13px; }
html body .pl-v360 .pl-library-heading h3 { margin:0; font-size:24px; line-height:1.25; color:var(--prep-text); }
html body .pl-v360 .pl-library-facts { display:flex; flex-wrap:wrap; gap:8px 32px; margin:4px 0 0; }
html body .pl-v360 .pl-library-facts > div { display:grid; gap:2px; }
html body .pl-v360 .pl-library-facts dt { display:inline-flex; align-items:center; gap:4px; font-size:12px; color:var(--prep-text3); }
html body .pl-v360 .pl-library-facts dt svg { width:14px; height:14px; }
html body .pl-v360 .pl-library-facts dd { margin:0; font-size:20px; font-weight:600; font-variant-numeric:tabular-nums; color:var(--prep-text); }
html body .pl-v360 .pl-library-meta { margin:0; color:var(--prep-text2); font-size:13px; }
html body .pl-v360 .pl-library-description { margin:0 0 12px; color:var(--prep-text2); white-space:pre-wrap; }
html body .pl-v360 .pl-library-tags { display:flex; flex-wrap:wrap; gap:4px; margin:0 0 16px; }
html body .pl-v360 .pl-library-tags span { border:1px solid var(--prep-line); color:var(--prep-text2); }
html body .pl-v360 .pl-library-flow { margin-top:8px; padding-top:16px; border-top:1px solid var(--prep-line); }
html body .pl-v360 .pl-library-flow > h4 { margin:0 0 12px; font-size:15px; font-weight:600; color:var(--prep-text); }
html body .pl-v360 .pl-library-steps { list-style:none; margin:0; padding:0; display:grid; gap:0; }
html body .pl-v360 .pl-library-step { position:relative; padding:0 0 20px 28px; }
html body .pl-v360 .pl-library-step::before { content:""; position:absolute; left:4px; top:5px; width:8px; height:8px; border:2px solid var(--prep-accent); border-radius:50%; background:var(--prep-surface); }
html body .pl-v360 .pl-library-step::after { content:""; position:absolute; left:9px; top:19px; bottom:0; width:2px; background:var(--prep-line); }
html body .pl-v360 .pl-library-step:last-child { padding-bottom:0; }
html body .pl-v360 .pl-library-step:last-child::after { display:none; }
html body .pl-v360 .pl-library-step-head { display:flex; flex-wrap:wrap; align-items:baseline; justify-content:space-between; gap:4px 12px; }
html body .pl-v360 .pl-library-step-head strong { font-size:15px; color:var(--prep-text); }
html body .pl-v360 .pl-library-step-head span { font-size:13px; color:var(--prep-text3); font-variant-numeric:tabular-nums; }
html body .pl-v360 .pl-library-exercises { list-style:none; margin:8px 0 0; padding:0; border:1px solid var(--prep-line); border-radius:8px; background:var(--prep-bg2); }
html body .pl-v360 .pl-library-exercises li { margin:0; padding:10px 12px; font-size:14px; line-height:1.5; color:var(--prep-text); white-space:pre-wrap; overflow-wrap:anywhere; }
html body .pl-v360 .pl-library-exercises li + li { border-top:1px solid var(--prep-line); }

/* ---------- Aktionsleiste ---------- */
html body .pl-v360 .pl-library-footer { display:flex; align-items:center; justify-content:flex-start; gap:8px; border-top:1px solid var(--prep-line); background:var(--prep-surface); }
html body .pl-v360 .pl-library-footer > .button { display:inline-flex; align-items:center; gap:8px; }
html body .pl-v360 .pl-library-footer > .button svg { flex:0 0 auto; }
html body .pl-v360 .pl-library-more { position:relative; }
html body .pl-v360 .pl-library-more > summary { display:inline-grid; place-items:center; width:44px; height:44px; min-height:44px; padding:0; gap:0; border:1px solid var(--prep-line); border-radius:8px; color:var(--prep-text); list-style:none; cursor:pointer; }
html body .pl-v360 .pl-library-more > summary:hover { background:var(--prep-raised); }
html body .pl-v360 .pl-library-more > summary::-webkit-details-marker { display:none; }
html body .pl-v360 .pl-library-menu { position:absolute; right:0; top:auto; bottom:calc(100% + 4px); z-index:5; display:grid; gap:2px; min-width:220px; max-width:min(300px,80vw); }
html body .pl-v360 .pl-library-menu-item { display:flex; align-items:center; width:100%; min-height:44px; padding:0 12px; border:0 !important; border-radius:6px; background:transparent !important; color:var(--prep-text) !important; text-align:left; font:inherit; font-size:14px; box-shadow:none !important; cursor:pointer; }
html body .pl-v360 .pl-library-menu-item:hover { background:var(--prep-bg2) !important; }
html body .pl-v360 .pl-library-menu-item.is-danger { margin-top:4px; border-top:1px solid var(--prep-line) !important; color:var(--prep-bad) !important; }
html body .pl-v360 .pl-library-back { display:none; }

/* ---------- Mobil: erst Liste, dann Detail mit Zurück ---------- */
@media (max-width:767px) {
  html body dialog.pl-v360-dialog:has(.is-detail) :is(.session-library-shell > p,#sessionLibraryTagFilters,.session-library-browser > details) { display:none; }
  html body .pl-v360.is-detail .pl-library-back { display:inline-flex; align-items:center; gap:4px; margin:0 0 16px; }
  html body .pl-v360 .pl-library-choice { min-height:52px; }
  html body .pl-v360 .pl-library-footer { position:sticky; bottom:0; flex-direction:row; }
  html body .pl-v360 .pl-library-footer > .pl-library-schedule { flex:1 1 100%; justify-content:center; }
  html body .pl-v360 .pl-library-footer > .button:not(.pl-library-schedule) { flex:1 1 auto; justify-content:center; }
  html body .pl-v360 .pl-library-menu { position:absolute; width:auto; max-width:calc(100vw - 48px); }
  html body .pl-v360 .pl-library-heading h3 { font-size:21px; }
}

/* ---------- Seitenleiste: Zeilenmenü (⋯) und "Häufig verwendet" ---------- */
html:root body #calendarSidebar .library-tree-session > .library-tree-schedule + .library-tree-row-menu{ position:relative; }
html:root body #calendarSidebar .library-tree-row-menu > summary { display:inline-grid; place-items:center; width:36px; height:36px; padding:0; border:1px solid transparent; border-radius:8px; color:var(--prep-text2); list-style:none; cursor:pointer; }
html:root body #calendarSidebar .library-tree-row-menu > summary::-webkit-details-marker { display:none; }
html:root body #calendarSidebar .library-tree-row-menu > summary:hover,
html:root body #calendarSidebar .library-tree-row-menu[open] > summary { background:var(--prep-raised); border-color:var(--prep-line); color:var(--prep-text); }
html:root body #calendarSidebar .library-tree-row-actions { position:absolute; right:0; top:calc(100% + 4px); z-index:30; display:grid; gap:2px; min-width:200px; }
html:root body #calendarSidebar .library-tree-row-actions > button { display:flex; align-items:center; width:100%; border:0 !important; background:transparent !important; font:inherit; text-align:left; box-shadow:none !important; white-space:nowrap; cursor:pointer; }
html:root body #calendarSidebar .library-tree-row-actions > button:hover { background:var(--prep-bg2) !important; }
html:root body #calendarSidebar .library-tree-frequent {    border-bottom:1px solid var(--prep-line); }
html:root body #calendarSidebar .library-tree-frequent > h4 { display:flex; align-items:center; gap:6px; margin:0 0 4px;  font-size:12px; font-weight:600; color:var(--prep-text2); }
html:root body #calendarSidebar .library-tree-frequent > h4 svg { color:var(--prep-accent); flex:0 0 auto; }
html:root body #calendarSidebar .library-tree-frequent .library-tree-session:last-child { border-bottom:0; }
html:root body #calendarSidebar .library-tree-uses { font-size:12px; color:var(--prep-text3); font-variant-numeric:tabular-nums; }
@media (pointer:coarse) {
  html:root body #calendarSidebar .library-tree-row-menu > summary { width:44px; height:44px; }
  html:root body #calendarSidebar .library-tree-row-actions > button { min-height:44px; }
}
