/* Kill theme chrome above the dashboard on mobile so the SPA sits flush
   with the top of the viewport (the shortcode tags <body> via the
   cow-ai-dashboard-page class filter in routes.php). Scope all overrides
   to that class so we don't touch pages that don't host the shortcode. */
@media (max-width: 900px) {
  body.cow-ai-dashboard-page .entry-title,
  body.cow-ai-dashboard-page .page-title,
  body.cow-ai-dashboard-page .entry-header,
  body.cow-ai-dashboard-page .et_post_meta_wrapper { display: none !important; }
  body.cow-ai-dashboard-page .entry-content,
  body.cow-ai-dashboard-page article .entry-content,
  body.cow-ai-dashboard-page .et_pb_section:first-of-type,
  body.cow-ai-dashboard-page .et_pb_row:first-of-type,
  body.cow-ai-dashboard-page #main-content,
  body.cow-ai-dashboard-page #page,
  body.cow-ai-dashboard-page .site-content,
  body.cow-ai-dashboard-page main { padding-top: 0 !important; margin-top: 0 !important; }
}

/* ---- design tokens ---- */
#cow-ai-dashboard-root {
  --cad-page-bg:   #f6f7fb;
  --cad-surface:   #ffffff;
  --cad-border:    #eef0f4;
  --cad-border-2:  #e5e7eb;
  --cad-text:      #0f172a;
  --cad-text-2:    #64748b;
  --cad-muted:     #94a3b8;
  --cad-primary:   #4f5dff;
  --cad-primary-2: #eceffe;
  --cad-accent:    #0ea5e9;
  --cad-danger:    #ef4444;
  --cad-danger-2:  #fee2e2;
  --cad-warn:      #f59e0b;
  --cad-warn-2:    #fef3c7;
  --cad-success:   #22c55e;
  --cad-success-2: #dcfce7;
  --cad-radius:    14px;
  --cad-radius-sm: 10px;
  --cad-shadow:    0 1px 2px rgba(15, 23, 42, 0.04), 0 6px 20px rgba(15, 23, 42, 0.04);
  --cad-space:     16px;
  --cad-font:      -apple-system, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  /* Unified pill token — every pill/chip in the app uses these */
  --cad-pill-radius: 999px;
  --cad-pill-pad-y:  3px;
  --cad-pill-pad-x:  10px;
}

/* ---- Dark theme ---- */
#cow-ai-dashboard-root[data-cad-theme="dark"] {
  --cad-page-bg:   #0b1220;
  --cad-surface:   #131c2e;
  --cad-border:    #1f2a44;
  --cad-border-2:  #2c3a5a;
  --cad-text:      #e6eaf2;
  --cad-text-2:    #9ba5bd;
  --cad-muted:     #6b7795;
  --cad-primary:   #818cf8;
  --cad-primary-2: #1e2244;
  --cad-accent:    #22d3ee;
  --cad-danger:    #f87171;
  --cad-danger-2:  #3b1d1d;
  --cad-warn:      #fbbf24;
  --cad-warn-2:    #3a2e0e;
  --cad-success:   #34d399;
  --cad-success-2: #15321f;
  --cad-radius:    14px;
  --cad-radius-sm: 10px;
  --cad-shadow:    0 1px 2px rgba(0,0,0,0.20), 0 8px 24px rgba(0,0,0,0.35);
}
#cow-ai-dashboard-root[data-cad-theme="dark"] .cad-user,
#cow-ai-dashboard-root[data-cad-theme="dark"] .cad-theme-switch,
#cow-ai-dashboard-root[data-cad-theme="dark"] .cad-search__input,
#cow-ai-dashboard-root[data-cad-theme="dark"] .cad-ctrl select,
#cow-ai-dashboard-root[data-cad-theme="dark"] .cad-setting__control input,
#cow-ai-dashboard-root[data-cad-theme="dark"] .cad-triage__note textarea,
#cow-ai-dashboard-root[data-cad-theme="dark"] .cad-lastseen-filters input {
  background: #0e1627; color: var(--cad-text);
}
#cow-ai-dashboard-root[data-cad-theme="dark"] .cad-table thead th {
  background: #101a2c; color: var(--cad-text-2);
}
#cow-ai-dashboard-root[data-cad-theme="dark"] .cad-table tbody tr:hover { background: #0f1830; }
#cow-ai-dashboard-root[data-cad-theme="dark"] .cad-brand__mark {
  background: linear-gradient(135deg, #818cf8 0%, #22d3ee 100%);
}
#cow-ai-dashboard-root[data-cad-theme="dark"] .cad-user__avatar {
  background: linear-gradient(135deg, #818cf8 0%, #22d3ee 100%);
}
#cow-ai-dashboard-root[data-cad-theme="dark"] .cad-search__input {
  background: #0e1627 url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ba5bd' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><path d='m21 21-4.3-4.3'/></svg>") no-repeat 11px center;
}
#cow-ai-dashboard-root[data-cad-theme="dark"] .cad-table-note td { background: #0e1627; }

#cow-ai-dashboard-root {
  font-family: var(--cad-font);
  color: var(--cad-text);
  font-size: 14px;
  line-height: 1.4;
}

/* Ensure `hidden` wins over display:flex/grid on our own classes. */
#cow-ai-dashboard-root [hidden] { display: none !important; }

/* ---- Mint theme overrides (opt-in via data-cad-theme="mint") ---- */
#cow-ai-dashboard-root[data-cad-theme="mint"] {
  --cad-page-bg:   #d6ebe6;
  --cad-surface:   #ffffff;
  --cad-border:    #e6efeb;
  --cad-border-2:  #d8e2de;
  --cad-text:      #0c2a27;
  --cad-text-2:    #5a7771;
  --cad-muted:     #9fb5b0;
  --cad-primary:   #5fa9a6;
  --cad-primary-2: #e3f2ef;
  --cad-accent:    #f4b18a;
  --cad-danger:    #e8776e;
  --cad-danger-2:  #fde3df;
  --cad-warn:      #e9a84a;
  --cad-warn-2:    #faecd1;
  --cad-success:   #63b898;
  --cad-success-2: #dff1e7;
  --cad-radius:    20px;
  --cad-radius-sm: 14px;
  --cad-shadow:    0 1px 2px rgba(20, 60, 55, 0.03), 0 10px 30px rgba(20, 60, 55, 0.06);
}
/* Mint theme: the icon-only "compact rail" look applies only when the
   sidebar is collapsed so the expand/collapse toggle still works. Mint-
   specific colour + branding rules stay unconditional below. */
#cow-ai-dashboard-root[data-cad-theme="mint"] .cad-app--sidebar-collapsed { grid-template-columns: 86px 1fr; }
@media (max-width: 820px) {
  #cow-ai-dashboard-root[data-cad-theme="mint"] .cad-app--sidebar-collapsed { grid-template-columns: 1fr; }
}
#cow-ai-dashboard-root[data-cad-theme="mint"] .cad-app--sidebar-collapsed .cad-sidebar { padding: 20px 12px; }
#cow-ai-dashboard-root[data-cad-theme="mint"] .cad-app--sidebar-collapsed .cad-nav { align-items: center; gap: 8px; }
#cow-ai-dashboard-root[data-cad-theme="mint"] .cad-app--sidebar-collapsed .cad-nav__item {
  width: 44px; height: 44px; padding: 0;
  display: grid; place-items: center;
  border-radius: 12px;
}
#cow-ai-dashboard-root[data-cad-theme="mint"] .cad-app--sidebar-collapsed .cad-nav__item--active {
  background: var(--cad-primary-2); color: var(--cad-primary);
}
#cow-ai-dashboard-root[data-cad-theme="mint"] .cad-app--sidebar-collapsed .cad-nav__icon { width: 20px; height: 20px; }
#cow-ai-dashboard-root[data-cad-theme="mint"] .cad-app--sidebar-collapsed .cad-brand { justify-content: center; padding: 0; }
/* Unconditional mint decoration */
#cow-ai-dashboard-root[data-cad-theme="mint"] .cad-brand__mark {
  background: linear-gradient(135deg, #5fa9a6 0%, #7ec0a5 100%);
}
#cow-ai-dashboard-root[data-cad-theme="mint"] .cad-user__avatar {
  background: linear-gradient(135deg, #5fa9a6 0%, #7ec0a5 100%);
}
#cow-ai-dashboard-root[data-cad-theme="mint"] .cad-app { background: var(--cad-page-bg); }

/* ---- Navy theme overrides ---- */
#cow-ai-dashboard-root[data-cad-theme="navy"] {
  --cad-page-bg:   #f5f4ef;
  --cad-surface:   #ffffff;
  --cad-border:    #eceae4;
  --cad-border-2:  #dedad2;
  --cad-text:      #101c3c;
  --cad-text-2:    #5b6585;
  --cad-muted:     #9aa2b8;
  --cad-primary:   #1d3a8a;
  --cad-primary-2: #e3e9fa;
  --cad-accent:    #3b82f6;
  --cad-danger:    #dc2626;
  --cad-danger-2:  #fee2e2;
  --cad-warn:      #d97706;
  --cad-warn-2:    #fef3c7;
  --cad-success:   #059669;
  --cad-success-2: #d1fae5;
  --cad-radius:    16px;
  --cad-radius-sm: 12px;
  --cad-shadow:    0 1px 2px rgba(16, 28, 60, 0.04), 0 4px 18px rgba(16, 28, 60, 0.06);
}
#cow-ai-dashboard-root[data-cad-theme="navy"] .cad-brand__mark {
  background: linear-gradient(135deg, #1d3a8a 0%, #3b82f6 100%);
}
#cow-ai-dashboard-root[data-cad-theme="navy"] .cad-user__avatar {
  background: linear-gradient(135deg, #1d3a8a 0%, #3b82f6 100%);
}
#cow-ai-dashboard-root[data-cad-theme="navy"] .cad-nav__item--active {
  background: var(--cad-primary);
  color: #ffffff;
}
#cow-ai-dashboard-root[data-cad-theme="navy"] .cad-kpi__icon {
  color: var(--cad-primary);
  background: var(--cad-primary-2);
}
#cow-ai-dashboard-root[data-cad-theme="navy"] .cad-chip--active,
#cow-ai-dashboard-root[data-cad-theme="navy"] .cad-btn--primary {
  background: var(--cad-primary);
  border-color: var(--cad-primary);
}

/* ---- Acaris brand theme (eu.acaris.net colour set: #2A2A81 indigo + #28D792 green) ---- */
#cow-ai-dashboard-root[data-cad-theme="acaris"] {
  --cad-page-bg:   #f4f6fb;
  --cad-surface:   #ffffff;
  --cad-border:    #e7e9f2;
  --cad-border-2:  #d5d9e7;
  --cad-text:      #141867;
  --cad-text-2:    #525a83;
  --cad-muted:     #8e94b3;
  --cad-primary:   #2a2a81;
  --cad-primary-2: #e8e8f5;
  --cad-accent:    #28d792;
  --cad-danger:    #cf2e2e;
  --cad-danger-2:  #fde1e1;
  --cad-warn:      #fcb900;
  --cad-warn-2:    #fff4cc;
  --cad-success:   #28d792;
  --cad-success-2: #d5f6e8;
  --cad-radius:    14px;
  --cad-radius-sm: 10px;
  --cad-shadow:    0 1px 2px rgba(20, 24, 103, 0.04), 0 8px 24px rgba(20, 24, 103, 0.06);
}
#cow-ai-dashboard-root[data-cad-theme="acaris"] .cad-brand__mark {
  background: linear-gradient(135deg, #2a2a81 0%, #28d792 100%);
}
#cow-ai-dashboard-root[data-cad-theme="acaris"] .cad-user__avatar {
  background: linear-gradient(135deg, #2a2a81 0%, #28d792 100%);
}
#cow-ai-dashboard-root[data-cad-theme="acaris"] .cad-nav__item--active {
  background: var(--cad-primary);
  color: #ffffff;
}
#cow-ai-dashboard-root[data-cad-theme="acaris"] .cad-chip--active,
#cow-ai-dashboard-root[data-cad-theme="acaris"] .cad-btn--primary {
  background: var(--cad-primary);
  border-color: var(--cad-primary);
  color: #ffffff;
}
#cow-ai-dashboard-root[data-cad-theme="acaris"] .cad-btn--primary:hover:not(:disabled) {
  background: #1f1f66;
  border-color: #1f1f66;
}
/* Table head in Acaris's own dark-on-tint style */
#cow-ai-dashboard-root[data-cad-theme="acaris"] .cad-table thead th {
  background: #f0f2f9;
  color: var(--cad-text);
}
/* Accent-green use: the "change going down" arrows stay green;
   also keep the success delta green (already default). */

/* ---- Theme switcher ---- */
#cow-ai-dashboard-root .cad-theme-switch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--cad-border);
  background: var(--cad-surface);
  border-radius: 999px;
  flex-shrink: 0;
}
#cow-ai-dashboard-root .cad-theme-swatch {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 120ms, border-color 120ms, box-shadow 120ms;
}
#cow-ai-dashboard-root .cad-theme-swatch--indigo {
  background: linear-gradient(135deg, #4f5dff 0%, #0ea5e9 100%);
}
#cow-ai-dashboard-root .cad-theme-swatch--mint {
  background: linear-gradient(135deg, #5fa9a6 0%, #7ec0a5 100%);
}
#cow-ai-dashboard-root .cad-theme-swatch--navy {
  background: linear-gradient(135deg, #1d3a8a 0%, #3b82f6 100%);
}
#cow-ai-dashboard-root .cad-theme-swatch--acaris {
  background: linear-gradient(135deg, #2a2a81 0%, #28d792 100%);
}
#cow-ai-dashboard-root .cad-theme-swatch--dark {
  background: linear-gradient(135deg, #0b1220 0%, #374151 100%);
}
#cow-ai-dashboard-root .cad-theme-swatch:hover { transform: scale(1.08); }
#cow-ai-dashboard-root .cad-theme-swatch--active {
  border-color: var(--cad-text);
  box-shadow: 0 0 0 2px var(--cad-surface), 0 0 0 4px var(--cad-text);
}

/* ---- app frame (sidebar + main) ---- */
#cow-ai-dashboard-root .cad-app {
  display: grid;
  grid-template-columns: 232px 1fr;
  gap: 0;
  min-height: 640px;
  background: var(--cad-page-bg);
  border-radius: var(--cad-radius);
  overflow: hidden;
  border: 1px solid var(--cad-border);
}

@media (max-width: 820px) {
  #cow-ai-dashboard-root .cad-app {
    grid-template-columns: 1fr;
  }
}

/* ---- sidebar ---- */
#cow-ai-dashboard-root .cad-sidebar {
  background: var(--cad-surface);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  border-right: 1px solid var(--cad-border);
  position: relative;
}

/* Pinned bottom of the sidebar — hosts the cross-link to the horse
   guard dashboard. margin-top: auto pushes it to the bottom regardless
   of nav length. */
#cow-ai-dashboard-root .cad-sidebar__bottom {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--cad-border);
}
#cow-ai-dashboard-root .cad-sidebar__switch {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--cad-text-2);
  font: 600 12px/1.2 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  letter-spacing: 0.03em;
  text-decoration: none;
  border: 1px solid var(--cad-border);
  background: transparent;
  transition: color 120ms, background 120ms, border-color 120ms;
}
#cow-ai-dashboard-root .cad-sidebar__switch:hover {
  color: var(--cad-primary);
  border-color: var(--cad-primary);
  background: var(--cad-surface-2, rgba(0,0,0,0.02));
}
#cow-ai-dashboard-root .cad-sidebar__switch-icon {
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px;
  background: var(--cad-primary-soft, rgba(0,180,136,0.15));
  color: var(--cad-primary);
  font-size: 12px;
  flex-shrink: 0;
}
#cow-ai-dashboard-root .cad-app--sidebar-collapsed .cad-sidebar__switch span:not(.cad-sidebar__switch-icon) { display: none; }
#cow-ai-dashboard-root .cad-app--sidebar-collapsed .cad-sidebar__switch {
  justify-content: center;
  padding: 8px;
}

/* ---- brand footer (ACARiS logo + copyright) ---- */
#cow-ai-dashboard-root .cad-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 22px 16px 10px;
  margin-top: 24px;
  border-top: 1px solid var(--cad-border);
  color: var(--cad-text-2);
  font: 500 11px/1 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  letter-spacing: 0.04em;
}
#cow-ai-dashboard-root .cad-footer__logo {
  height: 18px; width: auto;
  opacity: 0.75;
}
#cow-ai-dashboard-root .cad-footer__text { white-space: nowrap; }
#cow-ai-dashboard-root .cad-footer__switch {
  font: 600 11px/1 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--cad-text);
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--cad-border);
  background: transparent;
  transition: background 120ms, border-color 120ms, color 120ms;
}
#cow-ai-dashboard-root .cad-footer__switch:hover {
  color: var(--cad-primary);
  border-color: var(--cad-primary);
  background: var(--cad-primary-soft, rgba(0,180,136,0.08));
}
#cow-ai-dashboard-root .cad-sidebar__collapse {
  position: absolute;
  top: 16px; right: -14px;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1px solid var(--cad-border);
  background: var(--cad-surface);
  color: var(--cad-text-2);
  cursor: pointer;
  display: grid; place-items: center;
  box-shadow: var(--cad-shadow);
  z-index: 2;
  transition: color 120ms, border-color 120ms, transform 120ms;
}
#cow-ai-dashboard-root .cad-sidebar__collapse:hover {
  color: var(--cad-primary);
  border-color: var(--cad-primary);
}
#cow-ai-dashboard-root .cad-sidebar__collapse svg { width: 14px; height: 14px; }
@media (max-width: 820px) {
  #cow-ai-dashboard-root .cad-sidebar__collapse { display: none; }
}

/* User-triggered collapse (independent of theme) */
#cow-ai-dashboard-root .cad-app--sidebar-collapsed { grid-template-columns: 72px 1fr; }
#cow-ai-dashboard-root .cad-app--sidebar-collapsed .cad-sidebar { padding: 20px 10px; }
#cow-ai-dashboard-root .cad-app--sidebar-collapsed .cad-brand__name,
#cow-ai-dashboard-root .cad-app--sidebar-collapsed .cad-nav__section,
#cow-ai-dashboard-root .cad-app--sidebar-collapsed .cad-nav__item span { display: none; }
#cow-ai-dashboard-root .cad-app--sidebar-collapsed .cad-brand { justify-content: center; padding: 0; }
#cow-ai-dashboard-root .cad-app--sidebar-collapsed .cad-nav__item {
  width: 44px; height: 44px; padding: 0;
  display: grid; place-items: center;
  border-radius: 12px;
}
#cow-ai-dashboard-root .cad-app--sidebar-collapsed .cad-sidebar__collapse svg { transform: rotate(180deg); }
@media (max-width: 820px) {
  #cow-ai-dashboard-root .cad-app--sidebar-collapsed { grid-template-columns: 1fr; }
  #cow-ai-dashboard-root .cad-app--sidebar-collapsed .cad-sidebar { padding: 12px; }
  #cow-ai-dashboard-root .cad-app--sidebar-collapsed .cad-brand__name,
  #cow-ai-dashboard-root .cad-app--sidebar-collapsed .cad-nav__item span { display: inline; }
}
#cow-ai-dashboard-root .cad-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
}
#cow-ai-dashboard-root .cad-brand__mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--cad-primary) 0%, var(--cad-accent) 100%);
  display: grid;
  place-items: center;
  color: #ffffff;
  font-weight: 700;
  font-size: 14px;
}
#cow-ai-dashboard-root .cad-brand__logo {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: contain;
  background: #ffffff;
  box-shadow: 0 0 0 1px var(--cad-border);
  flex-shrink: 0;
}
#cow-ai-dashboard-root[data-cad-theme="dark"] .cad-brand__logo {
  background: #ffffff;
}
#cow-ai-dashboard-root .cad-brand__name {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.04em;
}

#cow-ai-dashboard-root .cad-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#cow-ai-dashboard-root .cad-nav__section {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
  color: var(--cad-muted);
  margin: 10px 8px 4px;
  font-weight: 600;
}
#cow-ai-dashboard-root .cad-nav__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: none;
  background: transparent;
  color: var(--cad-text-2);
  border-radius: 10px;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 120ms, color 120ms;
}
#cow-ai-dashboard-root .cad-nav__item:hover { background: #f8fafc; color: var(--cad-text); }
#cow-ai-dashboard-root .cad-nav__item--active {
  background: var(--cad-primary-2);
  color: var(--cad-primary);
  font-weight: 600;
}
#cow-ai-dashboard-root .cad-nav__icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
}

@media (max-width: 820px) {
  #cow-ai-dashboard-root .cad-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--cad-border);
    padding: 12px;
    gap: 10px;
  }
  #cow-ai-dashboard-root .cad-nav {
    flex-direction: row;
    overflow-x: auto;
    scrollbar-width: thin;
  }
  #cow-ai-dashboard-root .cad-nav__section { display: none; }
  #cow-ai-dashboard-root .cad-nav__item { white-space: nowrap; }
}

/* ---- main ---- */
#cow-ai-dashboard-root .cad-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px 22px 22px;
  min-width: 0;
}

/* ---- demo-farm banner ----
   Pinned above the topbar when the active farm is a demo alias. Amber so
   the user always knows they're in the masked view. Dismissible per
   session (sessionStorage, not localStorage — a fresh tab surfaces it
   again, which is the right default for "accidentally lost in the demo"
   cases). */
#cow-ai-dashboard-root .cad-demo-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: #fef3c7;
  color: #78350f;
  border: 1px solid #fcd34d;
  border-radius: 10px;
  font-size: 13.5px;
  line-height: 1.35;
}
#cow-ai-dashboard-root .cad-demo-banner[hidden] { display: none; }
#cow-ai-dashboard-root .cad-demo-banner__icon {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: #f59e0b;
  color: #ffffff;
  font-weight: 700;
  display: grid; place-items: center;
}
#cow-ai-dashboard-root .cad-demo-banner__text {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#cow-ai-dashboard-root .cad-demo-banner__title {
  font-weight: 600;
}
#cow-ai-dashboard-root .cad-demo-banner__close {
  flex: 0 0 auto;
  background: transparent;
  border: none;
  color: #78350f;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 6px;
}
#cow-ai-dashboard-root .cad-demo-banner__close:hover { background: rgba(245, 158, 11, 0.2); }

/* ---- top bar ---- */
#cow-ai-dashboard-root .cad-topbar {
  display: flex;
  align-items: center;
  gap: 14px;
}
#cow-ai-dashboard-root .cad-topbar__title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  flex-shrink: 0;
}
#cow-ai-dashboard-root .cad-search {
  position: relative;
  flex: 1 1 auto;
  max-width: 520px;
  margin-left: auto;
}
#cow-ai-dashboard-root .cad-search__input {
  width: 100%;
  box-sizing: border-box;
  padding: 9px 12px 9px 34px;
  border: 1px solid var(--cad-border-2);
  border-radius: 10px;
  background: var(--cad-surface) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><path d='m21 21-4.3-4.3'/></svg>") no-repeat 11px center;
  font: inherit;
  color: var(--cad-text);
}
#cow-ai-dashboard-root .cad-search__input:focus {
  outline: none;
  border-color: var(--cad-primary);
  box-shadow: 0 0 0 3px rgba(79, 93, 255, 0.15);
}
#cow-ai-dashboard-root .cad-search__results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  max-height: 340px;
  overflow-y: auto;
  background: var(--cad-surface);
  border: 1px solid var(--cad-border);
  border-radius: 10px;
  box-shadow: var(--cad-shadow);
  z-index: 20;
  font-size: 13px;
}
#cow-ai-dashboard-root .cad-search__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
}
#cow-ai-dashboard-root .cad-search__item:hover,
#cow-ai-dashboard-root .cad-search__item--active {
  background: var(--cad-primary-2);
}
#cow-ai-dashboard-root .cad-search__name { font-weight: 500; color: var(--cad-text); }
#cow-ai-dashboard-root .cad-search__meta {
  color: var(--cad-text-2);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
#cow-ai-dashboard-root .cad-search__msg {
  padding: 10px;
  color: var(--cad-text-2);
  font-size: 13px;
  text-align: center;
}
#cow-ai-dashboard-root .cad-search__msg--err { color: var(--cad-danger); }

#cow-ai-dashboard-root .cad-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--cad-border);
  background: var(--cad-surface);
  border-radius: 999px;
  flex-shrink: 0;
}
#cow-ai-dashboard-root .cad-user__avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cad-primary) 0%, var(--cad-accent) 100%);
  color: #ffffff;
  display: grid; place-items: center;
  font-weight: 600; font-size: 12px;
}
#cow-ai-dashboard-root .cad-user__text { line-height: 1.15; }
#cow-ai-dashboard-root .cad-user__name { font-weight: 600; font-size: 13px; }
#cow-ai-dashboard-root .cad-user__role { color: var(--cad-text-2); font-size: 11px; }
#cow-ai-dashboard-root .cad-user__logout {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  background: transparent;
  color: var(--cad-text-2);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid var(--cad-border);
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}
#cow-ai-dashboard-root .cad-user__logout:hover,
#cow-ai-dashboard-root .cad-user__logout:focus-visible {
  color: var(--cad-danger);
  border-color: color-mix(in srgb, var(--cad-danger) 40%, var(--cad-border));
  background: color-mix(in srgb, var(--cad-danger) 6%, transparent);
  outline: none;
}
@media (max-width: 640px) {
  /* Hide the text label on narrow screens — the door icon is self-explanatory. */
  #cow-ai-dashboard-root .cad-user__logout-label { display: none; }
  #cow-ai-dashboard-root .cad-user__logout { padding: 4px 8px; }
}

/* ---- welcome row ---- */
#cow-ai-dashboard-root .cad-welcome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
#cow-ai-dashboard-root .cad-welcome__title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
#cow-ai-dashboard-root .cad-welcome__date {
  margin: 2px 0 0;
  color: var(--cad-text-2);
  font-size: 13px;
}
#cow-ai-dashboard-root .cad-welcome__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---- KPI tiles ---- */
#cow-ai-dashboard-root .cad-kpis {
  display: grid;
  grid-template-columns: 1.6fr 1fr 1fr 1fr;   /* featured first tile */
  gap: 14px;
}
@media (max-width: 1000px) {
  #cow-ai-dashboard-root .cad-kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  #cow-ai-dashboard-root .cad-kpis { grid-template-columns: 1fr; }
}
/* Hero KPI — light primary tint background with dark text, big value.
   This keeps contrast readable on every theme (including mint / acaris /
   dark) unlike a coloured gradient with white text. */
#cow-ai-dashboard-root .cad-kpi--hero {
  background: var(--cad-primary-2);
  border-color: transparent;
  color: var(--cad-text);
  position: relative;
  overflow: hidden;
}
#cow-ai-dashboard-root .cad-kpi--hero::before {
  content: '';
  position: absolute;
  right: -40px; top: -40px;
  width: 140px; height: 140px;
  border-radius: 50%;
  background: var(--cad-primary);
  opacity: 0.06;
  pointer-events: none;
}
#cow-ai-dashboard-root .cad-kpi--hero .cad-kpi__label { color: var(--cad-text-2); }
#cow-ai-dashboard-root .cad-kpi--hero .cad-kpi__value {
  font-size: 32px;
  color: var(--cad-primary);
  font-weight: 700;
}
#cow-ai-dashboard-root .cad-kpi--hero .cad-kpi__delta { color: var(--cad-text-2); }
#cow-ai-dashboard-root .cad-kpi--hero .cad-kpi__icon {
  background: var(--cad-primary);
  color: #ffffff;
  width: 34px; height: 34px;
}
#cow-ai-dashboard-root .cad-kpi--hero .cad-kpi__icon svg { width: 16px; height: 16px; }
#cow-ai-dashboard-root .cad-kpi--hero.cad-kpi--clickable:hover {
  border-color: transparent;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  transform: translateY(-1px);
}
#cow-ai-dashboard-root .cad-kpi {
  background: var(--cad-surface);
  border: 1px solid var(--cad-border);
  border-radius: var(--cad-radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--cad-shadow);
}
#cow-ai-dashboard-root .cad-kpi__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
#cow-ai-dashboard-root .cad-kpi__label {
  color: var(--cad-text-2);
  font-size: 12px;
  font-weight: 500;
}
#cow-ai-dashboard-root .cad-kpi__icon {
  width: 28px; height: 28px;
  border-radius: 8px;
  display: grid; place-items: center;
  color: var(--cad-primary);
  background: var(--cad-primary-2);
}
#cow-ai-dashboard-root .cad-kpi__icon svg { width: 14px; height: 14px; }
#cow-ai-dashboard-root .cad-kpi__value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
#cow-ai-dashboard-root .cad-kpi__delta {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--cad-text-2);
  border-radius: var(--cad-pill-radius);
}
#cow-ai-dashboard-root .cad-kpi__delta--good { color: var(--cad-success); }
#cow-ai-dashboard-root .cad-kpi__delta--bad  { color: var(--cad-danger); }

/* ---- KPI wrapper + help popover ----
   The wrapper is the grid item; the inner .cad-kpi is a <button> that
   handles drill-down clicks. We park the ⓘ button and the popover
   outside that button (still inside the wrapper) so we avoid nested-
   button invalid HTML. The wrapper's position:relative anchors the
   absolute popover below the tile. */
#cow-ai-dashboard-root .cad-kpi-wrap {
  position: relative;
  display: flex;
  min-width: 0;
}
#cow-ai-dashboard-root .cad-kpi-wrap > .cad-kpi { flex: 1 1 auto; min-width: 0; }
#cow-ai-dashboard-root .cad-kpi__help {
  position: absolute;
  top: 10px;
  left: 10px;
  right: auto;
  z-index: 2;
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0;
  color: var(--cad-text-2);
  cursor: pointer;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  font: 600 12px/1 system-ui, -apple-system, Segoe UI, sans-serif;
  opacity: 0.75;
  transition: background-color 120ms ease, color 120ms ease, opacity 120ms ease;
}
#cow-ai-dashboard-root .cad-kpi__help:hover,
#cow-ai-dashboard-root .cad-kpi__help:focus-visible {
  background: var(--cad-primary-2);
  color: var(--cad-primary);
  opacity: 1;
  outline: none;
}
#cow-ai-dashboard-root .cad-kpi__help-pop {
  position: absolute;
  top: 100%;
  left: 8px;
  right: 8px;
  margin-top: 6px;
  z-index: 30;
  background: var(--cad-surface);
  border: 1px solid var(--cad-border);
  border-radius: var(--cad-radius);
  padding: 10px 12px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--cad-text);
}
#cow-ai-dashboard-root .cad-kpi__help-pop[hidden] { display: none; }
#cow-ai-dashboard-root .cad-kpi__help-pop strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
  font-weight: 600;
}
#cow-ai-dashboard-root .cad-kpi__help-pop p {
  margin: 0;
  color: var(--cad-text-2);
}

/* Make room for the top-left ⓘ button so the label text doesn't
   run underneath it. Only applied when the wrapper actually carries
   a help button. */
#cow-ai-dashboard-root .cad-kpi-wrap--has-help .cad-kpi__label {
  padding-left: 24px;
}

/* ---- card header action cluster ----
   Used in the Pens card to group the badge + "Show empty pens" button on
   the right-hand side of the header. */
#cow-ai-dashboard-root .cad-card__header-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
#cow-ai-dashboard-root .cad-btn--sm {
  padding: 4px 10px;
  font-size: 12px;
  line-height: 1.2;
}

/* ---- tab panels ---- */
#cow-ai-dashboard-root .cad-tab-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#cow-ai-dashboard-root .cad-tab-panel[hidden] { display: none; }

/* ---- cards ---- */
#cow-ai-dashboard-root .cad-card {
  background: var(--cad-surface);
  border: 1px solid var(--cad-border);
  border-radius: var(--cad-radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--cad-shadow);
}
#cow-ai-dashboard-root .cad-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
#cow-ai-dashboard-root .cad-card__title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
#cow-ai-dashboard-root .cad-card__footer {
  border-top: 1px solid var(--cad-border);
  padding-top: 10px;
  font-size: 12px;
}

/* ---- 2-up row: trend (wide) + pie (narrow) ---- */
#cow-ai-dashboard-root .cad-row {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
}
@media (max-width: 1000px) {
  #cow-ai-dashboard-root .cad-row { grid-template-columns: 1fr; }
}

/* ---- chart hosts ---- */
#cow-ai-dashboard-root .cad-chart-host {
  position: relative;
  height: 320px;
}
#cow-ai-dashboard-root .cad-chart-host--short { height: 240px; }
#cow-ai-dashboard-root .cad-chart-host--tall  { height: 480px; }

/* Herdenentwicklung page — header controls (pen select + range chips). */
#cow-ai-dashboard-root .cad-trend-page__controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
#cow-ai-dashboard-root .cad-trend-page__controls .cad-range {
  display: flex;
  gap: 6px;
}
#cow-ai-dashboard-root .cad-chart-host > canvas {
  position: absolute; inset: 0;
  width: 100% !important; height: 100% !important;
}
#cow-ai-dashboard-root .cad-placeholder {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--cad-text-2); font-size: 14px;
  pointer-events: none;
}
#cow-ai-dashboard-root .cad-placeholder--inline {
  position: static;
  padding: 24px 12px;
  pointer-events: auto;
}
#cow-ai-dashboard-root .cad-placeholder--error { color: var(--cad-danger); }

/* ---- chips / buttons ---- */
#cow-ai-dashboard-root .cad-chip {
  border: 1px solid var(--cad-border-2);
  background: var(--cad-surface);
  border-radius: var(--cad-pill-radius);
  padding: var(--cad-pill-pad-y) var(--cad-pill-pad-x);
  font-size: 12px;
  cursor: pointer;
  color: var(--cad-text-2);
  transition: background 120ms, color 120ms, border-color 120ms;
}
#cow-ai-dashboard-root .cad-chip:hover {
  border-color: var(--cad-primary);
  color: var(--cad-primary);
}
#cow-ai-dashboard-root .cad-chip--active {
  background: var(--cad-primary);
  color: #ffffff;
  border-color: var(--cad-primary);
}
#cow-ai-dashboard-root .cad-chip[disabled] {
  opacity: 0.4; cursor: not-allowed;
  border-color: var(--cad-border-2); color: var(--cad-text-2);
  background: transparent;
}
#cow-ai-dashboard-root .cad-range { display: flex; gap: 6px; }

/* ---- trend explanation paragraph ---- */
#cow-ai-dashboard-root .cad-trend-intro {
  margin: 4px 0 8px;
  color: var(--cad-text-2);
  font-size: 12px;
  line-height: 1.45;
}

/* ---- trend stats strip ---- */
#cow-ai-dashboard-root .cad-trend-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 10px 0 4px;
  border-top: 1px solid var(--cad-border);
  border-bottom: 1px solid var(--cad-border);
  margin-bottom: 4px;
}
@media (max-width: 900px) {
  #cow-ai-dashboard-root .cad-trend-stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  #cow-ai-dashboard-root .cad-trend-stats { grid-template-columns: 1fr; }
}
#cow-ai-dashboard-root .cad-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 10px;
}
#cow-ai-dashboard-root .cad-stat__label {
  color: var(--cad-text-2);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
#cow-ai-dashboard-root .cad-stat__value-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
#cow-ai-dashboard-root .cad-stat__value {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
#cow-ai-dashboard-root .cad-stat__delta {
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: var(--cad-pill-pad-y) var(--cad-pill-pad-x);
  border-radius: var(--cad-pill-radius);
}
#cow-ai-dashboard-root .cad-stat__delta--good { color: var(--cad-success); background: var(--cad-success-2); }
#cow-ai-dashboard-root .cad-stat__delta--bad  { color: var(--cad-danger);  background: var(--cad-danger-2); }
#cow-ai-dashboard-root .cad-stat__delta--flat { color: var(--cad-text-2);  background: #f1f5f9; }
#cow-ai-dashboard-root .cad-stat__sub {
  color: var(--cad-text-2);
  font-size: 11px;
}

/* ---- lactation-filter toggle (Settings) ---- */
#cow-ai-dashboard-root .cad-toggle--row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0 0;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}
#cow-ai-dashboard-root .cad-toggle--row input { accent-color: var(--cad-primary); width: 18px; height: 18px; }

/* ---- toggles (trend series) ---- */
#cow-ai-dashboard-root .cad-toggles {
  display: flex; flex-wrap: wrap; gap: 10px 16px; font-size: 12px;
}
#cow-ai-dashboard-root .cad-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer; user-select: none;
}
#cow-ai-dashboard-root .cad-toggle input { accent-color: var(--cad-primary); }

/* ---- alerts controls ---- */
#cow-ai-dashboard-root .cad-alerts-controls {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  font-size: 13px;
}
#cow-ai-dashboard-root .cad-ctrl { display: inline-flex; align-items: center; gap: 6px; }
#cow-ai-dashboard-root .cad-ctrl select {
  font: inherit; color: inherit;
  padding: 4px 8px;
  border: 1px solid var(--cad-border-2); border-radius: 8px;
  background: var(--cad-surface); cursor: pointer;
}
#cow-ai-dashboard-root .cad-daychip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--cad-primary-2); color: var(--cad-primary);
  border: 1px solid #cdd4fd;
  border-radius: 999px;
  padding: 3px 4px 3px 10px;
  font-size: 12px;
}
#cow-ai-dashboard-root .cad-daychip__x {
  border: none; background: transparent; color: inherit;
  font-size: 16px; line-height: 1; cursor: pointer;
  padding: 0 6px; border-radius: 999px;
}
#cow-ai-dashboard-root .cad-daychip__x:hover { background: #dadffd; }

/* ---- tables ---- */
#cow-ai-dashboard-root .cad-table-host { position: relative; overflow-x: auto; }
#cow-ai-dashboard-root .cad-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
#cow-ai-dashboard-root .cad-table thead th {
  text-align: left;
  font-weight: 600;
  color: var(--cad-text-2);
  padding: 9px 10px;
  border-bottom: 1px solid var(--cad-border);
  background: #fafbfc;
  position: sticky; top: 0;
  cursor: default;
  white-space: nowrap;
}
#cow-ai-dashboard-root .cad-table thead th[data-sort-key] {
  cursor: pointer;
  user-select: none;
}
#cow-ai-dashboard-root .cad-table thead th[data-sort-key]:hover { color: var(--cad-primary); }
#cow-ai-dashboard-root .cad-table thead th[data-sort-key]::after {
  content: ' ↕';
  opacity: 0.28;
  font-size: 10px;
  margin-left: 2px;
  color: var(--cad-text-2);
}
#cow-ai-dashboard-root .cad-table thead th[data-sort-active="asc"]::after {
  content: ' ▲';
  opacity: 1;
  color: var(--cad-primary);
}
#cow-ai-dashboard-root .cad-table thead th[data-sort-active="desc"]::after {
  content: ' ▼';
  opacity: 1;
  color: var(--cad-primary);
}

/* ---- filter bars (herd / checks) ---- */
#cow-ai-dashboard-root .cad-lastseen-filters {
  display: flex; flex-wrap: wrap; gap: 10px 14px;
  align-items: center;
  font-size: 13px;
}
#cow-ai-dashboard-root .cad-lastseen-filters input[type="date"],
#cow-ai-dashboard-root .cad-lastseen-filters input[type="search"] {
  font: inherit; padding: 6px 10px;
  border: 1px solid var(--cad-border-2); border-radius: 8px;
  min-width: 140px;
}
#cow-ai-dashboard-root .cad-table tbody td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--cad-border);
  vertical-align: top;
}
#cow-ai-dashboard-root .cad-table tbody tr:last-child td { border-bottom: none; }
#cow-ai-dashboard-root .cad-table tbody tr:hover { background: #fafbfc; }
#cow-ai-dashboard-root .cad-table .cad-num { text-align: right; font-variant-numeric: tabular-nums; }
#cow-ai-dashboard-root .cad-cow-link {
  color: var(--cad-primary);
  text-decoration: none;
  font-weight: 500;
}
#cow-ai-dashboard-root .cad-cow-link:hover { text-decoration: underline; }
#cow-ai-dashboard-root .cad-cow-id {
  display: block;
  color: var(--cad-text-2);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
#cow-ai-dashboard-root .cad-table-note td {
  color: var(--cad-text-2); text-align: center; padding: 12px 10px; font-size: 12px;
  background: #fafbfc;
}

/* ---- score pills ---- */
#cow-ai-dashboard-root .cad-score {
  display: inline-block;
  min-width: 2.75em;
  padding: var(--cad-pill-pad-y) var(--cad-pill-pad-x);
  border-radius: var(--cad-pill-radius);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
#cow-ai-dashboard-root .cad-score--high { background: var(--cad-danger-2); color: #b91c1c; }
#cow-ai-dashboard-root .cad-score--med  { background: var(--cad-warn-2);   color: #b45309; }
#cow-ai-dashboard-root .cad-score--low  { background: var(--cad-success-2);color: #166534; }

/* ---- change arrows ---- */
#cow-ai-dashboard-root .cad-change { font-variant-numeric: tabular-nums; font-weight: 500; }
#cow-ai-dashboard-root .cad-change--up   { color: var(--cad-danger); }
#cow-ai-dashboard-root .cad-change--down { color: var(--cad-success); }
#cow-ai-dashboard-root .cad-change--flat { color: var(--cad-text-2); }

/* ---- badges ---- */
#cow-ai-dashboard-root .cad-badge {
  display: inline-block;
  background: var(--cad-primary-2); color: var(--cad-primary);
  border: 1px solid var(--cad-border);
  border-radius: var(--cad-pill-radius);
  padding: var(--cad-pill-pad-y) var(--cad-pill-pad-x);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* ---- farm switcher ---- */
#cow-ai-dashboard-root .cad-farm-switch {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px;
  color: var(--cad-text-2);
  background: var(--cad-primary-2);
  border: 1px solid #cdd4fd;
  padding: 5px 10px;
  border-radius: 999px;
}
#cow-ai-dashboard-root .cad-farm-switch__label {
  text-transform: uppercase; letter-spacing: 0.06em;
  font-weight: 600; color: var(--cad-primary); font-size: 11px;
}
#cow-ai-dashboard-root .cad-farm-switch select {
  font: inherit; color: var(--cad-text); background: transparent;
  border: none; padding: 0; cursor: pointer; max-width: 220px;
}
#cow-ai-dashboard-root .cad-farm-switch select:focus { outline: none; }
#cow-ai-dashboard-root .cad-farm-switch select:disabled { cursor: wait; opacity: 0.6; }

/* ---- last-seen controls ---- */
#cow-ai-dashboard-root .cad-lastseen-controls {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 13px;
}
#cow-ai-dashboard-root .cad-lastseen-controls input[type="range"] {
  width: 200px; vertical-align: middle;
  accent-color: var(--cad-primary);
}
#cow-ai-dashboard-root .cad-slider-value {
  display: inline-block; min-width: 2em; text-align: right;
  font-weight: 600; color: var(--cad-primary);
  font-variant-numeric: tabular-nums;
}

/* ---- pager ---- */
#cow-ai-dashboard-root .cad-pager {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; font-size: 12px; color: var(--cad-text-2);
}
#cow-ai-dashboard-root .cad-pager__btns { display: flex; gap: 6px; }

/* ---- buttons ---- */
#cow-ai-dashboard-root .cad-btn {
  font: inherit;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
}
#cow-ai-dashboard-root .cad-btn:disabled { opacity: 0.5; cursor: wait; }
#cow-ai-dashboard-root .cad-btn--primary {
  background: var(--cad-primary); color: #ffffff; border-color: var(--cad-primary);
}
#cow-ai-dashboard-root .cad-btn--primary:hover:not(:disabled) { background: #3d4ae3; }
#cow-ai-dashboard-root .cad-btn--ghost {
  background: transparent; color: var(--cad-danger); border-color: var(--cad-border-2);
}
#cow-ai-dashboard-root .cad-btn--ghost:hover:not(:disabled) {
  border-color: var(--cad-danger); background: var(--cad-danger-2);
}
#cow-ai-dashboard-root .cad-chip--danger {
  color: var(--cad-danger); border-color: var(--cad-danger-2);
}
#cow-ai-dashboard-root .cad-chip--danger:hover {
  background: var(--cad-danger-2); color: #b91c1c; border-color: #fecaca;
}

/* Destructive button variant — used for "Delete demo farm" in the admin
   settings card. Sits alongside the existing primary/ghost variants. */
#cow-ai-dashboard-root .cad-btn--danger {
  background: var(--cad-danger);
  color: #ffffff;
  border-color: var(--cad-danger);
}
#cow-ai-dashboard-root .cad-btn--danger:hover:not(:disabled) {
  background: #b91c1c;
  border-color: #b91c1c;
}

/* ---- Admin demo-farm management card (Settings tab) ---- */
#cow-ai-dashboard-root .cad-demo-mgr {
  display: flex;
  flex-direction: column;
  gap: 24px;
}
#cow-ai-dashboard-root .cad-demo-mgr__subtitle {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 10px;
  color: var(--cad-text-1);
}
#cow-ai-dashboard-root .cad-demo-mgr__form {
  display: grid;
  grid-template-columns: 2fr 2fr auto auto;
  gap: 10px;
  align-items: end;
}
#cow-ai-dashboard-root .cad-demo-mgr__field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  color: var(--cad-text-2);
}
#cow-ai-dashboard-root .cad-demo-mgr__field select,
#cow-ai-dashboard-root .cad-demo-mgr__field input {
  border: 1px solid var(--cad-border-2);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  background: var(--cad-surface);
  color: var(--cad-text-1);
  min-height: 34px;
}
#cow-ai-dashboard-root .cad-demo-mgr__msg {
  font-size: 12.5px;
  align-self: center;
  min-width: 0;
}
#cow-ai-dashboard-root .cad-demo-mgr__msg--ok { color: var(--cad-good, #047857); }
#cow-ai-dashboard-root .cad-demo-mgr__msg--err { color: var(--cad-danger); }
#cow-ai-dashboard-root .cad-demo-mgr__empty {
  color: var(--cad-text-2);
  font-size: 13px;
  padding: 14px 0;
}
#cow-ai-dashboard-root .cad-demo-mgr__loading {
  color: var(--cad-text-2);
  font-size: 13px;
}
#cow-ai-dashboard-root .cad-demo-mgr__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
#cow-ai-dashboard-root .cad-demo-mgr__table th,
#cow-ai-dashboard-root .cad-demo-mgr__table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--cad-border-2);
  text-align: left;
  vertical-align: top;
}
#cow-ai-dashboard-root .cad-demo-mgr__table th {
  font-weight: 600;
  color: var(--cad-text-2);
  background: var(--cad-surface-2, transparent);
}
#cow-ai-dashboard-root .cad-demo-mgr__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}
#cow-ai-dashboard-root .cad-demo-mgr__chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 10px;
  cursor: default;
}
#cow-ai-dashboard-root .cad-demo-mgr__chip:hover {
  border-color: var(--cad-border-2);
  color: var(--cad-text-2);
}
#cow-ai-dashboard-root .cad-chip__close {
  background: transparent;
  border: none;
  color: var(--cad-text-2);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}
#cow-ai-dashboard-root .cad-chip__close:hover {
  background: var(--cad-danger-2);
  color: var(--cad-danger);
}
#cow-ai-dashboard-root .cad-demo-mgr__none {
  color: var(--cad-text-2);
  font-style: italic;
  font-size: 12.5px;
}
#cow-ai-dashboard-root .cad-demo-mgr__adduser {
  display: flex;
  gap: 6px;
  align-items: center;
}
#cow-ai-dashboard-root .cad-demo-mgr__email {
  flex: 1 1 auto;
  border: 1px solid var(--cad-border-2);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12.5px;
  min-height: 30px;
  min-width: 0;
}

@media (max-width: 720px) {
  #cow-ai-dashboard-root .cad-demo-mgr__form {
    grid-template-columns: 1fr;
  }
  #cow-ai-dashboard-root .cad-demo-mgr__table,
  #cow-ai-dashboard-root .cad-demo-mgr__table tbody,
  #cow-ai-dashboard-root .cad-demo-mgr__table tr,
  #cow-ai-dashboard-root .cad-demo-mgr__table td {
    display: block;
    width: 100%;
  }
  #cow-ai-dashboard-root .cad-demo-mgr__table thead { display: none; }
  #cow-ai-dashboard-root .cad-demo-mgr__table tr {
    border: 1px solid var(--cad-border-2);
    border-radius: 10px;
    padding: 8px 10px;
    margin-bottom: 10px;
  }
  #cow-ai-dashboard-root .cad-demo-mgr__table td {
    border-bottom: none;
    padding: 4px 0;
  }
}

/* ---- KPI clickable ---- */
#cow-ai-dashboard-root .cad-kpi--clickable {
  border: 1px solid var(--cad-border);
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: border-color 120ms, box-shadow 120ms, transform 120ms;
}
#cow-ai-dashboard-root .cad-kpi--clickable:hover {
  border-color: var(--cad-primary);
  box-shadow: 0 4px 12px rgba(79, 93, 255, 0.1);
  transform: translateY(-1px);
}

/* ---- truncate ---- */
#cow-ai-dashboard-root .cad-truncate {
  max-width: 260px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---- triage card on cow analysis ---- */
#cow-ai-dashboard-root .cad-triage {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(160px, 220px) 1fr;
  align-items: start;
}
@media (max-width: 720px) {
  #cow-ai-dashboard-root .cad-triage { grid-template-columns: 1fr; }
}
#cow-ai-dashboard-root .cad-triage__note {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--cad-text-2);
}
#cow-ai-dashboard-root .cad-triage__note textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--cad-border-2);
  border-radius: 8px;
  resize: vertical;
  min-height: 56px;
}
#cow-ai-dashboard-root .cad-triage__actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
#cow-ai-dashboard-root .cad-triage__msg {
  font-size: 12px;
  color: var(--cad-text-2);
}
#cow-ai-dashboard-root .cad-triage__msg--err { color: var(--cad-danger); }
#cow-ai-dashboard-root .cad-triage__meta {
  grid-column: 1 / -1;
  font-size: 12px;
  color: var(--cad-text-2);
}
#cow-ai-dashboard-root .cad-triage__log { grid-column: 1 / -1; margin-top: 4px; font-size: 13px; }
#cow-ai-dashboard-root .cad-triage__log summary { cursor: pointer; color: var(--cad-primary); }
#cow-ai-dashboard-root .cad-triage-log {
  list-style: none;
  padding: 10px 0 0;
  margin: 0;
  display: flex; flex-direction: column; gap: 8px;
}
#cow-ai-dashboard-root .cad-triage-log li {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 12px;
}
#cow-ai-dashboard-root .cad-triage-log__meta { color: var(--cad-text-2); }
#cow-ai-dashboard-root .cad-triage-log__note { color: var(--cad-text); font-style: italic; }
#cow-ai-dashboard-root .cad-triage-editor-select {
  font: inherit; padding: 6px 28px 6px 12px;
  border: 1px solid var(--cad-border-2); border-radius: 8px;
  cursor: pointer; background: var(--cad-surface); color: inherit;
}

/* ---- settings ---- */
#cow-ai-dashboard-root .cad-settings-grid {
  display: flex; flex-direction: column; gap: 4px;
}
#cow-ai-dashboard-root .cad-setting {
  display: grid;
  grid-template-columns: minmax(180px, 280px) 1fr;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--cad-border);
  font-size: 14px;
}
#cow-ai-dashboard-root .cad-setting:last-child { border-bottom: none; }
#cow-ai-dashboard-root .cad-setting__label { font-weight: 500; color: var(--cad-text); }
#cow-ai-dashboard-root .cad-setting__hint {
  font-weight: 400; font-size: 12px; color: var(--cad-text-2); margin-top: 2px;
}
#cow-ai-dashboard-root .cad-setting__value { color: var(--cad-text-2); font-variant-numeric: tabular-nums; }
#cow-ai-dashboard-root .cad-setting__control {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
#cow-ai-dashboard-root .cad-setting__control input[type="number"] {
  font: inherit; padding: 6px 10px;
  border: 1px solid var(--cad-border-2); border-radius: 8px;
  width: 100px;
}
#cow-ai-dashboard-root .cad-setting__control input:disabled { background: #f8fafc; color: var(--cad-text-2); }
#cow-ai-dashboard-root .cad-setting__msg { font-size: 12px; color: var(--cad-text-2); }
#cow-ai-dashboard-root .cad-setting__msg--ok  { color: var(--cad-success); }
#cow-ai-dashboard-root .cad-setting__msg--err { color: var(--cad-danger); }

/* ---- triage status ---- */
#cow-ai-dashboard-root .cad-status-filter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--cad-text-2);
}
#cow-ai-dashboard-root .cad-status-filter__label { font-weight: 600; color: var(--cad-text-2); }
#cow-ai-dashboard-root .cad-status-filter label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  user-select: none;
}
#cow-ai-dashboard-root .cad-status-filter input { accent-color: var(--cad-primary); }

#cow-ai-dashboard-root .cad-status-chip {
  display: inline-block;
  padding: var(--cad-pill-pad-y) var(--cad-pill-pad-x);
  border-radius: var(--cad-pill-radius);
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
  line-height: 1.4;
}
#cow-ai-dashboard-root .cad-status-chip--open           { background: #fee2e2; color: #b91c1c; }
#cow-ai-dashboard-root .cad-status-chip--seen           { background: #fef3c7; color: #b45309; }
#cow-ai-dashboard-root .cad-status-chip--trimmer_scheduled { background: #fde68a; color: #92400e; }
#cow-ai-dashboard-root .cad-status-chip--treated           { background: #cffafe; color: #155e75; }
#cow-ai-dashboard-root .cad-status-chip--aftercare_required{ background: #fef9c3; color: #854d0e; box-shadow: 0 0 0 1px rgba(133,77,14,0.25); }
#cow-ai-dashboard-root .cad-status-chip--recovering        { background: #ccfbf1; color: #0f766e; }
#cow-ai-dashboard-root .cad-status-chip--recovered         { background: #dcfce7; color: #166534; }
#cow-ai-dashboard-root .cad-status-chip--resolved          { background: #e5e7eb; color: #4b5563; }
#cow-ai-dashboard-root .cad-status-chip--new            { background: #fee2e2; color: #b91c1c; box-shadow: 0 0 0 1px rgba(185,28,28,0.25); }
#cow-ai-dashboard-root .cad-status-chip--snoozed_3d,
#cow-ai-dashboard-root .cad-status-chip--snoozed        { background: #ede9fe; color: #5b21b6; }
#cow-ai-dashboard-root .cad-status-chip--ignored        { background: #f1f5f9; color: #94a3b8; }

/* ---- cow lifecycle card (cow-detail tab) ---- */
#cow-ai-dashboard-root .cad-lifecycle {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px 16px;
}
#cow-ai-dashboard-root .cad-lifecycle__row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  align-items: baseline;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--cad-border);
}
#cow-ai-dashboard-root .cad-lifecycle__row:last-child { border-bottom: 0; }
#cow-ai-dashboard-root .cad-lifecycle__label {
  color: var(--cad-text-2);
  font-size: 13px;
  font-weight: 500;
}
#cow-ai-dashboard-root .cad-lifecycle__value {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
#cow-ai-dashboard-root .cad-lifecycle__ago {
  color: var(--cad-text-2);
  font-weight: 400;
  font-size: 12px;
  margin-left: 6px;
}
#cow-ai-dashboard-root .cad-lifecycle__row--overdue .cad-lifecycle__value,
#cow-ai-dashboard-root .cad-lifecycle__row--overdue .cad-lifecycle__ago { color: #b91c1c; }
@media (max-width: 520px) {
  #cow-ai-dashboard-root .cad-lifecycle__row { grid-template-columns: 1fr; }
  #cow-ai-dashboard-root .cad-lifecycle__value { text-align: left; }
}

/* Inline tags appended to the cow meta line. */
#cow-ai-dashboard-root .cad-tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
#cow-ai-dashboard-root .cad-tag--dry     { background: #ede9fe; color: #5b21b6; }
#cow-ai-dashboard-root .cad-tag--overdue { background: #fee2e2; color: #b91c1c; box-shadow: 0 0 0 1px rgba(185,28,28,0.25); }

/* Repro-state chips inside the lifecycle card. */
#cow-ai-dashboard-root .cad-repro-chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
#cow-ai-dashboard-root .cad-repro-chip--pregnant { background: #dcfce7; color: #166534; }
#cow-ai-dashboard-root .cad-repro-chip--open     { background: #fef3c7; color: #92400e; }
#cow-ai-dashboard-root .cad-repro-chip--dry      { background: #ede9fe; color: #5b21b6; }
#cow-ai-dashboard-root .cad-repro-chip--other    { background: #f1f5f9; color: #475569; }

/* Cows-to-watch row decorations — highlight new alerts, fade ignored ones. */
#cow-ai-dashboard-root tr.cad-row--new {
  background: linear-gradient(to right, rgba(220,38,38,0.10), rgba(220,38,38,0) 30%);
}
#cow-ai-dashboard-root tr.cad-row--new td:first-child {
  border-left: 3px solid #dc2626;
  padding-left: 10px;
}
#cow-ai-dashboard-root tr.cad-row--ignored { opacity: 0.55; }
#cow-ai-dashboard-root tr.cad-row--ignored td { font-style: italic; }

/* ---- video lightbox (fancybox-style overlay) ---- */
body.cad-no-scroll { overflow: hidden; }
.cad-video-lightbox {
  position: fixed;
  inset: 0;
  z-index: 2147483500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 11, 24, 0.82);
  animation: cad-lb-in 140ms ease-out both;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
@keyframes cad-lb-in { from { opacity: 0 } to { opacity: 1 } }
.cad-video-lightbox__inner {
  position: relative;
  max-width: 92vw;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cad-video-lightbox__video {
  display: block;
  width: auto;
  height: auto;
  max-width: 92vw;
  max-height: 80vh;
  background: #000;
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.cad-video-lightbox__close {
  position: absolute;
  top: -38px; right: -4px;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: rgba(255,255,255,0.92);
  color: #0f172a;
  border: none;
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.cad-video-lightbox__close:hover { background: #fff; }
.cad-video-lightbox__caption {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 6px 10px;
  background: rgba(255,255,255,0.08);
  color: #f8fafc;
  border-radius: 8px;
  font-size: 13px;
  width: fit-content;
  max-width: 100%;
}
.cad-video-lightbox__when { color: #cbd5e1; }
.cad-video-lightbox__cam  { color: #94a3b8; }

/* Status cell: bolder + shadowed pill when a real status is set; tiny
   timestamp underneath so it's obvious the cow has been acknowledged. */
#cow-ai-dashboard-root .cad-triage-select--set {
  font-weight: 700;
  box-shadow: inset 0 0 0 1px currentColor;
}
#cow-ai-dashboard-root .cad-triage-when {
  margin-top: 3px;
  font-size: 10.5px;
  color: var(--cad-text-2);
  white-space: nowrap;
}
#cow-ai-dashboard-root tr.cad-row--has-status .cad-triage-select {
  /* slightly stronger contrast to confirm the pill reflects a saved decision */
  letter-spacing: 0.02em;
}

#cow-ai-dashboard-root .cad-new-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: #dc2626;
  color: #fff;
  border-radius: 4px;
  vertical-align: middle;
}

#cow-ai-dashboard-root .cad-triage-select {
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 22px 3px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  cursor: pointer;
  outline: none;
  text-transform: capitalize;
}
#cow-ai-dashboard-root .cad-triage-select:focus-visible {
  box-shadow: 0 0 0 3px rgba(79, 93, 255, 0.2);
}
#cow-ai-dashboard-root .cad-triage-select--open           { background-color: #fee2e2; color: #b91c1c; border-color: #fecaca; }
#cow-ai-dashboard-root .cad-triage-select--seen           { background-color: #fef3c7; color: #b45309; border-color: #fde68a; }
#cow-ai-dashboard-root .cad-triage-select--trimmer_scheduled { background-color: #fde68a; color: #92400e; border-color: #fcd34d; }
#cow-ai-dashboard-root .cad-triage-select--treated        { background-color: #cffafe; color: #155e75; border-color: #a5f3fc; }
#cow-ai-dashboard-root .cad-triage-select--resolved       { background-color: #e5e7eb; color: #4b5563; border-color: #d1d5db; }
#cow-ai-dashboard-root .cad-triage-select:disabled { opacity: 0.5; cursor: wait; }

/* ---- treatment caption (alerts table; appears under the dropdown) ---- */
#cow-ai-dashboard-root .cad-triage-treatment {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 11px;
  color: #475569;
}
#cow-ai-dashboard-root .cad-triage-treatment__when {
  white-space: nowrap;
}

/* ---- treatment modal ---- */
#cow-ai-dashboard-root + .cad-modal-overlay,
.cad-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100000;
  padding: 16px;
}
.cad-modal {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
  padding: 20px 22px;
  width: min(440px, 100%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: #0f172a;
}
.cad-modal__title {
  margin: 0 0 8px 0;
  font-size: 18px;
  font-weight: 600;
}
.cad-modal__hint {
  margin: 0 0 14px 0;
  color: #475569;
  font-size: 13px;
  line-height: 1.4;
}
.cad-modal__field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}
.cad-modal__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 4px;
}
.cad-modal__field--target,
.cad-modal__field--date { margin-bottom: 0; }
.cad-modal__sub {
  margin: 0 0 12px 0;
  font-size: 12px;
  color: #64748b;
}
.cad-modal__label {
  font-size: 13px;
  font-weight: 500;
  color: #334155;
}
.cad-modal__note,
.cad-modal__date {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: #0f172a;
}
.cad-modal__note:focus,
.cad-modal__date:focus {
  outline: none;
  border-color: #4f5dff;
  box-shadow: 0 0 0 3px rgba(79, 93, 255, 0.18);
}
.cad-modal__err {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 12px;
}
.cad-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* ---- recovery tab ---- */
#cow-ai-dashboard-root .cad-recovery {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(440px, 1fr));
}
#cow-ai-dashboard-root .cad-recovery-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px;
  background: var(--cad-surface);
  border: 1px solid var(--cad-border);
  border-left: 4px solid #cbd5e1; /* default = stagnating */
  border-radius: var(--cad-radius-sm);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
#cow-ai-dashboard-root .cad-recovery-card--overdue    { border-left-color: #dc2626; background: linear-gradient(90deg, rgba(220,38,38,0.05), transparent 30%); }
#cow-ai-dashboard-root .cad-recovery-card--improving  { border-left-color: #16a34a; }
#cow-ai-dashboard-root .cad-recovery-card--recovered  { border-left-color: #15803d; opacity: 0.92; }
#cow-ai-dashboard-root .cad-recovery-card--stagnating { border-left-color: #cbd5e1; }

#cow-ai-dashboard-root .cad-recovery-card__head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
#cow-ai-dashboard-root .cad-recovery-marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: #cbd5e1;
  flex-shrink: 0;
}
#cow-ai-dashboard-root .cad-recovery-marker--overdue    { background: #dc2626; }
#cow-ai-dashboard-root .cad-recovery-marker--improving  { background: #16a34a; }
#cow-ai-dashboard-root .cad-recovery-marker--recovered  { background: #15803d; }
#cow-ai-dashboard-root .cad-recovery-marker--stagnating { background: #94a3b8; }

#cow-ai-dashboard-root .cad-recovery-card__title {
  font-weight: 600;
  font-size: 15px;
  color: var(--cad-text);
  text-decoration: none;
}
#cow-ai-dashboard-root .cad-recovery-card__title:hover { text-decoration: underline; }
#cow-ai-dashboard-root .cad-recovery-card__pen {
  font-size: 12px;
  color: var(--cad-muted);
}
#cow-ai-dashboard-root .cad-recovery-card__trend {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
#cow-ai-dashboard-root .cad-recovery-card--overdue   .cad-recovery-card__trend { background: #fee2e2; color: #b91c1c; }
#cow-ai-dashboard-root .cad-recovery-card--improving .cad-recovery-card__trend { background: #dcfce7; color: #166534; }
#cow-ai-dashboard-root .cad-recovery-card--recovered .cad-recovery-card__trend { background: #dcfce7; color: #15803d; }

#cow-ai-dashboard-root .cad-recovery-card__body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 14px;
  align-items: start;
}
#cow-ai-dashboard-root .cad-recovery-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 14px;
  margin: 0;
  font-size: 12px;
}
#cow-ai-dashboard-root .cad-recovery-stats > div { display: flex; flex-direction: column; }
#cow-ai-dashboard-root .cad-recovery-stats dt {
  color: var(--cad-muted);
  font-size: 11px;
  font-weight: 500;
  margin: 0;
}
#cow-ai-dashboard-root .cad-recovery-stats dd {
  margin: 0;
  font-size: 13px;
  color: var(--cad-text);
}
#cow-ai-dashboard-root .cad-recovery-due {
  color: var(--cad-muted);
  font-size: 11px;
}
#cow-ai-dashboard-root .cad-recovery-note {
  grid-column: 1 / -1;
  margin: 0;
  padding: 8px 10px;
  font-style: italic;
  color: #475569;
  font-size: 12px;
  background: #f8fafc;
  border-left: 2px solid #cbd5e1;
  border-radius: 4px;
}
#cow-ai-dashboard-root .cad-recovery-chart {
  position: relative;
  width: 100%;
  /* Tall enough to fit y-grid + x-axis date labels + the trim-day badge. */
  height: 150px;
}
#cow-ai-dashboard-root .cad-recovery-chart canvas {
  width: 100% !important;
  height: 100% !important;
}

/* Card-body collapses to single column on narrow screens — chart sits
   below the stats so the sparkline still has horizontal room. */
@media (max-width: 600px) {
  #cow-ai-dashboard-root .cad-recovery-card__body { grid-template-columns: 1fr; }
  #cow-ai-dashboard-root .cad-recovery-chart { height: 170px; }
}

/* ---- pen cards (overview) ---- */
#cow-ai-dashboard-root .cad-pens {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
#cow-ai-dashboard-root .cad-pen-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--cad-border);
  border-radius: var(--cad-radius-sm);
  text-decoration: none;
  color: inherit;
  background: var(--cad-surface);
  transition: border-color 120ms, box-shadow 120ms, transform 120ms;
}
#cow-ai-dashboard-root .cad-pen-card:hover {
  border-color: var(--cad-primary);
  box-shadow: 0 2px 8px rgba(79, 93, 255, 0.08);
  transform: translateY(-1px);
}
#cow-ai-dashboard-root .cad-pen-card__name {
  font-weight: 600;
  font-size: 14px;
  color: var(--cad-text);
}
#cow-ai-dashboard-root .cad-pen-card__count {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--cad-text);
}
#cow-ai-dashboard-root .cad-pen-card__count span {
  font-size: 12px;
  font-weight: 500;
  color: var(--cad-text-2);
  margin-left: 4px;
}
#cow-ai-dashboard-root .cad-pen-card__cta {
  font-size: 12px;
  color: var(--cad-primary);
  font-weight: 500;
}

/* ---- pen detail header ---- */
#cow-ai-dashboard-root .cad-pen-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
}
#cow-ai-dashboard-root .cad-pen-header [data-cad="pen-back"] {
  padding: 4px 10px;
  font-size: 12px;
}

/* ---- cow analysis ---- */
#cow-ai-dashboard-root .cad-cow-meta {
  margin: 4px 0 0;
  color: var(--cad-text-2);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
#cow-ai-dashboard-root .cad-empty-state {
  padding: 40px 16px;
  text-align: center;
  color: var(--cad-text-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
#cow-ai-dashboard-root .cad-empty-state h2 {
  margin: 0;
  font-size: 18px;
  color: var(--cad-text);
  font-weight: 600;
}
#cow-ai-dashboard-root .cad-empty-state p { margin: 0; font-size: 14px; max-width: 360px; }
#cow-ai-dashboard-root .cad-empty-illustration {
  width: 120px; height: 120px;
  color: var(--cad-primary);
  opacity: 0.75;
}
#cow-ai-dashboard-root .cad-empty-inline {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 20px 12px;
}
#cow-ai-dashboard-root .cad-empty-inline svg {
  width: 56px; height: 56px;
  color: var(--cad-muted);
  opacity: 0.8;
}
#cow-ai-dashboard-root .cad-link {
  color: var(--cad-primary);
  text-decoration: none;
}
#cow-ai-dashboard-root .cad-link:hover { text-decoration: underline; }

/* ---- cow video gallery ---- */
#cow-ai-dashboard-root .cad-videos {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
#cow-ai-dashboard-root .cad-video {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid var(--cad-border);
  border-radius: var(--cad-radius-sm);
  overflow: hidden;
  background: var(--cad-surface);
}
#cow-ai-dashboard-root .cad-video__media {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #0f172a;
  cursor: pointer;
  overflow: hidden;
}
#cow-ai-dashboard-root .cad-video__media--noimg {
  background: #1e293b;
}
#cow-ai-dashboard-root .cad-video__thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Demo-farm video blur: blur the thumbnail image and the lightbox <video>
   so cow identities aren't recognisable. The play button + score chip sit
   above the blurred layer because they're rendered as siblings of the
   <img>, not descendants. body.cad-demo-active is set by renderDemoBanner
   when /me says the active farm is a demo alias. */
body.cad-demo-active #cow-ai-dashboard-root .cad-video__thumb,
body.cad-demo-active .cad-video-lightbox__video {
  filter: blur(14px);
}
#cow-ai-dashboard-root .cad-video__play {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 48px; height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(15, 23, 42, 0.72);
  color: #ffffff;
  font-size: 18px;
  cursor: pointer;
  display: grid; place-items: center;
  transition: background 120ms, transform 120ms;
}
#cow-ai-dashboard-root .cad-video__media:hover .cad-video__play {
  background: var(--cad-primary);
  transform: scale(1.05);
}
#cow-ai-dashboard-root .cad-video__media video {
  width: 100%; height: 100%;
  display: block;
}
#cow-ai-dashboard-root .cad-video__meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--cad-text-2);
  padding: 0 10px 10px;
  flex-wrap: wrap;
}
#cow-ai-dashboard-root .cad-video__cam { color: var(--cad-muted); }
#cow-ai-dashboard-root .cad-video__err {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: #fca5a5; font-size: 12px;
  background: #1e293b;
  padding: 12px;
  text-align: center;
}

/* ---- fatal error ---- */
#cow-ai-dashboard-root .cad-error {
  color: var(--cad-danger);
  background: var(--cad-danger-2);
  border: 1px solid #fecaca;
  border-radius: var(--cad-radius);
  padding: 10px 14px;
  font-size: 13px;
}

/* ---- top-of-viewport toast ----
   Mounted on <body> (not inside the plugin root) so it floats above
   the dashboard no matter which tab is showing. Used by
   flashPdfSelectWarning when the user clicks Download PDF without
   selecting any cows. Auto-dismiss is handled by the JS. */
.cad-toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translate(-50%, -16px);
  background: #b91c1c;
  color: #ffffff;
  padding: 12px 22px;
  border-radius: 10px;
  font: 500 14px/1.3 system-ui, -apple-system, sans-serif;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.25);
  opacity: 0;
  visibility: hidden;
  transition: opacity 180ms ease, transform 180ms ease, visibility 0s 180ms;
  z-index: 99999;
  max-width: 90vw;
  text-align: center;
}
.cad-toast--show {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
  transition: opacity 180ms ease, transform 180ms ease, visibility 0s;
}

/* ---- responsive tweaks ---- */
@media (max-width: 820px) {
  #cow-ai-dashboard-root .cad-main { padding: 14px; }
  #cow-ai-dashboard-root .cad-topbar__title { font-size: 18px; }
  #cow-ai-dashboard-root .cad-user__text { display: none; }
  #cow-ai-dashboard-root .cad-chart-host { height: 260px; }
}
@media (max-width: 600px) {
  #cow-ai-dashboard-root .cad-chart-host { height: 240px; }
  #cow-ai-dashboard-root .cad-table { font-size: 12px; }
}

/* ======================================================================
   Mobile pass (≤640 px) — stop horizontal overflow and make the shell
   usable on a phone. Desktop/tablet layout above this breakpoint is
   untouched.
   ====================================================================== */
/* Edge-to-edge on tablet + mobile. The outer shortcode chrome (padding,
   rounded corners, soft shadow) makes sense in a desktop article but
   wastes horizontal space on phones/tablets. Full-bleed horizontally
   with width:100vw + negative L/R margins so the dashboard spans the
   viewport regardless of the WP theme's article side-padding. We
   intentionally DON'T pull up vertically — negative margin-top would
   tuck content behind the browser address bar or WP admin bar on
   mobile. Theme chrome above us is already killed by the body-class
   rule at the top of this file. */
@media (max-width: 900px) {
  #cow-ai-dashboard-root {
    padding: 10px 0 14px;
    border-radius: 0;
    box-shadow: none;
    width: 100vw;
    max-width: 100vw;
    position: relative;
    left: 50%;
    margin-left: -50vw;
    margin-right: -50vw;
    margin-top: 0;
    overflow-x: clip;
  }
}

@media (max-width: 640px) {
  /* ≤900px block already did the full-bleed; phone-tier only needs
     internal layout tweaks. */
  #cow-ai-dashboard-root {
    padding: 0;
  }
  #cow-ai-dashboard-root .cad-main { padding: 12px; min-width: 0; }
  #cow-ai-dashboard-root .cad-app { grid-template-columns: 1fr; }

  /* ---- sidebar → horizontal nav strip at the top ---- */
  #cow-ai-dashboard-root .cad-sidebar {
    padding: 8px 10px;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    border-right: 0;
    border-bottom: 1px solid var(--cad-border);
    overflow-x: auto;
    scrollbar-width: thin;
  }
  #cow-ai-dashboard-root .cad-sidebar::-webkit-scrollbar { height: 4px; }
  #cow-ai-dashboard-root .cad-sidebar__collapse { display: none; }
  #cow-ai-dashboard-root .cad-brand { flex-shrink: 0; padding: 0 4px 0 0; }
  #cow-ai-dashboard-root .cad-brand__name { display: none; }
  #cow-ai-dashboard-root .cad-nav {
    flex-direction: row;
    flex: 1 1 auto;
    gap: 4px;
  }
  #cow-ai-dashboard-root .cad-nav__section { display: none; }
  #cow-ai-dashboard-root .cad-nav__item {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    font-size: 12px;
    flex-shrink: 0;
    border-radius: 999px;
  }
  #cow-ai-dashboard-root .cad-nav__item span { white-space: nowrap; }

  /* ---- topbar: title + theme on row 1, search full-width on row 2 ---- */
  #cow-ai-dashboard-root .cad-topbar {
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
  }
  #cow-ai-dashboard-root .cad-topbar__title {
    font-size: 17px;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #cow-ai-dashboard-root .cad-search {
    order: 99;
    flex: 1 1 100%;
    max-width: none;
    margin-left: 0;
  }
  #cow-ai-dashboard-root .cad-theme-switch { gap: 4px; flex-shrink: 0; flex-wrap: wrap; }
  #cow-ai-dashboard-root .cad-theme-swatch { width: 22px; height: 22px; }
  /* User pill eats a lot of space and duplicates sidebar info → hide it. */
  #cow-ai-dashboard-root .cad-user { display: none; }

  /* ---- welcome row ---- */
  #cow-ai-dashboard-root .cad-welcome {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  #cow-ai-dashboard-root .cad-welcome__title { font-size: 16px; }
  #cow-ai-dashboard-root .cad-welcome__actions {
    width: 100%;
    gap: 8px;
  }
  #cow-ai-dashboard-root .cad-farm-switch { flex: 1 1 100%; }
  #cow-ai-dashboard-root .cad-farm-switch select { width: 100%; box-sizing: border-box; }

  /* ---- KPIs: 2 columns ---- */
  #cow-ai-dashboard-root .cad-kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  #cow-ai-dashboard-root .cad-kpi { min-width: 0; padding: 12px; }
  #cow-ai-dashboard-root .cad-kpi__value { font-size: 22px; }
  #cow-ai-dashboard-root .cad-kpi__help { top: 8px; left: 8px; }
  #cow-ai-dashboard-root .cad-kpi-wrap--has-help .cad-kpi__label { padding-left: 22px; }

  /* ---- cards that sat side-by-side → stack ---- */
  #cow-ai-dashboard-root .cad-row { grid-template-columns: 1fr; gap: 10px; }
  #cow-ai-dashboard-root .cad-card { padding: 14px; min-width: 0; overflow-wrap: anywhere; }
  #cow-ai-dashboard-root .cad-card__header { flex-wrap: wrap; gap: 8px; }

  /* ---- range / filter chips / date inputs wrap ---- */
  #cow-ai-dashboard-root .cad-range { flex-wrap: wrap; gap: 6px; }
  #cow-ai-dashboard-root .cad-status-filter { flex-wrap: wrap; gap: 6px; }
  #cow-ai-dashboard-root .cad-chip { font-size: 11px; padding: 5px 10px; }

  /* ---- tables stay intact but scroll inside their card ---- */
  #cow-ai-dashboard-root .cad-table-host {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
  #cow-ai-dashboard-root .cad-table { font-size: 12px; }
  #cow-ai-dashboard-root .cad-table thead th,
  #cow-ai-dashboard-root .cad-table tbody td { padding: 6px 8px; }

  /* ---- pager ---- */
  #cow-ai-dashboard-root .cad-pager { flex-wrap: wrap; gap: 6px; }

  /* ---- footer ---- */
  #cow-ai-dashboard-root .cad-footer {
    flex-direction: column;
    gap: 10px;
    padding: 16px 12px 8px;
    text-align: center;
  }
}

/* ---- language pill card (Settings → Preferences) ---- */
#cow-ai-dashboard-root .cad-hidden { display: none !important; }
#cow-ai-dashboard-root .cad-card--lang .cad-card__title { font-size: 14px; font-weight: 600; margin: 0; }
#cow-ai-dashboard-root .cad-card__hint {
  margin: 6px 0 12px;
  color: var(--cad-text-2);
  font-size: 12px;
  line-height: 1.45;
}
#cow-ai-dashboard-root .cad-lang-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
#cow-ai-dashboard-root .cad-pill-group {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  background: var(--cad-surface-2, var(--cad-surface));
  border: 1px solid var(--cad-border);
  border-radius: 999px;
}
#cow-ai-dashboard-root .cad-pill-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--cad-text);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
#cow-ai-dashboard-root .cad-pill-btn:hover { background: var(--cad-surface); }
#cow-ai-dashboard-root .cad-pill-btn.cad-active {
  background: var(--cad-accent);
  color: #fff;
  border-color: var(--cad-accent);
}
#cow-ai-dashboard-root .cad-apply-now-btn { white-space: nowrap; }
#cow-ai-dashboard-root .cad-pill-msg {
  font-size: 12px;
  color: var(--cad-text-2);
  margin-left: auto;
}
#cow-ai-dashboard-root .cad-pill-msg--saving { color: var(--cad-text-2); }
#cow-ai-dashboard-root .cad-pill-msg--ok     { color: var(--cad-accent); }
#cow-ai-dashboard-root .cad-pill-msg--err    { color: var(--cad-danger); }

/* Full-page blocker shown while the language save is in flight. Mounts on
   <body> (outside #cow-ai-dashboard-root) so it sits above everything,
   including any WP theme chrome, and survives the brief gap between the
   save response and the page reload. */
.cad-lang-blocker {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: cad-lang-blocker-in 120ms ease-out both;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
@keyframes cad-lang-blocker-in { from { opacity: 0; } to { opacity: 1; } }
.cad-lang-blocker__box {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 24px 32px;
  background: #ffffff;
  color: #0f172a;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  min-width: 220px;
  max-width: 90vw;
  text-align: center;
}
.cad-lang-blocker__spinner {
  width: 34px; height: 34px;
  border: 3px solid rgba(15,23,42,0.15);
  border-top-color: #4f5dff;
  border-radius: 50%;
  animation: cad-lang-blocker-spin 0.9s linear infinite;
}
@keyframes cad-lang-blocker-spin { to { transform: rotate(360deg); } }
.cad-lang-blocker__label {
  font-size: 14px;
  font-weight: 500;
  color: #0f172a;
}

/* ---------- Lameness-checks selection UI + print/PDF report ---------- */

/* Checkbox column width keeps the first column tight. */
#cow-ai-dashboard-root .cad-check-col {
  width: 28px;
  text-align: center;
}
#cow-ai-dashboard-root .cad-check-sel,
#cow-ai-dashboard-root .cad-check-col input[type="checkbox"] {
  cursor: pointer;
  width: 16px;
  height: 16px;
  accent-color: var(--cad-primary);
}
#cow-ai-dashboard-root .cad-row--selected {
  background: color-mix(in srgb, var(--cad-primary) 6%, transparent);
}

/* Floating action bar pinned to the bottom of the viewport. Rendered
   inside the SPA root so the plugin's CSS isolation applies. Hidden via
   [hidden] while selection is empty. */
#cow-ai-dashboard-root .cad-selection-bar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px 8px 16px;
  background: var(--cad-surface);
  border: 1px solid var(--cad-border);
  border-radius: 999px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
  font-size: 13px;
  max-width: calc(100vw - 32px);
}
#cow-ai-dashboard-root .cad-selection-bar[hidden] { display: none; }
#cow-ai-dashboard-root .cad-selection-bar__count {
  font-weight: 600;
  color: var(--cad-text);
  padding-right: 4px;
}
@media (max-width: 600px) {
  #cow-ai-dashboard-root .cad-selection-bar {
    flex-wrap: wrap;
    bottom: 12px;
    padding: 6px 10px;
    gap: 8px;
    font-size: 12px;
  }
}

/* The hidden print surface, shown only in the @media print block. */
.cad-print-view { display: none; }

/* Print stylesheet. Hides the entire SPA chrome and shows only the
   dedicated .cad-print-view. Landscape A4, fixed-layout table, wrappable
   long strings so 8-column reports don't spill off the page and thead
   re-prints on every page of a long selection. */
@media print {
  /* Hide every body child except our print surface (which the JS
     temporarily lifts up to <body> before window.print() for exactly
     this reason — position:absolute kills pagination, display:none
     on ancestors kills the descendant). */
  body > *:not(.cad-print-view) { display: none !important; }
  body > .cad-print-view { display: block !important; }
  .cad-print-view {
    position: static;
    width: auto;
    padding: 0;
    margin: 0;
    background: #fff;
    color: #000;
    font-family: system-ui, -apple-system, Segoe UI, sans-serif;
  }
  /* Landscape gives ~257mm usable width after 14mm margins, enough room
     for the 8-column All-cows roster. Shorter tables (Lameness checks /
     Hoof trimmer / Herd analysis) still look fine in landscape — they
     just leave some right-margin breathing room. */
  @page {
    size: A4 landscape;
    margin: 14mm;
  }
  .cad-print-header {
    margin-bottom: 6mm;
    border-bottom: 1pt solid #000;
    padding-bottom: 3mm;
  }
  .cad-print-header h1 { font-size: 15pt; margin: 0 0 2mm 0; font-weight: 700; }
  .cad-print-header .meta { font-size: 9pt; color: #333; }

  /* table-layout: fixed is the key fix — browsers will honour our
     col-widths rather than expanding to fit the longest cell content.
     word-break on cells lets long cow IDs / notes wrap instead of
     overflowing off the page. */
  .cad-print-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 9pt;
    table-layout: fixed;
    word-break: break-word;
    overflow-wrap: break-word;
  }
  /* tbody may break across pages; individual rows still try to stay
     whole. Header re-prints on every page courtesy of
     display: table-header-group. */
  .cad-print-table thead { display: table-header-group; }
  .cad-print-table tbody { page-break-inside: auto; break-inside: auto; }
  .cad-print-table tr {
    page-break-inside: avoid;
    break-inside: avoid;
  }
  .cad-print-table th,
  .cad-print-table td {
    border-bottom: 0.5pt solid #666;
    padding: 1.8mm 2mm;
    text-align: left;
    vertical-align: top;
    /* Redundant but belt-and-suspenders for Firefox / Chromium. */
    overflow: hidden;
    word-break: break-word;
  }
  .cad-print-table th {
    background: #f2f2f2;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 8pt;
    letter-spacing: 0.02em;
  }
  .cad-print-id {
    display: inline-block;
    color: #666;
    font-size: 7.5pt;
    font-family: ui-monospace, Menlo, monospace;
    word-break: break-all;
  }
  .cad-print-footer {
    margin-top: 6mm;
    padding-top: 2mm;
    border-top: 0.5pt solid #999;
    font-size: 7.5pt;
    color: #666;
    text-align: right;
  }

  /* Column width hints per report — <colgroup> isn't generated by the
     JS renderers, but :nth-child rules do the same job. Columns
     numbered from 1; percentages sum to 100%.
     All-cows report has 8 cols (Cow / Pen / Score / Δ / Hoof / Meas /
     Status / Note). Hoof trimmer has 5 cols. Cow-list herd report has 4.
     We can't reliably distinguish reports via class because all share
     .cad-print-table, so use a width ladder that works for every layout
     by column index — tighten numeric / short cells, give room to Cow,
     Note at the end can shrink gracefully. */
  .cad-print-table th:nth-child(1),
  .cad-print-table td:nth-child(1) { width: 18%; }   /* Cow (name + id) */
  .cad-print-table th:nth-child(2),
  .cad-print-table td:nth-child(2) { width: 12%; }   /* Pen */
  .cad-print-table th:nth-child(3),
  .cad-print-table td:nth-child(3) { width: 8%; }
  .cad-print-table th:nth-child(4),
  .cad-print-table td:nth-child(4) { width: 8%; }
  .cad-print-table th:nth-child(5),
  .cad-print-table td:nth-child(5) { width: 14%; }
  .cad-print-table th:nth-child(6),
  .cad-print-table td:nth-child(6) { width: 14%; }
  .cad-print-table th:nth-child(7),
  .cad-print-table td:nth-child(7) { width: 12%; }
  .cad-print-table th:nth-child(8),
  .cad-print-table td:nth-child(8) { width: 14%; }
  /* Numeric-aligning for score / delta cells is handled by the
     ".cad-num" class on the on-screen table but isn't carried into the
     PDF — that's fine, print output keeps everything left-aligned. */
}

/* ---------- Anonymous login card ----------
   Rendered when the user hits the cow-dashboard page while logged out.
   Posts to wp-login.php so the auth flow is WordPress's native one; we
   only style the shell. Uses the same theme variables the dashboard
   defines on :root so the card looks like part of the app even before
   any JS has run. */
.cad-login-shell {
  --cad-primary:    #4f5dff;
  --cad-primary-2:  #eef0ff;
  --cad-surface:    #ffffff;
  --cad-text:       #0f172a;
  --cad-text-2:     #64748b;
  --cad-border:     #e2e8f0;
  --cad-danger:     #dc2626;
  --cad-radius:     14px;
  min-height: 70vh;
  display: grid;
  place-items: center;
  padding: 48px 16px;
  font-family: system-ui, -apple-system, Segoe UI, sans-serif;
  background: linear-gradient(180deg, #f8fafc 0%, #eef1f9 100%);
}
.cad-login-card {
  width: 100%;
  max-width: 420px;
  background: var(--cad-surface);
  border: 1px solid var(--cad-border);
  border-radius: var(--cad-radius);
  padding: 32px 28px 26px;
  box-shadow: 0 14px 40px rgba(15, 23, 42, 0.10);
  color: var(--cad-text);
}
.cad-login-brand {
  text-align: center;
  margin-bottom: 22px;
}
.cad-login-brand__mark {
  display: inline-grid;
  place-items: center;
  width: 56px; height: 56px;
  border-radius: 16px;
  background: var(--cad-primary-2);
  font-size: 30px;
  margin-bottom: 10px;
}
.cad-login-brand__title {
  margin: 0 0 4px;
  font-size: 24px;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: var(--cad-primary);
}
.cad-login-brand__tag {
  margin: 0;
  font-size: 13px;
  color: var(--cad-text-2);
}
.cad-login-heading {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--cad-text);
  text-align: center;
}
.cad-login-error {
  background: #fef2f2;
  color: var(--cad-danger);
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  margin-bottom: 14px;
}
/* Style wp_login_form()'s native markup. WP outputs one <p> per field;
   we restyle without changing the HTML shape so the WordPress filter
   hooks (login_form_top / _middle / _bottom) any plugin might have
   registered still work. */
.cad-login-formwrap #cad-loginform {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 0;
}
.cad-login-formwrap #cad-loginform p {
  margin: 0 0 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cad-login-formwrap #cad-loginform label {
  font-size: 12px;
  font-weight: 500;
  color: var(--cad-text-2);
}
.cad-login-formwrap #cad-loginform input[type="text"],
.cad-login-formwrap #cad-loginform input[type="password"],
.cad-login-formwrap #cad-loginform input[type="email"] {
  border: 1px solid var(--cad-border);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 14px;
  color: var(--cad-text);
  background: #fff;
  transition: border-color 120ms ease, box-shadow 120ms ease;
  font-family: inherit;
  width: 100%;
  box-sizing: border-box;
}
.cad-login-formwrap #cad-loginform input[type="text"]:focus,
.cad-login-formwrap #cad-loginform input[type="password"]:focus,
.cad-login-formwrap #cad-loginform input[type="email"]:focus {
  border-color: var(--cad-primary);
  box-shadow: 0 0 0 3px rgba(79, 93, 255, 0.15);
  outline: none;
}
/* "Remember me" sits inline as a single label with a checkbox. */
.cad-login-formwrap #cad-loginform p.login-remember {
  flex-direction: row;
  align-items: center;
  font-size: 13px;
  color: var(--cad-text-2);
}
.cad-login-formwrap #cad-loginform p.login-remember label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--cad-text-2);
  font-weight: 400;
  cursor: pointer;
}
.cad-login-formwrap #cad-loginform p.login-submit {
  margin-top: 6px;
  margin-bottom: 0;
}
.cad-login-formwrap #cad-loginform input[type="submit"] {
  width: 100%;
  background: var(--cad-primary);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 120ms ease, transform 80ms ease;
  font-family: inherit;
}
.cad-login-formwrap #cad-loginform input[type="submit"]:hover  { background: #3d4ae3; }
.cad-login-formwrap #cad-loginform input[type="submit"]:active { transform: translateY(1px); }
.cad-login-link {
  display: block;
  text-align: center;
  font-size: 13px;
  color: var(--cad-primary);
  text-decoration: none;
  margin-top: 12px;
}
.cad-login-link:hover { text-decoration: underline; }
.cad-login-note {
  margin: 18px 0 0;
  font-size: 12px;
  color: var(--cad-text-2);
  text-align: center;
  line-height: 1.4;
}

/* ---------- Hoof analysis (Part A — per-cow card) ---------- */

#cow-ai-dashboard-root .cad-hoof-card .cad-hoof-body {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 18px;
  align-items: center;
}
#cow-ai-dashboard-root .cad-hoof-silhouette {
  display: grid;
  place-items: center;
}
#cow-ai-dashboard-root .cad-hoof-silhouette svg { max-width: 100%; height: auto; }
#cow-ai-dashboard-root .cad-hoof-sparks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}
#cow-ai-dashboard-root .cad-hoof-spark {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
#cow-ai-dashboard-root .cad-hoof-spark__label {
  font-size: 11px;
  color: var(--cad-text-2);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
}
#cow-ai-dashboard-root .cad-hoof-spark__value {
  font-weight: 700;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
#cow-ai-dashboard-root .cad-hoof-spark__svg {
  display: block;
  width: 100%;
  background: color-mix(in srgb, var(--cad-border) 25%, transparent);
  border-radius: 6px;
  padding: 2px;
}
#cow-ai-dashboard-root .cad-hoof-spark--empty .cad-hoof-spark__svg {
  display: grid;
  place-items: center;
  color: var(--cad-text-2);
  font-size: 11px;
}
#cow-ai-dashboard-root .cad-hoof-legend {
  grid-column: 1 / -1;
  display: flex;
  gap: 14px;
  font-size: 11px;
  color: var(--cad-text-2);
  padding-top: 8px;
  border-top: 1px dashed var(--cad-border);
}
#cow-ai-dashboard-root .cad-hoof-legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
#cow-ai-dashboard-root .cad-hoof-legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
@media (max-width: 640px) {
  #cow-ai-dashboard-root .cad-hoof-card .cad-hoof-body {
    grid-template-columns: 1fr;
  }
  #cow-ai-dashboard-root .cad-hoof-sparks {
    grid-template-columns: 1fr 1fr;
  }
}

/* Video thumbnail corner badges — port of the legacy .acaris-laming-badge
   markup, namespaced here. Only rendered when the cow_detail payload
   reports a hoof value ≥ 10 for that position. */
#cow-ai-dashboard-root .cad-video__media { position: relative; }
#cow-ai-dashboard-root .cad-hoof-badge {
  position: absolute;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  border-radius: 999px;
  text-shadow: 0 1px 0 rgba(0,0,0,0.3);
  box-shadow: 0 1px 2px rgba(0,0,0,0.35);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
#cow-ai-dashboard-root .cad-hoof-badge--pos-tl { top: 4px; left: 4px; }
#cow-ai-dashboard-root .cad-hoof-badge--pos-tr { top: 4px; right: 4px; }
#cow-ai-dashboard-root .cad-hoof-badge--pos-bl { bottom: 4px; left: 4px; }
#cow-ai-dashboard-root .cad-hoof-badge--pos-br { bottom: 4px; right: 4px; }

/* Sparkline hover dots + invisible hit rects. Dots are visible small
   markers; the rects catch pointer events over the full sparkline
   column so the tooltip activates even when the cursor isn't exactly
   on the line. */
#cow-ai-dashboard-root .cad-hoof-spark__hit { cursor: pointer; }
#cow-ai-dashboard-root .cad-hoof-spark__hit:hover { fill: rgba(15, 23, 42, 0.04); }

/* Tooltip — lives at document body level so it floats above the SPA
   and isn't clipped by cards or overflows. */
.cad-hoof-tip {
  position: fixed;
  z-index: 10000;
  pointer-events: none;
  background: #0f172a;
  color: #f8fafc;
  padding: 6px 9px;
  border-radius: 6px;
  font-size: 11.5px;
  line-height: 1.35;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.3);
  font-variant-numeric: tabular-nums;
  max-width: 240px;
}
.cad-hoof-tip[hidden] { display: none; }
.cad-hoof-tip strong { font-weight: 700; }
.cad-hoof-tip div    { opacity: 0.82; margin-top: 2px; font-size: 11px; }

/* ---------- All-cows table (new roster tab) ---------- */

#cow-ai-dashboard-root .cad-cows-table { font-size: 12.5px; }

/* Mini 2×2 hoof matrix in the All-cows table. Matches the Hoof-analysis
   tab swatches visually; colours come from the hoofColor() utility so
   any future threshold tweak propagates. */
#cow-ai-dashboard-root .cad-mini-hoof {
  display: inline-grid;
  grid-template-columns: 9px 9px;
  grid-template-rows: 9px 9px;
  gap: 1px;
  vertical-align: middle;
}
#cow-ai-dashboard-root .cad-mini-hoof i {
  display: block;
  border-radius: 1.5px;
  /* Theme-aware outline so the 4-cell grid stays visible on dark mode
     (where the previous near-black border faded into the surface). */
  border: 0.5px solid var(--cad-border-2);
}
/* Empty-hoof cell: theme-aware fill so the position is still recognisable
   when only the lame hoof is painted red. Light mode = very light grey,
   dark mode = mid grey via the same surface variable progression. */
#cow-ai-dashboard-root .cad-mini-hoof i.cad-mini-hoof__empty {
  background: var(--cad-border-2);
  opacity: 0.55;
}
#cow-ai-dashboard-root .cad-cows-table th,
#cow-ai-dashboard-root .cad-cows-table td {
  padding: 6px 8px;
  white-space: nowrap;
}
#cow-ai-dashboard-root .cad-cows-table td.cad-truncate {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Status chips in the All-cows table reuse the Lameness-check palette,
   with a small size tune to fit the denser table. */
#cow-ai-dashboard-root .cad-cows-table .cad-status-chip {
  font-size: 11px;
  padding: 1px 8px;
}
@media (max-width: 1100px) {
  /* Shrink at midsize: hide status-updated-at + note columns. Status
     tooltip + the dedicated cow-analysis page still carry the detail. */
  #cow-ai-dashboard-root .cad-cows-table th:nth-child(11),
  #cow-ai-dashboard-root .cad-cows-table td:nth-child(11),
  #cow-ai-dashboard-root .cad-cows-table th:nth-child(12),
  #cow-ai-dashboard-root .cad-cows-table td:nth-child(12) { display: none; }
}
@media (max-width: 760px) {
  /* Also drop last-measurement and days-since columns on mobile.
     Keep the Hoof swatch (col 6) — it's small and high-signal. */
  #cow-ai-dashboard-root .cad-cows-table th:nth-child(7),
  #cow-ai-dashboard-root .cad-cows-table td:nth-child(7),
  #cow-ai-dashboard-root .cad-cows-table th:nth-child(9),
  #cow-ai-dashboard-root .cad-cows-table td:nth-child(9) { display: none; }
}

/* ---------- Hoof analysis tab (Part B) ---------- */

#cow-ai-dashboard-root .cad-hoof-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 22px;
  align-items: center;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--cad-border);
}
#cow-ai-dashboard-root .cad-hoof-filter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
#cow-ai-dashboard-root .cad-hoof-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
#cow-ai-dashboard-root .cad-hoof-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px 10px;
  background: var(--cad-surface);
  border: 1px solid var(--cad-border);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 80ms ease;
}
#cow-ai-dashboard-root .cad-hoof-tile:hover {
  border-color: var(--cad-primary);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
  transform: translateY(-1px);
}
#cow-ai-dashboard-root .cad-hoof-tile--selected {
  border-color: var(--cad-primary);
  background: color-mix(in srgb, var(--cad-primary) 6%, var(--cad-surface));
}
#cow-ai-dashboard-root .cad-hoof-tile--expanded {
  grid-column: 1 / -1;
  cursor: default;
}
#cow-ai-dashboard-root .cad-hoof-tile__sel {
  position: absolute;
  top: 6px; right: 6px;
  width: 15px; height: 15px;
  cursor: pointer;
  accent-color: var(--cad-primary);
}
#cow-ai-dashboard-root .cad-hoof-tile__head { line-height: 1.2; padding-right: 22px; }
#cow-ai-dashboard-root .cad-hoof-tile__name {
  font-weight: 700;
  font-size: 13px;
  color: var(--cad-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#cow-ai-dashboard-root .cad-hoof-tile__meta {
  font-size: 10.5px;
  color: var(--cad-text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#cow-ai-dashboard-root .cad-hoof-matrix {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 4px;
  aspect-ratio: 1 / 0.9;
  min-height: 82px;
}
#cow-ai-dashboard-root .cad-hoof-swatch {
  display: grid;
  place-items: center;
  color: #ffffff;
  font-weight: 700;
  font-size: 13px;
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}
#cow-ai-dashboard-root .cad-hoof-tile__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 18px;
}
#cow-ai-dashboard-root .cad-hoof-tile__trend {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--cad-text-2);
  font-variant-numeric: tabular-nums;
}
#cow-ai-dashboard-root .cad-hoof-tile__trend--up   { color: var(--cad-danger); }
#cow-ai-dashboard-root .cad-hoof-tile__trend--down { color: var(--cad-success); }
#cow-ai-dashboard-root .cad-hoof-tile__pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--cad-danger) 12%, transparent);
  color: var(--cad-danger);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
#cow-ai-dashboard-root .cad-hoof-tile__expand {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--cad-border);
}
#cow-ai-dashboard-root .cad-hoof-tile__expand .cad-hoof-card--inline .cad-hoof-body {
  grid-template-columns: 180px 1fr;
}
@media (max-width: 640px) {
  #cow-ai-dashboard-root .cad-hoof-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  #cow-ai-dashboard-root .cad-hoof-tile__expand .cad-hoof-card--inline .cad-hoof-body {
    grid-template-columns: 1fr;
  }
}

/* Farm Status — last-call tiles for the three HERDE API endpoints. */
#cow-ai-dashboard-root .cad-api-tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 8px;
}
#cow-ai-dashboard-root .cad-api-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 20px 16px;
  border-radius: 14px;
  background: var(--cad-surface);
  border: 1px solid var(--cad-border);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
  overflow: hidden;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
#cow-ai-dashboard-root .cad-api-tile::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--cad-text-2);
  opacity: 0.3;
}
#cow-ai-dashboard-root .cad-api-tile:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.06);
}
#cow-ai-dashboard-root .cad-api-tile__row {
  display: flex;
  align-items: center;
  gap: 10px;
}
#cow-ai-dashboard-root .cad-api-tile__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--cad-text-2);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--cad-text-2) 18%, transparent);
  flex: 0 0 auto;
}
#cow-ai-dashboard-root .cad-api-tile__label {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--cad-text-2);
  text-transform: uppercase;
}
#cow-ai-dashboard-root .cad-api-tile__when {
  font-size: 20px;
  font-weight: 600;
  color: var(--cad-text);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
#cow-ai-dashboard-root .cad-api-tile__ago {
  align-self: flex-start;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: color-mix(in srgb, var(--cad-text-2) 12%, transparent);
  color: var(--cad-text-2);
}

#cow-ai-dashboard-root .cad-api-tile--ok::before     { background: var(--cad-success); opacity: 1; }
#cow-ai-dashboard-root .cad-api-tile--ok .cad-api-tile__dot {
  background: var(--cad-success);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--cad-success) 20%, transparent);
}
#cow-ai-dashboard-root .cad-api-tile--ok .cad-api-tile__ago {
  background: var(--cad-success-2);
  color: var(--cad-success);
}

#cow-ai-dashboard-root .cad-api-tile--warn::before   { background: var(--cad-warn); opacity: 1; }
#cow-ai-dashboard-root .cad-api-tile--warn .cad-api-tile__dot {
  background: var(--cad-warn);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--cad-warn) 22%, transparent);
}
#cow-ai-dashboard-root .cad-api-tile--warn .cad-api-tile__ago {
  background: var(--cad-warn-2);
  color: var(--cad-warn);
}

#cow-ai-dashboard-root .cad-api-tile--danger::before { background: var(--cad-danger); opacity: 1; }
#cow-ai-dashboard-root .cad-api-tile--danger {
  border-color: color-mix(in srgb, var(--cad-danger) 35%, var(--cad-border));
}
#cow-ai-dashboard-root .cad-api-tile--danger .cad-api-tile__dot {
  background: var(--cad-danger);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--cad-danger) 22%, transparent);
}
#cow-ai-dashboard-root .cad-api-tile--danger .cad-api-tile__ago {
  background: var(--cad-danger-2);
  color: var(--cad-danger);
}

#cow-ai-dashboard-root .cad-api-tile--empty {
  background: color-mix(in srgb, var(--cad-text-2) 4%, var(--cad-surface));
}
#cow-ai-dashboard-root .cad-api-tile--empty .cad-api-tile__when {
  color: var(--cad-text-2);
  font-style: italic;
  font-size: 16px;
}

@media (max-width: 900px) {
  #cow-ai-dashboard-root .cad-api-tiles { grid-template-columns: 1fr; }
}

#cow-ai-dashboard-root .cad-empty-row {
  text-align: center;
  padding: 24px 12px;
  color: var(--cad-text-2);
  font-style: italic;
}

/* Farm Status — sub-tab strip + Connection Info card layout. */
#cow-ai-dashboard-root .cad-subtabs {
  display: flex;
  gap: 6px;
  padding: 6px;
  margin-bottom: 16px;
  background: color-mix(in srgb, var(--cad-text-2) 8%, transparent);
  border-radius: 12px;
  width: fit-content;
}
#cow-ai-dashboard-root .cad-subtab {
  appearance: none;
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--cad-text-2);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}
#cow-ai-dashboard-root .cad-subtab:hover {
  color: var(--cad-text);
}
#cow-ai-dashboard-root .cad-subtab--active {
  background: var(--cad-surface);
  color: var(--cad-text);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

/* Connection-info credential rows. */
#cow-ai-dashboard-root .cad-credentials {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#cow-ai-dashboard-root .cad-credential-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid var(--cad-border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--cad-text-2) 4%, var(--cad-surface));
}
#cow-ai-dashboard-root .cad-credential-row__label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--cad-text-2);
  margin-bottom: 4px;
}
#cow-ai-dashboard-root .cad-credential-row__value {
  font-size: 13px;
  color: var(--cad-text);
  word-break: break-all;
  font-variant-numeric: tabular-nums;
}
#cow-ai-dashboard-root .cad-credential-row__pwd-wrap {
  display: flex;
  align-items: stretch;
  gap: 6px;
}
#cow-ai-dashboard-root .cad-credential-row__input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 6px 10px;
  border: 1px solid var(--cad-border);
  border-radius: 8px;
  background: var(--cad-surface);
  color: var(--cad-text);
  font: inherit;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
#cow-ai-dashboard-root .cad-credential-row__eye {
  appearance: none;
  background: var(--cad-surface);
  border: 1px solid var(--cad-border);
  border-radius: 8px;
  padding: 0 10px;
  cursor: pointer;
  color: var(--cad-text-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#cow-ai-dashboard-root .cad-credential-row__eye:hover {
  color: var(--cad-text);
  background: color-mix(in srgb, var(--cad-text-2) 6%, var(--cad-surface));
}
#cow-ai-dashboard-root .cad-credential-row__eye svg {
  width: 16px;
  height: 16px;
}

@media (max-width: 640px) {
  #cow-ai-dashboard-root .cad-credential-row { grid-template-columns: 1fr; }
}

/* Farm Status — camera tiles. Same visual language as .cad-api-tile so
   the two cards read as one design, with a richer body for the per-cam
   metadata. Traffic-light coloring drives both the left accent stripe
   and the status pill in the top-right. */
#cow-ai-dashboard-root .cad-cam-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 8px;
}
#cow-ai-dashboard-root .cad-cam-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 18px 14px;
  border-radius: 14px;
  background: var(--cad-surface);
  border: 1px solid var(--cad-border);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
  overflow: hidden;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
#cow-ai-dashboard-root .cad-cam-tile::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--cad-text-2);
  opacity: 0.3;
}
#cow-ai-dashboard-root .cad-cam-tile:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.06);
}
#cow-ai-dashboard-root .cad-cam-tile__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
#cow-ai-dashboard-root .cad-cam-tile__id {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--cad-text);
  font-variant-numeric: tabular-nums;
}
#cow-ai-dashboard-root .cad-cam-tile__badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: color-mix(in srgb, var(--cad-text-2) 14%, transparent);
  color: var(--cad-text-2);
  white-space: nowrap;
}
#cow-ai-dashboard-root .cad-cam-tile__badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}
#cow-ai-dashboard-root .cad-cam-tile__ping {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}
#cow-ai-dashboard-root .cad-cam-tile__ping::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}
#cow-ai-dashboard-root .cad-cam-tile__ping--ok {
  background: var(--cad-success-2);
  color: var(--cad-success);
}
#cow-ai-dashboard-root .cad-cam-tile__ping--danger {
  background: var(--cad-danger-2);
  color: var(--cad-danger);
}
#cow-ai-dashboard-root .cad-cam-tile__ping--probing {
  background: color-mix(in srgb, var(--cad-text-2) 12%, transparent);
  color: var(--cad-text-2);
}
#cow-ai-dashboard-root .cad-cam-tile__ping--probing::before {
  animation: cad-spinner-rotate 0.9s linear infinite;
  background: transparent;
  border: 2px solid currentColor;
  border-right-color: transparent;
  width: 8px;
  height: 8px;
}
#cow-ai-dashboard-root .cad-cam-tile__purpose {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--cad-text-2);
  text-transform: uppercase;
}
#cow-ai-dashboard-root .cad-cam-tile__meta {
  display: grid;
  gap: 10px;
  margin: 0;
}
#cow-ai-dashboard-root .cad-cam-tile__meta > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#cow-ai-dashboard-root .cad-cam-tile__meta dt {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--cad-text-2);
}
#cow-ai-dashboard-root .cad-cam-tile__meta dd {
  margin: 0;
  font-size: 13px;
  color: var(--cad-text);
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
#cow-ai-dashboard-root .cad-cam-tile__ago {
  font-size: 11px;
  color: var(--cad-text-2);
  font-weight: 500;
}
#cow-ai-dashboard-root .cad-cam-tile__actions {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}
#cow-ai-dashboard-root .cad-cam-tile__live,
#cow-ai-dashboard-root .cad-cam-tile__reboot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
#cow-ai-dashboard-root .cad-cam-tile__live-icon {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
}

/* Restart-cam button feedback states. */
#cow-ai-dashboard-root .cad-cam-tile__reboot[disabled] {
  cursor: progress;
  opacity: 0.95;
}
#cow-ai-dashboard-root .cad-cam-tile__reboot--success {
  background: var(--cad-success-2);
  color: var(--cad-success);
  border-color: color-mix(in srgb, var(--cad-success) 35%, var(--cad-border));
}
#cow-ai-dashboard-root .cad-cam-tile__reboot--error {
  background: var(--cad-danger-2);
  color: var(--cad-danger);
  border-color: color-mix(in srgb, var(--cad-danger) 35%, var(--cad-border));
}

/* Generic inline spinner used inside buttons and other small UI. */
#cow-ai-dashboard-root .cad-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: cad-spinner-rotate 0.7s linear infinite;
  flex: 0 0 auto;
}
#cow-ai-dashboard-root .cad-spinner--sm { width: 12px; height: 12px; border-width: 2px; }
@keyframes cad-spinner-rotate {
  to { transform: rotate(360deg); }
}

#cow-ai-dashboard-root .cad-cam-tile--ok::before     { background: var(--cad-success); opacity: 1; }
#cow-ai-dashboard-root .cad-cam-tile--ok .cad-cam-tile__badge {
  background: var(--cad-success-2);
  color: var(--cad-success);
}

#cow-ai-dashboard-root .cad-cam-tile--warn::before   { background: var(--cad-warn); opacity: 1; }
#cow-ai-dashboard-root .cad-cam-tile--warn .cad-cam-tile__badge {
  background: var(--cad-warn-2);
  color: var(--cad-warn);
}

#cow-ai-dashboard-root .cad-cam-tile--danger::before { background: var(--cad-danger); opacity: 1; }
#cow-ai-dashboard-root .cad-cam-tile--danger {
  border-color: color-mix(in srgb, var(--cad-danger) 35%, var(--cad-border));
}
#cow-ai-dashboard-root .cad-cam-tile--danger .cad-cam-tile__badge {
  background: var(--cad-danger-2);
  color: var(--cad-danger);
}
#cow-ai-dashboard-root .cad-cam-tile--danger .cad-cam-tile__live {
  opacity: 0.85;
}

/* Floating MJPEG preview anchored bottom-right. Lives outside the
   dashboard root so it floats over any tab; styled standalone so it
   inherits no theme tokens and works on any page background. */
.cad-stream-pip {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 360px;
  max-width: calc(100vw - 32px);
  background: #0f172a;
  color: #f8fafc;
  border-radius: 12px;
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.32),
              0 2px 8px rgba(15, 23, 42, 0.18);
  z-index: 99998;
  overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.cad-stream-pip__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px 8px 14px;
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.cad-stream-pip__title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cad-stream-pip__btns {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.cad-stream-pip__icon-btn {
  background: transparent;
  color: #f8fafc;
  border: 0;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.cad-stream-pip__icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}
.cad-stream-pip__icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.cad-stream-pip__icon-btn svg {
  width: 15px;
  height: 15px;
}
.cad-stream-pip__close {
  font-size: 20px;
}
.cad-stream-pip__body {
  position: relative;
  background: #000;
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cad-stream-pip__img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.cad-stream-pip__loader {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: #000;
  color: rgba(248, 250, 252, 0.85);
}
.cad-stream-pip__loader[hidden] { display: none; }
.cad-stream-pip__spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: #f8fafc;
  animation: cad-stream-pip-spin 0.9s linear infinite;
}
.cad-stream-pip__loader-text {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.cad-stream-pip__loader--error .cad-stream-pip__spinner {
  display: none;
}
.cad-stream-pip__loader--error .cad-stream-pip__loader-text {
  color: #fca5a5;
}
@keyframes cad-stream-pip-spin {
  to { transform: rotate(360deg); }
}
@media (max-width: 480px) {
  .cad-stream-pip { width: calc(100vw - 24px); right: 12px; bottom: 12px; }
}
