/*
 * Bulk Play Copy (#303)
 * ---------------------
 * Styles for the bulk-copy mode toggle, sticky action bar, per-card selection
 * checkboxes, selected-card highlight, master-view representative hint, and the
 * confirm modal. Lifted from the designer mockups
 * (docs/mockups/2026-09-21-issue-303-bulk-play-copy/src/_shared.css, the
 * ">>> NEW COMPONENT <<<" blocks) and adapted to the real DOM produced by
 * app/views/shared/_bulk_copy_controls.html.erb + app/javascript/bulk_copy.js.
 *
 * Design rules honoured:
 *   - Amber --primary is the ONLY selection accent (never offense/defence).
 *   - All values come from variables.css / existing components — no new tokens.
 *   - Selected card uses NO transform → zero layout shift.
 *   - Multi-cue selection (ring + wash + filled box + corner tick).
 *
 * NOTE ON LOAD ORDER: this file MUST be loaded AFTER forms_dark.css in the layout,
 * because forms_dark.css applies `!important` to every <input>/<select>. The
 * rules below use matching-or-higher specificity plus !important where needed so
 * the custom checkbox / toggle / select styling wins.
 */

/* ==========================================================================
   1 · Bulk-copy toggle button (toolbar)
   ========================================================================== */
.icon-btn.btn-bulk-toggle[aria-pressed="true"] {
  background: var(--primary) !important;
  color: #fff !important;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
}
.icon-btn.btn-bulk-toggle[aria-pressed="true"]:hover:not(:disabled) {
  background: var(--btn-primary-hover) !important;
}

/* Primary "Copy" CTAs (bar submit + confirm modal) must render amber.
   forms_dark.css applies a broad-brush `button:not(...)` rule at specificity
   (0,7,2) that forces every <button> to the secondary background, overriding
   the .btn-primary amber rule. We win via the existing element IDs (specificity
   1,x,y), which dominate regardless of theme since the tokens swap themselves. */
#bulk-bar [data-bulk-copy-submit].btn-primary,
#bulk-copy-confirm-overlay [data-bulk-confirm-copy].btn-primary {
  background: var(--btn-primary-bg) !important;
  color: var(--btn-primary-text) !important;
  border-color: var(--btn-primary-bg) !important;
}
#bulk-bar [data-bulk-copy-submit].btn-primary:hover:not(:disabled),
#bulk-copy-confirm-overlay [data-bulk-confirm-copy].btn-primary:hover:not(:disabled) {
  background: var(--btn-primary-hover) !important;
  border-color: var(--btn-primary-hover) !important;
}

/* ==========================================================================
   2 · Sticky bulk action bar
   ========================================================================== */
.bulk-bar {
  position: sticky;
  /* Dock just below the sticky top bar (mockups had no top bar). */
  top: var(--topbar-height);
  z-index: 150;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
  background: var(--primary-light);
  border: 1px solid rgba(var(--primary-rgb), 0.35);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 0.65rem 0.9rem;
  margin-bottom: 1rem;
}
/* Respect the `hidden` attribute the JS toggles (author styles beat UA [hidden]). */
.bulk-bar[hidden] {
  display: none;
}
html.dark-mode .bulk-bar {
  background: var(--bg-tertiary);
  border-color: rgba(var(--primary-rgb), 0.4);
}

/* Select-all control ------------------------------------------------------- */
.bulk-select-all {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-color);
  cursor: pointer;
  user-select: none;
}
html.dark-mode .bulk-select-all {
  color: var(--text-color);
}
.bulk-select-all > span {
  white-space: nowrap;
}

/* Live count -------------------------------------------------------------- */
.bulk-bar-count {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}
.bulk-bar-count strong {
  color: var(--primary);
  font-weight: 700;
}

/* Divider ----------------------------------------------------------------- */
.bulk-bar-divider {
  width: 1px;
  align-self: stretch;
  background: rgba(var(--primary-rgb), 0.25);
  margin: 0 0.1rem;
}

/* Destination picker ------------------------------------------------------ */
.bulk-bar-destination {
  display: inline-flex;
  align-items: center;
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
}
.bulk-bar .form-control,
.bulk-bar #bulk-target-playbook {
  min-width: 15rem;
  max-width: 20rem;
  width: auto;
  padding: 0.45rem 0.65rem;
  font-size: 0.875rem;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  color: var(--input-text);
}
.bulk-bar .form-control:focus,
.bulk-bar #bulk-target-playbook:focus {
  outline: none;
  border-color: var(--input-focus) !important;
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15);
}

/* Right-aligned actions --------------------------------------------------- */
.bulk-bar-actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

/* ==========================================================================
   3 · Custom checkbox visuals (per-card + select-all)
   The real DOM nests the <input> inside a <label>. With `appearance: none` the
   input becomes a regular box so ::before/::after render reliably.
   ========================================================================== */

/* Per-card checkbox: the <label.bulk-checkbox> is the positioned wrapper. */
.bulk-checkbox {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 30;
  display: none;
  line-height: 0;
  cursor: pointer;
}
/* Revealed only while the surrounding root is in bulk-copy mode. */
.bulk-copy-mode .bulk-checkbox {
  display: inline-flex;
}

/* The actual checkbox box (per-card + select-all share this look). */
.bulk-copy-mode .bulk-checkbox-input,
.bulk-select-all #bulk-select-all {
  appearance: none;
  -webkit-appearance: none;
  width: 1.375rem;
  height: 1.375rem;
  margin: 0;
  flex-shrink: 0;
  background: var(--card-bg) !important;
  border: 2px solid var(--border-color) !important;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  transition: background 0.12s ease, border-color 0.12s ease;
}
/* Select-all box is slightly smaller and sits inline (no floating shadow). */
.bulk-select-all #bulk-select-all {
  width: 1.25rem;
  height: 1.25rem;
  box-shadow: none;
}

/* Checked → amber fill + white tick --------------------------------------- */
.bulk-copy-mode .bulk-checkbox-input:checked,
.bulk-select-all #bulk-select-all:checked {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
}
.bulk-copy-mode .bulk-checkbox-input:checked::after,
.bulk-select-all #bulk-select-all:checked::after {
  content: "";
  width: 0.7rem;
  height: 0.4rem;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translateY(-1px);
}

/* Indeterminate (mixed) select-all → amber fill + white dash -------------- */
.bulk-select-all #bulk-select-all:indeterminate {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
}
.bulk-select-all #bulk-select-all:indeterminate::after {
  content: "";
  width: 0.7rem;
  height: 0;
  border-top: 2px solid #fff;
  transform: none;
}

/* Keyboard focus ring ----------------------------------------------------- */
.bulk-copy-mode .bulk-checkbox-input:focus-visible,
.bulk-select-all #bulk-select-all:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.45);
}

/* ==========================================================================
   4 · Selected card state (no transform → zero layout shift)
   ========================================================================== */
.play-card.is-selected {
  box-shadow: 0 0 0 3px var(--primary), var(--shadow-md);
  background:
    linear-gradient(rgba(var(--primary-rgb), 0.06), rgba(var(--primary-rgb), 0.06)),
    var(--card-bg);
}
html.dark-mode .play-card.is-selected {
  background:
    linear-gradient(rgba(var(--primary-rgb), 0.12), rgba(var(--primary-rgb), 0.12)),
    var(--card-bg);
}
/* Keep the hover lift consistent so selection never shifts layout. */
.play-card.is-selected:hover {
  transform: translateY(-2px);
}
/* Corner tick badge for extra legibility on busy diagrams. */
.play-card.is-selected::after {
  content: "\2713";
  position: absolute;
  bottom: 0.4rem;
  right: 0.4rem;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 25;
  box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   5 · Drag-handle suppression while in bulk mode
   (Reorder is mutually exclusive with bulk selection.)
   ========================================================================== */
.bulk-copy-mode .drag-handle {
  display: none;
}

/* ==========================================================================
   6 · Master-view representative-play hint
   JS toggles the `hidden` attribute; we style the visible state.
   ========================================================================== */
.master-hint {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 15;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0));
  color: #fff;
  font-size: 0.62rem;
  line-height: 1.25;
  padding: 1.1rem 0.5rem 0.4rem;
  pointer-events: none;
  text-align: center;
}
.master-hint[hidden] {
  display: none;
}
.master-hint svg {
  vertical-align: -2px;
  margin-right: 0.15rem;
}

/* ==========================================================================
   7 · Confirm modal summary
   ========================================================================== */
.bulk-confirm-summary {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0.65rem 0.85rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  max-height: 12rem;
  overflow: auto;
}
.bulk-confirm-item {
  font-size: 0.85rem;
  padding: 0.2rem 0;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.bulk-confirm-swatch {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid color-mix(in srgb, var(--text-color) 20%, transparent);
}
.bulk-confirm-name {
  color: var(--text-color);
}
#bulk-copy-confirm-text {
  color: var(--text-color);
  line-height: 1.45;
}
#bulk-copy-confirm-text strong {
  color: var(--primary);
}

/* ==========================================================================
   8 · Responsive
   ========================================================================== */
@media (max-width: 560px) {
  .bulk-bar {
    gap: 0.5rem;
  }
  .bulk-bar-divider {
    display: none;
  }
  .bulk-bar-destination {
    width: 100%;
  }
  .bulk-bar .form-control,
  .bulk-bar #bulk-target-playbook {
    max-width: none;
    width: 100%;
  }
  .bulk-bar-actions {
    width: 100%;
  }
  .bulk-bar-actions .btn {
    flex: 1;
  }
}

/* ==========================================================================
   9 · Print — never show bulk-copy chrome on printed output
   ========================================================================== */
@media print {
  .bulk-bar,
  .bulk-checkbox,
  .btn-bulk-toggle,
  #bulk-copy-confirm-overlay,
  .master-hint {
    display: none !important;
  }
}
