/**
 * Styles shared by the desktop portal and the mobile app: the photo viewer
 * (cms-lightbox.js) and inline field validation messages (cms-forms.js).
 * Colours come from each app's own tokens when present, with fallbacks so
 * this file also works on its own.
 */

/* ==========================================================================
   Inline field validation
   ========================================================================== */
.cms-field-error {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.35;
  font-weight: 600;
  color: var(--pay-unpaid-text, #b91c1c);
}
/* A leading icon, so the error isn't conveyed by colour alone. */
.cms-field-error::before {
  content: "";
  flex: 0 0 16px;
  height: 16px;
  margin-top: 1px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='12' y1='8' x2='12' y2='12'/%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='12' y1='8' x2='12' y2='12'/%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'/%3E%3C/svg%3E") center / contain no-repeat;
}

.form-input.is-invalid,
.form-select.is-invalid,
textarea.form-input.is-invalid,
.select2-container.is-invalid .select2-selection {
  border-color: var(--pay-unpaid-text, #b91c1c) !important;
  box-shadow: 0 0 0 3px rgba(185, 28, 28, 0.14);
}

/* ==========================================================================
   Photo viewer
   ========================================================================== */
.cms-lb {
  position: fixed;
  inset: 0;
  z-index: 2147483000; /* above Bootstrap modals (1055) and the mobile sheets */
  display: flex;
  flex-direction: column;
  background: rgba(8, 10, 16, 0.94);
  color: #fff;
  opacity: 0;
  transition: opacity 0.18s ease;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: contain;
  outline: none;
}
.cms-lb.is-open {
  opacity: 1;
}

.cms-lb-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none; /* we handle pinch, pan and swipe ourselves */
  cursor: zoom-in;
  user-select: none;
  -webkit-user-select: none;
}
.cms-lb.is-zoomed .cms-lb-stage {
  cursor: grab;
}
.cms-lb-stage:active {
  cursor: grabbing;
}

.cms-lb-img {
  /* Never wider/taller than the area between the top bar and bottom bar, so
     the whole photo is visible at "fit" and proportions are untouched. */
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  opacity: 0;
  transform-origin: 50% 50%;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none; /* the stage receives every gesture */
}
.cms-lb-img.is-ready {
  opacity: 1;
}
.cms-lb-img.cms-lb-animate {
  transition: transform 0.2s ease;
}

.cms-lb-loading,
.cms-lb-error {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  max-width: min(86vw, 360px);
}
.cms-lb-loading[hidden],
.cms-lb-error[hidden] {
  display: none;
}
.cms-lb-spinner {
  display: block;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  animation: cms-lb-spin 0.8s linear infinite;
}
@keyframes cms-lb-spin {
  to { transform: rotate(360deg); }
}
.cms-lb-error-msg {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 600;
}
.cms-lb-error-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.cms-lb-retry,
.cms-lb-original {
  min-height: 44px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}
.cms-lb-retry {
  border: 0;
  background: #fff;
  color: #111;
}
.cms-lb-original {
  border: 1px solid rgba(255, 255, 255, 0.5);
  color: #fff;
  background: transparent;
}

/* Top bar: counter - title - close */
.cms-lb-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(8px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 8px calc(12px + env(safe-area-inset-left));
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0));
  pointer-events: none;
}
.cms-lb-top > * {
  pointer-events: auto;
}
.cms-lb-counter {
  flex: 0 0 auto;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.cms-lb-counter[hidden] {
  display: none;
}
.cms-lb-title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 600;
  opacity: 0.9;
  pointer-events: none;
}

/* Buttons - 44px touch targets */
.cms-lb-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}
.cms-lb-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.cms-lb-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}
.cms-lb-btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.cms-lb-btn:focus-visible,
.cms-lb-retry:focus-visible,
.cms-lb-original:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}
.cms-lb-close {
  margin-left: auto;
}

/* Prev / next, vertically centred at the edges */
.cms-lb-nav {
  position: absolute;
  top: 50%;
  z-index: 2;
  margin-top: -22px;
}
.cms-lb-nav[hidden] {
  display: none;
}
.cms-lb-prev {
  left: calc(10px + env(safe-area-inset-left));
}
.cms-lb-next {
  right: calc(10px + env(safe-area-inset-right));
}

/* Bottom: caption + zoom controls */
.cms-lb-bar {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  padding: 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
}
.cms-lb-caption {
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  bottom: calc(76px + env(safe-area-inset-bottom));
  padding: 0 16px;
  text-align: center;
  font-size: 13px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}
.cms-lb-caption[hidden] {
  display: none;
}

/* Phones: pinch is the natural zoom, so drop the +/- buttons to free space
   (reset stays - it's the visible way back to fit-size). */
@media (pointer: coarse) {
  .cms-lb-zoom-in,
  .cms-lb-zoom-out {
    display: none;
  }
  .cms-lb-bar {
    padding: 4px;
  }
  .cms-lb:not(.is-zoomed) .cms-lb-bar {
    display: none;
  }
  .cms-lb-caption {
    bottom: calc(20px + env(safe-area-inset-bottom));
  }
  .cms-lb.is-zoomed .cms-lb-caption {
    bottom: calc(76px + env(safe-area-inset-bottom));
  }
}

/* Short landscape phones: nav buttons slightly smaller, nothing overlaps. */
@media (max-height: 420px) {
  .cms-lb-btn {
    width: 40px;
    height: 40px;
  }
  .cms-lb-caption {
    display: none;
  }
}

/* Document thumbnails in patient lists (both apps) */
.cms-doc-thumb {
  flex: 0 0 auto;
  display: inline-block;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  overflow: hidden;
  background: #e2e8f0;
  border: 1px solid rgba(15, 23, 42, 0.12);
  line-height: 0;
}
.cms-doc-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.cms-doc-thumb:focus-visible {
  outline: 3px solid var(--primary-600, #800080);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .cms-lb,
  .cms-lb-img.cms-lb-animate,
  .cms-lb-btn {
    transition: none;
  }
  .cms-lb-spinner {
    animation-duration: 2.4s; /* still reads as "loading", far less motion */
  }
}
