/* Pecus Chain brand fonts (Raleway — manuale d'uso §2) */
@font-face {
  font-family: "Raleway";
  src: url("fonts/Raleway/Raleway-Light.ttf") format("truetype");
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Raleway";
  src: url("fonts/Raleway/Raleway-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Raleway";
  src: url("fonts/Raleway/Raleway-Medium.ttf") format("truetype");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Raleway";
  src: url("fonts/Raleway/Raleway-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Raleway";
  src: url("fonts/Raleway/Raleway-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Raleway";
  src: url("fonts/Raleway/Raleway-ExtraBold.ttf") format("truetype");
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

/* Pecus Chain brand palette (manuale d'uso §1 — codici esatti, non approssimare) */
:root {
  /* Verde Pecus — primario, deve dominare */
  --pc-primary:     #6b8e23;
  --pc-primary-dk:  #4a6007;
  --pc-primary-lt:  #a9c84d;

  /* Marrone Terra — secondario, usato per il testo (mai nero puro) */
  --pc-brown:       #8b6c4f;
  --pc-brown-dk:    #362a1f;
  --pc-brown-lt:    #d9a56b;

  /* Blu Tech — accento dati/tecnologia, con parsimonia */
  --pc-accent-blue:     #407491;
  --pc-accent-blue-dk:  #1b4b66;
  --pc-accent-blue-lt:  #9fbccc;

  /* Giallo Sole — accento energia/CTA, con parsimonia */
  --pc-accent-yellow:     #ffb347;
  --pc-accent-yellow-dk:  #ba7d35;
  --pc-accent-yellow-lt:  #ffca7e;

  /* Neutri Caldi — sfondi (mai bianco/nero puri dove evitabile) */
  --pc-bg:          #fafaf5;
  --pc-bg-card:     #ffffff;
  --pc-border:      #dbd8d5;
  --pc-text:        #362a1f;
  --pc-text-muted:  #8b6c4f;
  --pc-warn:        #b8860b;
  --pc-danger:      #b03000;
  --pc-sidebar-bg:  #f1f0ec;
}

body {
  background-color: var(--pc-bg);
  color: var(--pc-text);
  font-family: "Raleway", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

.navbar {
  background-color: #ffffff !important;
  border-bottom: 2px solid var(--pc-primary);
}

.navbar-brand { letter-spacing: 0.03em; }
.navbar-brand img { height: 26px; }
.navbar-brand-name { height: 30px; width: auto; }

.navbar-link {
  color: var(--pc-text);
}
.navbar-link:hover, .navbar-link.fw-bold {
  color: var(--pc-primary-dk);
}

.sidebar {
  background: var(--pc-sidebar-bg);
  border-right: 1px solid var(--pc-border);
  min-height: calc(100vh - 56px);
  padding: 1.5rem 1rem;
}

.sidebar label { font-size: 0.78rem; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--pc-text-muted); font-weight: 600; }

.form-select, .form-control {
  border-color: var(--pc-border);
  background-color: #fff;
  color: var(--pc-text);
}
.form-select:focus, .form-control:focus {
  border-color: var(--pc-primary);
  box-shadow: 0 0 0 0.2rem rgba(74,96,7,0.15);
}

.btn-primary {
  background-color: var(--pc-primary);
  border-color: var(--pc-primary);
  font-weight: 600;
}
.btn-primary:hover {
  background-color: var(--pc-primary-dk);
  border-color: var(--pc-primary-dk);
}

/* Balanced 2×2 grid so the four buttons always fit the narrow sidebar
   (they previously overflowed as a single non-wrapping flex row). */
.period-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem;
}

.btn-period {
  background: #fff;
  border: 1px solid var(--pc-border);
  color: var(--pc-text-muted);
  font-size: 0.82rem;
  padding: 0.25rem 0.4rem;
  border-radius: 0.375rem;
  cursor: pointer;
  width: 100%;
  box-sizing: border-box;
  text-align: center;
  white-space: nowrap;
}
.btn-period:hover, .btn-period.active {
  background: var(--pc-primary);
  border-color: var(--pc-primary);
  color: #fff;
}

.area-radio { display: none; }
.area-label {
  display: block;
  padding: 0.4rem 0.7rem;
  border-radius: 0.375rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--pc-text-muted);
  border: 1px solid transparent;
  margin-bottom: 0.2rem;
  transition: all 0.15s;
}
.area-label:hover { background: #e8f0d4; color: var(--pc-text); }
.area-radio:checked + .area-label {
  background: var(--pc-primary);
  color: #fff;
  border-color: var(--pc-primary);
}

.result-card {
  background: var(--pc-bg-card);
  border: 1px solid var(--pc-border);
  border-radius: 0.75rem;
  padding: 1.5rem;
  margin-top: 1rem;
  box-shadow: 0 1px 4px rgba(74,96,7,0.08);
}

.result-card .card-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--pc-primary-dk);
  margin-bottom: 0.25rem;
}

.result-meta { font-size: 0.8rem; color: var(--pc-text-muted); margin-bottom: 1rem; }

.summary-box {
  background: var(--pc-bg);
  border-left: 3px solid var(--pc-primary);
  border-radius: 0 0.375rem 0.375rem 0;
  padding: 0.8rem 1rem;
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--pc-text);
  margin-bottom: 1rem;
}

.cow-table th { font-size: 0.78rem; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--pc-text-muted); font-weight: 600; }
.cow-table td { font-size: 0.88rem; vertical-align: middle; }
/* `.badge` di Bootstrap non imposta alcuno sfondo: senza una regola dedicata
   l'etichetta resta testo bianco su bianco (invisibile). `.badge-patologia` e'
   il fallback che ogni badge di patologia deve portare, cosi' una patologia
   nuova (es. mastitis_at_calving) resta leggibile anche prima di avere un colore. */
.badge-patologia   { background-color: #5a6570; }
.badge-mastitis    { background-color: #b03000; }
.badge-mastitis_at_calving { background-color: #8c2a55; }
.badge-subclinical_mastitis { background-color: #a0522d; }
.badge-lameness    { background-color: #b8860b; }
.badge-ketosis     { background-color: #6a4a9a; }
.badge-heat_stress { background-color: #c05000; }
.badge-displaced_abomasum { background-color: #2f6f6f; }
.badge-milk_fever  { background-color: #2c5f9e; }
.badge-metritis    { background-color: #9a3b6a; }
.badge-retained_placenta { background-color: #7a5c2e; }
.badge-respiratory { background-color: #3f7a4d; }
.badge-unresolved  { background-color: #6c757d; }

.unresolved-section { border-left: 3px solid #fd7e14; padding-left: 0.75rem; margin-bottom: 1rem; }
.exec-log { font-size: 0.76rem; font-family: monospace; background: var(--pc-bg);
  border: 1px solid var(--pc-border); border-radius: 0.25rem;
  padding: 0.6rem 0.75rem; max-height: 220px; overflow-y: auto; margin-top: 0.4rem; }
.exec-log div { white-space: pre-wrap; line-height: 1.45; color: var(--pc-text-muted); }

/* ── Debug section (log di esecuzione + tracciamento agent/prompt) ── */
.debug-section { border: 1px solid var(--pc-border); border-radius: 0.5rem;
  background: var(--pc-bg); }
.debug-summary { cursor: pointer; user-select: none; padding: 0.65rem 0.9rem;
  font-size: 0.8rem; font-weight: 600; color: var(--pc-text-muted);
  text-transform: uppercase; letter-spacing: 0.04em; }
.debug-section[open] .debug-summary { border-bottom: 1px solid var(--pc-border); }
.debug-body { padding: 0.9rem; display: flex; flex-direction: column; gap: 1rem; }
.debug-block-title { font-size: 0.75rem; font-weight: 600; color: var(--pc-text);
  text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 0.4rem; }
.debug-kv { display: flex; gap: 0.5rem; align-items: baseline; margin-bottom: 0.5rem;
  font-size: 0.8rem; }
.debug-kv span { color: var(--pc-text-muted); font-weight: 600; }
.debug-kv code { background: var(--pc-bg-card); border: 1px solid var(--pc-border);
  border-radius: 0.25rem; padding: 0.05rem 0.35rem; color: var(--pc-primary-dk); }
.debug-sub { border: 1px solid var(--pc-border); border-radius: 0.375rem;
  background: var(--pc-bg-card); margin-bottom: 0.4rem; }
.debug-sub > summary { cursor: pointer; user-select: none; padding: 0.4rem 0.6rem;
  font-size: 0.8rem; color: var(--pc-text); }
.debug-step { padding: 0 0.6rem 0.6rem; }
.debug-step-h { font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--pc-text-muted); margin: 0.6rem 0 0.2rem; }
.debug-step-label { font-family: monospace; font-weight: 600; color: var(--pc-primary-dk); }
.debug-pre { font-family: "SFMono-Regular", Consolas, monospace; font-size: 0.74rem;
  line-height: 1.5; white-space: pre-wrap; word-break: break-word; color: var(--pc-text);
  background: var(--pc-bg); border: 1px solid var(--pc-border); border-radius: 0.25rem;
  padding: 0.5rem 0.6rem; max-height: 340px; overflow-y: auto; margin: 0; }

.progress-container {
  background: var(--pc-bg-card);
  border: 1px solid var(--pc-border);
  border-radius: 0.75rem;
  padding: 1.25rem;
  margin-top: 1rem;
}
.log-output {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.78rem;
  color: var(--pc-text-muted);
  max-height: 140px;
  overflow-y: auto;
  background: var(--pc-bg);
  border-radius: 0.375rem;
  padding: 0.5rem 0.75rem;
  margin-top: 0.5rem;
  white-space: pre-wrap;
}

.history-row { cursor: pointer; transition: background 0.1s; }
.history-row:hover { background: var(--pc-bg); }

.kb-card {
  background: var(--pc-bg-card);
  border: 1px solid var(--pc-border);
  border-radius: 0.75rem;
  padding: 1.25rem;
}

/* Mantiene sempre disponibile lo scorrimento orizzontale delle tabelle larghe,
   anche quando il cursore e' sopra la card anziche' sul bordo della viewport. */
.conversation-table-scroll {
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
}
.conversation-table { min-width: 760px; }
.kb-entry { border-bottom: 1px solid var(--pc-border); padding: 0.6rem 0; gap: 0.75rem; }
.kb-entry:last-child { border-bottom: none; }
/* nomi PDF lunghi (spesso >60 caratteri, senza spazi): manda a capo invece di
   sfondare la card. min-width:0 permette al flex-item di restringersi; il form
   di eliminazione resta a larghezza fissa. */
.kb-entry__body { min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
.kb-entry > form { flex-shrink: 0; }

/* ── Markdown-rendered content ──────────────────────────────────────── */
.md-content h2 { font-size: 1rem; font-weight: 700; color: var(--pc-primary-dk);
  margin-top: 1.25rem; margin-bottom: 0.4rem; border-bottom: 1px solid var(--pc-border);
  padding-bottom: 0.2rem; }
.md-content h3 { font-size: 0.92rem; font-weight: 700; color: var(--pc-text);
  margin-top: 1rem; margin-bottom: 0.3rem; }
.md-content p  { font-size: 0.9rem; line-height: 1.65; margin-bottom: 0.6rem; }
.md-content ul, .md-content ol { font-size: 0.9rem; padding-left: 1.4rem;
  margin-bottom: 0.6rem; }
.md-content li { margin-bottom: 0.25rem; line-height: 1.55; }
.md-content table { width: 100%; border-collapse: collapse; font-size: 0.85rem;
  margin: 0.6rem 0; }
.md-content th { background: var(--pc-bg); color: var(--pc-text-muted);
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em;
  font-weight: 600; padding: 0.4rem 0.6rem; border: 1px solid var(--pc-border); }
.md-content td { padding: 0.35rem 0.6rem; border: 1px solid var(--pc-border);
  vertical-align: top; }
.md-content strong { color: var(--pc-text); }

/* ── Full-report sections ─────────────────────────────────────────── */
.report-section {
  border: 1px solid var(--pc-border);
  border-radius: 0.5rem;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  background: var(--pc-bg-card);
}
.report-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--pc-text-muted);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.report-kpi {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.report-kpi-item {
  background: var(--pc-bg);
  border: 1px solid var(--pc-border);
  border-radius: 0.375rem;
  padding: 0.3rem 0.65rem;
  font-size: 0.82rem;
}
.report-kpi-item span { font-weight: 700; color: var(--pc-primary-dk); }

/* ── Cow Dashboard ───────────────────────────────────────────────── */
.dash-header {
  background: var(--pc-primary-dk);
  color: #fff;
  padding: 1rem 1.5rem 0.75rem;
  border-bottom: 3px solid var(--pc-primary);
}
.dash-header h1 { font-size: 1.25rem; font-weight: 700; margin: 0; }
.dash-header .subtitle { font-size: 0.85rem; color: var(--pc-border); margin-top: 0.15rem; }

.kpi-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  font-size: 0.8rem;
  color: #fff;
}
.kpi-chip.negative { background: rgba(176,48,0,0.35); border-color: rgba(176,48,0,0.6); }
.kpi-chip.positive { background: rgba(74,96,7,0.35); border-color: rgba(74,96,7,0.6); }

.dash-card {
  background: var(--pc-bg-card);
  border: 1px solid var(--pc-border);
  border-radius: 0.5rem;
  padding: 1rem;
  margin-bottom: 1rem;
}
.dash-card-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--pc-text-muted);
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.dash-chart-wrap { width: 100%; min-height: 260px; }

.dash-llm-block {
  background: var(--pc-bg);
  border-left: 4px solid var(--pc-accent-blue);
  border-radius: 0 0.375rem 0.375rem 0;
  padding: 0.85rem 1rem;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--pc-text);
}
.dash-llm-block .signal-pill {
  display: inline-block;
  background: var(--pc-accent-blue);
  color: #fff;
  border-radius: 0.3rem;
  padding: 0.15rem 0.5rem;
  font-size: 0.77rem;
  margin: 0.15rem 0.15rem 0 0;
}

.lac-table { font-size: 0.82rem; }
.lac-table thead th { font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--pc-text-muted); border-color: var(--pc-border); }
.lac-table tbody td { border-color: var(--pc-border); }

/* ── Print / PDF export ───────────────────────────────────────────── */
.btn-pdf {
  background: none;
  border: 1px solid var(--pc-border);
  color: var(--pc-text-muted);
  font-size: 0.82rem;
  padding: 0.3rem 0.75rem;
  border-radius: 0.375rem;
  cursor: pointer;
}
.btn-pdf:hover { background: var(--pc-primary); color: #fff; border-color: var(--pc-primary); }

.print-only-header { display: none; }

@media print {
  nav, .sidebar, .btn-pdf, .btn-period, [data-bs-toggle="modal"],
  #analyze-form, #history-container, .log-output, .progress-container,
  .no-print { display: none !important; }
  .print-only-header { display: block !important; }

  .col-md-9, .col-xl-10 {
    width: 100% !important;
    flex: 0 0 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
  }
  body { background: #fff !important; color: #000; font-size: 11pt; }
  .result-card { border: none !important; box-shadow: none !important;
    padding: 0 !important; margin: 0 !important; }
  .report-section { break-inside: avoid; border: 1px solid #ccc !important; }
  img { max-width: 100% !important; page-break-inside: avoid; }
  h2, h3 { page-break-after: avoid; }
  .md-content table { page-break-inside: avoid; }
  @page { margin: 1.5cm; }
}
