:root {
  /* ── Backgrounds (Clean, Luminous & Modern Enterprise AgTech) ─ */
  --bg0: #f8fafc;                  /* Slate-50: Crisp, luminous base */
  --bg1: #ffffff;                  /* Pure White Card Surface */
  --bg-elevated: #f1f5f9;          /* Slate-100: Hover / Track */
  --bg-glass: rgba(255, 255, 255, 0.92);
  --line: #e2e8f0;                 /* Slate-200: Crisp micro border */
  --line-strong: #cbd5e1;          /* Slate-300 */

  /* ── Primary Emerald (Nature, Health & Smart Agriculture) ── */
  --leaf: #059669;
  --leaf-bright: #10b981;
  --leaf-dim: rgba(16, 185, 129, 0.1);
  --leaf-border: rgba(16, 185, 129, 0.28);

  /* ── Radiant Amber & Gold (Livestock / Equine / Heritage) ── */
  --sand: #d97706;
  --sand-dim: rgba(217, 119, 6, 0.1);
  --sand-bright: #f59e0b;
  --sand-border: rgba(217, 119, 6, 0.28);

  /* ── Auxiliary Colors (Water Cyan & Alerts) ──────────────── */
  --cyan: #0284c7;
  --cyan-dim: rgba(2, 132, 199, 0.1);
  --danger: #dc2626;
  --danger-dim: rgba(220, 38, 38, 0.08);
  --warn: #d97706;

  /* ── Typography & Contrast Hierarchy (Deep Slate) ────────── */
  --text: #0f172a;                 /* Slate-900: High-contrast, sharp */
  --muted: #475569;                /* Slate-600: Clean readability */
  --dim: #64748b;                  /* Slate-500: Subtitles and units */

  /* ── Structural Radii & Shadows ──────────────────────────── */
  --radius: 14px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --shadow-card: 0 1px 3px rgba(15, 23, 42, 0.04), 0 8px 24px -4px rgba(15, 23, 42, 0.06);
  --shadow-card-hover: 0 4px 6px -1px rgba(15, 23, 42, 0.05), 0 14px 28px -4px rgba(15, 23, 42, 0.1);
  --shadow-glow-emerald: 0 4px 20px rgba(16, 185, 129, 0.16);
  --shadow-glow-amber: 0 4px 20px rgba(245, 158, 11, 0.16);

  /* ── Fonts ──────────────────────────────────────────────── */
  --font-display: "Cairo", system-ui, -apple-system, sans-serif;
  --font-body: "IBM Plex Sans Arabic", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

/* display rules on main, badges, etc. must never beat the hidden attribute */
[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: var(--font-body);
  background: var(--bg0);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Modern Luminous Atmosphere ────────────────────────────── */
.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle 900px at 50% -140px, rgba(16, 185, 129, 0.06), transparent 70%),
    radial-gradient(circle 600px at 95% 100%, rgba(217, 119, 6, 0.04), transparent 65%),
    radial-gradient(circle 500px at 5% 90%, rgba(2, 132, 199, 0.04), transparent 60%),
    #f8fafc;
  pointer-events: none;
}

/* ── Master Sticky Header ──────────────────────────────────── */
.main-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04), 0 6px 20px rgba(0, 0, 0, 0.02);
  transition: all 0.25s ease;
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0.75rem clamp(1rem, 3vw, 2.5rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  flex-wrap: wrap;
}

/* 1. Brand Logo Block */
.brand-block {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  text-decoration: none;
  cursor: pointer;
  flex-shrink: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.16), rgba(217, 119, 6, 0.12));
  border: 1px solid rgba(16, 185, 129, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.15);
  color: var(--leaf);
}

.brand-eye-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
  color: #0f172a;
  line-height: 1.1;
}

.brand-tag {
  font-size: 0.72rem;
  color: var(--leaf);
  letter-spacing: 0.05em;
  font-weight: 700;
}

/* 2. Master Segmented Switcher (Center Command Pill) */
.master-workspace-nav {
  flex: 1;
  display: flex;
  justify-content: center;
  min-width: 280px;
}

.master-segmented-pill {
  display: inline-flex;
  background: #f1f5f9;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 4px;
  gap: 5px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
}

.ws-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 1.25rem;
  border-radius: 10px;
  background: transparent;
  color: var(--dim);
  border: 1px solid transparent;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
}

.ws-pill-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.6);
}

.ws-pill-btn.active {
  background: #ffffff;
  color: #0f172a;
  border-color: #cbd5e1;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

.ws-pill-btn#wsGreenhouseBtn.active {
  color: #047857;
  border-color: rgba(16, 185, 129, 0.35);
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.15);
}

.ws-pill-btn#wsLivestockBtn.active {
  color: #b45309;
  border-color: rgba(217, 119, 6, 0.35);
  box-shadow: 0 2px 10px rgba(217, 119, 6, 0.15);
}

.ws-pill-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.ws-pill-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 0 8px rgba(220, 38, 38, 0.4);
  animation: pulse-ring 2s infinite;
}

@keyframes pulse-ring {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* 3. Header Controls */
.header-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.farm-select-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: border-color 0.2s ease;
}

.farm-select-pill:hover {
  border-color: var(--line-strong);
}

.farm-select-pill select {
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  direction: rtl;
}

.farm-select-pill select option {
  background: #ffffff;
  color: var(--text);
}

.meta-badges-group {
  display: flex;
  gap: 0.4rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  background: var(--sand-dim);
  color: var(--sand);
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--sand-border);
}

.role-badge {
  background: var(--leaf-dim);
  color: var(--leaf);
  border-color: var(--leaf-border);
}

.plan-badge {
  background: var(--sand-dim);
  color: var(--sand);
  border-color: var(--sand-border);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.btn-hdr {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.85rem;
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--line);
  font-size: 0.82rem;
  font-family: var(--font-body);
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: all 0.2s ease;
}

.btn-hdr:hover {
  background: var(--bg-elevated);
  border-color: var(--line-strong);
}

.btn-hdr.logout-btn {
  color: #dc2626;
  background: var(--danger-dim);
  border-color: rgba(220, 38, 38, 0.2);
}

.btn-hdr.logout-btn:hover {
  background: rgba(220, 38, 38, 0.15);
  border-color: rgba(220, 38, 38, 0.35);
}

.live-indicator-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.65rem;
  background: var(--leaf-dim);
  border: 1px solid var(--leaf-border);
  border-radius: 999px;
  font-size: 0.72rem;
  color: var(--leaf);
  font-weight: 700;
}

.pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--leaf-bright);
  box-shadow: 0 0 8px var(--leaf-bright);
  animation: blink 1.4s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ── Sub-Navigation Bar (Horizontal Categories) ────────────── */
.sub-navbar {
  position: sticky;
  top: 61px;
  z-index: 90;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  padding: 0.45rem clamp(1rem, 3vw, 2.5rem);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.02);
}

.sub-nav-track {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 0.1rem 0;
}

.sub-nav-track::-webkit-scrollbar {
  display: none;
}

.sub-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 1.1rem;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.sub-pill:hover {
  color: var(--text);
  background: #f1f5f9;
}

.sub-pill.active {
  background: #ffffff;
  color: #0f172a;
  border-color: #cbd5e1;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

#greenhouseSubNav .sub-pill.active {
  background: #ffffff;
  border-color: rgba(16, 185, 129, 0.35);
  color: #047857;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.12);
}

.sub-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #ffffff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
}

/* ── Panel Category Filtering & Layout ─────────────────────── */
#livestock-workspace [data-cat-hidden="true"],
#greenhouse-workspace [data-cat-hidden="true"] {
  display: none !important;
}

#monitoringSections {
  display: contents;
}

#monitoringSections[hidden] {
  display: none !important;
}

.split:has(> [data-cat-hidden="true"]) {
  grid-template-columns: 1fr;
}

#livestock-workspace > .panel,
#livestock-workspace > .split,
#livestock-workspace > .hero,
#greenhouse-workspace > section {
  animation: fadeInPanel 0.28s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes fadeInPanel {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

main {
  padding: 1.75rem clamp(1rem, 3vw, 2.5rem) 4rem;
  display: grid;
  gap: 1.75rem;
  max-width: 1440px;
  margin: 0 auto;
}

.hero {
  padding: 0.5rem 0 1rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.5rem;
  animation: rise 0.6s ease-out both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hero h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.4rem, 2.5vw, 1.85rem);
  color: var(--text);
  letter-spacing: -0.02em;
}

.lede {
  margin: 0.4rem 0 1.25rem;
  max-width: 44rem;
  color: var(--muted);
  font-size: 0.95rem;
}

/* ── KPI Metric Cards Strip ────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  width: 100%;
  margin: 1rem 0 0.5rem;
}

.stat {
  padding: 1.25rem 1.4rem;
  border-radius: var(--radius);
  background: #ffffff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
  transition: transform 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease;
  position: relative;
  overflow: hidden;
}

.stat:hover {
  transform: translateY(-2px);
  border-color: rgba(16, 185, 129, 0.4);
  box-shadow: var(--shadow-card-hover);
}

.stat-value {
  display: block;
  font-family: var(--font-display);
  font-size: 2.1rem;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stat-label {
  color: var(--dim);
  font-size: 0.84rem;
  margin-top: 0.35rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* ── Executive Panels ──────────────────────────────────────── */
.panel {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
  box-shadow: var(--shadow-card);
  animation: rise 0.6s ease-out both;
  animation-delay: 0.08s;
  transition: box-shadow 0.2s ease;
}

.panel-head {
  margin-bottom: 1.25rem;
}

.panel-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: -0.01em;
}

.panel-sub {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

body.role-shepherd .manager-only {
  display: none !important;
}

.admin-panel {
  border-color: var(--sand-border);
}

.admin-stats {
  margin: 0.75rem 0 0.5rem;
}

.security-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 0 0 1rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  border: 1px solid rgba(220, 38, 38, 0.25);
  background: var(--danger-dim);
}

.security-banner code {
  direction: ltr;
  unicode-bidi: embed;
  color: #b91c1c;
  font-weight: 600;
}

.sub-heading {
  margin: 1.5rem 0 0.4rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: #0f172a;
}

.notify-browser,
.notify-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.link-box {
  margin-top: 0.75rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  border: 1px dashed var(--leaf-border);
  background: var(--leaf-dim);
}

.link-box a {
  word-break: break-all;
  color: var(--leaf);
  font-weight: 600;
}

.audit-box {
  max-height: 360px;
  overflow-y: auto;
}

.member-actions {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
}

/* ── Live Wall & Vision Cameras ────────────────────────────── */
.live-wall-panel {
  border-color: rgba(16, 185, 129, 0.25);
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.03), #ffffff);
}

.live-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}

.live-badge-row {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.live-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.45);
  animation: live-pulse 1.4s ease infinite;
}

@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.4); }
  70% { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
  100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

.camera-grid,
.live-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
}

.live-card {
  min-height: 220px;
  padding: 0;
  background: #0f172a;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
  position: relative;
}

.live-shot {
  aspect-ratio: 16 / 9;
  width: 100%;
}

.live-frame {
  animation: none !important;
}

.live-card.is-offline {
  border-color: rgba(220, 38, 38, 0.5);
}

.live-card.is-offline .live-frame {
  filter: grayscale(1) brightness(0.4);
}

.cam-overlay {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  padding: 0.75rem 0.85rem 2.8rem;
  background: linear-gradient(transparent, rgba(15, 23, 42, 0.92));
  pointer-events: none;
}

.cam-overlay .cam-title {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: #ffffff;
}

.live-actions {
  position: absolute;
  inset-inline: 0.55rem;
  bottom: 0.45rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  z-index: 2;
}

.cam-card {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #ffffff;
  box-shadow: var(--shadow-card);
  transition: transform 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease;
}

.cam-card:hover {
  transform: translateY(-2px);
  border-color: rgba(217, 119, 6, 0.4);
  box-shadow: var(--shadow-card-hover);
}

.cam-shot {
  aspect-ratio: 16 / 10;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.08), transparent), #0f172a;
  display: grid;
  place-items: center;
  color: #94a3b8;
  font-size: 0.85rem;
  overflow: hidden;
}

.cam-shot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  animation: fade-in 0.45s ease both;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.cam-body {
  padding: 1.1rem 1.25rem 1.35rem;
}

.cam-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: #0f172a;
}

.cam-id {
  color: var(--dim);
  font-size: 0.75rem;
}

/* ── Split Layouts ─────────────────────────────────────────── */
.split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 1.5rem;
}

/* ── Alert Stream ──────────────────────────────────────────── */
.alerts-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: 1.15rem;
}

.filter-tabs {
  display: flex;
  gap: 0.4rem;
}

.filter-tabs .tab {
  appearance: none;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 0.82rem;
  padding: 0.4rem 0.95rem;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

.filter-tabs .tab:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

.filter-tabs .tab.active {
  color: #b45309;
  border-color: rgba(217, 119, 6, 0.4);
  background: var(--sand-dim);
  font-weight: 700;
}

.alert-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.alert-item {
  padding: 1.1rem 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  animation: rise 0.5s ease both;
  transition: border-color 0.2s ease;
}

.alert-item.critical {
  border-color: rgba(220, 38, 38, 0.35);
  background: linear-gradient(90deg, rgba(220, 38, 38, 0.05), #ffffff);
}

.alert-item.warning {
  border-color: rgba(217, 119, 6, 0.35);
  background: linear-gradient(90deg, rgba(217, 119, 6, 0.05), #ffffff);
}

.alert-row {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 1rem;
  align-items: start;
}

.alert-thumb {
  width: 88px;
  height: 66px;
  border-radius: 10px;
  overflow: hidden;
  background: #f1f5f9;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.75rem;
}

.alert-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.alert-item.acked {
  opacity: 0.6;
}

.alert-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.98rem;
  color: #0f172a;
}

.alert-msg {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.alert-meta {
  margin-top: 0.55rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.85rem;
  color: var(--sand);
  font-size: 0.75rem;
  font-weight: 600;
}

.btn-ack {
  appearance: none;
  border: 1px solid rgba(217, 119, 6, 0.35);
  background: var(--sand-dim);
  color: var(--sand);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.4rem 0.95rem;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-ack:hover {
  background: rgba(217, 119, 6, 0.2);
  border-color: var(--sand);
}

/* ── Forms, Buttons & Inputs ───────────────────────────────── */
.upload-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.85rem 1rem;
  align-items: end;
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fafc;
}

.upload-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.upload-form select,
.upload-form input[type="file"],
.upload-form input[type="text"],
.upload-form input[type="password"] {
  font-family: var(--font-body);
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  outline: none;
}

.btn-primary {
  appearance: none;
  border: 0;
  background: linear-gradient(135deg, #059669, #10b981);
  color: #ffffff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.65rem 1.35rem;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.25);
  transition: all 0.2s ease;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #047857, #059669);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.35);
}

.btn-secondary {
  appearance: none;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  border-radius: 10px;
  padding: 0.6rem 1rem;
  font-family: var(--font-body);
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: all 0.2s ease;
}

.btn-secondary:hover {
  border-color: var(--line-strong);
  background: var(--bg-elevated);
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.cam-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.75rem;
}

/* ── Plan & Subscription Cards ─────────────────────────────── */
.plan-card {
  padding: 1.35rem 1.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #ffffff;
  box-shadow: var(--shadow-card);
}

.plan-card h3 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: #0f172a;
}

.plan-card p {
  margin: 0.35rem 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.plan-card dl {
  margin: 1rem 0 0;
  display: grid;
  gap: 0.55rem;
}

.plan-card dt {
  color: var(--dim);
  font-size: 0.8rem;
}

.plan-card dd {
  margin: 0;
  font-weight: 600;
  color: var(--text);
}

.threshold-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--line);
}

.threshold-row:last-child {
  border-bottom: 0;
}

.empty {
  color: var(--muted);
  margin: 0;
  padding: 1.5rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
  background: #ffffff;
}

/* ── ROI / Vision Canvas Tool ──────────────────────────────── */
.roi-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.roi-stage {
  width: 100%;
  overflow: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #0f172a;
}

#roiCanvas {
  display: block;
  max-width: 100%;
  touch-action: none;
  cursor: crosshair;
}

/* ── Gallery & Lightbox ────────────────────────────────────── */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-top: 0.85rem;
}

.gallery-item {
  appearance: none;
  border: 1px solid var(--line);
  background: #ffffff;
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  cursor: zoom-in;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: start;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.gallery-item img {
  display: block;
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
}

.gallery-item span {
  display: block;
  padding: 0.45rem 0.55rem;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.lightbox[hidden] {
  display: none !important;
}

.lightbox img {
  max-width: min(96vw, 1100px);
  max-height: 86vh;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  border: 1px solid var(--line);
}

.lightbox-close {
  position: absolute;
  top: 1.5rem;
  inset-inline-start: 1.5rem;
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.85);
  color: var(--text);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-weight: 600;
}

/* ── Authentication Login Gate ─────────────────────────────── */
.login-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
}

.login-gate[hidden] {
  display: none !important;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 0.85rem;
  padding: 2.25rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: #ffffff;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.08), 0 1px 3px rgba(0, 0, 0, 0.04);
}

.login-card .brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.85rem;
  font-weight: 800;
  color: #0f172a;
  text-align: center;
}

.login-card .brand-en {
  margin: 0;
  font-size: 0.82rem;
  color: var(--leaf);
  letter-spacing: 0.08em;
  text-align: center;
  font-weight: 700;
  text-transform: uppercase;
}

.login-card label {
  display: grid;
  gap: 0.4rem;
  font-size: 0.88rem;
  color: var(--muted);
  font-weight: 600;
}

.login-card input {
  width: 100%;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.login-card input:focus {
  border-color: var(--leaf);
  box-shadow: 0 0 0 3px var(--leaf-dim);
  background: #ffffff;
}

/* ── Footer ────────────────────────────────────────────────── */
.foot {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1.5rem clamp(1.25rem, 4vw, 3rem) 2.5rem;
  color: var(--dim);
  font-size: 0.84rem;
  border-top: 1px solid var(--line);
  max-width: 1440px;
  margin: 0 auto;
}

.foot a {
  color: var(--leaf);
  text-decoration: none;
  font-weight: 600;
}

.foot a:hover {
  text-decoration: underline;
}

/* ── Mobile & Responsive Tuning ────────────────────────────── */
@media (max-width: 860px) {
  .header-inner {
    padding: 0.6rem 0.85rem;
    gap: 0.65rem;
  }

  .master-workspace-nav {
    order: 3;
    width: 100%;
    min-width: unset;
  }

  .master-segmented-pill {
    width: 100%;
  }

  .ws-pill-btn {
    flex: 1;
    justify-content: center;
    padding: 0.5rem 0.45rem;
    font-size: 0.84rem;
  }

  .sub-navbar {
    top: 0;
    position: relative;
    padding: 0.4rem 0.65rem;
  }

  .sub-pill {
    padding: 0.4rem 0.85rem;
    font-size: 0.82rem;
  }

  .split,
  .stats,
  .admin-stats,
  .live-grid {
    grid-template-columns: 1fr;
  }

  button,
  .btn-primary,
  .btn-secondary {
    min-height: 44px;
  }

  .upload-form {
    grid-template-columns: 1fr;
  }

  .live-actions {
    position: static;
    padding: 0.4rem;
  }
}

@media print {
  .atmosphere,
  .top,
  .login-gate,
  .manager-only,
  .notify-browser,
  .notify-actions,
  form,
  footer,
  .security-banner,
  #adminSection,
  #accountSection,
  #notifySection {
    display: none !important;
  }

  body {
    background: #fff;
    color: #111;
  }

  .panel {
    break-inside: avoid;
    border: 1px solid #ccc;
    background: #fff;
  }
}

/* ── Shared utility classes used across the livestock screens ── */
.hint { color: var(--muted); font-size: 0.78rem; }
.muted { color: var(--muted); }
.summary-box { padding: 0.25rem 0; }
.upload-status { grid-column: 1 / -1; margin: 0; color: var(--sand); font-size: 0.9rem; min-height: 1.2em; }
.llm-note { margin: 0.55rem 0 0; font-size: 0.88rem; color: var(--leaf); line-height: 1.45; }
.narrative { margin: 0.75rem 0 1rem; padding-inline-start: 1.2rem; color: var(--text); }
.narrative li { margin: 0.25rem 0; }

.tag { display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 0.2rem 0.6rem; border-radius: 999px; background: var(--bg-elevated); border: 1px solid var(--line); color: var(--muted); }
.tag.ok { color: var(--leaf); background: var(--leaf-dim); border-color: var(--leaf-border); }
.tag.warn { color: var(--warn); background: var(--sand-dim); border-color: var(--sand-border); }
.tag.danger { color: var(--danger); background: var(--danger-dim); border-color: rgba(220, 38, 38, 0.35); animation: tag-pulse 2s ease-in-out infinite; }
@keyframes tag-pulse { 50% { box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.12); } }

.module-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.75rem 0.9rem; border-radius: var(--radius); border: 1px solid var(--line); background: var(--bg1); }
.module-row.locked { opacity: 0.7; background: var(--bg-elevated); }
.module-row small.muted, .module-row .muted { display: block; font-size: 0.75rem; font-weight: 400; }
.module-row input { width: auto; transform: scale(1.2); }

@media (prefers-reduced-motion: reduce) { .tag.danger { animation: none; } }
