/* global.css - Styles for tables, headers, badges, modals, fonts, filter funnel, etc. */

/* Success Banner Animation */
#successBanner {
  transition: opacity 0.5s ease-in-out;
  z-index: 9999;
}

#successBanner.hidden {
  display: none;
}

body {
  font-family: "Inter", "Segoe UI", Arial, sans-serif;
  background-color: #f3f4f6;
  color: #222;
}

/* Global Table Styles */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background-color: #fff;
  overflow-x: auto;
}

/* Header: styles merged into the sticky header block below to avoid duplicates */

/* Rows */
tbody tr {
  transition: background 0.2s ease-in-out;
}
tbody tr:nth-child(even) {
  background: #f9fafb;
}
tbody tr:hover {
  background: #f3e8ff; /* subtle highlight */
}

/* Cells */
td {
  padding: 0.7em;
  border-bottom: 1px solid #e5e7eb;
  vertical-align: middle;
}

/* Badge Styles */
.badge {
  /* Use inline-flex so icons (SVG) and text align and aren't clipped */
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 999px;
  padding: 0.25em 0.85em;
  font-size: 0.9em;
  font-weight: 500;
  white-space: nowrap;
  vertical-align: middle;
  border: 1px solid transparent;
}
.badge.bg-green-500 {
  background: #22c55e;
  color: #fff;
  border-color: #16a34a;
}
.badge.bg-red-500 {
  background: #ef4444;
  color: #fff;
  border-color: #b91c1c;
}
.badge.bg-yellow-400 {
  background: #facc15;
  color: #78350f;
  border-color: #fbbf24;
}
.badge.bg-blue-100 {
  background: #dbeafe;
  color: #2563eb;
  border-color: #93c5fd;
}
.badge.bg-primary {
  background: #3b82f6;
  color: #fff;
  border-color: #2563eb;
}
.badge.bg-secondary {
  background: #818cf8;
  color: #fff;
  border-color: #6366f1;
}
.badge.bg-gray-200 {
  background: #e5e7eb;
  color: #374151;
  border-color: #d1d5db;
}

/* Filter Funnel Icon */
.fa-filter,
.fa-funnel {
  color: #64748b;
  font-size: 1.1em;
  transition: color 0.2s;
}
#filterBtn:hover .fa-filter,
#filterBtn:focus .fa-filter {
  color: #2563eb;
}

/* Filter Dropdown */
#filterDropdown {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 0.75rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
  padding: 1rem;
  min-width: 16rem;
  z-index: 100;
  transition: opacity 0.2s;
  /* anchor to the right edge of the reference container by default */
  right: 0;
  left: auto;
  box-sizing: border-box;
}
#filterDropdown label {
  color: #374151;
  font-weight: 600;
  margin-bottom: 0.25em;
}
#filterDropdown select {
  width: 100%;
  padding: 0.3em 0.5em;
  border-radius: 0.5em;
  border: 1px solid #d1d5db;
  background: #f9fafb;
  font-size: 0.95em;
  margin-bottom: 0.5em;
}
#filterDropdown .btn {
  font-size: 0.95em;
  padding: 0.3em 1em;
}

.btn, button {
  /* Consolidated base button styles (merged from duplicate rules) */
  font-family: inherit;
  border-radius: 0.5em;
  border: none;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.btn-primary {
  background: #3b82f6;
  color: #fff;
}
.btn svg,
.badge svg,
.modal-box svg {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: middle;
}

/* Only apply a fill when the SVG does not already specify one. This preserves
   SVGs that intentionally use fill="none" (stroke-only icons) or a specific
   fill color. */
.btn svg:not([fill]),
.badge svg:not([fill]),
.modal-box svg:not([fill]) {
  fill: currentColor;
}

/* Also ensure stroke inherits currentColor when the SVG does not set its own stroke */
.btn svg:not([stroke]),
.badge svg:not([stroke]),
.modal-box svg:not([stroke]) {
  stroke: currentColor;
}

/* Ensure SVGs explicitly using fill="none" remain unfilled */
.btn svg[fill="none"],
.badge svg[fill="none"],
.modal-box svg[fill="none"] {
  fill: none;
}
.btn-primary:hover {
  background: #2563eb;
}
.btn-warning {
  background: #f59e42;
  color: #fff;
}
.btn-warning:hover {
  background: #d97706;
}
.btn-success {
  background: #22c55e;
  color: #fff;
}
.btn-success:hover {
  background: #16a34a;
}
.btn-error {
  background: #ef4444;
  color: #fff;
}
.btn-error:hover {
  background: #b91c1c;
}
.btn-outline {
  background: #fff;
  border: 1px solid #d1d5db;
  color: #374151;
}
.btn-outline:hover {
  background: #f3f4f6;
}

/* Misc */
input,
select,
textarea {
  font-family: inherit;
  font-size: 1em;
}
.input-bordered {
  border: 1px solid #d1d5db;
  border-radius: 0.5em;
  background: #fff;
  padding: 0.5em 0.75em;
  transition: border 0.2s;
}
.input-bordered:focus {
  border-color: #3b82f6;
  outline: none;
}

/* Responsive helpers and breakpoints */
:root {
  --break-sm: 480px;
  --break-md: 768px;
  --break-lg: 1024px;
  --break-xl: 1280px;
}

/* Global scaling for type and spacing at different breakpoints */
html {
  font-size: 16px;
}
@media (max-width: 1024px) {
  html {
    font-size: 15px;
  }
}
@media (max-width: 768px) {
  /* Ensure the drawer container always creates a stacking context and sits above
     sticky table headers during open/close animations. Setting these rules on
     the container (not just the checked state) prevents flicker during the
     closing transition where the checked selector no longer applies. */
  .drawer-side,
  .drawer-side aside {
    /* keep a stable stacking context so sticky elements cannot paint above */
    transform: translateZ(0);
    will-change: transform, opacity;
    z-index: 10050;
  }

  /* when the drawer toggle is checked, make the drawer-side a fixed overlay above headers */
  /* drawer checked-state positioning/rules are declared at the 1024px media query below
     to avoid duplication. The container-level stacking context above ensures no flicker
     during closing animations. */
}
@media (max-width: 480px) {
  html {
    font-size: 13px;
    z-index: 10050; /* slightly higher to avoid rare header overlap (was 10010) */
  }
}

/* Table responsiveness: keep horizontal scroll but improve compactness on small devices */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
/* New: make the table take available vertical space and keep tbody scrollable
   Usage: wrap your table with <div class="table-viewport"> <div class="table-wrapper table-scroll"> <table>...</table> </div> </div>
   The .table-viewport will size to viewport height minus optional header/toolbars using --table-offset
   Default --table-offset is 160px (header + controls). Adjust per page. */
.table-viewport {
  --table-offset: 160px; /* space to subtract from 100vh (header, toolbars, paddings) */
  width: 100%;
  height: calc(100vh - var(--table-offset));
  max-height: calc(100vh - var(--table-offset));
  display: flex;
  flex-direction: column;
}

.table-scroll {
  flex: 1 1 auto; /* fill remaining height */
  overflow: auto; /* enable vertical + horizontal scroll when needed */
  -webkit-overflow-scrolling: touch;
}

/* Ensure sticky thead remains visible inside the scroll container */
.table-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 60;
}

/* Make tbody scroll independently while table layout preserved */
.table-scroll table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed; /* helps with consistent column widths */
}

/* Allow cells to wrap text and show ellipsis where appropriate */
td, th {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
td.multi-line, th.multi-line {
  white-space: normal; /* allow wrapping when you want multi-line cells */
}

/* When viewport is narrow, relax fixed layout and allow horizontal scroll as fallback */
@media (max-width: 640px) {
  .table-scroll table {
    table-layout: auto;
    min-width: 600px; /* keep columns readable and enable horizontal scroll */
  }
  td, th { white-space: normal; }
}
table {
  display: table;
  min-width: 600px;
}
@media (max-width: 1024px) {
  table {
    min-width: 540px;
  }
}
@media (max-width: 768px) {
  table {
    min-width: 480px;
  }
  thead th,
  td {
    padding: 0.5em;
  }
}
@media (max-width: 480px) {
  table {
    min-width: 420px;
  }
  thead th,
  td {
    padding: 0.45em;
    font-size: 12px;
  }
}

/* Sticky table headers with solid background to avoid blending with table rows when scrolling */
thead th {
  position: sticky;
  top: 0;
  z-index: 60; /* keep above table rows */
  background-color: #f3f4f6; /* matches header background for a solid look */
  color: #111827; /* dark gray text */
  font-weight: 600;
  padding: 0.75em;
  text-align: left;
  border-bottom: 2px solid #e5e7eb;
  white-space: nowrap; /* prevent header text from breaking */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
}

/* Ensure sticky header also looks correct inside scroll containers */
.table-wrapper thead th {
  background-color: #f3f4f6;
}

/* Compact rows on small screens: smaller line-height and tighter spacing */
@media (max-width: 640px) {
  tbody tr {
    line-height: 1.15;
  }
  td {
    padding: 0.45em 0.5em;
  }
}

/* Buttons scaling */
.btn {
  padding: 0.45em 1em;
  font-size: 0.98rem;
}
.btn-circle {
  width: 2em;
  height: 2em;
  min-width: 2em;
  min-height: 2em;
  padding: 0 !important; /* ensure icon takes full circle */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
 .btn svg {
  width: 0.9em;
  height: 0.9em;
  display: inline-block;
  vertical-align: middle;
  pointer-events: none; /* clicks should hit the button, not the svg */
}
@media (max-width: 768px) {
  .btn {
    padding: 0.4em 0.85em;
    font-size: 0.95rem;
  }
  .btn-circle {
    width: 1.85em;
    height: 1.85em;
  }
}
@media (max-width: 480px) {
  .btn {
    padding: 0.35em 0.6em;
    font-size: 0.92rem;
  }
  .btn-circle {
    width: 1.6em;
    height: 1.6em;
  }
}

/* Filter dropdown responsiveness */
#filterDropdown {
  min-width: 16rem;
}
@media (max-width: 768px) {
  /* (no global svg override here) */
  #filterDropdown {
    min-width: 60vw;
  }
}
@media (max-width: 480px) {
  #filterDropdown {
    min-width: 88vw;
  }
}

/* Utility: stack action buttons in compact areas */
.stack-vertical-sm {
  display: flex;
  gap: 0.5rem;
}
@media (max-width: 480px) {
  .stack-vertical-sm {
    flex-direction: column;
  }
}

/* Table horizontal scroll fix */
.overflow-x-auto {
  overflow-x: auto !important;
}

/* Ensure the mobile drawer/sidebar overlays sticky table headers on small devices
   Uses the checkbox state used by DaisyUI's drawer component (#sidebar-drawer) */
@media (max-width: 1024px) {
  /* when the drawer toggle is checked, make the drawer-side a fixed overlay above headers */
  #sidebar-drawer:checked ~ .drawer-side {
   /* Use a new stacking context and ensure it sits above sticky table headers.
     position: fixed is required so the aside overlays the page content while open. */
   position: fixed !important;
   top: 0;
   left: 0;
   height: 100vh;
   z-index: 99999 !important; /* slightly higher to avoid rare header overlap (was 10010) */
   width: auto;
   /* Use transform to create a new stacking context during transitions and avoid
     subpixel rendering issues where sticky elements may paint above the aside. */
   transform: translateZ(0);
  }

  /* ensure the overlay label sits below the sidebar but above content */
  #sidebar-drawer:checked ~ .drawer-side .drawer-overlay {
    /* place overlay just underneath the aside to keep aside interactive */
    z-index: 10040;
    /* allow clicks to pass to overlay to close; ensure full-screen coverage */
    position: fixed;
    inset: 0 0 0 0;
    background: rgba(0,0,0,0.32);
  }

  /* ensure the actual aside inside the drawer-side is also above headers */
  #sidebar-drawer:checked ~ .drawer-side aside {
    z-index: 10060;
    position: relative;
    /* ensure the aside creates its own stacking context so sticky children can't escape */
    isolation: isolate;
  }
}

/* Mobile-only improvements: ensure long sidebars don't hide the bottom action (logout)
   Provide extra padding for the aside and make the footer/logout always reachable. */
@media (max-width: 640px) {
  .drawer-side aside {
    padding-bottom: 5.5rem; /* reserve space for bottom action */
  }

  /* If you want a fixed bottom logout on mobile, a helper class is available */
  .sidebar-bottom-action {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10070;
    padding: 0.5rem 1rem;
    background: linear-gradient(to top, rgba(255,255,255,0.95), rgba(255,255,255,0));
    box-shadow: 0 -6px 18px rgba(0,0,0,0.08);
  }
  .sidebar-bottom-action .btn {
    width: 100%;
  }
  .drawer-side[data-mobile-bottom="true"] aside + .sidebar-bottom-action {
    display: block;
  }
}

/* =========================
   Centralized Modal Styling
   ========================= */
.modal {
  z-index: 100000; /* always on top */
  padding: 0;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.5); /* softer overlay */
}

/* Main modal box */
.modal-box {
  box-sizing: border-box;
  max-width: 40rem; /* ~640px */
  width: calc(100% - 2rem);
  max-height: 85vh;
  overflow-y: auto;
  background: #fff;
  padding: 1.5rem;
  border-radius: 0.75rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
  animation: modal-pop 160ms ease-out;
}

/* Compact variants */
.modal-box.small {
  max-width: 22rem;
}
.modal-box.medium {
  max-width: 32rem;
}
.modal-box.large {
  max-width: 48rem;
}

/* Headings */
.modal-box h2,
.modal-box h3 {
  margin-bottom: 1rem;
  font-size: 1.25rem;
  font-weight: 600;
  color: #222;
}

/* Labels */
.modal-box label {
  display: block;
  margin-bottom: 0.4rem;
  font-weight: 500;
  font-size: 0.95rem;
  color: #444;
}

/* Inputs, selects, textareas */
.modal-box input:not([type="checkbox"]),
.modal-box select,
.modal-box textarea {
  width: 100%;
  min-height: .75rem; /* comfortable height (~44px) */
  padding: 0.50rem 0.75rem; /* balanced spacing */
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  background: #f3f1f6;
  font-size: 0.75rem;
  line-height: 1.5; /* fixes placeholder clipping */
  color: #000000b9; /* base-400 */
  transition: border-color 0.2s, background 0.2s;
}

.modal-box input:not([type="checkbox"])::placeholder,
.modal-box textarea::placeholder {
  color: #000000; /* base-400 */
}

.modal-box input:not([type="checkbox"]):focus,
.modal-box select:focus,
.modal-box textarea:focus {
  border-color: #2563eb;
  background: #ffffff;
  color: #111; /* darker text when typing */
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.modal-box input:not([type="checkbox"]):disabled,
.modal-box select:disabled,
.modal-box textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}


/* Buttons */
.modal-box .btn {
  padding: 0.6rem 1.2rem;
  border-radius: 0.5rem;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.modal-box .btn-primary {
  background: #2563eb;
  color: #fff;
  border: none;
}
.modal-box .btn-primary:hover {
  background: #1d4ed8;
}

.modal-box .btn-secondary {
  background: #f3f4f6;
  color: #111;
  border: 1px solid #d1d5db;
}
.modal-box .btn-secondary:hover {
  background: #e5e7eb;
}

/* Responsive tweaks */
@media (max-width: 480px) {
  .modal-box {
    width: calc(100% - 1rem);
    padding: 1rem;
  }
}

/* Animation */
@keyframes modal-pop {
  0% {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}


/* =====================
   Custom Checkbox Style
   ===================== */
.modal-box input[type="checkbox"] {
  appearance: none; /* remove default browser style */
  -webkit-appearance: none;
  -moz-appearance: none;

  width: 1.15rem;
  height: 1.15rem;
  border: 2px solid #2563eb;
  border-radius: 50%; /* circle instead of square */
  display: inline-block;
  position: relative;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  vertical-align: middle;
  margin-right: 0.5rem;
}

.modal-box input[type="checkbox"]:checked {
  background: #2563eb;
  border-color: #2563eb;
}

/* Neutralize any other checkbox pseudo-element animations coming from libraries
   (DaisyUI/Tailwind plugins may add their own ::before/::after). Then define
   a single ::after checkmark with a short opacity/scale transition so only one
   animation/transition runs. */
.modal-box input[type="checkbox"]::before,
.modal-box input[type="checkbox"]::after {
  animation: none !important;
  transition: none !important;
  -webkit-animation: none !important;
  -webkit-transition: none !important;
}

.modal-box input[type="checkbox"]:checked::after {
  opacity: 1;
  transform: translate(-50%, -58%) scale(1);
}

/* High-specificity override to ensure custom checkbox visuals and animation
   survive Tailwind/DaisyUI or other library overrides in production builds.
   This rule targets checkboxes inside modal-box and any descendant wrappers
   (adds an attribute selector to increase specificity). It forces appearance
   and defines a simple scale+opacity transition for the ::after marker. */
.modal-box[data-custom-override] input[type="checkbox"],
.modal-box[data-custom-override] input[type="checkbox"]::after {
  appearance: none !important;
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
}
.modal-box[data-custom-override] input[type="checkbox"] {
  width: 1.15rem !important;
  height: 1.15rem !important;
  border: 2px solid #2563eb !important;
  border-radius: 50% !important;
  background: transparent !important;
  position: relative !important;
  transition: background 0.12s ease, border-color 0.12s ease !important;
}
.modal-box[data-custom-override] input[type="checkbox"]::after {
  content: "" !important;
  position: absolute !important;
  left: 50% !important;
  top: 50% !important;
  width: 0.55rem !important;
  height: 0.55rem !important;
  background: white !important;
  border-radius: 50% !important;
  transform: translate(-50%, -58%) scale(0.6) !important;
  opacity: 0 !important;
  transition: opacity 140ms cubic-bezier(.2,.9,.2,1), transform 160ms cubic-bezier(.2,.9,.2,1) !important;
  box-shadow: 0 1px 0 rgba(0,0,0,0.08) inset !important;
}
.modal-box[data-custom-override] input[type="checkbox"]:checked {
  background: #2563eb !important;
  border-color: #2563eb !important;
}
.modal-box[data-custom-override] input[type="checkbox"]:checked::after {
  opacity: 1 !important;
  transform: translate(-50%, -58%) scale(1) !important;
}

/* Lower-right sticky logo stamp */
body::after {
  content: "";
  position: fixed;
  right: 16px; /* small gap from right edge */
  bottom: 5px; /* small gap from bottom edge */
  width: 92px; /* smaller stamp */
  height: 46px;
  max-width: 12vw;
  max-height: 12vh;
  background-image: url("/assets/images/cardiosource-logo-old.png");
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center;
  opacity: 0.22; /* increased visibility */
  z-index: 1000000; /* on top of almost everything */
  pointer-events: none; /* don't block clicks */
  /* keep color as-is so logo retains its brand colors */
}

/* Slightly larger and more visible on wider screens */
@media (min-width: 1200px) {
  body::after {
    width: 120px;
    height: 60px;
    opacity: 0.24;
  }
}

@media (min-width: 1600px) {
  body::after {
    width: 140px;
    height: 70px;
    opacity: 0.26;
  }
}



/* ==============================
   Floating Select Dropdown Styles
   ============================== */

/* Floating overlay used by attachFloatingDropdown() */
.floating-select-dropdown {
  position: absolute;
  z-index: 9999;
  background: white;
  border: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 8px 24px rgba(2,6,23,0.08);
  border-radius: 6px;
  max-height: 320px;
  overflow-y: auto;
  min-width: 220px;
  padding: 6px 0;
}
.floating-select-item {
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.92rem;
  line-height: 1.05;
}
.floating-select-item:hover { background: rgba(59,130,246,0.06); }
.floating-select-item.disabled { opacity: 0.5; cursor: default; }

/* Utility when switching native select to listbox size on small screens */
.select-scrollable {
  height: auto !important;
}
/* Utility: responsive scrolling for filter dropdowns used across pages
  - Uses viewport-height based max to adapt on small screens
  - Provides internal vertical scrolling when content exceeds the max
  - Add this class to any dropdown container to enable behavior */
.filter-dropdown-scroll {
  /* On large screens allow up to 50vh, on small screens up to 60vh */
  max-height: 50vh;
  overflow-y: auto;
  overflow-x: hidden;
}
@media (max-width: 640px) {
  .filter-dropdown-scroll {
    max-height: 60vh;
  }
  /* On small screens, center the filter dropdown and constrain its width so it fits the viewport */
  #filterDropdown {
    position: fixed !important;
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%);
    top: calc(var(--top-offset, 56px)); /* allow small offset from top (header height); adjustable via CSS var */
    min-width: auto !important;
    max-width: calc(100% - 32px) !important; /* leave 16px margin each side */
    width: auto;
    border-radius: 0.5rem;
    box-sizing: border-box;
    z-index: 1100;
  }
}
/* Typeahead dropdown styles */
.typeahead-list {
  box-sizing: border-box;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  overflow: auto;
  max-height: 320px;
  font-size: 0.95rem;
  padding: 6px 6px;
}
.typeahead-item {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  color: #111827;
}
.typeahead-item + .typeahead-item { margin-top: 4px; }
.typeahead-item:hover,
.typeahead-item[aria-selected="true"] {
  background: #f3f4f6;
}
.typeahead-item .ta-title {
  font-weight: 600;
  color: #0f172a;
  display: block;
}
.typeahead-item .ta-meta {
  display: block;
  font-size: 0.82rem;
  color: #6b7280;
  margin-top: 2px;
}
.typeahead-item .ta-meta .muted {
  color: #9ca3af;
  margin-left: 6px;
}
.typeahead-item .ta-email {
  display: inline-block;
  font-weight: 500;
  color: #2563eb;
  margin-left: 8px;
}

/* small helper to render clinic/district pill in meta */
.typeahead-pill {
  display: inline-block;
  background: #eef2ff;
  color: #3730a3;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.75rem;
  margin-right: 6px;
}