/* ===== breakdown_of_unbagged_and_not_dispatched_html (HTML form, scoped) =====
   Every rule here comes from the form's old <style> block, which Anvil's server
   strips out of an HTML template. Linked eagerly from this dependency's
   anvil.yaml native_deps.head_html, which is also what styles the designer
   canvas. Declarations are byte for byte; only the selector preludes changed.

   SCOPE. The form root is <div class="wi-container wi-fade-in px-anvil-reset
   themed-scrollbar">, and .wi-container is the private name every descendant
   rule scopes on with :where(), which adds no specificity and so cannot change
   which rule wins. Scoping on px-anvil-reset or themed-scrollbar would reach
   every screen in the host app. Four kinds of rule stay bare:

     * the root's own rules - .wi-container, [data-theme="dark"] .wi-container
       and .wi-fade-in. Their subject IS the root, so a :where(.wi-container)
       ancestor would never match.
     * [data-theme="dark"] .wi-header. It is the FIRST rule in this file and the
       light-mode .wi-header follows it; the pair is kept exactly as the style
       block ordered it. Do not move it and do not give it :where().
     * the .wi-comments-slot-top family. It is already root-relative, every
       declaration is !important, and the first arm is a child combinator aimed
       at the comments panel's Anvil wrapper. Left as written.
     * the remaining [data-theme="dark"] arms take the scope INSIDE the theme
       attribute ([data-theme="dark"] :where(.wi-container) .x), because the
       attribute sits on <html>, outside this root.

   ORDER. From a head link these rules lose every specificity TIE to the
   stylesheets the toolkit appends at runtime (px_theme.ensure_theme_injected,
   pxmar_bridge.ensure_injected). Audited, and there is none to lose:
   every selector in this file is led by a private .wi-* class, none of which is
   declared by _px_theme_css.py, by PXM_SHARED_CSS, or by any host theme asset.
   px-internal's wedge_input_html.css also uses a wi- prefix, but its six names
   (.wi-wrap, .wi-input, .wi-input-row, .wi-focused, .wi-flash, .wi-error) do
   not appear here and its rules are scoped to its own root.

   No rule in this file is aimed at an element that leaves the root: this
   screen's JavaScript makes no appendChild or appendTo('body') call, and the
   only px-modal-portal reference in it is a READ inside wiResolveCommentsScope.
   The overlay is .px-loading-overlay, not .px-modal-overlay, so the toolkit
   never portals it either.

   The keyframes name is already private (wiFadeIn) and is declared nowhere else
   in the estate, so it carries across unchanged. */

/* ========================================
   WARNING ITEMS POPUP - Based on Prescription Details
   ======================================== */

/* Dark mode header - muted orange */
[data-theme="dark"] .wi-header {
  background: linear-gradient(135deg, #92400e 0%, #b45309 100%);
}

.wi-container {
  /* Accent theming - purple accent */
  --accent: #6f42c1;
  --px-loading-accent: var(--accent);
  --accent-subtle: rgba(111, 66, 193, 0.08);
  --wi-success: #1a7f37;
  --wi-success-bg: #dafbe1;
  --wi-warning: #9a6700;
  --wi-warning-bg: #fff8c5;
  --wi-error: #cf222e;
  --wi-error-bg: #ffebe9;
  --wi-row-hover: rgba(111, 66, 193, 0.04);

  font-family: var(--px-font);
  background: var(--px-bg-card);
  color: var(--px-text-primary);
  max-height: 75vh;
  overflow-y: auto;
  padding: 8px 12px 0;
}

[data-theme="dark"] .wi-container {
  --accent: #8b5cf6;
  --accent-subtle: rgba(139, 92, 246, 0.15);
  --wi-success: #4ade80;
  --wi-success-bg: rgba(74, 222, 128, 0.15);
  --wi-warning: #fbbf24;
  --wi-warning-bg: rgba(251, 191, 36, 0.15);
  --wi-error: #f87171;
  --wi-error-bg: rgba(248, 113, 113, 0.15);
  --wi-row-hover: rgba(139, 92, 246, 0.12);
}

/* Header */
:where(.wi-container) .wi-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: linear-gradient(135deg, #d97706 0%, #f59e0b 100%);
  color: white;
  border-radius: 6px;
  margin: 0 0 16px 0;
}

:where(.wi-container) .wi-header-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

:where(.wi-container) .wi-header-title {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

:where(.wi-container) .wi-header-meta {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
  opacity: 0.9;
}

:where(.wi-container) .wi-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

:where(.wi-container) .wi-counts-badge {
  background: rgba(255,255,255,0.18);
  padding: 5px 12px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 500;
  border: 1px solid rgba(255,255,255,0.2);
}

/* Patient Group - Full box around patient header + items */
:where(.wi-container) .wi-patient-group {
  border: 2px solid #94a3b8;
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  margin: 16px 0;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

[data-theme="dark"] :where(.wi-container) .wi-patient-group {
  border-color: #64748b;
  border-left-color: var(--accent);
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}

:where(.wi-container) .wi-patient-group:first-of-type {
  margin-top: 0;
}

/* Patient Header inside group */
:where(.wi-container) .wi-patient-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--px-bg-elevated);
  padding: 12px 16px;
  transition: opacity 0.15s, transform 0.15s, background-color 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
  border-bottom: 1px solid var(--px-border);
}

:where(.wi-container) .wi-patient-header-clickable {
  cursor: pointer;
}

:where(.wi-container) .wi-patient-header-clickable:hover {
  background: var(--accent-subtle);
}

:where(.wi-container) .wi-patient-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

:where(.wi-container) .wi-patient-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--px-text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

:where(.wi-container) .wi-patient-name::before {
  content: '';
  width: 4px;
  height: 1.1em;
  background: linear-gradient(135deg, #d97706 0%, #f59e0b 100%);
  border-radius: 2px;
  flex-shrink: 0;
}

[data-theme="dark"] :where(.wi-container) .wi-patient-name::before {
  background: linear-gradient(135deg, #92400e 0%, #b45309 100%);
}

:where(.wi-container) .wi-patient-meta {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  color: var(--px-text-muted);
}

:where(.wi-container) .wi-view-btn {
  padding: 6px 14px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: transparent;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s, background-color 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}

:where(.wi-container) .wi-view-btn:hover {
  background: var(--accent);
  color: white;
}

/* Table */
:where(.wi-container) .wi-table-container {
  overflow: hidden;
}

:where(.wi-container) .wi-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  table-layout: fixed;
}

:where(.wi-container) .wi-table thead {
  background: var(--px-bg-elevated);
}

:where(.wi-container) .wi-table th {
  padding: 10px 8px;
  text-align: left;
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--px-text-secondary);
  border-bottom: 1px solid var(--px-border-strong);
  white-space: nowrap;
}

:where(.wi-container) .wi-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--px-border);
  vertical-align: middle;
}

:where(.wi-container) .wi-table tbody tr:last-child td {
  border-bottom: none;
}

:where(.wi-container) .wi-table tbody tr:hover {
  background: var(--wi-row-hover);
}

/* Item name row - name + warning badge inline */
:where(.wi-container) .wi-item-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

:where(.wi-container) .wi-item-name {
  font-weight: 500;
  color: var(--px-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Mobile date summary - hidden on desktop */
:where(.wi-container) .wi-mobile-dates {
  display: none;
}

:where(.wi-container) .wi-mobile-date {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  color: var(--px-text-secondary);
  white-space: nowrap;
}

/* RX Instructions */
:where(.wi-container) .wi-rx-instructions {
  font-size: 0.75rem;
  color: var(--px-text-secondary);
  white-space: normal;
  word-wrap: break-word;
  line-height: 1.4;
  max-height: 3.6em;
  overflow: hidden;
}

/* Badges */
:where(.wi-container) .wi-acute-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 600;
  background: #1a7f37;
  color: white;
  letter-spacing: 0.02em;
}

:where(.wi-container) .wi-warning-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

:where(.wi-container) .wi-warning-badge.unbagged {
  background: #FFC107;
  color: #000;
}

:where(.wi-container) .wi-warning-badge.undispatched {
  background: #F44336;
  color: #fff;
}

:where(.wi-container) .wi-warning-badge.late-dispatch {
  background: #FF9800;
  color: #000;
}

:where(.wi-container) .wi-cancelled-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 600;
  background: var(--wi-error-bg);
  color: var(--wi-error);
}

/* Date/time cells */
:where(.wi-container) .wi-datetime {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  color: var(--px-text-secondary);
  white-space: nowrap;
}

:where(.wi-container) .wi-datetime.empty {
  color: var(--px-text-muted);
}

/* Owing status */
:where(.wi-container) .wi-owing-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 500;
}

:where(.wi-container) .wi-owing-status.open {
  background: var(--wi-warning-bg);
  color: var(--wi-warning);
}

:where(.wi-container) .wi-owing-status.completed {
  background: var(--wi-success-bg);
  color: var(--wi-success);
}

:where(.wi-container) .wi-owing-status .owing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

:where(.wi-container) .wi-owing-status.open .owing-dot {
  background: var(--wi-warning);
}

:where(.wi-container) .wi-owing-status.completed .owing-dot {
  background: var(--wi-success);
}

/* Bagged cells */
:where(.wi-container) .wi-bagged-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

:where(.wi-container) .wi-bag-ids {
  font-size: 0.68rem;
  color: var(--px-text-muted);
  font-family: 'IBM Plex Mono', monospace;
}

/* Dispatch cells */
:where(.wi-container) .wi-dispatch-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Empty state */
:where(.wi-container) .wi-empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--px-text-muted);
  font-size: 0.85rem;
}

/* Comments slot at top - ensure full width */
/* Neutralise ALL Anvil ColumnPanel / Bootstrap wrapper styles */
.wi-comments-slot-top {
  width: 100%;
  margin-bottom: 16px;
  overflow: visible !important;
}

.wi-comments-slot-top > div,
.wi-comments-slot-top .column-panel,
.wi-comments-slot-top .anvil-container,
.wi-comments-slot-top .anvil-component,
.wi-comments-slot-top .anvil-panel-section,
.wi-comments-slot-top .anvil-panel-section-gutter,
.wi-comments-slot-top .anvil-panel-row {
  width: 100% !important;
  padding: 0 !important;
  margin: 0 !important;
  overflow: visible !important;
}

.wi-comments-slot-top .row {
  margin-left: 0 !important;
  margin-right: 0 !important;
}

.wi-comments-slot-top [class*="col-"] {
  padding-left: 0 !important;
  padding-right: 0 !important;
}

.wi-comments-slot-top .comments-section {
  width: 100%;
  box-sizing: border-box;
  margin-top: 0;
}

/* Comment action buttons in table */
:where(.wi-container) .wi-comments-cell {
  text-align: center;
  vertical-align: middle !important;
}

:where(.wi-container) .wi-comment-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

:where(.wi-container) .wi-add-comment-btn,
:where(.wi-container) .wi-view-comments-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--px-border);
  border-radius: 4px;
  background: var(--px-bg-elevated);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s, background-color 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}

:where(.wi-container) .wi-add-comment-btn svg,
:where(.wi-container) .wi-view-comments-btn svg {
  width: 14px;
  height: 14px;
  color: var(--px-text-secondary);
}

:where(.wi-container) .wi-add-comment-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
}

:where(.wi-container) .wi-add-comment-btn:hover svg {
  color: white;
}

:where(.wi-container) .wi-add-comment-btn.selected {
  background: var(--accent);
  border-color: var(--accent);
}

:where(.wi-container) .wi-add-comment-btn.selected svg {
  color: white;
}

:where(.wi-container) .wi-view-comments-btn:hover:not(:disabled) {
  background: var(--accent-subtle);
  border-color: var(--accent);
}

:where(.wi-container) .wi-view-comments-btn:hover:not(:disabled) svg {
  color: var(--accent);
}

:where(.wi-container) .wi-view-comments-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

:where(.wi-container) .wi-view-comments-btn.has-comments {
  position: relative;
}

:where(.wi-container) .wi-comment-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  font-size: 10px;
  font-weight: 600;
  font-family: 'IBM Plex Mono', monospace;
  line-height: 16px;
  text-align: center;
  color: white;
  background: var(--accent);
  border-radius: 8px;
}

:where(.wi-container) .wi-comment-badge.has-open {
  background: var(--wi-error);
}

/* Selected items indicator in compose */
:where(.wi-container) .wi-selected-items-indicator {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 8px;
  background: var(--px-bg-elevated);
  border: 1px solid var(--px-border);
  border-radius: 4px;
  margin-bottom: 8px;
}

:where(.wi-container) .wi-selected-item-tag {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  background: var(--accent-subtle);
  border-radius: 3px;
  font-size: 0.7rem;
  color: var(--accent);
}

:where(.wi-container) .wi-selected-item-tag .remove-btn {
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.7;
}

:where(.wi-container) .wi-selected-item-tag .remove-btn:hover {
  opacity: 1;
}

:where(.wi-container) .wi-patient-items-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}

:where(.wi-container) .wi-patient-items-group:last-child {
  margin-bottom: 0;
}

:where(.wi-container) .wi-patient-items-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--px-text-secondary);
  margin-right: 2px;
}

/* Filter Bar */
:where(.wi-container) .wi-filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--px-bg-elevated);
  border: 1px solid var(--px-border);
  border-radius: 6px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

:where(.wi-container) .wi-filter-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--px-text-secondary);
}

:where(.wi-container) .wi-filter-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: opacity 0.15s, transform 0.15s, background-color 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}

:where(.wi-container) .wi-filter-checkbox:hover {
  background: var(--accent-subtle);
}

:where(.wi-container) .wi-filter-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent);
}

:where(.wi-container) .wi-filter-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

:where(.wi-container) .wi-filter-badge.unbagged {
  background: #FFC107;
  color: #000;
}

:where(.wi-container) .wi-filter-badge.late-dispatch {
  background: #FF9800;
  color: #000;
}

:where(.wi-container) .wi-filter-badge.undispatched {
  background: #F44336;
  color: #fff;
}

:where(.wi-container) .wi-filter-count {
  font-size: 0.75rem;
  color: var(--px-text-muted);
  font-family: 'IBM Plex Mono', monospace;
}

/* Dim unchecked filter labels */
:where(.wi-container) .wi-filter-checkbox:has(input:not(:checked)) {
  opacity: 0.5;
}

/* Animation */
.wi-fade-in {
  animation: wiFadeIn 0.25s ease;
}

@keyframes wiFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ========================================
   MOBILE RESPONSIVE
   ======================================== */

@media (max-width: 700px) {
  /* Header stacks */
  :where(.wi-container) .wi-header {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }
  :where(.wi-container) .wi-counts-badge {
    align-self: flex-start;
  }

  /* Filter bar - smaller on mobile */
  :where(.wi-container) .wi-filter-bar {
    padding: 8px 12px;
    gap: 8px;
  }
  :where(.wi-container) .wi-filter-label {
    font-size: 0.75rem;
    width: 100%;
  }
  :where(.wi-container) .wi-filter-checkbox {
    padding: 3px 6px;
  }
  :where(.wi-container) .wi-filter-badge {
    font-size: 0.6rem;
  }
  :where(.wi-container) .wi-filter-count {
    font-size: 0.7rem;
  }

  /* Patient divider stacks */
  :where(.wi-container) .wi-patient-header {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }
  :where(.wi-container) .wi-view-btn {
    width: 100%;
    text-align: center;
  }

  /* Table to cards */
  :where(.wi-container) .wi-table-container {
    border: none;
    background: transparent;
    overflow: visible;
  }

  :where(.wi-container) .wi-table thead {
    display: none;
  }

  :where(.wi-container) .wi-table,
  :where(.wi-container) .wi-table tbody {
    display: block;
    width: 100%;
  }

  :where(.wi-container) .wi-table tbody tr {
    display: flex;
    flex-direction: column;
    background: var(--px-bg-card);
    border: 1px solid var(--px-border);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 8px;
  }

  :where(.wi-container) .wi-table td {
    border: none !important;
    padding: 3px 0 !important;
    display: block;
  }

  /* Item name as card header */
  :where(.wi-container) .wi-table td:first-child {
    padding-bottom: 8px !important;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--px-border) !important;
  }

  :where(.wi-container) .wi-item-name {
    white-space: normal;
    font-size: 0.9rem;
    overflow: visible;
    text-overflow: clip;
  }

  /* Mobile date summary - 2-column grid */
  :where(.wi-container) .wi-mobile-dates {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 12px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--px-border);
  }

  :where(.wi-container) .wi-mobile-date {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    color: var(--px-text-secondary);
  }

  /* Bold Downloaded and Dispatched dates */
  :where(.wi-container) .wi-mobile-date[title="Downloaded"],
  :where(.wi-container) .wi-mobile-date[title="Dispatched"] {
    font-weight: 600;
    color: var(--px-text-primary);
  }

  /* Hide all columns except item name on mobile */
  /* Columns: Item(1), Instructions(2), Downloaded(3), Labelled(4), Owing(5), Bagged(6), Dispatched(7) */
  :where(.wi-container) .wi-table td:nth-child(2),
  :where(.wi-container) .wi-table td:nth-child(3),
  :where(.wi-container) .wi-table td:nth-child(4),
  :where(.wi-container) .wi-table td:nth-child(5),
  :where(.wi-container) .wi-table td:nth-child(6),
  :where(.wi-container) .wi-table td:nth-child(7) {
    display: none !important;
  }
}

@media (max-width: 500px) {
  :where(.wi-container) .wi-header {
    padding: 12px 14px;
  }
  :where(.wi-container) .wi-header-title {
    font-size: 1rem;
  }
  :where(.wi-container) .wi-header-meta {
    font-size: 0.7rem;
  }

  :where(.wi-container) .wi-filter-bar {
    padding: 6px 10px;
  }
  :where(.wi-container) .wi-filter-label {
    font-size: 0.7rem;
  }

  :where(.wi-container) .wi-patient-header {
    padding: 8px 12px;
  }
  :where(.wi-container) .wi-patient-name {
    font-size: 0.9rem;
  }
  :where(.wi-container) .wi-patient-meta {
    font-size: 0.68rem;
  }

  :where(.wi-container) .wi-table tbody tr {
    padding: 10px 12px 10px 16px;
  }
}
