/* ============================================================================
   FilterPanel — Selection Filter component (cosmic-crafting-parasol S2)
   Vanilla-JS component styling. Honors FFA design tokens from styles.css.
   ============================================================================ */

.fp-host {
  width: 100%;
  font-family: inherit;
}

.fp-root {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm, 0.5rem);
  padding: var(--space-md, 1rem);
  background: var(--color-bg, #fff);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--radius-md, 0.5rem);
  position: relative;
}

/* ---- Search row ---------------------------------------------------------- */

.fp-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-sm, 0.5rem);
}

.fp-search-row {
  position: relative;
}

.fp-search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-light, #6b7280);
  font-size: var(--font-base, 1rem);
  pointer-events: none;
}

.fp-search-input {
  flex: 1 1 240px;
  min-width: 200px;
  padding: var(--space-sm, 0.5rem) var(--space-md, 1rem) var(--space-sm, 0.5rem) 2.25rem;
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--radius-full, 9999px);
  font-size: var(--font-sm, 0.875rem);
  background: var(--color-bg-secondary, #f3f4f6);
  transition: border-color 0.15s, background 0.15s;
}

.fp-search-input:focus {
  outline: none;
  border-color: var(--color-primary, #3b82f6);
  background: #fff;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.fp-add-btn {
  flex: 0 0 auto;
  padding: var(--space-sm, 0.5rem) var(--space-md, 1rem);
  border: 1px dashed var(--color-border, #e5e7eb);
  background: transparent;
  border-radius: var(--radius-full, 9999px);
  font-size: var(--font-sm, 0.875rem);
  color: var(--color-text, #1f2937);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.fp-add-btn:hover {
  background: var(--color-bg-secondary, #f3f4f6);
  border-color: var(--color-primary, #3b82f6);
  color: var(--color-primary, #3b82f6);
  border-style: solid;
}

/* ---- Chip strip ---------------------------------------------------------- */

.fp-chip-strip {
  min-height: 2rem;
  align-items: center;
}

.fp-chip-empty {
  font-size: var(--font-sm, 0.875rem);
  color: var(--color-text-lighter, #9ca3af);
  font-style: italic;
}

.fp-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.5rem 0.25rem 0.6rem;
  background: linear-gradient(135deg,
    var(--ffa-warm-amber, rgba(245, 158, 11, 0.08)),
    var(--ffa-warm-pink,  rgba(236, 72,  153, 0.06)));
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: var(--radius-full, 9999px);
  font-size: var(--font-sm, 0.875rem);
  color: var(--color-text, #1f2937);
  transition: box-shadow 0.15s, border-color 0.15s;
}

.fp-chip:hover {
  border-color: rgba(245, 158, 11, 0.6);
  box-shadow: 0 1px 4px rgba(245, 158, 11, 0.12);
}

.fp-chip-icon {
  font-size: 0.95em;
  line-height: 1;
}

.fp-chip-label {
  background: transparent;
  border: 0;
  font: inherit;
  color: inherit;
  padding: 0;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  max-width: 28ch;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fp-chip-label:hover {
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: rgba(245, 158, 11, 0.6);
}

.fp-chip-edit,
.fp-chip-remove {
  background: transparent;
  border: 0;
  padding: 0 0.15rem;
  font: inherit;
  color: var(--color-text-light, #6b7280);
  cursor: pointer;
  line-height: 1;
}

.fp-chip-remove {
  font-size: 1.1em;
  color: var(--color-text-lighter, #9ca3af);
}

.fp-chip-remove:hover {
  color: var(--color-danger, #ef4444);
}

.fp-chip-edit:hover {
  color: var(--color-primary, #3b82f6);
}

/* ---- Row actions (right-side: Clear all, Save as) ----------------------- */

.fp-row-actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm, 0.5rem);
}

.fp-clear-all,
.fp-save-as {
  background: transparent;
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--radius-full, 9999px);
  padding: 0.3rem 0.75rem;
  font-size: var(--font-sm, 0.875rem);
  color: var(--color-text, #1f2937);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.fp-clear-all:hover {
  border-color: var(--color-danger, #ef4444);
  color: var(--color-danger, #ef4444);
  background: rgba(239, 68, 68, 0.05);
}

.fp-save-as {
  border-color: var(--color-primary, #3b82f6);
  color: var(--color-primary, #3b82f6);
}

.fp-save-as:hover {
  background: var(--color-primary, #3b82f6);
  color: #fff;
}

/* ---- Caption ------------------------------------------------------------- */

.fp-caption {
  font-size: var(--font-xs, 0.75rem);
  color: var(--color-text-light, #6b7280);
  font-style: italic;
  padding: 0.25rem 0;
  border-top: 1px dashed var(--color-border, #e5e7eb);
}

/* ---- Popover ("[+ Add filter ▾]") --------------------------------------- */

.fp-popover {
  position: absolute;
  z-index: var(--z-tooltip, 50);
  background: #fff;
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--radius-md, 0.5rem);
  box-shadow: var(--shadow-lg, 0 10px 15px rgba(0, 0, 0, 0.1));
  padding: 0.4rem;
  min-width: 12rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  margin-top: 0.5rem;
  right: 0;
}

.fp-popover-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.6rem;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm, 0.25rem);
  font-size: var(--font-sm, 0.875rem);
  color: var(--color-text, #1f2937);
  cursor: pointer;
  text-align: left;
}

.fp-popover-item:hover {
  background: var(--color-bg-secondary, #f3f4f6);
  color: var(--color-primary, #3b82f6);
}

.fp-popover-empty {
  padding: 0.6rem;
  font-size: var(--font-sm, 0.875rem);
  color: var(--color-text-lighter, #9ca3af);
  font-style: italic;
}

.fp-popover-icon {
  font-size: 1em;
  width: 1.25rem;
  text-align: center;
}

/* ---- Editor (in-place pickers) ------------------------------------------ */

.fp-editor {
  background: var(--color-bg-secondary, #f3f4f6);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--radius-md, 0.5rem);
  padding: var(--space-md, 1rem);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm, 0.5rem);
}

.fp-editor-title {
  font-weight: var(--font-semibold, 600);
  font-size: var(--font-sm, 0.875rem);
  color: var(--color-text, #1f2937);
}

.fp-editor-options {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm, 0.5rem) var(--space-md, 1rem);
}

.fp-editor-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm, 0.5rem) var(--space-md, 1rem);
  font-size: var(--font-sm, 0.875rem);
}

.fp-checkbox-row,
.fp-radio-row {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: var(--font-sm, 0.875rem);
  color: var(--color-text, #1f2937);
  cursor: pointer;
  user-select: none;
}

.fp-relation-label {
  color: var(--color-text-light, #6b7280);
  font-size: var(--font-sm, 0.875rem);
}

.fp-people-count {
  color: var(--color-text-light, #6b7280);
  font-size: var(--font-sm, 0.875rem);
}

.fp-profile-current {
  font-weight: var(--font-medium, 500);
}

.fp-editor-actions {
  display: flex;
  gap: var(--space-sm, 0.5rem);
  margin-top: var(--space-sm, 0.5rem);
}

.fp-editor-actions button {
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--radius-md, 0.5rem);
  background: #fff;
  font-size: var(--font-sm, 0.875rem);
  color: var(--color-text, #1f2937);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.fp-editor-actions button:first-child {
  background: var(--color-primary, #3b82f6);
  color: #fff;
  border-color: var(--color-primary, #3b82f6);
}

.fp-editor-actions button:first-child:hover {
  background: #2563eb;
  border-color: #2563eb;
}

.fp-editor-actions button:hover {
  background: var(--color-bg-secondary, #f3f4f6);
}

/* ---- Save-as-Profile inline form (S4 D1) ------------------------------- */

.fp-saveas-form {
  background: var(--color-bg-secondary, #f3f4f6);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--radius-md, 0.5rem);
  padding: var(--space-md, 1rem);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm, 0.5rem);
  /* Subtle accent matching the Save-as button */
  border-color: rgba(59, 130, 246, 0.35);
  box-shadow: 0 1px 4px rgba(59, 130, 246, 0.08);
}

.fp-saveas-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.fp-saveas-label {
  font-size: var(--font-sm, 0.875rem);
  color: var(--color-text, #1f2937);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.fp-saveas-label input {
  padding: var(--space-sm, 0.5rem) var(--space-md, 0.75rem);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--radius-md, 0.5rem);
  font-size: var(--font-sm, 0.875rem);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.fp-saveas-label input:focus {
  outline: none;
  border-color: var(--color-primary, #3b82f6);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.fp-saveas-status {
  font-size: var(--font-xs, 0.75rem);
  color: var(--color-text-light, #6b7280);
  font-style: italic;
  min-height: 1.1em;
}

.fp-saveas-status-error {
  color: var(--color-danger, #ef4444);
  font-style: normal;
}

/* ---- Profile-edit modal hardening (S4 D2) ------------------------------- */
/* The Profile Manager modal scoped to the active profile reuses the existing
   .story-profile-modal-overlay chrome from styles.css. Provide minimal
   defensive sizing in case those rules are unavailable / overridden. */

.story-profile-modal-overlay .story-profile-list {
  max-height: 60vh;
  overflow-y: auto;
}

@media (max-width: 768px) {
  .story-profile-modal-overlay .story-profile-modal {
    width: 96vw;
    max-width: 96vw;
    max-height: 92vh;
  }
}

/* ---- Mobile toggle + bottom sheet --------------------------------------- */

.fp-mobile-toggle {
  display: none;
}

.fp-mobile-sheet {
  display: none;
}

@media (max-width: 768px) {
  /* Collapse desktop UI */
  .fp-root .fp-search-row,
  .fp-root .fp-chip-strip,
  .fp-root .fp-caption {
    display: none;
  }

  .fp-mobile-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.85rem;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: var(--radius-full, 9999px);
    background: #fff;
    color: var(--color-text, #1f2937);
    font-size: var(--font-sm, 0.875rem);
    cursor: pointer;
  }

  .fp-mobile-toggle-count {
    background: var(--color-primary, #3b82f6);
    color: #fff;
    font-size: var(--font-xs, 0.75rem);
    border-radius: var(--radius-full, 9999px);
    padding: 0.1rem 0.5rem;
    min-width: 1.25rem;
    text-align: center;
  }

  .fp-mobile-sheet {
    display: block;
    position: fixed;
    inset: 0;
    z-index: var(--z-modal-secondary, 10001);
  }

  .fp-mobile-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
  }

  /* meticulous-tailoring-canvas S1 (2026-05-10) — D-A3 / Issue #6: Filter
     Library was a bottom half-sheet (max-height: 85vh anchored at bottom: 0)
     whose lower portion sat behind the TabBar — Person section + below-the-fold
     filters were unreachable on iPhone. Per the train's full-screen rule
     (UMI-as-reference framing), Filter Library is a major modal and must
     fill the iPhone display. inset: 0 + max-height: none + safe-area top
     padding mirrors the .browse-media-modal mobile pattern (browse-media.css
     line 65-74). border-radius removed (no longer a sheet). */
  .fp-mobile-sheet-body {
    position: absolute;
    inset: 0;
    max-height: none;
    background: #fff;
    border-radius: 0;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.18);
    animation: fp-sheet-slide-up 0.2s ease-out;
  }

  @keyframes fp-sheet-slide-up {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }

  .fp-mobile-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md, 1rem);
    border-bottom: 1px solid var(--color-border, #e5e7eb);
    font-weight: var(--font-semibold, 600);
    flex-shrink: 0;
  }

  .fp-mobile-sheet-header button {
    background: transparent;
    border: 0;
    font-size: calc(1.5rem * var(--type-scale, 1));
    line-height: 1;
    cursor: pointer;
    color: var(--color-text-light, #6b7280);
  }

  .fp-mobile-sheet-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: var(--space-md, 1rem);
    display: flex;
    flex-direction: column;
    gap: var(--space-md, 1rem);
  }

  .fp-mobile-block {
    border-radius: var(--radius-md, 0.5rem);
  }

  .fp-mobile-sheet-footer {
    display: flex;
    justify-content: space-between;
    gap: var(--space-sm, 0.5rem);
    padding: var(--space-md, 1rem);
    border-top: 1px solid var(--color-border, #e5e7eb);
    background: var(--color-bg-secondary, #f3f4f6);
    flex-shrink: 0;
  }

  .fp-mobile-sheet-footer button {
    flex: 1;
    padding: 0.6rem 1rem;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: var(--radius-md, 0.5rem);
    background: #fff;
    font-size: var(--font-sm, 0.875rem);
    cursor: pointer;
  }

  .fp-mobile-sheet-footer button:last-child {
    background: var(--color-primary, #3b82f6);
    color: #fff;
    border-color: var(--color-primary, #3b82f6);
  }
}

/* Greg G-014 (2026-09-18, FergiPhone greg-l1-iphone-7, media/C6): "Open filters"
   drew 368×36 — a full-width bar 8 px under the floor. */
@media (pointer: coarse) {
  .fp-mobile-toggle { min-height: 44px; }
}
