/* Summary Table Component Styles - Compiled CSS */

/* ============================================ */
/* Summary Table Container */
/* ============================================ */
.summary-table-container {
  margin-top: 1.5rem;
  margin-bottom: 1.5rem;
  width: 100%;
  overflow: hidden;
  border-radius: 0.5rem;
  border: 1px solid #e5e7eb;
  background-color: #fff;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.summary-table {
  display: flex;
  width: 100%;
  flex-direction: column;
}

/* ============================================ */
/* Table Header */
/* ============================================ */
.summary-table-header {
  display: flex;
  background: linear-gradient(to bottom, #f8fafc 0%, #f1f5f9 100%);
  border-bottom: 2px solid var(--color-primary);
}

.summary-header-cell {
  flex: 1;
  padding: 1rem 1.5rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
}

/* ============================================ */
/* Table Rows */
/* ============================================ */
.summary-row {
  display: flex;
  flex-direction: row;
  border-bottom: 1px solid #f3f4f6;
  transition: background-color 0.15s ease;
}

.summary-row:hover {
  background-color: #f8fafc;
}

.summary-row:last-child {
  border-bottom: none;
}

/* ============================================ */
/* Table Cells */
/* ============================================ */
.summary-cell {
  display: flex;
  flex: 1;
  align-items: center;
  padding: 1rem 1.5rem;
  font-size: 0.875rem;
  color: #374151;
  min-width: 0;
}

.summary-cell.label {
  background-color: #fafafa;
  font-weight: 600;
  color: #1e293b;
  width: 30%;
  flex: none;
}

/* Mobile header labels - ALWAYS hidden by default */
.mobile-header,
.summary-table .mobile-header,
.summary-row .mobile-header,
.summary-cell .mobile-header {
  display: none !important;
  visibility: hidden !important;
}

/* ============================================ */
/* Row Groups */
/* ============================================ */
.table-row-group {
  border-bottom: 1px solid #e5e7eb;
}

.table-row-group:last-child {
  border-bottom: none;
}

.row-group-header {
  display: flex;
  cursor: pointer;
  user-select: none;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: linear-gradient(to right, #f8fafc, #f1f5f9);
  transition: background-color 0.2s ease;
}

.row-group-header:hover {
  background: linear-gradient(to right, #f1f5f9, #e2e8f0);
}

.group-title {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--color-primary);
  letter-spacing: 0.05em;
}

.group-title-shimmer {
  background: linear-gradient(90deg, var(--color-primary) 25%, #e8c4b0 50%, var(--color-primary) 75%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: title-shimmer 2s ease-in-out infinite;
}

.chevron {
  width: 1rem;
  height: 1rem;
  color: var(--color-primary);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.chevron.rotate-180 {
  transform: rotate(180deg);
}

/* ============================================ */
/* Summary Section Styling */
/* ============================================ */
.summary-section {
  margin-bottom: 2rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--color-primary);
}

.section-toggle-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  margin-left: -0.25rem;
  border-radius: 0.25rem;
  transition: background-color 0.15s ease;
}

.section-toggle-btn:hover {
  background-color: #f9fafb;
}

.section-chevron {
  width: 1.25rem;
  height: 1.25rem;
  color: var(--color-primary);
  transition: transform 0.2s ease;
}

.section-chevron.rotate-180 {
  transform: rotate(180deg);
}

.section-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: #1f2937;
}

.legacy-content {
  font-size: 0.875rem;
  color: #4b5563;
  font-style: italic;
}

.no-data-message {
  font-size: 0.875rem;
  color: #6b7280;
  font-style: italic;
}

/* ============================================ */
/* Citable Cell Styling */
/* ============================================ */
/* nowrap keeps the copy button beside the value: wrapping the flex row dropped the
   button onto a line of its own whenever the value filled the width. The value wraps
   inside its own box instead. Its min-width stays auto (its longest word): at 0 a long
   unbroken token - a medication name, an id - spilled out over the button. */
.citable-cell {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: baseline;
}

.cell-value {
  margin-right: 0.25rem;
}

.cell-clickable {
  cursor: pointer;
  transition: color 0.15s ease;
}

.cell-clickable:hover {
  color: var(--color-primary);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 4px;
}

/* ============================================ */
/* Per-field copy (discharged_summary_copy)     */
/* ============================================ */
/* CopyTextButton. The wrapper is the flex item and is positioned, so the button's
   sr-only status span (position: absolute) is placed inside it. Unanchored, that span
   is placed against the page itself, escapes every overflow wrapper up to MainLayout,
   and makes the whole document scroll - sidebar and all - as far as the last cell sits
   down the summary. */
.copy-btn-wrap {
  position: relative;
  display: inline-flex;
  align-self: center;
  flex-shrink: 0;
  margin-left: 0.25rem;
}

/* Hidden until the cell is hovered or the button is focused; feedback stays visible
   for its duration even once the pointer has moved on. */
.cell-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem;
  border: 1px solid transparent;
  border-radius: 0.375rem;
  background: none;
  color: #6b7280;
  font-size: 0.75rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.summary-cell:hover .cell-copy-btn,
.citable-cell:hover .cell-copy-btn,
.cell-copy-btn:focus-visible,
.cell-copy-btn.is-copied,
.cell-copy-btn.is-failed {
  opacity: 1;
}

/* Inside a pill row the container's gap already spaces it from the last pill. */
.label-container .copy-btn-wrap {
  margin-left: 0;
}

/* The patient's name and MRN in the top bar. Nothing there to hover first, so the
   button is always shown, quieter until pointed at; and compact, so it does not make
   the one-line header taller. */
.patient-identity-copy .cell-copy-btn {
  opacity: 0.6;
  padding: 0.125rem;
}

.patient-identity-copy .cell-copy-btn svg {
  width: 12px;
  height: 12px;
}

.patient-identity-copy .copy-btn-wrap {
  margin-left: 0;
}

.patient-identity-copy .cell-copy-btn:hover,
.patient-identity-copy .cell-copy-btn:focus-visible,
.patient-identity-copy .cell-copy-btn.is-copied,
.patient-identity-copy .cell-copy-btn.is-failed {
  opacity: 1;
}

.cell-copy-btn:hover {
  color: var(--color-primary);
  background-color: #f3f4f6;
  border-color: #e5e7eb;
}

.cell-copy-btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.cell-copy-btn.is-copied {
  color: #15803d;
  background-color: #dcfce7;
  border-color: #86efac;
}

.cell-copy-btn.is-failed {
  color: #b91c1c;
  background-color: #fee2e2;
  border-color: #fca5a5;
}

.cell-copy-status {
  font-weight: 600;
  white-space: nowrap;
}

/* No hover on touch screens: keep the button visible, just quieter. */
@media (hover: none) {
  .cell-copy-btn {
    opacity: 0.6;
  }
}

/* Summary export menu (top of the summary) */
.summary-export {
  position: relative;
}

.summary-export-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
}

.summary-export-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.25rem);
  z-index: 50;
  min-width: 15rem;
  padding: 0.25rem 0;
  background-color: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}

.summary-export-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  padding: 0.5rem 0.875rem;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
}

.summary-export-item:hover,
.summary-export-item:focus-visible {
  background-color: #f3f4f6;
  outline: none;
}

.summary-export-item-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #1f2937;
}

.summary-export-item-hint {
  font-size: 0.75rem;
  color: #6b7280;
}

/* ============================================ */
/* Label/Tag Styling for multi-value cells */
/* ============================================ */
.label-container {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.label-prefix {
  font-size: 0.875rem;
  color: #6b7280;
  margin-right: 0.25rem;
}

.cell-label {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background-color: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 0.25rem;
  font-size: 0.8125rem;
  color: #374151;
}

.label-container:hover .cell-label {
  background-color: #e5e7eb;
}

.label-container:hover .label-prefix {
  color: var(--color-primary);
}

/* ============================================ */
/* Medication Diff Highlighting */
/* ============================================ */
.cell-label-added {
  background-color: #dcfce7;  /* Light green */
  border-color: #86efac;
}

.cell-label-removed {
  background-color: #fee2e2;  /* Light red */
  border-color: #fca5a5;
}

.label-container:hover .cell-label-added {
  background-color: #bbf7d0;
}

.label-container:hover .cell-label-removed {
  background-color: #fecaca;
}

/* Re-issued under the same name at a new frequency */
.cell-label-changed {
  background-color: #fef3c7;  /* Light amber */
  border-color: #fcd34d;
}

.label-container:hover .cell-label-changed {
  background-color: #fde68a;
}

.no-medication-changes {
  font-size: 0.875rem;
  color: #6b7280;
  font-style: italic;
}

/* ============================================ */
/* Missing Fields Row - Full Width */
/* ============================================ */
.missing-fields-row {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 0.75rem 1.5rem;
  border-top: 1px solid #e5e7eb;
  cursor: pointer;
  position: relative;
}

.missing-fields-text {
  color: #6b7280;
  font-size: 0.875rem;
  font-style: italic;
}

.missing-fields-row:hover .missing-fields-text {
  color: var(--color-primary);
}

.missing-fields-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.missing-fields-icon {
  color: #9ca3af;
  flex-shrink: 0;
}

.missing-fields-row:hover .missing-fields-icon {
  color: var(--color-primary);
}

.missing-fields-hint {
  color: #9ca3af;
  font-size: 0.75rem;
  font-style: normal;
}

/* Hide hint on desktop (hover works), show on touch devices */
@media (hover: hover) {
  .missing-fields-hint {
    display: none;
  }
}

.missing-fields-tooltip {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background-color: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 0.375rem;
  font-size: 0.8125rem;
  color: #374151;
  font-style: normal;
  line-height: 1.5;
}

.missing-fields-labels {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.missing-field-label {
  display: inline-block;
  padding: 0.25rem 0.625rem;
  background-color: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 0.25rem;
  font-size: 0.8125rem;
  color: #92400e;
}

/* Error cell styling */
.cell-error {
    background-color: #fef2f2;
}

.cell-error-text {
    color: #dc2626;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.cell-error-icon {
    color: #dc2626;
    flex-shrink: 0;
}

/* ============================================ */
/* Sticky Top Progress Strip (replaces between-sections bar) */
/* ============================================ */
.streaming-top-strip {
    position: sticky;
    top: 0;
    z-index: 10;
    height: 3px;
    background: #e5e7eb;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.streaming-top-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary, #4f46e5), #818cf8);
    transition: width 0.3s cubic-bezier(0.23, 1, 0.32, 1);
}

/* Cell Style Variations */
.cell-bold {
  font-weight: 600;
  color: #111827;
}

.cell-emphasized {
  color: var(--color-primary);
  font-weight: 500;
}

.cell-subdued {
  color: #6b7280;
}

/* ============================================ */
/* Citation Badges */
/* ============================================ */
.citation-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-left: 3px;
  font-size: 10px;
  font-weight: 600;
  color: white;
  background: var(--color-primary);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.15s ease;
}

.citation-badge:hover {
  background: var(--color-primary-hover);
  transform: scale(1.1);
}

/* ============================================ */
/* Table Style Variations */
/* ============================================ */

/* Patient Summary Style - 2 column layout */
.table-patient-summary .summary-header-cell:first-child,
.table-patient-summary .summary-cell:first-child,
.table-patient-summary .summary-header-cell.label,
.table-patient-summary .summary-cell.label {
  width: 30%;
  min-width: 180px;
  flex: none;
}

/* Comparative Style - Variable columns with fixed label */
.table-comparative .summary-header-cell,
.table-comparative .summary-cell {
  flex: 1;
  min-width: 120px;
}

.table-comparative .summary-header-cell:first-child,
.table-comparative .summary-cell:first-child,
.table-comparative .summary-header-cell.label,
.table-comparative .summary-cell.label {
  width: 200px;
  min-width: 200px;
  max-width: 200px;
  flex: none;
}

/* Contact List Style */
.table-contact-list .summary-header-cell,
.table-contact-list .summary-cell {
  flex: 1;
}

/* Assessment Changes Style */
.table-assessment-changes .summary-header-cell,
.table-assessment-changes .summary-cell {
  flex: 1;
  min-width: 120px;
}

.table-assessment-changes .summary-header-cell:first-child,
.table-assessment-changes .summary-cell:first-child,
.table-assessment-changes .summary-header-cell.label,
.table-assessment-changes .summary-cell.label {
  width: 200px;
  min-width: 200px;
  max-width: 200px;
  flex: none;
}

/* Documentation List Style */
.table-documentation-list .summary-header-cell,
.table-documentation-list .summary-cell {
  flex: 1;
}

/* Ensure header label cells match data label cells */
.summary-header-cell.label {
  background-color: #fafafa;
  font-weight: 700;
}

/* ============================================ */
/* Collapsible Category Components */
/* ============================================ */
.collapsible-category {
  margin-bottom: 1rem;
}

.category-header {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background-color: #f9fafb;
  text-align: left;
  border-radius: 0.5rem;
  border: 1px solid #e5e7eb;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.category-header:hover {
  background-color: #f3f4f6;
}

.category-title {
  font-size: 1rem;
  font-weight: 600;
  color: #1f2937;
}

.category-icon {
  width: 1.25rem;
  height: 1.25rem;
  color: #6b7280;
  transition: transform 0.15s ease;
}

.category-icon.rotate-180 {
  transform: rotate(180deg);
}

.category-content {
  margin-top: 0.5rem;
  border-left: 2px solid #e5e7eb;
  padding-left: 1rem;
}

/* ============================================ */
/* Copy/Paste Protection (Compliance) */
/* ============================================ */
.summary-content {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.summary-content * {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* ============================================ */
/* Mobile Card Styles */
/* ============================================ */
.summary-card {
  border-bottom: 1px solid #e5e7eb;
  padding: 1rem;
}

.summary-card:last-child {
  border-bottom: none;
}

.summary-card > * + * {
  margin-top: 0.75rem;
}

.summary-card-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.summary-card-label {
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  color: #6b7280;
}

.summary-card-value {
  text-align: right;
  font-size: 0.875rem;
  color: #111827;
}

/* ============================================ */
/* Desktop Responsive Styles - Hide mobile elements */
/* ============================================ */
@media (min-width: 768px) {
  .mobile-header {
    display: none !important;
  }
  
  .summary-table-header {
    display: flex;
  }
  
  .summary-row {
    display: flex;
    flex-direction: row;
  }
}

/* ============================================ */
/* Tablet & Mobile Responsive Styles */
/* ============================================ */
@media (max-width: 767px) {
  .summary-table {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .summary-table-header {
    display: none !important;
  }

  .summary-row {
    display: flex;
    flex-direction: column;
    border-radius: 0.5rem;
    border: 1px solid #e5e7eb;
    background-color: #fff;
    padding: 0.75rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
  }

  .summary-cell {
    padding: 0.5rem 0;
    flex-direction: column;
    align-items: flex-start;
  }

  .summary-cell.label {
    width: auto;
    flex: initial;
    margin-bottom: 0.25rem;
    font-weight: 600;
    color: var(--color-primary);
    background-color: transparent;
  }

  .mobile-header,
  .summary-table .mobile-header,
  .summary-row .mobile-header,
  .summary-cell .mobile-header {
    display: inline !important;
    visibility: visible !important;
    margin-right: 0.5rem;
    font-weight: 500;
    color: #6b7280;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
  }

  .summary-table {
    font-size: 0.875rem;
  }

  .section-title {
    font-size: 1.125rem;
  }

  .row-group-header {
    padding: 0.5rem 1rem;
  }

  .group-title {
    font-size: 0.75rem;
  }
}

/* ============================================ */
/* Touch-friendly citation badges on mobile */
/* ============================================ */
@media (max-width: 767px) {
  .citation-badge {
    width: 22px;
    height: 22px;
    font-size: 11px;
    margin-left: 4px;
  }
}

/* ============================================ */
/* Ensure tables don't overflow on small screens */
/* ============================================ */
.summary-table-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 768px) {
  .summary-table-container {
    overflow-x: visible;
  }
}

/* Tables with many columns should always be horizontally scrollable */
.summary-table-container.table-comparative,
.summary-table-container.table-assessment-changes {
  overflow-x: auto;
}

/* ============================================ */
/* Skeleton Loader */
/* ============================================ */
.skeleton-line {
  height: 0.875rem;
  border-radius: 0.25rem;
  background-color: #e5e7eb;
}

.skeleton-title {
  border-radius: 0.25rem;
  background-color: #e5e7eb;
}

.skeleton-shimmer {
  background: linear-gradient(90deg, #e5e7eb 25%, #f3f4f6 50%, #e5e7eb 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
}

@keyframes skeleton-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ============================================ */
/* PHI Masking                                  */
/* ============================================ */
.phi-blur {
  filter: blur(6px);
  user-select: none;
  pointer-events: none;
  transition: filter 0.2s ease;
}

/* ============================================ */
/* Section title shimmer during streaming       */
/* ============================================ */
@keyframes title-shimmer {
  0%   { background-position: 200% center; }
  100% { background-position: -200% center; }
}

.section-title-streaming {
  background: linear-gradient(90deg, #1f2937 30%, #9ca3af 50%, #1f2937 70%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: title-shimmer 2s ease-in-out infinite;
}

/* ============================================ */
/* Section body fade-in on expand               */
/* ============================================ */
@keyframes section-body-enter {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.section-body-enter {
  animation: section-body-enter 250ms ease-out forwards;
}

/* ============================================ */
/* Per-cell skeleton shimmer                    */
/* ============================================ */
.cell-skeleton {
  display: inline-block;
  width: 65%;
  min-width: 48px;
  height: 0.875rem;
  border-radius: 0.25rem;
  background: linear-gradient(90deg, #e5e7eb 25%, #f3f4f6 50%, #e5e7eb 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
}

/* ============================================ */
/* Cell value fade-in when data arrives         */
/* ============================================ */
@keyframes cell-value-enter {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.cell-value-enter {
  animation: cell-value-enter 200ms ease-out forwards;
}
