/* Shared modal component — used across every portal (PLATFORM today;
   COMPETITION/STUDIO later, per owner's ask). Lives outside any one
   portal's folder since it's genuinely cross-portal, same reasoning as
   public/sdk/ being its own top-level sibling.

   Uses the same CSS custom property NAMES the PLATFORM console already
   defines on :root (--bg, --panel, --panel-border, --text, --accent,
   --danger, --radius), with fallback values so this file still renders
   sensibly in a portal that hasn't defined them yet. */

.cr-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  overflow-y: auto;
  padding: 40px 16px; /* enforced min top/bottom margin, even while scrolled */
  background: rgba(6, 7, 10, 0.6);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.cr-modal-overlay.cr-modal-hidden { display: none; }

/* margin:auto on the panel (not justify/align-items:center on the
   overlay) is the deliberate choice here — a flex container with
   align-items/justify-content:center clips an overflowing child at the
   top when the container scrolls (a well-known flexbox behavior), which
   would break "tall content causes full scrolling with a real top
   margin." margin:auto degrades correctly: centers when it fits, and
   still exposes the full element (with the overlay's own padding acting
   as the top/bottom margin) via ordinary scrolling when it doesn't. */
.cr-modal-panel {
  position: relative;
  margin: auto;
  width: 100%;
  max-width: var(--cr-modal-width, 480px);
  background: var(--panel, #171a21);
  border: 1px solid var(--panel-border, #262b36);
  border-radius: var(--radius, 10px);
  color: var(--text, #e6e9ef);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.cr-modal-panel.cr-modal-size-sm { --cr-modal-width: 360px; }
.cr-modal-panel.cr-modal-size-md { --cr-modal-width: 480px; }
.cr-modal-panel.cr-modal-size-lg { --cr-modal-width: 680px; }
.cr-modal-panel.cr-modal-size-xl { --cr-modal-width: 900px; }

/* Internal-scroll variant (opt-in): the panel itself gets a max height
   and only its body scrolls, instead of the whole overlay. */
.cr-modal-panel.cr-modal-internal-scroll {
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
}
.cr-modal-panel.cr-modal-internal-scroll .cr-modal-body {
  overflow-y: auto;
  min-height: 0;
}

.cr-modal-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 44px 16px 20px; /* right padding clears the close X */
  border-bottom: 1px solid var(--panel-border, #262b36);
  flex: none;
}
.cr-modal-titlebar.cr-modal-draggable { cursor: grab; user-select: none; }
.cr-modal-titlebar.cr-modal-draggable:active { cursor: grabbing; }
.cr-modal-title { margin: 0; font-size: 15px; font-weight: 600; }

/* The close X always exists — never something a caller has to remember
   to add as a button — positioned top-right of the panel whether or not
   a title row is present. */
.cr-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-dim, #9aa3b2);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.cr-modal-close:hover { background: rgba(255, 255, 255, 0.08); color: var(--text, #e6e9ef); }

.cr-modal-body {
  padding: 20px;
}
.cr-modal-panel.cr-modal-no-titlebar .cr-modal-body { padding-top: 40px; } /* room for the floating X */

.cr-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--panel-border, #262b36);
  flex: none;
}
.cr-modal-footer:empty { display: none; }

.cr-modal-btn {
  appearance: none;
  border: none;
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent, #5b8cff);
  color: white;
}
.cr-modal-btn:hover { filter: brightness(1.08); }
.cr-modal-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.cr-modal-btn-ghost { background: transparent; border: 1px solid var(--panel-border, #262b36); color: var(--text, #e6e9ef); }
.cr-modal-btn-danger { background: var(--danger, #ff6b6b); }
.cr-modal-btn-icon { display: inline-flex; flex: none; }

/* Screen takeover on mobile — same breakpoint the PLATFORM shell already
   uses for its own sidebar collapse. Opt-out via mobileTakeover:false. */
@media (max-width: 768px) {
  .cr-modal-overlay.cr-modal-mobile-takeover { padding: 0; }
  .cr-modal-overlay.cr-modal-mobile-takeover .cr-modal-panel {
    margin: 0;
    width: 100vw;
    max-width: none;
    min-height: 100vh;
    max-height: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
  }
  .cr-modal-overlay.cr-modal-mobile-takeover .cr-modal-panel .cr-modal-body {
    flex: 1;
    overflow-y: auto;
  }
}

.cr-modal-panel.cr-modal-dragging { transition: none; }
