/**
 * Clinic portal panel (be-25).
 *
 * Tokens only — no hardcoded surface/text/line colours.
 * Dark status tints for Appearance pref live in clinic-theme.css (be-31, app darkColors).
 * Light defaults stay here.
 */
:root {
  --portal-ok-bg: #ecfdf3;
  --portal-ok-line: #bbf7d0;
  --portal-ok-ink: #14532d;
  --portal-warn-bg: #fffbeb;
  --portal-warn-line: #fde68a;
  --portal-warn-ink: #854d0e;
  --portal-err-bg: #fef2f2;
  --portal-err-line: #fecaca;
  --portal-err-ink: #991b1b;
  --portal-neutral-bg: #f3f4f6;
  --portal-neutral-line: var(--line);
  --portal-neutral-ink: var(--muted);
}

.portal-wrap {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}
body.portal-app .portal-wrap {
  max-width: var(--wrap-wide);
}

/* ── Modern Clinic Shell & Sidebar Layout ────────────────────────────────── */

body.clinic-console {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 480px at 10% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent),
    radial-gradient(900px 420px at 100% 0%, color-mix(in srgb, var(--bg-sky) 55%, transparent), transparent),
    var(--bg-page);
  color: var(--text);
  font-family: var(--font-text);
}

.clinic-login-wrap {
  max-width: 440px;
  margin: 0 auto;
  padding: 48px 16px 64px;
  min-height: 100vh;
  display: flex;
  align-items: center;
  box-sizing: border-box;
}

.clinic-login-wrap[hidden],
.clinic-shell[hidden] {
  display: none !important;
}

.clinic-login-wrap .login-card {
  width: 100%;
  padding: 28px 24px 24px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.clinic-login-wrap h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  margin: 12px 0 6px;
  color: var(--navy);
}

.clinic-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
  width: 100%;
}

.clinic-sidebar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px 14px;
  background: color-mix(in srgb, var(--surface) 88%, var(--invert-bg));
  border-inline-end: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.clinic-sidebar .panel-brand {
  margin: 4px 8px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

.clinic-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.clinic-nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  text-align: start;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.clinic-nav-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.clinic-nav-btn[aria-current='page'] {
  background: var(--accent-light);
  color: var(--accent-ink);
}

.clinic-nav-ico {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 7px;
  display: inline-grid;
  place-items: center;
  font-size: 0.85rem;
  font-weight: 800;
  background: var(--surface);
  color: var(--navy);
  border: 1px solid var(--line);
  flex-shrink: 0;
}

.clinic-nav-btn[aria-current='page'] .clinic-nav-ico {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.clinic-side-foot {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 8px 4px;
  border-top: 1px solid var(--line);
  margin-top: 12px;
}

.clinic-side-foot .portal-select {
  margin: 0;
  min-height: 38px;
}

.clinic-side-foot .portal-btn {
  margin: 0;
  width: 100%;
}

.clinic-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 24px 32px 48px;
}

.clinic-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 22px;
}

.clinic-topbar h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 2.2vw, 1.85rem);
  color: var(--navy);
  letter-spacing: -0.02em;
}

.clinic-topbar .lead {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.94rem;
  max-width: 58ch;
}

.clinic-topbar-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.clinic-email-chip {
  font-size: 0.85rem;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--line);
}

.clinic-view {
  display: none;
  flex-direction: column;
  gap: 18px;
  animation: clinicIn 0.18s ease;
}

.clinic-view.is-active {
  display: flex;
}

@keyframes clinicIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.clinic-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg, 12px);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.clinic-card-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-2) 80%, var(--surface));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.clinic-card-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--navy);
}

.clinic-card-head p {
  margin: 4px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.clinic-card-body {
  padding: 18px 20px;
}

.clinic-card-body.no-pad {
  padding: 0;
}

@media (max-width: 900px) {
  .clinic-shell {
    grid-template-columns: 1fr;
  }
  .clinic-sidebar {
    border-inline-end: none;
    border-bottom: 1px solid var(--line);
    padding: 12px 12px 8px;
  }
  .clinic-nav {
    flex-direction: row;
    overflow-x: auto;
    gap: 6px;
  }
  .clinic-nav-btn {
    flex: 0 0 auto;
    white-space: nowrap;
  }
  .clinic-side-foot {
    flex-direction: row;
    align-items: center;
    margin-top: 8px;
    padding-top: 10px;
  }
  .clinic-side-foot .portal-btn {
    width: auto;
  }
  .clinic-main {
    padding: 16px 14px 36px;
  }
}

.portal-input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  margin: 6px 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  min-height: var(--tap-min);
}
.portal-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--navy);
  /* Not --surface: the fill is --navy, which inverts in dark, so the ink has to
     invert with it rather than staying white. */
  color: var(--bg-page);
  font-weight: 700;
  border: none;
  cursor: pointer;
  min-height: var(--tap-min);
  text-decoration: none;
  font-size: 14px;
  font-family: inherit;
}
.portal-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}
.portal-btn.secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}
/* --danger does not flip in tokens.css, so #c0392b would sit at ~3:1 on a dark
   surface. The portal's own err ink inverts and stays legible in both schemes. */
.portal-btn.danger {
  background: transparent;
  color: var(--portal-err-ink);
  border: 1px solid var(--portal-err-line);
  font-weight: 600;
}
.portal-btn.danger:hover {
  background: var(--portal-err-bg);
}
.portal-btn:focus-visible,
.portal-input:focus-visible,
.portal-select:focus-visible,
.chip-btn:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.invite-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}
.invite-actions .portal-btn {
  margin-top: 0;
}
.portal-select {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  min-height: var(--tap-min);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}

#app-flash {
  position: sticky;
  top: 8px;
  z-index: 5;
  margin: 0 0 16px;
}

.row-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 5px;
  align-items: center;
  justify-content: flex-end;
}
.row-actions .portal-btn {
  margin-top: 0;
  margin-left: 0;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  min-height: 30px;
  border-radius: 6px;
  white-space: nowrap;
  line-height: 1.2;
}
/* Linked rows: three equal columns so Cover AI / Stop AI don't shift Revoke. */
.worklist-table .row-actions--trio {
  display: grid;
  grid-template-columns: 5.6rem 5.6rem 5.2rem;
  gap: 5px;
  width: max-content;
  margin-inline-start: auto;
  justify-content: stretch;
  align-items: stretch;
}
.worklist-table .row-actions--trio .portal-btn {
  width: 100%;
  box-sizing: border-box;
  justify-content: center;
  padding-left: 4px;
  padding-right: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.worklist-table td.actions-cell {
  white-space: nowrap;
  text-align: end;
}
.sponsor-form.row-actions {
  flex-wrap: wrap;
  justify-content: flex-start;
  max-width: none;
}
.sponsor-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 700;
  border: 1px solid transparent;
  white-space: nowrap;
}
.chip.ok {
  color: var(--portal-ok-ink);
  background: var(--portal-ok-bg);
  border-color: var(--portal-ok-line);
}
.chip.soon {
  color: var(--portal-warn-ink);
  background: var(--portal-warn-bg);
  border-color: var(--portal-warn-line);
}
.chip.off {
  color: var(--portal-neutral-ink);
  background: var(--portal-neutral-bg);
  border-color: var(--portal-neutral-line);
}
.chip.gone {
  color: var(--portal-err-ink);
  background: var(--portal-err-bg);
  border-color: var(--portal-err-line);
}

.portal-status {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  line-height: 1.45;
  border: 1px solid transparent;
}
.portal-status[hidden] {
  display: none !important;
}
.portal-status.ok {
  color: var(--portal-ok-ink);
  background: var(--portal-ok-bg);
  border-color: var(--portal-ok-line);
}
.portal-status.warn {
  color: var(--portal-warn-ink);
  background: var(--portal-warn-bg);
  border-color: var(--portal-warn-line);
}
.portal-status.err {
  color: var(--portal-err-ink);
  background: var(--portal-err-bg);
  border-color: var(--portal-err-line);
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}
.error {
  color: var(--portal-err-ink);
  font-size: 0.9rem;
  margin-top: 8px;
}
.field-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 8px;
}

/* Login */
.login-card {
  margin-top: 24px;
}
.login-card h1 {
  margin: 0 0 8px;
  font-size: 1.5rem;
  color: var(--navy);
}

/* App header */
.panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.panel-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}
.panel-brand img {
  width: 36px;
  height: 36px;
  border-radius: 8px;
}
.panel-brand-text {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  color: var(--navy);
}
.panel-brand-sub {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}
.panel-header-meta {
  margin-inline-start: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.balance-chip {
  font-size: 0.85rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
}
.panel-header .portal-btn {
  margin-top: 0;
}

/* Invite strip */
.invite-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 16px;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}
.invite-strip .invite-field {
  flex: 1 1 220px;
  min-width: 0;
}
.invite-strip .portal-input {
  margin: 4px 0 0;
}
.invite-strip .portal-btn {
  margin-top: 0;
}
.invite-note {
  margin: -8px 0 16px;
}

/* Filters */
.worklist-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  min-height: var(--tap-min);
}
.chip-btn.active {
  background: var(--navy);
  color: var(--bg-page);
  border-color: var(--navy);
}
.chip-btn .n {
  opacity: 0.75;
  font-weight: 500;
}
.worklist-sort {
  min-width: 140px;
  margin-inline-start: auto;
}

/* Table — fixed layout so Name stays compact; Email + Actions take the rest */
.worklist-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow-x: auto;
  background: var(--surface);
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.worklist-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  table-layout: fixed;
}
.worklist-table th {
  text-align: start;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 8px 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  font-weight: 700;
  /* Top, not bottom: every column label then shares one baseline and the two
     filter inputs hang below them instead of shoving their labels upward. */
  vertical-align: top;
  padding-bottom: 10px;
}
.worklist-table th .col-head-label {
  display: block;
  margin-bottom: 6px;
  line-height: 1.4;
}
.worklist-table th.col-name {
  width: 16%;
}
.worklist-table th.col-email {
  width: 24%;
}
.worklist-table th.col-sync {
  /* Needs room for relative time + "Android · 1.2.44 (73)" — 8% overflowed into Sponsor. */
  width: 15%;
}
.worklist-table th.col-sponsor {
  width: 18%;
}
.worklist-table th.col-actions {
  width: 27%;
  text-align: end;
}
.worklist-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  font-size: 0.9rem;
}
.worklist-table tbody tr {
  transition: background-color 120ms ease;
}
.worklist-table tbody tr:hover {
  background: var(--surface-2);
}
.worklist-table tbody tr:focus-within {
  background: var(--surface-2);
}
.worklist-table tr:last-child td {
  border-bottom: none;
}
/* One alignment per column: the name text itself carries dir="auto", so a
   Hebrew row shapes RTL without jumping to the far edge of the column. */
.worklist-table .name-cell {
  text-align: start;
}
.worklist-table .name-cell .name-primary {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.worklist-table .name-cell .name-empty {
  color: var(--muted);
  font-weight: 500;
}
.worklist-table .name-cell .status-line {
  margin-top: 4px;
}
.chip.status-chip {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  padding: 1px 7px;
}
.worklist-table .email-cell {
  font-weight: 500;
  font-size: 0.84rem;
  font-variant-ligatures: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.worklist-table .sync-cell {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
  min-width: 0;
  overflow: hidden;
}
.worklist-table .sync-cell .sync-ago {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.worklist-table .sync-cell .sync-client {
  display: block;
  margin-top: 3px;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--muted);
  opacity: 0.9;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
  /* Platform · version is LTR; keeps "Android · 1.2.44 (73)" from bidi-scrambling in he/ar. */
  direction: ltr;
  unicode-bidi: isolate;
  text-align: start;
}
html[lang]:not([lang='en']) .worklist-table .sync-cell {
  font-size: 0.72rem;
  letter-spacing: -0.01em;
}
.worklist-table .sponsor-cell {
  min-width: 0;
  overflow: hidden;
}
.worklist-table .sponsor-cell .chip {
  display: inline-block;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

/* Modern column filters — compact search + clear × */
.ux-filter {
  position: relative;
  display: flex;
  align-items: center;
  margin-top: 2px;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 500;
}
.ux-filter-input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  margin: 0;
  padding: 6px 28px 6px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  line-height: 1.3;
  min-height: 32px;
}
.worklist-table th.col-name .ux-filter-input {
  max-width: 100%;
}
.ux-filter-input::placeholder {
  color: var(--muted);
  opacity: 0.85;
}
.ux-filter-input:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--navy) 22%, transparent);
}
.ux-filter-input::-webkit-search-decoration,
.ux-filter-input::-webkit-search-cancel-button,
.ux-filter-input::-webkit-search-results-button,
.ux-filter-input::-webkit-search-results-decoration {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}
.ux-filter-clear {
  position: absolute;
  inset-inline-end: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ux-filter-clear:hover {
  background: var(--surface-2);
  color: var(--text);
}
.ux-filter-clear[hidden] {
  display: none !important;
}
html[dir='rtl'] .ux-filter-input {
  padding: 7px 10px 7px 30px;
}
.worklist-empty {
  padding: 28px 16px;
  text-align: center;
}
.worklist-pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 0.9rem;
}
/* Author `display: flex` outranks the UA `[hidden]` rule, so a single-page
   worklist kept rendering Previous/Next. */
.worklist-pager[hidden] {
  display: none !important;
}
.worklist-pager .portal-btn {
  margin-top: 0;
  min-height: var(--tap-min);
  padding: 8px 12px;
}

/* Secondary */
.secondary-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 16px;
  background: var(--surface);
}
.secondary-panel h2 {
  margin: 0 0 8px;
  font-size: 1rem;
  color: var(--navy);
}
.secondary-panel summary {
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  min-height: var(--tap-min);
  padding: 4px 0;
}
.dev-only[hidden] {
  display: none !important;
}

/* Usage events + invoice history (be-06 two-layer billing, alpha zero-charge) */
.usage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-top: 10px;
}
.usage-table th,
.usage-table td {
  text-align: start;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.usage-table td[dir='ltr'] {
  overflow-wrap: anywhere;
  white-space: normal;
}
.usage-table th {
  color: var(--muted);
  font-weight: 600;
}

/* Worklist loading skeleton (be-22) */
.worklist-skeleton .worklist-skel-block {
  height: 44px;
  border-radius: var(--radius-md);
  background: linear-gradient(
    90deg,
    var(--surface-2) 0%,
    var(--surface) 45%,
    var(--surface-2) 90%
  );
  background-size: 200% 100%;
  animation: portal-skel-pulse 1.2s ease-in-out infinite;
  margin: 6px 0;
}
@keyframes portal-skel-pulse {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .worklist-skeleton .worklist-skel-block {
    animation: none;
    background: var(--surface-2);
  }
}
.balance-chip .muted,
#wallet-balance.muted {
  font-weight: 600;
  color: var(--muted);
}

@media (max-width: 720px) {
  .worklist-table,
  .worklist-table tbody,
  .worklist-table tr,
  .worklist-table td {
    display: block;
    width: 100%;
  }
  .worklist-table thead {
    display: block;
    width: 100%;
  }
  .worklist-table thead tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
  }
  .worklist-table thead th {
    display: none;
    padding: 0;
    border: none;
    background: transparent;
  }
  .worklist-table thead th.col-name,
  .worklist-table thead th.col-email {
    display: block;
  }
  .worklist-table tbody tr {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
  }
  .worklist-table td {
    padding: 4px 0;
    border: none;
  }
  .worklist-table td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    font-weight: 700;
    margin-bottom: 2px;
  }
  .worklist-table {
    min-width: 0;
    table-layout: auto;
  }
  .worklist-table .ux-filter-input {
    min-width: 0;
  }
  .worklist-table td.actions-cell {
    text-align: start;
  }
  .row-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  .worklist-table .name-cell .name-primary,
  .worklist-table .email-cell {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
  }
  .panel-header-meta {
    margin-inline-start: 0;
    width: 100%;
  }
}

/* ── Macro Trends Report (Phase 1) ───────────────────────────────────────── */

.macro-report-panel {
  margin: 16px 0 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg, 12px);
  padding: 14px 18px;
}

.macro-report-panel[open] summary {
  margin-bottom: 14px;
}

.macro-report-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  padding: 12px 14px;
  background: var(--surface-2, #f9fafb);
  border: 1px solid var(--line);
  border-radius: var(--radius-md, 8px);
  margin-bottom: 16px;
}

.macro-report-days {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.macro-days-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  user-select: none;
}

.macro-days-label input[type='radio'] {
  margin: 0;
  cursor: pointer;
}

.macro-ai-toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
  user-select: none;
}

.macro-ai-toggle-label input[type='checkbox'] {
  margin: 0;
  cursor: pointer;
}

.macro-report-progress {
  padding: 10px 14px;
  background: var(--portal-ok-bg);
  border: 1px solid var(--portal-ok-line);
  color: var(--portal-ok-ink);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
}

.macro-report-output {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.macro-report-placeholder {
  padding: 18px;
  text-align: center;
  margin: 0;
}

.macro-patient-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md, 10px);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.macro-patient-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.macro-patient-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.macro-patient-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.macro-patient-email {
  font-size: 13px;
  color: var(--muted);
}

.macro-patient-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.macro-chip-days {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 12px;
  background: var(--surface-2, #f3f4f6);
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 600;
}

.macro-metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.macro-metric-item {
  background: var(--surface-2, #f9fafb);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.macro-metric-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.macro-metric-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
}

.macro-metric-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
}

.macro-badge-on-target {
  background: var(--portal-ok-bg);
  color: var(--portal-ok-ink);
  border: 1px solid var(--portal-ok-line);
}

.macro-badge-over {
  background: var(--portal-warn-bg);
  color: var(--portal-warn-ink);
  border: 1px solid var(--portal-warn-line);
}

.macro-badge-under {
  background: var(--portal-neutral-bg);
  color: var(--portal-neutral-ink);
  border: 1px solid var(--portal-neutral-line);
}

.macro-metric-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}

.macro-metric-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  font-size: 13px;
}

.macro-metric-sublabel {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

.macro-metric-num {
  unicode-bidi: isolate;
  text-align: end;
  color: var(--text);
}

.macro-row-actual .macro-metric-num {
  font-size: 14px;
  font-weight: 700;
}

.macro-row-target .macro-metric-num {
  font-size: 12px;
  color: var(--muted);
}

details.macro-ai-summary-box {
  background: var(--surface-2, #f9fafb);
  border: 1px solid var(--line);
  border-inline-start: 4px solid var(--accent, #3b82f6);
  border-radius: 8px;
  padding: 0;
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  overflow: hidden;
}

details.macro-ai-summary-box summary.macro-ai-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  color: var(--accent, #3b82f6);
  user-select: none;
  list-style: none;
}

details.macro-ai-summary-box summary.macro-ai-header::-webkit-details-marker {
  display: none;
}

details.macro-ai-summary-box summary.macro-ai-header:hover {
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}

.macro-ai-content {
  padding: 10px 14px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.macro-ai-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.macro-btn-rerun {
  font-size: 12px;
  padding: 4px 8px;
  min-height: auto;
  margin: 0;
}

