/* ============================================================================
   legacy-page-fixes.css — what survived of the four 2025 "-fix" stylesheets.

   WHERE THESE CAME FROM. `visitor-photo-modal-fix.css`,
   `button-overlap-fix.css`, `visit-history-table-fix.css` and
   `contact-info-styling-fix.css` were `<link>`ed at the BOTTOM OF <body> from
   layouts/eduqueue.html, which gave them the last word in the entire
   application, on every page, for over a year. Between them they held 571
   lines and ~100 `!important` declarations, and what they were mostly doing
   with that authority was delivering a `margin-left: auto` to a card header.

   They are merged here, and this file loads in the HEAD, BEFORE the kit. That
   is the whole point: the component layer is the base and a page fix layers
   under it, not over it.

   WHY THE MOVE IS SAFE, AND WHERE IT ISN'T. Almost everything that survived
   is scoped to a page-unique `#id` — `#visit-history`, `#imagePreviewModal`,
   `#contact-section-wrapper` — so it still outranks every class-based kit
   rule from this earlier position, and moving it cost it nothing. What did
   NOT survive is the handful of bare class/element rules that were silently
   beating the kit from the bottom of the body: `.btn`, `.card-header`,
   `.table-responsive` and the DataTables chrome are in components.css now,
   defined once.

   `!important` is down from ~100 to 2 because an id beats a class without
   one. Do not re-add it here; if a rule needs `!important` to win from this
   position, it is fighting the component layer and belongs in a conversation
   about the component layer.
   ========================================================================== */

/* ============================================================================
   1. The image lightbox — eduqueue/page/lookup.html
   ========================================================================== */

/* Was: a global `.modal, .modal *, .modal-dialog, .modal-dialog *
   { backdrop-filter: none; filter: none !important }`. From the bottom of
   <body> that killed every filter on every element inside every dialog in
   the app — including, now, the `filter: brightness()` the component layer
   uses for a pressed danger button, and the deliberate `blur(8px)` the
   building-selection modal asks for in the shell's own stylesheet.
   The intent was always just "the visitor photo must not be blurry". Scoped
   to the two dialogs that meant it. */
#imagePreviewModal,
#imagePreviewModal *,
.visitor-detail-modal,
.visitor-detail-modal * {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  filter: none;
}
#imagePreviewModal ~ .modal-backdrop {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

/* Above the scanner overlays, which run at four figures of z-index. */
#imagePreviewModal { z-index: 10070; }
#imagePreviewModal .modal-dialog { z-index: 10071; }
#imagePreviewModal .modal-content {
  z-index: 10072;
  background-color: var(--eq-surface);
  opacity: 1;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}
#imagePreviewModal .modal-header {
  background-color: var(--eq-surface-2);
  border-bottom: 1px solid var(--eq-line);
  padding: 1rem 1.5rem;
}
#imagePreviewModal .modal-title { font-weight: 600; color: var(--eq-ink); }
#imagePreviewModal .modal-body { padding: 2rem; background-color: var(--eq-surface); }
#imagePreviewModal .close { opacity: .6; transition: opacity .2s; }
#imagePreviewModal .close:hover { opacity: 1; }
#imagePreviewModal.fade .modal-dialog { transition: transform .3s ease-out; }
#imagePreviewModal.show .modal-dialog { transform: none; }

/* The photo itself. `max-height: 70vh` is what keeps a portrait licence scan
   inside the viewport; the page's own 400x400 is a separate open defect. */
#fullSizeImage {
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .1);
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
}

/* A scanner overlay is `position: fixed` and would otherwise sit on top of a
   dialog opened from the same screen. Functional, not cosmetic. */
.modal-open .barcode-scanner-overlay,
.modal-open .scanner-overlay {
  display: none !important;      /* the scanner JS sets display inline */
  opacity: 0 !important;         /* and opacity with it */
  pointer-events: none;
}

/* ============================================================================
   2. Photo buttons on the visitor form — eduqueue/page/_form.html
   ========================================================================== */

/* Selecting on the text of an `onclick` attribute is indefensible, and it is
   load-bearing: these three buttons overlapped their neighbours. The
   `margin: 5px !important` and `display: inline-block !important` they
   carried are gone — nothing competes for either from this position — and
   the stacking stays, because it is what stopped the camera button
   disappearing behind the preview. */
button[onclick*="Camera"],
button[onclick*="upload"],
button[onclick*="Photo"] {
  position: relative;
  z-index: 10;
  display: inline-block;
  margin: 5px;
}

/* ============================================================================
   3. Visit-history table — eduqueue/page/_visitor_history.html, _form.html,
      visitorProfile.html
   ========================================================================== */

.visit-history-card {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  margin: 0 0 2rem;
  border-radius: var(--eq-radius-sm);
  box-shadow: var(--eq-shadow);
  border: 1px solid var(--eq-line);
}
.visit-history-body { padding: 0; width: 100%; overflow: hidden; }
.visit-history-card * { max-width: 100%; }

/* `table-layout: fixed` plus explicit column widths is what keeps six columns
   of visit history inside a 1,100px panel instead of overflowing into the
   `overflow-x: clip` container, where the overflow is invisible. */
#visit-history {
  width: 100%;
  table-layout: fixed;
  margin: 0;
  border: none;
}
#visit-history_wrapper { width: 100%; margin: 0; padding: 0; }
#visit-history thead th {
  padding: 1rem .75rem;
  font-size: .7rem;
  white-space: normal;
  word-wrap: break-word;
}
#visit-history thead th:nth-child(1),
#visit-history thead th:nth-child(2) { width: 15%; min-width: 100px; }
#visit-history thead th:nth-child(3),
#visit-history thead th:nth-child(4) { width: 15%; min-width: 80px; }
#visit-history thead th:nth-child(5) { width: 25%; min-width: 120px; }
#visit-history thead th:nth-child(6) { width: 15%; min-width: 100px; }
#visit-history tbody td {
  padding: .75rem;
  font-size: .813rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
}
#visit-history tbody tr:hover {
  background-color: var(--eq-accent-wash);
  transform: none;
  box-shadow: inset 3px 0 0 var(--eq-accent-2);
}

.checkin-time,
.checkout-time { display: block; font-size: .875rem; line-height: 1.4; }
.checkin-time i,
.checkout-time i { display: inline-block; margin-right: .25rem; font-size: .75rem; }
.checkin-time span,
.checkout-time span { display: inline; font-size: .875rem; }

.location-badge,
.building-badge {
  padding: .25rem .5rem;
  font-size: .75rem;
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reason-text { max-width: 200px; word-wrap: break-word; white-space: normal; line-height: 1.3; }
.notes-content { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notes-content:hover { white-space: normal; overflow: visible; }

/* DataTables draws its sort glyph as a background-position, so a sortable
   header needs room on the right or the glyph lands on the last word. */
.sorting,
.sorting_asc,
.sorting_desc { padding-right: 1.5rem; background-position: center right .5rem; }

.collapsible-section { margin: 0; width: 100%; }
.collapsible-section .collapsible-content { padding: 1.5rem .75rem; }
.collapsible-header {
  padding: 1rem 1.5rem;
  background: var(--eq-surface-2);
  border-top: 1px solid var(--eq-line);
  cursor: pointer;
}
.visitor-analytics-section { margin: 1rem 0; }

@media (max-width: 768px) {
  #visit-history { font-size: .75rem; }
  #visit-history thead th { padding: .5rem; font-size: .65rem; }
  #visit-history tbody td { padding: .5rem; font-size: .75rem; }
  /* The building column is the one a visitor's own history repeats most. */
  #visit-history thead th:nth-child(3),
  #visit-history tbody td:nth-child(3) { display: none; }
  #visit-history thead th:nth-child(1),
  #visit-history thead th:nth-child(2) { width: 25%; }
  #visit-history thead th:nth-child(4) { width: 20%; }
  #visit-history thead th:nth-child(5) { width: 30%; }
}

/* ============================================================================
   4. Contact-information section — eduqueue/page/_form.html
   ========================================================================== */

/* This whole section's markup is built at runtime by
   static/js/contact-info-styling-fix.js, which finds the collapsible whose
   heading reads "Contact Information", gives it the id below and rebuilds the
   fields into a grid. No template contains any of these hooks, which is why
   grepping the templates for them finds nothing.

   Every rule here used to carry `!important` and a hardcoded `white` /
   `#f3f4f6` / `#374151`, so this one section rendered light grey with
   near-black labels under the dark and high-contrast themes. The id gives
   (1,1,0) against the component layer's (0,1,0), so none of the `!important`
   was ever needed; they are all gone and the colours are tokens. */
#contact-section-wrapper,
#contact-section-wrapper .collapsible-section,
#contact-section-wrapper .collapsible-content,
#contact-section-wrapper .form-section-content { background: var(--eq-surface); }
#contact-section-wrapper .collapsible-content { padding: 0; }
#contact-section-wrapper .form-section-content { padding: 1.5rem; }
#contact-section-wrapper {
  margin: 0;
  border-bottom: 1px solid var(--eq-line);
}
.form-section + #contact-section-wrapper { border-top: none; }

#contact-section-wrapper .form-control {
  background-color: var(--eq-surface-2);
  border: 1px solid var(--eq-line);
}
#contact-section-wrapper .form-control:focus {
  background-color: var(--eq-field);
  border-color: var(--eq-accent);
  box-shadow: 0 0 0 3px var(--eq-accent-tint);
  outline: none;
}
#contact-section-wrapper select.form-control { background-color: var(--eq-surface-2); }
#contact-section-wrapper .form-control:disabled { background-color: var(--eq-line); cursor: not-allowed; }
#contact-section-wrapper label {
  font-size: .875rem;
  font-weight: 600;
  color: var(--eq-text);
  margin-bottom: .375rem;
}

.contact-info-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.contact-info-grid .email-field,
.contact-info-grid .phone-field { grid-column: span 2; }

.address-section { margin-top: 1.5rem; }
.address-section h5 {
  margin: 0 0 1rem;
  color: var(--eq-muted);
  font-weight: 600;
  font-size: .875rem;
  text-transform: uppercase;
  letter-spacing: .025em;
  display: flex;
  align-items: center;
}
.address-section h5 i { margin-right: .5rem; font-size: .875rem; color: var(--eq-faint); }
.address-street { margin-bottom: 1rem; }
.address-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 1rem; }

@media (max-width: 1200px) {
  .contact-info-grid { grid-template-columns: repeat(2, 1fr); }
  .contact-info-grid .email-field,
  .contact-info-grid .phone-field { grid-column: span 1; }
  .address-grid { grid-template-columns: 1fr 1fr; }
  .address-grid > :last-child { grid-column: span 2; }
}
@media (max-width: 768px) {
  .contact-info-grid { grid-template-columns: 1fr; }
  .contact-info-grid .email-field,
  .contact-info-grid .phone-field { grid-column: span 1; }
  .address-grid { grid-template-columns: 1fr; }
  .address-grid > * { grid-column: span 1; }
}
