/* Shared dialog surfaces, loaded after page styles. */
:root {
  --dialog-surface: #1b293d;
  --dialog-border: rgba(157, 181, 212, 0.2);
  --dialog-muted: #a7b9ce;
}

body .modal-content,
body .rating-modal .modal-content,
body .chapter-modal > .modal-content {
  border: 1px solid var(--dialog-border);
  border-radius: 18px;
  background: linear-gradient(145deg, #203149, var(--dialog-surface) 60%);
  color: #eaf0f8;
  box-shadow: 0 28px 80px #0008, inset 0 1px 0 #ffffff08;
  background-clip: padding-box;
}

body .modal-content .modal-header {
  gap: 1rem;
  margin: 0;
  padding: 1.25rem 1.4rem;
  border-bottom: 1px solid var(--dialog-border);
  border-radius: 18px 18px 0 0;
  background: #ffffff02;
}

body .modal-content .modal-header :is(h3, h5, .modal-title) {
  margin: 0;
  color: #f2f6fc;
  font-size: 1.08rem;
  font-weight: 700;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

body .modal-content .modal-body {
  padding: 1.4rem;
  color: #c5d2e3;
  line-height: 1.65;
}

body .modal-content .modal-body h4 {
  color: #edf4fc;
  font-size: 1.1rem;
}

body .modal-content .modal-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.6rem !important;
  margin-top: 0 !important;
  padding: 1rem 1.4rem;
  border-top: 1px solid var(--dialog-border);
  border-radius: 0 0 18px 18px;
  background: #0c172528;
}

body .modal-content .modal-footer > * { margin: 0; }

body .modal-content :is(.form-label, label) {
  color: #c7d5e7;
  font-size: 0.88rem;
  font-weight: 600;
}

body .modal-content :is(.form-control, .form-select) {
  min-height: 44px;
  padding: 0.7rem 0.85rem;
  border: 1px solid #3a4d67;
  border-radius: 10px;
  background-color: #111e30 !important;
  color: #edf3fb !important;
  font-size: 0.93rem;
  line-height: 1.5;
}

body .modal-content :is(.form-control, .form-select):focus {
  border-color: var(--custom-blue);
  box-shadow: 0 0 0 3px #42a9e124;
}

body .modal-content .form-control::placeholder { color: #8fa3bd; }
body .modal-content textarea { resize: vertical; }

body .modal-content .modal-footer .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 42px;
  padding: 0.6rem 1rem;
  border-radius: 9px;
  font-size: 0.87rem;
  font-weight: 600;
  line-height: 1.4;
}

body .modal-content .btn-primary {
  border-color: var(--custom-blue);
  background: var(--custom-blue);
  color: var(--custom-blue-text);
}

body .modal-content .btn-primary:hover { background: var(--custom-blue-active); border-color: var(--custom-blue-active); }

body .modal-content :is(.btn-secondary, .modal-footer .btn[data-bs-dismiss]) {
  border: 1px solid #41536d;
  background: #ffffff05;
  color: var(--button-grey-text, #d0deee);
}

body .modal-content :is(.btn-secondary, .modal-footer .btn[data-bs-dismiss]):hover {
  border-color: #6982a3;
  background: #ffffff0d;
}

body .modal-content :is(.btn, .btn-close, .close-modal):focus-visible {
  outline: 2px solid var(--custom-blue);
  outline-offset: 3px;
  box-shadow: none;
}

body .modal-content .btn-close {
  flex-shrink: 0;
  padding: 0.65rem;
  border-radius: 8px;
  opacity: 0.7;
  filter: invert(1) grayscale(100%) brightness(200%);
}

body .modal-content .btn-close:hover { opacity: 1; }

body .modal-content .close-modal {
  position: static;
  display: grid;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--dialog-border);
  border-radius: 8px;
  background: #ffffff06;
  color: #d8e4f2;
  font-size: 1.5rem;
  line-height: 1;
  transform: none;
}

.modal-backdrop { --bs-backdrop-opacity: 0.7; }

/* Custom dialogs remain below Bootstrap confirmation dialogs. */
body #rating-modal-container,
body .chapter-modal {
  z-index: 1040;
  padding: 1rem;
  background: #060d18b3;
  backdrop-filter: blur(6px);
  overflow-y: auto;
}

body #rating-modal-container .rating-modal {
  position: relative;
  top: auto;
  left: auto;
  width: min(100%, 500px);
  max-width: 500px;
  max-height: calc(100dvh - 2rem);
  padding: 0;
  overflow-y: auto;
  border: 0;
  border-radius: 18px;
  background: transparent;
  transform: none;
}

body .chapter-modal > .modal-content {
  width: min(100%, 600px);
  max-height: calc(100dvh - 2rem);
  padding: 0;
  overflow-y: auto;
}

body .chapter-modal .chapter-list { padding: 1rem 1.25rem; }
body .chapter-modal .chapter-item { border-color: var(--dialog-border); border-radius: 10px; background: #111e30; }
body .chapter-modal .chapter-item.active { border-color: var(--custom-blue); background: #223b54; }

body .rating-modal .star-rating {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

body .rating-modal .star-rating__star {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  padding: 8px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 10px;
  background: rgba(148, 163, 184, 0.06);
  color: #a7b9ce;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

body .rating-modal .star-rating__star svg {
  width: 26px;
  height: 26px;
  fill: transparent;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linejoin: round;
}

body .rating-modal .star-rating__star.is-filled {
  border-color: rgba(237, 182, 76, 0.3);
  background: rgba(237, 182, 76, 0.09);
  color: #f8c75b;
}

body .rating-modal .star-rating__star.is-filled svg { fill: currentColor; }
body .rating-modal .star-rating__star:focus-visible { outline: 2px solid var(--custom-blue); outline-offset: 3px; }
body .rating-modal .selected-rating { display: inline-flex; padding: 3px 9px; border: 1px solid rgba(237, 182, 76, 0.3); border-radius: 8px; background: rgba(237, 182, 76, 0.09); color: #f8c75b; font-size: 1.1rem; font-weight: 700; white-space: nowrap; }

@media (max-width: 575.98px) {
  body .modal-content :is(.modal-header, .modal-body, .modal-footer) { padding: 1rem; }
  body .modal-content .modal-footer .btn { min-height: 44px; }
  body .rating-modal .star-rating-container { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  .modal.fade .modal-dialog { transition: none; }
}
