:root {
  --bg-gradient: radial-gradient(circle at top, #243c2b 0%, #111d15 50%, #090f0b 100%);
  --panel: rgba(22, 38, 28, 0.88);
  --panel-card: rgba(14, 26, 19, 0.75);
  --border: rgba(244, 240, 223, 0.16);
  --border-focus: #9bb477;
  --cream: #f4f0df;
  --cream-dim: rgba(244, 240, 223, 0.7);
  --muted: #a3b098;
  --green: #7fa871;
  --green-bright: #a4d48f;
  --gold: #d8a23d;
  --red: #df6452;
  --red-bg: rgba(223, 100, 82, 0.18);
  --gold-bg: rgba(216, 162, 61, 0.18);
  --green-bg: rgba(127, 168, 113, 0.18);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow: 0 16px 36px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  min-height: 100vh;
  background: var(--bg-gradient);
  color: var(--cream);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

.analysis-app {
  max-width: 1380px;
  margin: 0 auto;
  padding: 20px 24px 60px;
}

/* Header */
.analysis-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.analysis-brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.analysis-logo {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid var(--green);
  background: #fff;
  padding: 3px;
  object-fit: contain;
}

.analysis-brand h1 {
  font-size: clamp(1.25rem, 2.8vw, 1.7rem);
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
}

.analysis-farm-name {
  color: var(--muted);
  font-size: 0.9rem;
}

.analysis-topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.analysis-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
}

.analysis-btn.primary {
  background: var(--green);
  color: #0d1a10;
}
.analysis-btn.primary:hover {
  background: var(--green-bright);
}

.analysis-btn.outline {
  background: rgba(255, 255, 255, 0.05);
  color: var(--cream);
  border-color: var(--border);
}
.analysis-btn.outline:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--green);
}

.analysis-alert {
  padding: 14px 20px;
  margin-bottom: 20px;
  background: var(--red-bg);
  border: 1px solid var(--red);
  color: #ffb8ad;
  border-radius: var(--radius-md);
}
.analysis-alert.hidden { display: none; }

/* KPI Grid */
.analysis-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.kpi-card {
  padding: 16px 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--border);
}
.kpi-card.accent-green::before { background: var(--green); }
.kpi-card.accent-gold::before { background: var(--gold); }
.kpi-card.accent-red::before { background: var(--red); }

.kpi-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.kpi-title {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.kpi-icon {
  font-size: 1.25rem;
  opacity: 0.8;
}

.kpi-value {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.1;
  color: #fff;
}

.kpi-sub {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 4px;
}

/* Nav Tabs */
.analysis-nav-tabs {
  display: flex;
  gap: 6px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 22px;
  padding-bottom: 2px;
  overflow-x: auto;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 22px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  border-bottom: 3px solid transparent;
  margin-bottom: -4px;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--cream);
  background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
  color: #fff;
  border-bottom-color: var(--green);
  background: rgba(127, 168, 113, 0.1);
}

.tab-btn .badge-pill {
  padding: 2px 7px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 700;
}
.tab-btn.active .badge-pill {
  background: var(--green);
  color: #0b1a0f;
}

/* Panels */
.tab-panel {
  display: block;
}
.tab-panel.hidden {
  display: none !important;
}

/* Radar Layout */
.radar-split-layout {
  display: grid;
  grid-template-columns: minmax(320px, 500px) 1fr;
  gap: 24px;
  align-items: start;
  margin-bottom: 24px;
}
@media (max-width: 980px) {
  .radar-split-layout { grid-template-columns: 1fr; }
}

.radar-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.radar-card-head {
  width: 100%;
  margin-bottom: 12px;
}
.radar-card-head h3 {
  font-size: 1.15rem;
  color: #fff;
  font-weight: 700;
}
.radar-card-head p {
  font-size: 0.85rem;
  color: var(--muted);
}

.radar-svg-container {
  width: 100%;
  max-width: 480px;
  position: relative;
  user-select: none;
}

.radar-svg {
  width: 100%;
  height: auto;
  overflow: visible;
  filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.4));
}

.radar-grid-ring {
  fill: rgba(255, 255, 255, 0.015);
  stroke: rgba(244, 240, 223, 0.18);
  stroke-width: 1.2;
}

.radar-grid-axis {
  stroke: rgba(244, 240, 223, 0.22);
  stroke-width: 1.2;
  stroke-dasharray: 3 3;
}

.radar-polygon-area {
  fill: url(#radarGradient);
  stroke: var(--green-bright);
  stroke-width: 2.5;
  filter: drop-shadow(0 0 10px rgba(164, 212, 143, 0.35));
  transition: all 0.3s ease;
}

.radar-vertex-circle {
  stroke: #111d15;
  stroke-width: 2.5;
  cursor: pointer;
  transition: transform 0.2s ease, r 0.2s ease;
}
.radar-vertex-circle:hover {
  r: 7;
}

.radar-axis-tag-rect {
  fill: #1a2e21;
  stroke: var(--border);
  stroke-width: 1;
  rx: 4;
  cursor: pointer;
}
.radar-axis-tag-rect:hover {
  fill: #264330;
  stroke: var(--green);
}

.radar-axis-tag-text {
  fill: #fff;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  pointer-events: none;
}

.radar-scale-text {
  fill: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.radar-legend-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  width: 100%;
  font-size: 0.82rem;
  color: var(--muted);
}
.radar-legend-bar span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

/* Radar Side Info & Interpretation */
.radar-info-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}
.radar-info-card h3 {
  font-size: 1.15rem;
  color: #fff;
  margin-bottom: 8px;
}

.findings-bars-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0;
}

.finding-bar-item {
  display: grid;
  grid-template-columns: minmax(130px, 180px) 1fr 50px;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s ease;
}
.finding-bar-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.finding-bar-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--cream);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.finding-bar-track {
  height: 16px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 99px;
  overflow: hidden;
}
.finding-bar-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #628c57, #a4d48f);
  min-width: 4px;
}
.finding-bar-fill.accent-red {
  background: linear-gradient(90deg, #b84f3e, #df6452);
}
.finding-bar-fill.accent-gold {
  background: linear-gradient(90deg, #a87928, #d8a23d);
}
.finding-bar-count {
  font-weight: 700;
  font-size: 0.88rem;
  text-align: right;
  color: #fff;
}

.recommendations-box {
  margin-top: 18px;
  padding: 16px;
  background: rgba(0, 0, 0, 0.22);
  border-radius: var(--radius-md);
  border-left: 4px solid var(--green);
}
.recommendations-box h4 {
  font-size: 0.95rem;
  margin-bottom: 6px;
  color: #fff;
}
.recommendations-box ul {
  padding-left: 20px;
  font-size: 0.88rem;
  color: var(--cream-dim);
}
.recommendations-box li {
  margin-bottom: 6px;
}

/* =============================================================================
   CATALOG VIEW (NO ENDLESS SCROLLING)
   ============================================================================= */
.catalog-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}

.catalog-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.catalog-search-wrap {
  position: relative;
  flex: 1 1 280px;
  max-width: 420px;
}

.catalog-search-input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  background: var(--panel-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.15s ease;
}
.catalog-search-input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 2px rgba(127, 168, 113, 0.25);
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
  font-size: 1rem;
}

.catalog-filters-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.filter-chip {
  padding: 6px 14px;
  background: var(--panel-card);
  border: 1px solid var(--border);
  border-radius: 99px;
  color: var(--cream-dim);
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.filter-chip:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}
.filter-chip.active {
  background: var(--green);
  color: #0b1a0f;
  border-color: var(--green);
}

.catalog-select-filter {
  padding: 7px 12px;
  background: var(--panel-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 0.85rem;
  outline: none;
}

/* Pagination Bar */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  flex-wrap: wrap;
  font-size: 0.88rem;
  color: var(--muted);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.page-btn {
  padding: 6px 12px;
  background: var(--panel-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--cream);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s ease;
}
.page-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--green);
}
.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.page-btn.active {
  background: var(--green);
  color: #0d1a10;
  border-color: var(--green);
}

/* Catalog Table View */
.catalog-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin-bottom: 16px;
}

.catalog-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.catalog-table th {
  padding: 12px 14px;
  background: rgba(0, 0, 0, 0.4);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

.catalog-table td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(244, 240, 223, 0.07);
  color: var(--cream);
}

.catalog-table tr:hover td {
  background: rgba(255, 255, 255, 0.035);
}

.catalog-table tr.has-defect td {
  border-left: 3px solid var(--red);
}
.catalog-table tr.has-care td {
  border-left: 3px solid var(--gold);
}

.badge-tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.76rem;
  font-weight: 700;
  margin: 2px 3px 2px 0;
}
.badge-tag.severity-1 { background: rgba(127, 168, 113, 0.25); color: #b7e3a8; border: 1px solid #7fa871; }
.badge-tag.severity-2 { background: var(--gold-bg); color: #ffd67a; border: 1px solid var(--gold); }
.badge-tag.severity-3, .badge-tag.severity-4 { background: var(--red-bg); color: #ffaca0; border: 1px solid var(--red); }
.badge-tag.care { background: rgba(85, 140, 195, 0.2); color: #9ec9f7; border: 1px solid #558cc3; }
.badge-tag.ok { background: rgba(255, 255, 255, 0.06); color: var(--muted); }

/* Modal Drawer for Animal Hoof Details */
.analysis-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.analysis-modal.hidden { display: none; }

.analysis-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 12, 8, 0.8);
  backdrop-filter: blur(6px);
}

.analysis-modal-card {
  position: relative;
  width: min(780px, 100%);
  max-height: 90vh;
  background: #14241a;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.analysis-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  background: rgba(0, 0, 0, 0.3);
  border-bottom: 1px solid var(--border);
}

.analysis-modal-eyebrow {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.06em;
}

.analysis-modal-head h2 {
  font-size: 1.35rem;
  color: #fff;
}

.analysis-modal-close {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--cream);
  font-size: 1.2rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-content: center;
  transition: all 0.15s ease;
}
.analysis-modal-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.analysis-modal-body {
  padding: 24px;
  overflow-y: auto;
}

/* 4-Quadrant Hoof Display */
.hoof-matrix-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 14px;
}
@media (max-width: 600px) {
  .hoof-matrix-grid { grid-template-columns: 1fr; }
}

.hoof-quadrant {
  padding: 16px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.hoof-quadrant.affected {
  border-color: rgba(223, 100, 82, 0.4);
  background: rgba(125, 55, 53, 0.18);
}

.hoof-quadrant-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
}

.hoof-claws-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hoof-claw-item {
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

/* Timeline Bars */
.timeline-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.timeline-row {
  display: grid;
  grid-template-columns: 100px 1fr 70px;
  gap: 14px;
  align-items: center;
}

.timeline-date {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--cream);
}

.timeline-track {
  height: 22px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.timeline-fill {
  height: 100%;
  background: linear-gradient(90deg, #628c57, #a4d48f);
  display: flex;
  align-items: center;
  padding-left: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #0b1a0f;
  min-width: 24px;
}

/* Spinner */
.analysis-loading {
  text-align: center;
  padding: 80px 20px;
  color: var(--muted);
}

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Radar Metric Switcher */
.radar-metric-toggle {
  display: flex;
  gap: 8px;
  margin: 10px 0 16px;
  background: rgba(0, 0, 0, 0.25);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.metric-btn {
  flex: 1;
  padding: 6px 12px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.15s ease;
}
.metric-btn:hover {
  color: #fff;
}
.metric-btn.active {
  background: var(--green);
  color: #0b1a0f;
}

/* Cluster & Häufungs-Insights */
.cluster-insights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 24px;
}

.cluster-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}
.cluster-card h4 {
  font-size: 0.98rem;
  color: #fff;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.cluster-card p.cluster-sub {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 14px;
}

.cluster-row-item {
  display: grid;
  grid-template-columns: minmax(110px, 130px) 1fr 65px;
  gap: 10px;
  align-items: center;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.2);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.cluster-row-item:hover {
  background: rgba(255, 255, 255, 0.06);
}
.cluster-row-label {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--cream);
}
.cluster-row-track {
  height: 12px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 99px;
  overflow: hidden;
}
.cluster-row-fill {
  height: 100%;
  border-radius: 99px;
  min-width: 4px;
}
.cluster-row-count {
  font-size: 0.82rem;
  font-weight: 700;
  text-align: right;
  color: #fff;
}

/* Limb 4-Box Scheme */
.limb-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.limb-box {
  padding: 12px;
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
  text-align: center;
}
.limb-box.highlight {
  border-color: var(--red);
  background: rgba(223, 100, 82, 0.12);
}
.limb-name {
  font-size: 0.76rem;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.05em;
}
.limb-value {
  font-size: 1.45rem;
  font-weight: 800;
  color: #fff;
  margin: 3px 0;
}
.limb-sub {
  font-size: 0.78rem;
  color: var(--muted);
}

