/* =========================================================
   BuriedKeep Core Listing Panel

   Purpose:
     Reusable, plugin-optional Listing Panel framework.

   Filesystem path:
     shared/css/core-listing-panel.css

   Browser path:
     /_shared/css/core-listing-panel.css

   Rules:
     - Core supplies layout/behavior styling.
     - Plugins supply data, storage, and meaning.
     - Uses theme variables from global-1.css.
   ========================================================= */

/* Canonical, theme-aware Listing Panel appearance tokens.
   Plugins supply records and actions, not standard pillbox appearance.
   Theme selectors target the containing panel so independently themed panels work. */
.bk-listing-panel-core {
  --bk-listing-pill-background: rgba(255,255,255,0.48);
  --bk-listing-pill-hover-background: rgba(255,255,255,0.68);
  --bk-listing-pill-selected-background: rgba(255,255,255,0.78);
  --bk-listing-pill-border-color: #d9d3b9;
  --bk-listing-pill-selected-border-color: var(--theme-gold-border, #d0a94f);
}
.bk-panel.theme-gold .bk-listing-panel-core {
  --bk-listing-pill-selected-border-color: var(--theme-gold-border, #d0a94f);
}
.bk-panel.theme-silver .bk-listing-panel-core {
  --bk-listing-pill-selected-border-color: var(--theme-silver-border, #b6b7c5);
}
.bk-panel.theme-copper .bk-listing-panel-core {
  --bk-listing-pill-selected-border-color: var(--theme-copper-border, #a1674a);
}

.bk-listing-panel-core {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-height: 0;
}

.bk-listing-panel-core .bk-listing-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 32px;
  border-bottom: var(--border-soft);
  padding-bottom: 0.35rem;
}

.bk-listing-panel-core .bk-listing-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  line-height: 1.1;
  color: var(--text-main);
}

.bk-listing-panel-core .bk-listing-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex: 0 0 auto;
}

.bk-listing-panel-core .bk-listing-icon-button {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.bk-listing-panel-core .bk-listing-icon-button:hover {
  background: rgba(0,0,0,0.07);
}

.bk-listing-panel-core .bk-listing-icon-button img {
  width: 18px;
  height: 18px;
  display: block;
}

.bk-listing-panel-core .bk-listing-items {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-height: 0;
  overflow: auto;
  padding: 0.15rem 0.1rem 0.1rem;
}

.bk-listing-panel-core .bk-listing-empty,
.bk-listing-panel-core .bk-listing-loading {
  padding: 0.75rem;
  border-radius: 12px;
  border: var(--border-soft);
  background: rgba(255,255,255,0.45);
  opacity: 0.82;
  font-size: 0.95rem;
}

.bk-listing-pillbox {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 0.16rem;
  min-height: 34px;
  padding: 0.42rem 0.58rem;
  border: 1px solid var(--bk-listing-pill-border-color);
  border-radius: 999px;
  background: var(--bk-listing-pill-background);
  color: var(--text-main);
  text-align: left;
  cursor: pointer;
  box-sizing: border-box;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.bk-listing-pillbox:hover {
  background: var(--bk-listing-pill-hover-background);
}

.bk-listing-pillbox.is-selected {
  border: 1px solid var(--bk-listing-pill-selected-border-color);
  background: var(--bk-listing-pill-selected-background);
}

.bk-listing-pillbox.is-favorite .bk-listing-primary::before {
  content: "★";
  margin-right: 0.35rem;
  color: var(--accent-gold);
}

.bk-listing-pillbox.is-dragging {
  opacity: 0.45;
}

.bk-listing-pillbox.drop-before {
  box-shadow: 0 -3px 0 var(--accent-gold);
}

.bk-listing-pillbox.drop-after {
  box-shadow: 0 3px 0 var(--accent-gold);
}

.bk-listing-primary {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-text, var(--font-body));
  font-size: var(--bk-note-text-size, 16px);
  font-weight: 850;
  line-height: 1.16;
}

.bk-listing-secondary {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-text, var(--font-body));
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.1;
  opacity: 0.72;
}

.bk-listing-pillbox[data-pillbox-mode="one-row"] .bk-listing-secondary {
  display: none;
}

.bk-listing-context-menu {
  position: fixed;
  z-index: 2600;
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  padding: 0.3rem;
  border: var(--border-soft);
  border-radius: 12px;
  background: var(--bg-panel);
  box-shadow: var(--shadow-soft);
}

.bk-listing-context-menu[hidden] {
  display: none;
}

.bk-listing-context-action {
  appearance: none;
  -webkit-appearance: none;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.bk-listing-context-action:hover {
  background: rgba(0,0,0,0.07);
}

.bk-listing-context-action img {
  display: block;
  width: 18px;
  height: 18px;
}

.bk-listing-context-action.is-danger:hover {
  background: rgba(122,11,11,0.12);
}

/* ===== v0.2 Pass 2: adaptive width + hierarchy ===== */
.bk-listing-panel-core { --bk-listing-compact-width: 52px; box-sizing:border-box; transition: width .18s ease; }
.bk-listing-panel-core[data-listing-width-state="normal"] { width: 100%; max-width:100%; }
.bk-listing-panel-core[data-listing-width-state="expanded"] {
  width: var(--bk-listing-expanded-width, 66.666vw);
  max-width:none;
  position:relative;
  z-index:40;
  overflow:auto;
  box-shadow:8px 0 18px rgba(0,0,0,.18);
}
.bk-listing-panel-core[data-listing-width-state="compact"] {
  width: var(--bk-listing-compact-width);
  min-width:var(--bk-listing-compact-width);
  max-width:var(--bk-listing-compact-width);
  overflow:hidden;
}
.bk-listing-panel-core[data-listing-width-state="compact"] .bk-listing-title,
.bk-listing-panel-core[data-listing-width-state="compact"] .bk-listing-header-actions,
.bk-listing-panel-core[data-listing-width-state="compact"] .bk-listing-items { opacity: 0; pointer-events: none; }
.bk-listing-panel-core .bk-listing-header-actions { display:flex; align-items:center; gap:.25rem; }
.bk-listing-category { display:block; min-width:0; }
.bk-listing-category-header { display:flex; align-items:center; gap:.25rem; min-height:32px; padding-left:calc(var(--bk-category-depth, 0) * 1rem); border-radius:8px; }
.bk-listing-category-header:hover { background:rgba(255,255,255,.34); }
.bk-listing-category-name { min-width:0; flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-weight:800; }
.bk-listing-category-actions { display:inline-flex; gap:.2rem; margin-left:auto; }
.bk-listing-disclosure { width:26px; height:26px; padding:5px; border:0; background:transparent; border-radius:6px; cursor:pointer; }
.bk-listing-disclosure img { width:16px; height:16px; display:block; }
.bk-listing-category-create { display:flex; align-items:center; gap:.25rem; padding:.3rem .2rem; }
.bk-listing-category-create input { min-width:0; flex:1; padding:.4rem .5rem; border:var(--border-soft); border-radius:8px; background:var(--bg-panel); color:var(--text-main); }
.bk-listing-pillbox { margin-left:calc(var(--bk-category-depth, 0) * 1rem); width:calc(100% - (var(--bk-category-depth, 0) * 1rem)); }
.bk-listing-first-line { display:flex; align-items:center; gap:.65rem; min-width:0; }
.bk-listing-first-line .bk-listing-primary { flex:1; }
.bk-listing-expanded-dates { flex:0 0 auto; font-size:.75rem; font-weight:650; opacity:.72; white-space:nowrap; }
.bk-listing-panel-core[data-listing-width-state="expanded"] .bk-listing-secondary { display:block; }
.bk-listing-panel-core[data-listing-width-state="expanded"] .bk-listing-pillbox { border-radius:16px; }
.bk-listing-pillbox.drop-inside,.bk-listing-category-header.drop-inside { box-shadow:inset 0 0 0 2px var(--accent-gold); }
.bk-listing-category-header.drop-before { box-shadow:0 -3px 0 var(--accent-gold); }
.bk-listing-category-header.drop-after { box-shadow:0 3px 0 var(--accent-gold); }
@media (max-width: 800px) {
  .bk-listing-panel-core[data-listing-width-state="expanded"] { width:100%; flex-basis:100%; }
}
/* Pass 3 inline category rename */
.bk-listing-category-rename-input {
  box-sizing: border-box;
  min-width: 6rem;
  width: min(18rem, calc(100% - 5rem));
  font: inherit;
  line-height: inherit;
}
.bk-listing-category-rename-input.is-invalid {
  outline: 2px solid currentColor;
}
/* Pass 3 compact anchored Move to Category chooser */
.bk-listing-move-chooser {
  box-sizing: border-box;
  max-height: 16rem;
  overflow-y: auto;
  padding: .25rem;
  border: var(--border-soft);
  border-radius: 8px;
  background: var(--bg-panel);
  color: var(--text-main);
  box-shadow: 0 8px 22px rgba(0,0,0,.22);
}
.bk-listing-move-option {
  box-sizing: border-box;
  padding: .38rem .55rem;
  border-radius: 6px;
  cursor: default;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bk-listing-move-option.is-selected {
  outline: 1px solid var(--accent-gold);
  background: rgba(255,255,255,.34);
}
/* Pass 3 compact anchored Delete confirmation */
.bk-listing-delete-popover {
  box-sizing: border-box;
  padding: .55rem;
  border: var(--border-soft);
  border-radius: 8px;
  background: var(--bg-panel);
  color: var(--text-main);
  box-shadow: 0 8px 22px rgba(0,0,0,.22);
}
.bk-listing-delete-message { margin-bottom: .45rem; }
.bk-listing-delete-actions { display:flex; justify-content:flex-end; gap:.35rem; }
.bk-listing-delete-icon {
  display:inline-flex; align-items:center; justify-content:center;
  width:30px; height:30px; padding:0;
  border:var(--border-soft); border-radius:6px;
  background:var(--bg-panel); color:var(--text-main);
  font:inherit; font-weight:800; cursor:pointer;
}
.bk-listing-delete-icon:hover,
.bk-listing-delete-icon:focus { outline:1px solid var(--accent-gold); }
.bk-listing-delete-choice {
  display:block; width:100%; text-align:left;
  padding:.38rem .5rem; margin-top:.25rem;
  border:0; border-radius:6px; background:transparent; color:inherit; cursor:pointer;
}
.bk-listing-delete-choice:hover,
.bk-listing-delete-choice:focus { background:rgba(255,255,255,.34); outline:1px solid var(--accent-gold); }
/* Pass 3 single-step nonempty category Delete chooser */
.bk-listing-delete-mode-choices {
  display:flex;
  flex-direction:column;
  gap:.3rem;
  margin:.2rem 0 .5rem;
}
.bk-listing-delete-mode-choice {
  display:flex;
  align-items:center;
  gap:.45rem;
  padding:.28rem .35rem;
  border-radius:6px;
  cursor:pointer;
}
.bk-listing-delete-mode-choice:hover,
.bk-listing-delete-mode-choice:focus-within {
  background:rgba(255,255,255,.34);
}
.bk-listing-delete-mode-choice input[type="checkbox"] {
  flex:0 0 auto;
}
.bk-listing-delete-mode-popover .bk-listing-delete-actions {
  justify-content:flex-start;
}
/* Pass 3 Delete action alignment: OK checkmark then Cancel X, lower right */
.bk-listing-delete-popover .bk-listing-delete-actions,
.bk-listing-delete-mode-popover .bk-listing-delete-actions {
  justify-content: flex-end;
  align-items: center;
}

/* Workspace theme is authoritative over legacy panel-specific classes. */
body .bk-panel.bk-core-listings .bk-listing-panel-core {
  --bk-listing-pill-selected-border-color: var(--bk-workspace-border);
}

/* Pillbox button and label: do not inherit browser button defaults. */
.bk-listing-panel-core .bk-listing-pillbox,
.bk-listing-pillbox, .bk-listing-pillbox .bk-listing-primary, .bk-listing-pillbox .bk-listing-secondary { font-family: var(--bk-standard-ui-font, "Metamorphous", serif); font-size: 12px; }

/* Shared Listing Panel category labels: independent of note pillbox size. */
.bk-listing-panel-core .bk-listing-category-name {
  font-family: var(--bk-standard-ui-font, "Metamorphous", serif);
  font-size: 14px;
}
