/* ChiroVision Compact Tool Header — Desktop C + Phone A
   Desktop:  single 46 px row of grouped dropdown menus at the top of the page
   Mobile:   same DOM converts to a bottom sheet drawer with a drag handle */

/* Hide the legacy tool-header row ONLY when the new header successfully built.
   chirovision-header.js sets body.cv-header-active on success; if JS fails or
   is disabled, .cv-legacy-header stays visible so the app is still usable. */
body.cv-header-active .cv-legacy-header { display: none !important; }

/* Root */
.cv-tool-header {
  --cv-h-bg: linear-gradient(180deg, rgba(15,23,42,0.94), rgba(2,6,23,0.98));
  --cv-h-border: rgba(110,231,245,0.22);
  --cv-cyan: #6ee7f5;
  --cv-mint: #86efac;
  --cv-rose: #f472b6;
  --cv-text: #e5e7eb;
  --cv-mute: #94a3b8;

  position: sticky;
  top: 0;
  z-index: 9500;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  min-height: 46px;
  background: var(--cv-h-bg);
  border-bottom: 1px solid var(--cv-h-border);
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  color: var(--cv-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

.cv-th-handle { display: none; }

.cv-th-title {
  display: flex; align-items: baseline; gap: 8px;
  padding-right: 8px;
  border-right: 1px solid rgba(255,255,255,0.09);
  margin-right: 4px;
  min-width: 0;
  max-width: 40%;
}
.cv-th-title-main {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 14.5px; color: #fff; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cv-th-title-sub {
  color: var(--cv-mute); font-size: 11.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.cv-th-menus {
  display: flex; align-items: center; gap: 6px;
  flex: 1; flex-wrap: nowrap;
  overflow: hidden;
}

.cv-th-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 11px;
  border-radius: 7px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.04);
  color: var(--cv-text);
  font: inherit; font-size: 12.5px; font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.cv-th-btn:hover { background: rgba(255,255,255,0.09); }
.cv-th-btn.active { background: rgba(255,255,255,0.13); border-color: rgba(110,231,245,0.5); }
.cv-th-btn-import.active { border-color: rgba(110,231,245,0.65); background: rgba(110,231,245,0.12); color: var(--cv-cyan); }
.cv-th-btn-save.active   { border-color: rgba(134,239,172,0.55); background: rgba(134,239,172,0.12); color: var(--cv-mint); }
.cv-th-btn-patient       { color: var(--cv-text); }
.cv-th-btn-import        { color: var(--cv-cyan); border-color: rgba(110,231,245,0.4); background: rgba(110,231,245,0.06); }
.cv-th-btn-save          { color: var(--cv-mint); border-color: rgba(134,239,172,0.4); background: rgba(134,239,172,0.06); }
.cv-th-btn-files         { color: var(--cv-text); }

.cv-th-glyph { font-size: 14px; }
.cv-th-caret { color: var(--cv-mute); font-size: 10px; margin-left: 1px; }

.cv-th-count {
  min-width: 20px; padding: 0 6px; margin-left: 3px;
  border-radius: 999px;
  background: var(--cv-cyan); color: #04121a;
  font-size: 11px; font-weight: 800; line-height: 18px;
  text-align: center;
  display: none;
}

/* Right-side status pill (patient name / MRN / scan count) — auto-populated
   by index.html's updatePatientStatusDisplay via the #patient-status element,
   which we mirror. Kept optional so pages without it degrade gracefully. */
#cv-th-status {
  color: var(--cv-mute); font-size: 11.5px; margin-left: auto;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 260px;
}

/* Dropdown menus — absolute popover under the button that opened them */
.cv-th-menu {
  display: none;
  position: absolute;
  top: 100%; left: 0; right: auto;
  min-width: 240px;
  max-width: 480px;
  margin-top: 6px;
  padding: 12px;
  background: linear-gradient(180deg, rgba(15,23,42,0.97), rgba(2,6,23,0.99));
  border: 1px solid rgba(110,231,245,0.35);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.55);
  z-index: 9600;
  color: var(--cv-text);
  gap: 8px;
}
.cv-th-menu.open { display: flex; flex-direction: column; }

/* Constrain buttons inside menus to stack cleanly */
.cv-th-menu .btn,
.cv-th-menu button,
.cv-th-menu a.btn {
  display: inline-flex;
  justify-content: flex-start;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.04);
  color: var(--cv-text);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
}
.cv-th-menu select { min-width: 100%; }
.cv-th-menu .patient-images-inline,
.cv-th-menu .patient-buttons-wrapper {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}

/* Reasonable horizontal alignment for each menu */
#cv-th-menu-patient  { left: max(6px, 12%); }
#cv-th-menu-import   { left: max(6px, 34%); }
#cv-th-menu-save     { left: max(6px, 56%); }

/* ────────────────────────────────────────────────────────────────────────
   MOBILE (Phone A) — bottom sheet drawer
   The whole header slides to the bottom and shows a drag-handle. Tapping
   any menu button, or dragging the handle up, expands the sheet.
   ──────────────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .cv-tool-header {
    position: fixed;
    top: auto;
    left: 0; right: 0; bottom: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0 12px 14px;
    min-height: 0;
    border-bottom: none;
    border-top: 1px solid rgba(110,231,245,0.4);
    border-radius: 20px 20px 0 0;
    transform: translateY(calc(100% - 78px));
    transition: transform .28s ease;
    box-shadow: 0 -12px 32px rgba(0,0,0,0.6);
    max-height: 88vh;
    overflow-y: auto;
  }
  .cv-tool-header.cv-th-sheet-open { transform: translateY(0); }

  .cv-th-handle {
    display: block;
    align-self: center;
    width: 42px; height: 4px;
    background: rgba(255,255,255,0.35);
    border-radius: 999px;
    margin: 8px 0 6px;
    cursor: pointer;
  }

  .cv-th-title {
    border-right: none; padding: 0 4px 8px; max-width: 100%;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 8px;
    justify-content: center;
  }
  .cv-th-title-main { font-size: 15px; text-align: center; }

  .cv-th-menus {
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    padding: 4px 0 8px;
  }
  .cv-th-btn { padding: 8px 14px; font-size: 13px; flex: 1 1 45%; justify-content: center; }
  .cv-th-btn-files { flex-basis: 100%; }

  .cv-th-menu {
    position: static;
    min-width: 0;
    max-width: 100%;
    margin-top: 0;
    box-shadow: none;
    background: rgba(255,255,255,0.02);
  }

  /* Pad the page so the sticky sheet doesn't cover content at rest */
  body { padding-bottom: 96px; }
}

/* Extra breathing room when the popover would otherwise overflow the right edge */
@media (min-width: 769px) and (max-width: 1024px) {
  .cv-th-title { max-width: 30%; }
  .cv-th-title-sub { display: none; }
  .cv-th-btn .cv-th-label { display: none; }
  .cv-th-btn .cv-th-glyph { font-size: 15px; }
}
