/* ============================================================================
   "Use existing file" picker
   ----------------------------------------------------------------------------
   Scoped under #existingForm with explicit values rather than leaning on the
   generic panel input rules, so this block stays self-contained and predictable
   no matter what is loaded before or after it. Every rule that must win uses
   #existingForm, which is more specific than any bare class or element rule.
   ========================================================================== */

#existingForm {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

#existingForm:not([hidden]) {
  display: flex;
}

#existingForm .picker {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin: 0;
}

/* ---------- Trigger button ---------- */

#existingForm .picker-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--text-dim);
}

#existingForm .picker-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  margin: 0;
  padding: 12px 15px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  color: var(--text);
  font: inherit;
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  appearance: none;
  -webkit-appearance: none;
}

#existingForm .picker-btn:hover {
  border-color: #45455c;
  background: #1b1b26;
}

#existingForm .picker-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#existingForm .picker-btn[aria-expanded="true"] {
  border-color: var(--accent);
  background: rgba(255, 45, 85, 0.07);
}

#existingForm .picker-value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#existingForm .picker-value.placeholder {
  color: var(--text-dim);
  font-weight: 500;
}

#existingForm .picker-caret {
  flex: 0 0 auto;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--text-dim);
  transition: transform 0.18s ease;
}

#existingForm .picker-btn[aria-expanded="true"] .picker-caret {
  transform: rotate(180deg);
}

/* ---------- Dropdown menu ----------
   Fixed positioning is set deliberately: positionPicker() in admin.js places it
   against the trigger's viewport rect, so no ancestor overflow can clip it, it
   survives page scroll, and it can flip above the button on short screens. */

#existingForm .picker-menu {
  position: fixed;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 12px;
  border: 1px solid #33334a;
  border-radius: 13px;
  background: #16161f;
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.7);
  overflow: hidden;
}

/* ---------- Search box ---------- */

#existingForm .picker-menu input[type="search"] {
  display: block;
  flex: 0 0 auto;
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #0d0d14;
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  line-height: 1.4;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

#existingForm .picker-menu input[type="search"]::placeholder {
  color: #6c6c80;
}

#existingForm .picker-menu input[type="search"]:focus {
  border-color: var(--accent);
}

/* ---------- File rows ---------- */

#existingForm .picker-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  /* Shrinkable so the menu can be height-capped; the list scrolls internally. */
  flex: 1 1 auto;
  min-height: 0;
  max-height: 300px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #3a3a4e transparent;
}

#existingForm .picker-list::-webkit-scrollbar {
  width: 9px;
}

#existingForm .picker-list::-webkit-scrollbar-thumb {
  background: #3a3a4e;
  border-radius: 6px;
}

#existingForm .picker-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.13s ease, border-color 0.13s ease;
  appearance: none;
  -webkit-appearance: none;
}

#existingForm .picker-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

#existingForm .picker-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

#existingForm .picker-item.selected {
  border-color: var(--accent);
  background: rgba(255, 45, 85, 0.11);
}

#existingForm .picker-item-body {
  flex: 1;
  min-width: 0;
}

#existingForm .picker-item-name {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#existingForm .picker-item-sub {
  margin-top: 3px;
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#existingForm .picker-item-check {
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 15px;
  font-weight: 800;
  line-height: 1;
}

/* ---------- Empty state and footer ---------- */

#existingForm .picker-empty {
  padding: 18px 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-dim);
  text-align: center;
}

#existingForm .picker-foot {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-dim);
}

#existingForm .picker-foot .btn {
  flex: 0 0 auto;
}

/* ---------- Narrow screens ---------- */

@media (max-width: 560px) {
  #existingForm .picker-list {
    max-height: 240px;
  }

  #existingForm .picker-item-sub {
    white-space: normal;
    word-break: break-word;
  }
}
