/* ============================================================
   Frosted-glass modals — every Bootstrap .modal in the app.
   Tinted by the user's chosen theme colour (--sc-accent-rgb, which
   flips to the lighter dark-mode accent automatically), with the
   fill kept ~80% opaque so text and inputs stay fully readable.
   Loaded after controls.css / student-shell.css; the extra
   `.modal` ancestor beats their `.modal-content` !important rules
   without touching page-specific sizing.
   ============================================================ */
:root {
  --mg-accent: var(--sc-accent-rgb, var(--accent-rgb, 59, 130, 246));
  /* Neutral slate tint (not the theme accent) so the white panels inside
     the modal stand out against it. Accent stays on focus rings only. */
  --mg-tint: 100, 116, 139;
  --mg-fill: 255, 255, 255;
  --mg-fill-alpha: 0.80;
  --mg-wash-top: 0.20;
  --mg-wash-bottom: 0.05;
  --mg-border: rgba(255, 255, 255, 0.70);
  --mg-hairline: rgba(var(--mg-tint), 0.16);
  --mg-text: #0f172a;
  --mg-field: rgba(255, 255, 255, 0.72);
  --mg-field-border: rgba(var(--mg-tint), 0.22);
  --mg-shadow:
    0 24px 60px rgba(15, 23, 42, 0.22),
    0 4px 14px rgba(15, 23, 42, 0.08),
    0 0 0 1px rgba(var(--mg-tint), 0.10);
  --mg-backdrop: rgba(15, 23, 42, 0.18);
  --mg-backdrop-wash: rgba(var(--mg-tint), 0.30);
}
html.dark-mode,
body.dark-mode {
  --mg-tint: 148, 163, 184;
  --mg-fill: 16, 20, 30;
  --mg-fill-alpha: 0.78;
  --mg-wash-top: 0.20;
  --mg-wash-bottom: 0.07;
  --mg-border: rgba(255, 255, 255, 0.12);
  --mg-hairline: rgba(var(--mg-tint), 0.24);
  --mg-text: #e5e7eb;
  --mg-field: rgba(8, 11, 18, 0.50);
  --mg-field-border: rgba(var(--mg-tint), 0.32);
  --mg-shadow:
    0 28px 70px rgba(0, 0, 0, 0.60),
    0 4px 16px rgba(0, 0, 0, 0.40),
    0 0 0 1px rgba(var(--mg-tint), 0.16);
  --mg-backdrop: rgba(2, 6, 14, 0.45);
  --mg-backdrop-wash: rgba(var(--mg-tint), 0.38);
}

/* Backdrop: dimmed, accent-washed, softly blurred page behind. */
.modal-backdrop,
.modal-backdrop.show,
body.dark-mode .modal-backdrop,
body.dark-mode .modal-backdrop.show {
  background:
    linear-gradient(var(--mg-backdrop-wash), var(--mg-backdrop-wash)),
    var(--mg-backdrop) !important;
  opacity: 1 !important;
  -webkit-backdrop-filter: blur(14px) saturate(150%);
  backdrop-filter: blur(14px) saturate(150%);
}

/* The glass pane. */
.modal .modal-dialog .modal-content {
  background:
    linear-gradient(160deg,
      rgba(var(--mg-tint), var(--mg-wash-top)) 0%,
      rgba(var(--mg-tint), var(--mg-wash-bottom)) 55%,
      rgba(var(--mg-tint), calc(var(--mg-wash-bottom) + 0.03)) 100%),
    rgba(var(--mg-fill), var(--mg-fill-alpha)) !important;
  -webkit-backdrop-filter: blur(26px) saturate(165%);
  backdrop-filter: blur(26px) saturate(165%);
  border: 1px solid var(--mg-border) !important;
  border-radius: 18px !important;
  box-shadow: var(--mg-shadow) !important;
  color: var(--mg-text);
}
/* If the browser can't blur, fall back to a near-solid pane so the
   page text underneath never reads through. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .modal .modal-dialog .modal-content {
    background:
      linear-gradient(rgba(var(--mg-tint), 0.10), rgba(var(--mg-tint), 0.10)),
      rgb(var(--mg-fill)) !important;
  }
}

/* Header / footer: lighter glass strips separated by accent hairlines. */
.modal .modal-content > .modal-header,
.modal .modal-content > form > .modal-header {
  background: rgba(var(--mg-tint), 0.07) !important;
  border-bottom: 1px solid var(--mg-hairline) !important;
}
.modal .modal-content > .modal-footer,
.modal .modal-content > form > .modal-footer {
  background: rgba(var(--mg-tint), 0.05) !important;
  border-top: 1px solid var(--mg-hairline) !important;
}
.modal .modal-title { color: var(--mg-text); }

/* Inputs sit on a slightly firmer pane so typing stays crisp. */
.modal .modal-content .form-control,
.modal .modal-content .form-select,
.modal .modal-content textarea,
.modal .modal-content input[type="text"],
.modal .modal-content input[type="number"],
.modal .modal-content input[type="search"],
.modal .modal-content input[type="email"],
.modal .modal-content input[type="password"],
.modal .modal-content input[type="date"],
.modal .modal-content input[type="time"] {
  background-color: var(--mg-field) !important;
  border-color: var(--mg-field-border) !important;
  color: var(--mg-text);
}
.modal .modal-content .form-control:focus,
.modal .modal-content .form-select:focus {
  border-color: rgb(var(--mg-accent)) !important;
  box-shadow: 0 0 0 3px rgba(var(--mg-accent), 0.22) !important;
}

/* Close button: readable on both fills. */
.modal .modal-content .btn-close { opacity: .65; }
.modal .modal-content .btn-close:hover { opacity: 1; }
body.dark-mode .modal .modal-content .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }

/* Entrance: gentle rise + scale. */
@media (prefers-reduced-motion: no-preference) {
  .modal.fade .modal-dialog {
    transition: transform .26s cubic-bezier(.2, .8, .2, 1), opacity .2s ease;
    transform: translateY(14px) scale(.975);
  }
  .modal.show .modal-dialog { transform: none; }
}
