/* ========================================
   UTILITY & LEGACY HELPERS
   Used by JS-generated content & Tailwind pages
   ======================================== */
/* ========================================
   CSS VARIABLES (Root)
   ======================================== */
:root {
  --danger: #dc2626;
  --text-secondary: #6b7280;
  --border: #e5e7eb;
}


/* Visibility Utilities */
.hide {
  display: none !important;
}

.show {
  display: initial !important;
}

/* Center modals when visible (supports both .show and .modal--active patterns) */
.modal.show,
.modal.modal--active {
  display: flex !important;
  align-items: center;
  justify-content: center;
}

/* Loading spinner */
.loading__spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid #e5e7eb;
  border-top-color: #6200ea;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ========================================
   MODAL STYLES
   ======================================== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  display: none;
}

/* Fallback for legacy modals without .modal parent class */
.modal--active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal__overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  z-index: 1001;
}

.modal__card,
.modal__content {
  position: relative;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  z-index: 1002;
}

/* Override tailwind.css opacity:0/transform defaults for modal--active state */
.modal.modal--active .modal__card,
.modal.modal--active .modal__content {
  opacity: 1;
  transform: none;
}

.modal__header {
  padding: 24px 24px 16px 24px;
  border-bottom: 1px solid #e0e0e0;
}

.modal__title {
  margin: 0 0 8px 0;
  font-size: 1.5rem;
  color: #1a1a1a;
}

.modal__close {
  background: none;
  border: none;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0.35rem;
  border-radius: 50%;
  color: #64748b;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal__close:hover {
  background: #f8fafc;
  color: #1a1a1a;
}

.modal__body {
  padding: 24px;
  overflow-y: auto;
}

.modal__footer {
  padding: 16px 24px;
  border-top: 1px solid #e0e0e0;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* ========================================
   GENERIC TABLE SPACING (for tables without .table class)
   ======================================== */
table tbody tr {
  border-bottom: 1px solid #e5e7eb;
}

table tbody td {
  padding: 1rem 1.5rem;
  vertical-align: middle;
}

table tbody tr:hover {
  background-color: #f9fafb;
}


/* ========================================
   TABLE STYLES (Legacy & Dynamic)
   ======================================== */
.table-container {
  overflow-x: auto;
  width: 100%;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table thead th {
  padding: 1rem 1.5rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
  background: #f9fafb;
  border-bottom: 2px solid #e5e7eb;
}

.table tbody tr {
  border-bottom: 1px solid #e5e7eb;
}

.table tbody td {
  padding: 1rem 1.5rem;
  vertical-align: middle;
  border-bottom: 1px solid #e5e7eb;
}

.table tbody tr:hover {
  background-color: #f9fafb;
}

/* ========================================
   TOOLTIP
   ======================================== */
.tooltip:hover .tooltip__content {
  display: block;
}

/* ========================================
   CARD STYLES
   ======================================== */
.card {
  background: white;
  border-radius: 0.75rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  margin-bottom: 1.5rem;
}

.card__header {
  padding: 1.5rem;
  border-bottom: 1px solid #e5e7eb;
}

.card__header h4,
.card__header h3 {
  font-size: 1.125rem;
  font-weight: 600;
  color: #1e3a5f;
  margin: 0;
}

.card__body {
  padding: 1.5rem;
}

.card__footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
}

/* Report content specific overrides */
.card>#reportContent,
.card #reportContent {
  padding: 1.5rem;
}

#reportContent .alert {
  margin: 0 0 1.5rem 0;
}

#reportContent .table-container {
  margin: 0 -1.5rem;
  width: calc(100% + 3rem);
}

#reportContent .card__footer {
  margin: 0 -1.5rem -1.5rem -1.5rem;
  border-bottom-left-radius: 0.75rem;
  border-bottom-right-radius: 0.75rem;
}

/* ========================================
   PAGE HEADERS
   ======================================== */
.page-header {
  margin-bottom: 1.5rem;
}

.page-header h1,
.page-header h2 {
  font-size: 2rem;
  font-weight: 700;
  color: #1e3a5f;
  margin: 0 0 0.5rem 0;
}

.page-header p {
  color: #6b7280;
  margin: 0;
}

/* Sticky Header */
header.h-16 {
  position: sticky;
  top: 0;
  z-index: 40;
}

/* ========================================
   TEXT & LAYOUT UTILITIES
   ======================================== */
.text-error {
  color: #dc2626;
}

.text-muted {
  color: #6b7280;
}

.text-success {
  color: #059669;
}

.text-warn {
  color: #d97706;
}

.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.flex {
  display: flex;
}

.justify-between {
  justify-content: space-between;
}

.align-center {
  align-items: center;
}

.gap-2 {
  gap: 0.5rem;
}

.gap-3 {
  gap: 0.75rem;
}

/* Spacing */
.mb-1 {
  margin-bottom: 0.25rem;
}

.mb-2 {
  margin-bottom: 0.5rem;
}

.mb-3 {
  margin-bottom: 0.75rem;
}

.mb-4 {
  margin-bottom: 1rem;
}

.mt-2 {
  margin-top: 0.5rem;
}

.mt-3 {
  margin-top: 0.75rem;
}

.py-5 {
  padding-top: 1.25rem;
  padding-bottom: 1.25rem;
}

/* ========================================
   BUTTONS
   ======================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
}

.btn--sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
}

.btn--primary {
  background-color: #3b82f6;
  color: white;
}

.btn--primary:hover {
  background-color: #2563eb;
}

.btn--secondary {
  background-color: #f3f4f6;
  color: #1e3a5f;
  border: 1px solid #e5e7eb;
}

.btn--secondary:hover {
  background-color: #e5e7eb;
}

/* ========================================
   EMPTY STATE
   ======================================== */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
}

.empty-state h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: #1e3a5f;
  margin: 0 0 0.5rem 0;
}

.empty-state p {
  color: #6b7280;
  margin: 0 0 1rem 0;
}

/* ========================================
   TABS
   ======================================== */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
}

.tab {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #6b7280;
  background: transparent;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab:hover {
  color: #1e3a5f;
  background: #f3f4f6;
}

.tab--active {
  color: #1e3a5f;
  background: #e0e7ff;
}

/* ========================================
   STATS CARDS
   ======================================== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: white;
  border-radius: 0.75rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  padding: 1.5rem;
  text-align: center;
}

.stat-card__value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #1e3a5f;
  margin-bottom: 0.25rem;
}

.stat-card__label {
  font-size: 0.75rem;
  color: #6b7280;
}

/* Stat Variants */
.stat-card--warn .stat-card__value {
  color: #d97706;
}

.stat-card--error .stat-card__value {
  color: #dc2626;
}

.stat-card--success .stat-card__value {
  color: #059669;
}

.stat-card--critical .stat-card__value {
  color: #dc2626;
}

.stat-card--info .stat-card__value {
  color: #3b82f6;
}

/* ========================================
   ALERTS
   ======================================== */
.alert {
  padding: 1rem 1.5rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
}

.alert--error {
  background-color: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

.alert--warn {
  background-color: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
}

.alert--success {
  background-color: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

.alert h4 {
  color: inherit;
  font-size: 1rem;
}

.alert p {
  color: inherit;
  opacity: 0.9;
}

/* ========================================
   FORM CONTROLS (Dynamic & Modal Forms)
   ======================================== */

.form-control,
.form__input,
.form__select,
.form__textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: #1f2937;
  background-color: #fff;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

/* Focus States */
.form-control:focus,
.form__input:focus,
.form__select:focus,
.form__textarea:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form__group {
  margin-bottom: 1rem;
}

.form__label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: #374151;
  margin-bottom: 0.5rem;
}

textarea.form__input,
textarea.form__textarea {
  resize: vertical;
  min-height: 80px;
}

/* Custom Select styling (SVG Arrow) */
select.form__input,
select.form__select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.5rem center;
  background-repeat: no-repeat;
  background-size: 1.5em 1.5em;
  padding-right: 2.5rem;
}

/* ========================================
   BUTTON SPACING
   ======================================== */
/* Button spacing when side-by-side */
.btn+.btn {
  margin-left: 0.5rem;
}

/* ========================================
   ADDITIONAL BUTTON VARIANTS
   ======================================== */
.btn--error,
.btn--danger {
  background-color: #dc2626;
  color: white;
}

.btn--error:hover,
.btn--danger:hover {
  background-color: #b91c1c;
}

.btn--success {
  background-color: #059669;
  color: white;
}

.btn--success:hover {
  background-color: #047857;
}

/* ========================================
   TOOLTIP STYLES (Sidebar)
   Uses position:fixed to escape overflow:auto clipping
   ======================================== */
.tooltip {
  position: static;
}

/* Hide content by default */
.tooltip__content {
  visibility: hidden;
  opacity: 0;
  position: fixed;
  left: 270px;
  margin-left: 12px;
  padding: 0.5rem 0.75rem;
  background-color: #1e293b;
  color: #fff;
  border-radius: 0.375rem;
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 9999;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  pointer-events: none;
  transition: opacity 0.15s, visibility 0.15s;
}

/* Add arrow pointing left */
.tooltip__content::before {
  content: "";
  position: absolute;
  top: 50%;
  right: 100%;
  margin-top: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: transparent #1e293b transparent transparent;
}

/* Show on hover */
.tooltip:hover .tooltip__content {
  visibility: visible;
  opacity: 1;
}

/* ========================================
   PRINT STYLES
   Professional print layout for incident reports
   ======================================== */

/* Print header - hidden on screen, visible when printing */
.print-header {
  display: none;
}

@media print {
  /* ---- FORCE HIDE SIDEBAR ---- */
  aside,
  aside.sticky,
  [aria-label="Audit navigation"],
  [aria-label*="navigation"] {
    display: none !important;
    width: 0 !important;
    visibility: hidden !important;
  }

  /* ---- HIDE NON-ESSENTIAL ELEMENTS ---- */
  /* Top header bar */
  header.h-16 {
    display: none !important;
  }

  /* Hide delete buttons and loading states */
  .btn--danger,
  [class*="delete"],
  [class*="Delete"],
  .loading,
  [class*="Loading"],
  [class*="Error"] {
    display: none !important;
  }

  /* Action buttons */
  #editBtn,
  #investigateBtn,
  #addWitnessBtn,
  #uploadBtn,
  #statusBtn,
  #createActionBtn,
  .flex.flex-wrap.items-center.gap-2.mb-6 {
    display: none !important;
  }

  /* Tab buttons row */
  .tabs {
    display: none !important;
  }

  /* Modal dialogs */
  .modal,
  #reviewModal,
  .fixed.inset-0,
  [class*="fixed"][class*="inset-0"] {
    display: none !important;
    visibility: hidden !important;
  }

  /* Force hide loading and error states - Audits */
  div#loadingState,
  div#errorState,
  #loadingState,
  #errorState {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    overflow: hidden !important;
  }

  /* Hide Create Action Plan buttons */
  #createActionPlanBtn,
  #createActionPlanBtn2,
  a[href*="create"],
  [onclick*="createAction"],
  [onclick*="CreateAction"] {
    display: none !important;
  }

  /* Hide Delete buttons (specific selectors only - .text-red-600 alone is too broad) */
  button.text-red-600,
  a.text-red-600,
  .btn-delete-file {
    display: none !important;
  }

  /* ---- HIDE ALL INTERACTIVE ELEMENTS ---- */
  /* Forms and inputs */
  input,
  textarea,
  select {
    display: none !important;
  }

  /* All buttons */
  button,
  .btn {
    display: none !important;
  }

  /* Forms */
  form {
    display: none !important;
  }

  /* Hide empty states */
  .empty-state,
  .no-print {
    display: none !important;
  }

  /* ---- SHOW ALL TAB CONTENT ---- */
  /* Override .hide class for tab panels - Incidents */
  #investigationTab,
  #witnessesTab,
  #actionsTab,
  #filesTab,
  #lessonsTab {
    display: block !important;
  }

  /* Override .hide class for tab panels - Risks */
  #detailsTab,
  #mitigationTab,
  #reviewsTab,
  #updatesTab {
    display: block !important;
  }

  /* Override .hide class for tab panels - Audits */
  #overviewTab,
  #responsesTab,
  #evidenceTab,
  #actionPlansTab {
    display: block !important;
  }

  /* Override .hide class for tab panels - Meetings */
  #detailsTab,
  #attendeesTab,
  #agendaTab,
  #minutesTab,
  #actionsTab,
  #filesTab {
    display: block !important;
  }

  /* Hide action buttons - Risks */
  #reviewBtn,
  #mitigateBtn,
  #closedRiskTooltip {
    display: none !important;
  }

  /* Hide action buttons - Action Plans */
  #backBtn,
  #progressBtn,
  #completeBtn,
  #addCommentBtn,
  #uploadBtn,
  #commentText {
    display: none !important;
  }

  /* ---- FORCE SINGLE COLUMN LAYOUT ---- */
  /* Target specific Tailwind grid classes */
  .grid-cols-1,
  .grid-cols-2,
  .grid-cols-3,
  .grid-cols-4,
  .md\:grid-cols-2,
  .md\:grid-cols-3,
  .md\:grid-cols-4,
  .lg\:grid-cols-2,
  .lg\:grid-cols-3,
  .lg\:grid-cols-4 {
    display: block !important;
    grid-template-columns: none !important;
  }

  .grid-cols-1 > *,
  .grid-cols-2 > *,
  .grid-cols-3 > *,
  .grid-cols-4 > *,
  .md\:grid-cols-2 > *,
  .md\:grid-cols-3 > *,
  .md\:grid-cols-4 > *,
  .lg\:grid-cols-2 > *,
  .lg\:grid-cols-3 > *,
  .lg\:grid-cols-4 > * {
    width: 100% !important;
    max-width: 100% !important;
    margin-bottom: 0.75rem !important;
  }

  /* Kill all grid and flex side-by-side layouts */
  .grid {
    display: block !important;
  }

  .flex {
    display: block !important;
  }

  .flex > * {
    width: 100% !important;
    margin-bottom: 0.5rem !important;
  }
  .grid > *,
  [class*="grid-cols-"] > * {
    width: 100% !important;
    margin-bottom: 1rem;
  }

  /* Override flex layouts that create side-by-side columns */
  .flex.gap-6 > *,
  .flex.gap-8 > * {
    width: 100% !important;
    margin-bottom: 1rem;
  }

  /* ---- LAYOUT ADJUSTMENTS ---- */
  /* Override tailwind.css print rule that hides main */
  body {
    margin: 0;
    padding: 0;
    background: white !important;
  }

  main {
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Ensure content container is visible */
  .flex-1.overflow-y-auto.overflow-x-hidden.p-6,
  .flex-1.flex.flex-col {
    display: block !important;
  }

  /* Content area */
  .flex-1.overflow-y-auto.overflow-x-hidden.p-6 {
    padding: 0.5rem !important;
    overflow: visible !important;
  }

  /* ---- PRINT HEADER ---- */
  .print-header {
    display: block !important;
    padding: 1rem 0;
    margin-bottom: 1rem;
    border-bottom: 2px solid #1e3a5f;
  }

  .print-header__logo {
    font-size: 0.875rem;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.5rem;
  }

  .print-header__title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #1e3a5f;
    margin: 0 0 0.5rem 0;
  }

  .print-header__meta {
    font-size: 0.75rem;
    color: #6b7280;
  }

  /* ---- CARD STYLING FOR PRINT ---- */
  .bg-white.rounded-xl.shadow-sm.border {
    box-shadow: none !important;
    border: 1px solid #e5e7eb !important;
    margin-bottom: 1rem;
    page-break-inside: avoid;
  }

  /* Section headers */
  .p-6.border-b h4 {
    font-size: 1rem;
    color: #1e3a5f;
  }

  /* Reduce padding for print */
  .p-6 {
    padding: 0.75rem !important;
  }

  /* ---- SECTION SEPARATION ---- */
  #investigationTab,
  #witnessesTab,
  #actionsTab,
  #filesTab,
  #lessonsTab,
  #detailsTab,
  #mitigationTab,
  #reviewsTab,
  #updatesTab,
  #overviewTab,
  #responsesTab,
  #evidenceTab,
  #actionPlansTab,
  #attendeesTab,
  #agendaTab,
  #minutesTab {
    border-top: 1px solid #ccc;
    padding-top: 1rem;
    margin-top: 1rem;
  }

  /* ---- BADGE STYLING FOR PRINT ---- */
  /* Make badges print-friendly (black & white) */
  .badge,
  [class*="badge"] {
    border: 1px solid #1e3a5f !important;
    background: white !important;
    color: #1e3a5f !important;
    padding: 0.125rem 0.375rem;
    font-size: 0.625rem;
  }

  /* ---- PAGE BREAKS ---- */
  /* Avoid breaking inside cards */
  .bg-white.rounded-xl {
    page-break-inside: avoid;
  }

  /* ---- TYPOGRAPHY ---- */
  /* Ensure good contrast for printing */
  body {
    font-size: 10pt;
    line-height: 1.4;
    color: #000 !important;
  }

  p, span, div {
    color: inherit;
  }

  .text-navy {
    color: #000 !important;
  }

  .text-graytext {
    color: #4b5563 !important;
  }

  /* Smaller text sizes for print */
  .text-sm {
    font-size: 0.75rem !important;
  }

  .text-xs {
    font-size: 0.625rem !important;
  }

  /* ---- LINKS ---- */
  a {
    color: #000 !important;
    text-decoration: none !important;
  }

  /* Show file attachments */
  a[download] {
    display: inline !important;
  }

  /* ---- TABLES ---- */
  table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
  }

  table th,
  table td {
    border: 1px solid #e5e7eb;
    padding: 0.375rem;
    text-align: left;
  }

  /* ---- FOOTER ---- */
  @page {
    margin: 1cm;
  }

  /* ---- AUDIT DYNAMIC PRINT CONTAINER SUPPORT ---- */
  /* Hide all page content except print container when printing audits */
  body.print-audit-full > *:not(#printContainer),
  body.print-audit-summary > *:not(#printContainer) {
    display: none !important;
  }

  /* Show the dynamically generated print container */
  body.print-audit-full #printContainer,
  body.print-audit-summary #printContainer {
    display: block !important;
  }

  /* Ensure print container content is visible */
  #printContainer .print-content {
    display: block !important;
  }

  #printContainer .print-meta {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #e5e7eb;
  }

  #printContainer .print-meta p {
    margin: 0.25rem 0;
  }

  #printContainer .print-section {
    margin-bottom: 1.5rem;
    page-break-inside: avoid;
  }

  #printContainer .print-section h2 {
    font-size: 1rem;
    font-weight: 600;
    color: #1e3a5f;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e5e7eb;
  }

  #printContainer .print-question {
    margin-bottom: 1rem;
    padding: 0.5rem;
    background: #f9fafb;
    border-radius: 4px;
  }

  #printContainer .print-question-text {
    margin: 0 0 0.25rem 0;
  }

  #printContainer .print-response {
    margin: 0;
  }

  #printContainer .print-auto-data {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: #fff;
    border-left: 3px solid #1e3a5f;
  }

  #printContainer .print-notes {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: #fffbeb;
    border-left: 3px solid #f59e0b;
  }
}