/* Common Modal Styles
 * Universal modal styles used across all pages (home.html and builder.html)
 * Used by common/modals/Modal.js and common/UtilsShare.js
 *
 * Modal Size Reference Table:
 * ┌────────┬───────────────────┬────────────────┬───────────────────────┬────────────────┬────────────────┬───────────┬───────────┐
 * │  Size  │    Breakpoint     │     Width      │        Height         │   Max-Width    │   Max-Height   │ Draggable │ Resizable │
 * ├────────┼───────────────────┼────────────────┼───────────────────────┼────────────────┼────────────────┼───────────┼───────────┤
 * │ Small  │ Desktop (>1024)   │ 400px          │ auto                  │ 400px          │ 100% - space-4 │ ✓         │ ✗         │
 * │        │ Tablet (768-1024) │ 400px          │ auto                  │ 400px          │ 100% - space-4 │ ✓         │ ✗         │
 * │        │ Mobile (480-768)  │ 400px          │ auto                  │ —              │ 100% - space-2 │ ✗         │ ✗         │
 * │        │ Mini (≤480)       │ 100% - space-2 │ auto                  │ —              │ 100% - space-2 │ ✗         │ ✗         │
 * ├────────┼───────────────────┼────────────────┼───────────────────────┼────────────────┼────────────────┼───────────┼───────────┤
 * │ Medium │ Desktop (>1024)   │ 80vw           │ 80vh                  │ 100% - space-4 │ 100% - space-4 │ ✓         │ ✓         │
 * │        │ Tablet (768-1024) │ 90vw           │ 90vh                  │ 100% - space-4 │ 100% - space-4 │ ✓         │ ✓         │
 * │        │ Mobile (480-768)  │ 100% - space-2 │ 100% - space-2        │ —              │ —              │ ✗         │ ✗         │
 * │        │ Mini (≤480)       │ 100% - space-2 │ 100% - space-2        │ —              │ —              │ ✗         │ ✗         │
 * ├────────┼───────────────────┼────────────────┼───────────────────────┼────────────────┼────────────────┼───────────┼───────────┤
 * │ Large  │ Desktop (>1024)   │ 100% - space-4 │ 100% - space-4        │ —              │ —              │ ✗         │ ✗         │
 * │        │ Tablet (768-1024) │ 100% - space-4 │ 100% - space-4        │ —              │ —              │ ✗         │ ✗         │
 * │        │ Mobile (480-768)  │ 100% - space-2 │ 100% - space-2        │ —              │ —              │ ✗         │ ✗         │
 * │        │ Mini (≤480)       │ 100% - space-2 │ 100% - space-2        │ —              │ —              │ ✗         │ ✗         │
 * └────────┴───────────────────┴────────────────┴───────────────────────┴────────────────┴────────────────┴───────────┴───────────┘
 *
 * Note: "100% - space-N" means calc(100% - var(--space-N) * 2), i.e., space-N on each side.
 * That margin is one token, --modal-margin (below): space-4, and space-2 at
 * 768px and below. Every size, and the JS (the widening cap, drag and resize
 * edges), takes it from there, so modals cannot drift apart.
 *
 * Small grows past 400px when its content cannot fit (a table, a row of
 * controls that overflows sideways), up to 100% - --modal-margin: Modal.create
 * measures it (#fitToContent). Text wraps, so a modal of text stays 400px.
 */

/* The space between a modal and the screen's edge, a side. Registered as a
   length so it computes to px, which is what the JS reads. */
@property --modal-margin {
  syntax: '<length>';
  inherits: true;
  initial-value: 20px;
}

:root {
  --modal-margin: var(--space-4);
}

@media (max-width: 768px) {
  :root {
    --modal-margin: var(--space-2);
  }
}

/* ============================================================================
   Modal Close Button
   ============================================================================ */

.button-bare-inst-modal-close {
  --button-size: 32px;
  --icon-size: 20px;
  --icon-inset: calc((var(--button-size) - var(--icon-size)) / 2);
  position: absolute;
  top: calc(var(--space-2) - var(--icon-inset));
  right: calc(var(--space-2) - var(--icon-inset));
  width: var(--button-size);
  height: var(--button-size);
  color: var(--color-text-dark);
  padding: 0;
  z-index: 1000;
}

.button-bare-inst-modal-close svg {
  width: var(--icon-size);
  height: var(--icon-size);
}

:where(html[data-pointer='mouse']) .button-bare-inst-modal-close:hover {
  color: var(--color-text);
}

/* ============================================================================
   Modal Forms (used by auth/account modals)
   ============================================================================ */

.form-part-group {
  /* No margin - relies on parent gap/padding for spacing */
}

.form-part-group label {
  display: block;
  margin-bottom: var(--space-1);
  color: var(--color-text);
}

.form-part-group > :last-child {
  margin-bottom: 0;
}

/* ============================================================================
   Modal Draggable (default size)
   ============================================================================ */

.modal-part-header-draggable {
  cursor: grab;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

.modal-part-header-draggable:active,
.modal-dragging .modal-part-header-draggable {
  cursor: grabbing;
}

.modal-dragging,
.modal-resizing {
  -webkit-user-select: none;
  user-select: none;
}

/* ============================================================================
   Modal Resizable (medium size)
   ============================================================================ */

.modal-part-resize {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  touch-action: none;
}

.modal-part-resize::before {
  content: '';
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--color-border-light);
  border-bottom: 2px solid var(--color-border-light);
}

/* Hide resize handle on mobile */
@media (max-width: 768px) {
  .modal-part-resize {
    display: none;
  }
}

/* ============================================================================
   Modal Size Variants (see table at top of file)
   ============================================================================ */

/* Small size (default): 400px fixed, constrained max-height */
.modal-sm {
  width: 400px;
  max-width: 400px;
  max-height: calc(100% - var(--modal-margin) * 2);
}

@media (max-width: 768px) {
  .modal-sm {
    max-width: none;
  }
}

@media (max-width: 480px) {
  .modal-sm {
    width: calc(100% - var(--modal-margin) * 2);
  }
}

/* Medium size: 80vw/90vw at desktop/tablet, full at mobile */
.modal-md {
  width: 80vw;
  height: 80vh;
  max-width: calc(100% - var(--modal-margin) * 2);
  max-height: calc(100% - var(--modal-margin) * 2);
}

@media (max-width: 1024px) {
  .modal-md {
    width: 90vw;
    height: 90vh;
  }
}

@media (max-width: 768px) {
  .modal-md {
    width: calc(100% - var(--modal-margin) * 2);
    height: calc(100% - var(--modal-margin) * 2);
    max-width: none;
    max-height: none;
  }
}

/* Large size: full viewport minus spacing, centered */
.modal-lg {
  width: calc(100% - var(--modal-margin) * 2);
  height: calc(100% - var(--modal-margin) * 2);
}

/* ============================================================================
   Modal Prompt (used by Modal.showPrompt)
   ============================================================================ */

.modal-part-prompt-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* ============================================================================
   Modal Bar Checkbox (modifier on .form-part-checkbox-row for the buttonBarLeading slot)
   ============================================================================ */

/* Pairs with .form-part-checkbox-row (in common/style.css). Centers the row
   vertically against the taller buttons in .modal-part-buttons. */
.modal-part-bar-checkbox {
  align-self: center;
}
