/* ch_table_html: the monthly scripts table and its phone cards.
   Every rule scoped under the form root :where(.ch-table-root), zero specificity.
   Inside the 900px block, div.ch-card, div.ch-card.row-no-prescription,
   div.ch-card.row-interim and div.ch-card-header carry an element selector: the
   same classes in theme.css tied them, and the inline style block won by order.
   theme.css's .ch-card:hover still out-ranks div.ch-card, as it did. */

:where(.ch-table-root) .ch-table-card {
  background: var(--ch-bg-card);
  border: 1px solid var(--ch-border);
  border-radius: var(--ch-radius-lg);
}

/* ── Mobile card layout ── */
:where(.ch-table-root) .ch-card-container { display: none; }

@media (max-width: 900px) {
  :where(.ch-table-root) .ch-table-card { display: none; }
  :where(.ch-table-root) .ch-card-container {
    display: block;
    padding: 0 4px;
  }

  :where(.ch-table-root) div.ch-card {
    background: var(--ch-bg-card);
    border: 1px solid var(--ch-border);
    border-radius: var(--ch-radius-lg);
    padding: 14px 16px;
    margin-bottom: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  }

  :where(.ch-table-root) div.ch-card.row-no-prescription {
    border-left: 4px solid var(--ch-pill-no-prescription-text);
    background: var(--ch-row-no-prescription);
  }

  :where(.ch-table-root) div.ch-card.row-interim {
    border-left: 4px solid var(--ch-accent-primary);
    background: var(--ch-row-interim);
  }

  :where(.ch-table-root) div.ch-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--ch-border);
  }

  :where(.ch-table-root) .ch-card-patient {
    font-size: 15px;
    font-weight: 700;
    color: var(--ch-text-primary);
  }

  :where(.ch-table-root) .ch-card-home {
    font-size: 11px;
    color: var(--ch-text-muted);
    margin-top: 2px;
  }

  :where(.ch-table-root) .ch-card-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  :where(.ch-table-root) .ch-card-field {
    display: flex;
    flex-direction: column;
  }

  :where(.ch-table-root) .ch-card-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--ch-text-muted);
    margin-bottom: 1px;
  }

  :where(.ch-table-root) .ch-card-value {
    font-size: 13px;
    color: var(--ch-text-primary);
  }

  :where(.ch-table-root) .ch-card-actions {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--ch-border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
  }

  :where(.ch-table-root) .ch-card-actions .ch-action-btn {
    padding: 10px 16px;
    font-size: 13px;
    min-height: 40px;
  }

  :where(.ch-table-root) .ch-card-actions .ch-confirm-yes,
  :where(.ch-table-root) .ch-card-actions .ch-confirm-no {
    padding: 10px 16px;
    font-size: 13px;
  }
}

:where(.ch-table-root) .ch-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 900px;
}

:where(.ch-table-root) .ch-table thead {
  background: var(--ch-bg-secondary);
  position: sticky;
  top: var(--ch-sticky-top);
  z-index: 10;
}

:where(.ch-table-root) .ch-table th {
  padding: 12px 10px;
  text-align: left;
  font-weight: 600;
  color: var(--ch-text-primary);
  border-bottom: 2px solid var(--ch-border);
  white-space: nowrap;
}

:where(.ch-table-root) .ch-table td {
  padding: 10px;
  color: var(--ch-text-primary);
  border-bottom: 1px solid var(--ch-border);
  vertical-align: middle;
}

/* Lock action column width so inline confirm doesn't reflow the table */
:where(.ch-table-root) .ch-table th:last-child,
:where(.ch-table-root) .ch-table td:last-child {
  min-width: 160px;
  width: 160px;
}

:where(.ch-table-root) .ch-table tbody tr:hover {
  background: var(--ch-bg-secondary);
}

/* Row highlighting */
:where(.ch-table-root) .ch-table tbody tr.row-no-prescription {
  background: var(--ch-row-no-prescription);
}

:where(.ch-table-root) .ch-table tbody tr.row-interim {
  background: var(--ch-row-interim);
}

:where(.ch-table-root) .ch-table tbody tr.row-no-prescription:hover,
:where(.ch-table-root) .ch-table tbody tr.row-interim:hover {
  filter: brightness(0.97);
}

/* Status cell type colouring */
:where(.ch-table-root) .ch-status-cell-acute {
  background: var(--ch-row-acute);
}

:where(.ch-table-root) .ch-status-cell-monthly {
  background: var(--ch-row-monthly);
}

/* Row removal animation */
:where(.ch-table-root) .ch-table tbody tr.ch-row-removing {
  opacity: 0;
  transform: translateX(30px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

:where(.ch-table-root) .ch-card.ch-row-removing {
  opacity: 0;
  transform: translateX(30px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

/* Status pills */
:where(.ch-table-root) .ch-pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: var(--ch-radius-full);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

:where(.ch-table-root) .ch-pill-no-prescription {
  background: var(--ch-pill-no-prescription-bg);
  color: var(--ch-pill-no-prescription-text);
}

:where(.ch-table-root) .ch-pill-prescribed {
  background: var(--ch-pill-prescribed-bg);
  color: var(--ch-pill-prescribed-text);
}

:where(.ch-table-root) .ch-pill-processing {
  background: var(--ch-pill-processing-bg);
  color: var(--ch-pill-processing-text);
}

:where(.ch-table-root) .ch-pill-bagged {
  background: var(--ch-pill-bagged-bg);
  color: var(--ch-pill-bagged-text);
}

:where(.ch-table-root) .ch-pill-dispatched {
  background: var(--ch-pill-dispatched-bg);
  color: var(--ch-pill-dispatched-text);
}

:where(.ch-table-root) .ch-pill-cancelled {
  background: var(--ch-pill-cancelled-bg);
  color: var(--ch-pill-cancelled-text);
}

:where(.ch-table-root) .ch-pill-spoke {
  background: var(--ch-info-bg);
  color: var(--ch-info);
  border: 1px solid var(--ch-info-border);
}

/* Type indicators */
:where(.ch-table-root) .ch-type-badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 3px;
  margin-right: 4px;
}

:where(.ch-table-root) .ch-type-acute {
  background: var(--ch-success-bg);
  color: var(--ch-success);
}

:where(.ch-table-root) .ch-type-monthly {
  background: var(--ch-warning-bg);
  color: var(--ch-warning);
}

/* Deactivated-home chip — sits beside the home name on the row AND the
   card. Deliberately quiet (the same muted-warning palette as the
   monthly type badge, no border, no icon): the home is switched off for
   NEW work, but everything on this screen is already in progress and
   still actionable, so the chip must read as a label rather than as a
   blocker. Never wraps mid-word away from the name it annotates. */
:where(.ch-table-root) .ch-deactivated-chip {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 1px 6px;
  border-radius: var(--ch-radius-full);
  background: var(--ch-warning-bg);
  color: var(--ch-warning);
  white-space: nowrap;
  vertical-align: middle;
}

/* Action cell — vertically centre buttons regardless of variant or
   how many stack. inline-flex keeps the wrapper inline-level so the
   td's existing vertical-align:middle actually positions it; block-
   level (display:flex) wrappers were being stuck at the top because
   the td's vertical-align doesn't apply to block content reliably. */
:where(.ch-table-root) td[id^="action-cell-"] { vertical-align: middle !important; }
:where(.ch-table-root) .ch-action-cell-inner {
  display: inline-flex;
  vertical-align: middle;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

/* Local-dispense pill: same palette as spoke but allowed to wrap.
   The status text is rendered with an explicit <br> between "for"
   and "local" plus a third line for the returned_at timestamp.
   Pill text drops to 10px and the timestamp drops to 9px so the
   badge stays compact within the column. */
:where(.ch-table-root) .ch-pill-local-return {
  background: var(--ch-info-bg);
  color: var(--ch-info);
  border: 1px solid var(--ch-info-border);
  white-space: normal;
  line-height: 1.2;
  font-size: 10px;
  text-align: center;
}
:where(.ch-table-root) .ch-pill-local-return .ch-pill-time {
  display: inline-block;
  margin-top: 2px;
  font-size: 9px;
  opacity: 0.85;
}

/* Action buttons */
:where(.ch-table-root) .ch-action-btn {
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 500;
  font-family: var(--ch-font-primary);
  border: none;
  border-radius: var(--ch-radius-sm);
  cursor: pointer;
  transition: opacity var(--ch-transition-fast), transform var(--ch-transition-fast), background-color var(--ch-transition-fast), color var(--ch-transition-fast), border-color var(--ch-transition-fast), box-shadow var(--ch-transition-fast);
  white-space: nowrap;
}

:where(.ch-table-root) .ch-action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

:where(.ch-table-root) .ch-action-btn-danger {
  background: var(--ch-danger-bg);
  color: var(--ch-danger);
}

:where(.ch-table-root) .ch-action-btn-danger:hover:not(:disabled) {
  background: var(--ch-danger);
  color: white;
}

:where(.ch-table-root) .ch-action-btn-warning {
  background: var(--ch-warning-bg);
  color: var(--ch-warning);
}

:where(.ch-table-root) .ch-action-btn-warning:hover:not(:disabled) {
  background: var(--ch-warning);
  color: white;
}

/* Action cell: flex-wrap with gap keeps spacing consistent whether buttons sit
   side-by-side or wrap to a new line. Scoped to desktop table only. */
:where(.ch-table-root) .ch-table td:last-child {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

:where(.ch-table-root) .ch-action-btn-primary {
  background: var(--ch-accent-secondary);
  color: var(--ch-accent-primary-text, #b45309);
}

:where(.ch-table-root) .ch-action-btn-primary:hover:not(:disabled) {
  background: var(--ch-accent-primary);
  color: white;
}

:where(.ch-table-root) .ch-action-btn-secondary {
  background: var(--ch-bg-secondary);
  color: var(--ch-text-muted);
}

/* Active, clickable secondary action (e.g. Return to Spine). Uses the
   info/teal palette so it reads as enabled and stays visually distinct
   from the orange primary action; the muted -secondary style above is
   reserved for genuinely disabled/informational chips. */
:where(.ch-table-root) .ch-action-btn-info {
  background: var(--ch-info-bg);
  color: var(--ch-info);
}

:where(.ch-table-root) .ch-action-btn-info:hover:not(:disabled) {
  background: var(--ch-info);
  color: white;
}

:where(.ch-table-root) .ch-confirm-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

:where(.ch-table-root) .ch-confirm-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ch-danger);
}

:where(.ch-table-root) .ch-confirm-yes,
:where(.ch-table-root) .ch-confirm-no {
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 3px;
  cursor: pointer;
  transition: opacity var(--ch-transition-fast), transform var(--ch-transition-fast), background-color var(--ch-transition-fast), color var(--ch-transition-fast), border-color var(--ch-transition-fast), box-shadow var(--ch-transition-fast);
}

:where(.ch-table-root) .ch-confirm-yes {
  background: var(--ch-danger);
  color: white;
  border: none;
}

:where(.ch-table-root) .ch-confirm-no {
  background: var(--ch-bg-card);
  color: var(--ch-text-primary);
  border: 1px solid var(--ch-border);
}

/* Empty state */
:where(.ch-table-root) .ch-table-empty {
  padding: 48px;
  text-align: center;
  color: var(--ch-text-muted);
  font-size: 14px;
}

/* Infinite-scroll sentinel */
:where(.ch-table-root) .ch-scroll-sentinel {
  height: 1px;
}

/* Loading more indicator */
:where(.ch-table-root) .ch-loading-more {
  padding: 16px;
  text-align: center;
  color: var(--ch-text-muted);
  font-size: 13px;
  display: none;
}

/* Potential change highlight */
:where(.ch-table-root) .ch-potential-change {
  background: var(--ch-warning-bg);
  color: var(--ch-warning);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 11px;
}

/* PIL info icon */
:where(.ch-table-root) .ch-pil-icon {
  display: inline-block;
  width: 16px;
  height: 16px;
  cursor: pointer;
  vertical-align: middle;
  opacity: 0.7;
  transition: opacity var(--ch-transition-fast);
  text-decoration: none;
}

:where(.ch-table-root) .ch-pil-icon:hover {
  opacity: 1;
}

:where(.ch-table-root) .ch-pil-icon:focus {
  opacity: 1;
  outline: 2px solid var(--ch-border-focus);
  outline-offset: 2px;
  border-radius: 50%;
}

:where(.ch-table-root) .ch-pil-icon svg {
  width: 100%;
  height: 100%;
  fill: var(--ch-accent-primary);
}

/* Script image icon */
:where(.ch-table-root) .ch-image-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity var(--ch-transition-fast);
  color: var(--ch-accent-primary);
  border: none;
  background: none;
  padding: 0;
}

:where(.ch-table-root) .ch-image-icon:hover {
  opacity: 1;
}

:where(.ch-table-root) .ch-image-icon:focus {
  opacity: 1;
  outline: 2px solid var(--ch-border-focus);
  outline-offset: 2px;
  border-radius: 50%;
}

:where(.ch-table-root) .ch-image-icon svg {
  width: 100%;
  height: 100%;
  fill: var(--ch-accent-primary);
}

:where(.ch-table-root) .ch-wholesaler-unavailable-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ch-warning);
  font-size: 15px;
  line-height: 1;
  cursor: help;
}
