/* Knowledge 3.2: item list with selection and drag and drop, drop targets, the folder picker, dialogs, the access
   confirmation, removing folders and the share panel. Tokens from app.css only; every selector is prefixed kd-. */

/* ---------------------------------------------------------------- items you can select and drag */
.kd-items { list-style: none; margin: 0; padding: 0; }
.kd-item { position: relative; display: grid; grid-template-columns: 28px auto minmax(0, 1fr) auto; align-items: center;
  gap: var(--s3); padding: var(--s3) var(--s4) var(--s3) var(--s3); border-bottom: 1px solid var(--border); min-height: 56px;
  transition: background .12s, opacity .12s; }
.kd-item:last-child { border-bottom: 0; }
.kd-item:hover { background: var(--surface-2); }
.kd-item.kd-selected { background: var(--accent-soft); }
.kd-item[draggable="true"] { -webkit-touch-callout: none; }
.kd-item[draggable="true"] .kd-item-text { cursor: grab; }
.kd-item.kd-being-dragged { opacity: .45; }
.kd-item-text { min-width: 0; }
.kd-item-text .title { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.kd-item .meta { font-size: 12.5px; color: var(--muted); display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; margin-top: 2px; }
.kd-item .meta > * + *::before { content: "·"; margin-right: var(--s2); color: var(--faint); }
.kd-item .kd-desc { margin-top: 2px; }
.kd-check { display: grid; place-items: center; min-width: 24px; min-height: 24px; }
.kd-check input { width: 18px; height: 18px; margin: 0; accent-color: var(--violet); cursor: pointer; }
.kd-folder-sm { width: 26px; height: 26px; border-radius: 8px; }

/* ---------------------------------------------------------------- selection bar */
.kd-selbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s2) var(--s3);
  padding: var(--s2) var(--s4) var(--s2) var(--s3); border-bottom: 1px solid var(--border); background: var(--surface-2);
  min-height: 48px; }
.kd-selbar.kd-has-sel { background: var(--accent-soft); }
.kd-selcount { font-size: 13px; color: var(--muted); min-width: 0; }
.kd-selbar.kd-has-sel .kd-selcount { color: var(--accent-text); font-weight: 600; }
.kd-selactions { display: flex; flex-wrap: wrap; gap: var(--s2); }
.kd-drophint { display: flex; align-items: center; gap: 6px; margin: 0; padding: var(--s3) var(--s4); font-size: 12.5px;
  color: var(--muted); border-top: 1px dashed var(--border); }
.kd-drophint[hidden] { display: none; }
.kd-filter-details { border-top: 1px solid var(--border); padding: var(--s3) var(--s4) 0; margin: 0; }
.kd-filter-details > summary { margin-bottom: var(--s3); }
.kd-filter-details .kd-filter-body { padding: 0 0 var(--s4); }

/* ---------------------------------------------------------------- row menu */
.kd-menu { position: relative; }
.kd-menu > summary { list-style: none; min-width: 32px; min-height: 32px; padding: 0 6px; }
.kd-menu > summary::-webkit-details-marker { display: none; }
.kd-menu-list { position: absolute; right: 0; top: calc(100% + 4px); z-index: 30; min-width: 190px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-pop);
  display: grid; gap: 2px; }
.kd-menu-list a { display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 4px 10px; border-radius: 8px;
  color: var(--text-2); font-size: 13.5px; white-space: nowrap; }
.kd-menu-list a:hover, .kd-menu-list a:focus-visible { background: var(--surface-2); text-decoration: none; color: var(--text); }
.kd-menu-list a.kd-danger { color: var(--danger); }

/* ---------------------------------------------------------------- drop targets */
[data-kd-target].kd-drop-ok { position: relative; outline: 2px solid var(--violet); outline-offset: -2px;
  background: var(--accent-soft) !important; border-radius: 8px; }
[data-kd-target].kd-drop-ok::after { content: attr(data-kd-drop-label); position: absolute; right: 8px; top: 50%;
  transform: translateY(-50%); z-index: 2; padding: 2px 10px; border-radius: 999px; font: 600 12px/20px var(--font);
  background: var(--violet); color: #fff; pointer-events: none; white-space: nowrap; }
.kd-items-card.kd-drop-ok::after { top: 24px; }
.kd-crumbs a.kd-drop-ok::after, .kd-tree a.kd-drop-ok::after { top: -22px; right: 0; transform: none; }
body.kd-dragging .kd-tree a, body.kd-dragging .kd-crumbs a { transition: background .1s; }
body.kd-busy { cursor: progress; }
.kd-ghost { position: absolute; top: -1000px; left: -1000px; max-width: 260px; padding: 6px 12px; border-radius: 999px;
  background: var(--violet); color: #fff; font: 600 13px/1.3 var(--font); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; box-shadow: var(--shadow-pop); pointer-events: none; z-index: 1000; }
.kd-ghost.kd-ghost-touch { position: fixed; top: 0; left: 0; }

/* ---------------------------------------------------------------- dialogs and the folder picker */
dialog.kd-dialog { width: min(560px, calc(100vw - 32px)); max-height: min(86vh, 760px); overflow: auto; padding: var(--s5);
  border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-pop); }
dialog.kd-dialog::backdrop { background: rgba(21, 16, 42, .45); }
.kd-dialog-h { font: 600 18px/1.3 var(--font-display); margin: 0 0 var(--s4); }
.kd-picker { max-height: min(52vh, 460px); overflow: auto; border: 1px solid var(--border); border-radius: var(--r);
  padding: var(--s2); background: var(--surface); }
.kd-pick { list-style: none; margin: 0; padding: 0 0 0 18px; }
.kd-pick.kd-pick-root { padding-left: 0; }
.kd-pick-row { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 4px 8px; border-radius: 8px;
  font-size: 14px; cursor: pointer; min-width: 0; }
.kd-pick-row > span:first-of-type { overflow-wrap: anywhere; min-width: 0; }
.kd-pick-row .icon { color: var(--violet); flex: none; }
.kd-pick-row:hover { background: var(--surface-2); }
.kd-pick-row:has(input:checked) { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.kd-pick-row input { margin: 0; accent-color: var(--violet); width: 16px; height: 16px; flex: none; }
.kd-pick-row.kd-off { color: var(--faint); cursor: not-allowed; }
.kd-pick-row.kd-off .icon { color: var(--faint); }
.kd-pick-note { margin-left: auto; }
.kd-picker-form .form-actions { margin-top: var(--s4); }
.kd-chosen-list .link-row { min-height: 44px; }

/* ---------------------------------------------------------------- access-change confirmation */
.kd-confirm-lead { margin: 0 0 var(--s4); line-height: 1.5; }
.kd-change { border: 1px solid var(--border); border-radius: var(--r); margin-bottom: var(--s3); overflow: hidden; }
.kd-change-h { margin: 0; padding: var(--s2) var(--s3); font-size: 13px; font-weight: 600; background: var(--surface-2);
  border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.kd-change-list { list-style: none; margin: 0; padding: 0; }
.kd-change-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px var(--s3);
  padding: var(--s2) var(--s3); border-bottom: 1px solid var(--border); }
.kd-change-row:last-child { border-bottom: 0; }
.kd-change-row.gain { box-shadow: inset 3px 0 0 var(--warn); }
.kd-change-row.lose, .kd-change-row.both { box-shadow: inset 3px 0 0 var(--info); }
.kd-change-who { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.kd-change-what { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; }
.kd-lvl { padding: 1px 8px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); }
.kd-lvl-new { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.kd-arrow { color: var(--muted); }
.kd-confirm-form { margin-top: var(--s4); }
.kd-confirm-card { max-width: 760px; }

/* ---------------------------------------------------------------- removing a folder */
.kd-counts { list-style: none; margin: 0 0 var(--s4); padding: 0; display: flex; flex-wrap: wrap; gap: var(--s3); }
.kd-counts li { display: flex; align-items: baseline; gap: 6px; padding: var(--s2) var(--s3); border-radius: var(--r);
  background: var(--surface-2); }
.kd-counts strong { font: 600 20px/1 var(--font-display); }
.kd-options { display: grid; gap: var(--s3); }
.kd-option { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s3); align-items: start; padding: var(--s3);
  border: 1px solid var(--border); border-radius: var(--r); cursor: pointer; }
.kd-option:has(input:checked) { border-color: var(--violet); background: var(--accent-soft); }
.kd-option input { margin-top: 3px; accent-color: var(--violet); }
.kd-option > span { display: grid; gap: 4px; min-width: 0; }
.kd-option.kd-off { opacity: .7; cursor: not-allowed; }
.kd-option-sub { margin: 0 0 0 calc(var(--s3) + 22px); }
.kd-why-not { color: var(--warn); }
.kd-soon { color: var(--warn); font-weight: 600; }
.kd-remove { max-width: 760px; }

/* ---------------------------------------------------------------- share panel */
.kd-share-add { border-bottom: 1px solid var(--border); }
.kd-share-form { display: grid; grid-template-columns: minmax(0, 2fr) minmax(130px, 1fr) auto; gap: var(--s3); align-items: end; }
.kd-share-who { grid-column: 1; min-width: 0; }
.kd-share-who .kd-who-filter { margin-bottom: 6px; }
.kd-share-sub { grid-column: 1 / -1; order: 4; }
.kd-share-sub[hidden] { display: none; }
.kd-share-go { display: flex; align-items: end; }
.kd-people-h { font-size: 14px; margin: 0 0 var(--s2); }
.kd-group-h { margin: var(--s4) 0 var(--s2); font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); overflow-wrap: anywhere; }
.kd-group-h:first-of-type { margin-top: var(--s2); }
.kd-group-h a { text-transform: none; letter-spacing: 0; font-size: 13px; }
.kd-people-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.kd-person-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto auto; align-items: center; gap: var(--s3);
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); }
.kd-person-row.kd-inherited { grid-template-columns: 34px minmax(0, 1fr) auto; background: var(--surface-2); }
.kd-avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft);
  color: var(--accent-text); }
.kd-av-everyone { background: var(--good-soft); color: var(--good); }
.kd-av-role { background: var(--info-soft); color: var(--info); }
.kd-person { display: flex; flex-direction: column; min-width: 0; }
.kd-person .kd-who { overflow-wrap: anywhere; }
.kd-level-form { margin: 0; display: flex; gap: 6px; align-items: center; }
.kd-level { min-width: 120px; max-width: 220px; height: 34px; }
.kd-remove-form { margin: 0; }
.kd-x { min-width: 32px; padding: 0 6px; }
.kd-pill { display: inline-flex; align-items: center; min-height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12.5px;
  font-weight: 600; background: var(--accent-soft); color: var(--accent-text); white-space: nowrap; }
.kd-levels { margin: 0; display: grid; gap: var(--s2); }
.kd-levels div { display: grid; gap: 2px; }
.kd-levels dt { font-weight: 600; }
.kd-levels dd { margin: 0; color: var(--muted); }
.kd-check-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s3); align-items: end; }
.kd-explain-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); margin: var(--s4) 0 var(--s2); }
.kd-explain-head .kd-check-h { margin: 0; }
.kd-explain .kd-why { display: block; margin-top: 2px; color: var(--text-2); }
.kd-explain li > span:last-child { min-width: 0; overflow-wrap: anywhere; }

@media (max-width: 640px) {
  .kd-item { grid-template-columns: 24px auto minmax(0, 1fr) auto; gap: var(--s2); padding: var(--s3) var(--s2); }
  .kd-share-form { grid-template-columns: minmax(0, 1fr); }
  .kd-share-sub { order: 0; }
  .kd-person-row { grid-template-columns: 30px minmax(0, 1fr) auto; }
  .kd-person-row .kd-level-form { grid-column: 2 / 3; }
  .kd-person-row .kd-remove-form { grid-column: 3; grid-row: 2; }
  .kd-person-row .kd-avatar { width: 30px; height: 30px; }
  .kd-person-row.kd-inherited { grid-template-columns: 30px minmax(0, 1fr); }
  .kd-person-row.kd-inherited .kd-pill { grid-column: 2; justify-self: start; }
  .kd-level { min-width: 0; width: 100%; max-width: none; }
  .kd-check-form { grid-template-columns: minmax(0, 1fr); }
  .kd-option-sub { margin-left: 0; }
  dialog.kd-dialog { padding: var(--s4); }
}
@media (prefers-reduced-motion: reduce) { .kd-item { transition: none; } }
