/* =========================================================
   Registro de Aplicaciones · Granja Experimental El Edén
   Identidad Cibochem — todos los colores viven en :root
   ========================================================= */
:root {
  color-scheme: light;
  /* Marca Cibochem (azul del logotipo) */
  --brand: #5e87ba;
  --brand-600: #4a72a5;
  --brand-700: #3b5e8c;
  --brand-800: #2c4a72;
  --brand-900: #1f3557;
  --brand-100: #dde7f3;
  --brand-50: #eef3fa;
  /* Acento campo */
  --leaf: #3f8f4a;
  --leaf-50: #e9f4ea;

  /* Superficies y tinta */
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #1c2838;
  --text-2: #4a5568;
  --muted: #7a8699;
  --border: #dde3ec;
  --border-strong: #c5cfdc;

  /* Estados (reservados, siempre con texto o icono) */
  --ok: #0ca30c;
  --ok-ink: #006300;
  --ok-bg: #e7f6e7;
  --warn: #fab219;
  --warn-ink: #8a5a00;
  --warn-bg: #fff4dc;
  --danger: #d03b3b;
  --danger-ink: #a12a2a;
  --danger-bg: #fbe9e9;

  /* Gráficas (paleta categórica validada, orden fijo) */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --grid: #e6e9ef;
  --axis: #c3c9d4;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(28, 40, 56, .06), 0 2px 8px rgba(28, 40, 56, .05);
  --shadow-lg: 0 10px 40px rgba(20, 35, 60, .22);
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 14.5px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-700); }
h1, h2, h3, h4 { margin: 0; font-weight: 800; letter-spacing: -.01em; }
h2 { font-size: 18px; }
h3 { font-size: 15.5px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  z-index: 30;
}
.brand { padding: 20px 20px 14px; border-bottom: 1px solid var(--border); }
.brand-logo { width: 150px; display: block; }
.brand-sub { margin-top: 10px; font-size: 12.5px; color: var(--text-2); line-height: 1.3; }
.brand-sub strong { color: var(--brand-700); font-size: 15px; }
.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  text-decoration: none; color: var(--text-2); font-weight: 700; font-size: 14px;
  position: relative;
}
.nav a .ico { width: 22px; text-align: center; font-size: 15px; color: var(--muted); }
.nav a:hover { background: var(--brand-50); color: var(--brand-800); }
.nav a.active { background: var(--brand); color: #fff; }
.nav a.active .ico { color: #fff; }
.nav-badge {
  margin-left: auto; background: var(--danger); color: #fff; font-size: 11px;
  border-radius: 20px; padding: 1px 7px; font-weight: 800;
}
.nav a.active .nav-badge { background: #fff; color: var(--brand-700); }
.sidebar-foot { padding: 12px 16px 16px; border-top: 1px solid var(--border); }
.slogan { font-size: 12px; color: var(--brand); margin-top: 8px; }
.file-status { font-size: 12px; color: var(--text-2); display: flex; flex-direction: column; gap: 6px; }
.file-status .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 28px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 21px; color: var(--brand-900); }
.crumb { font-size: 12.5px; color: var(--muted); }
.topbar-title { flex: 1; min-width: 0; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.topbar .menu-toggle { display: none; }
.content { padding: 22px 28px 60px; max-width: 1480px; width: 100%; }
.banner {
  margin: 14px 28px 0; padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--warn-bg); color: var(--warn-ink); border: 1px solid #f3d48c;
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
}
.banner .grow { flex: 1; min-width: 200px; }

/* ---------- Botones ---------- */
.btn {
  font: inherit; font-weight: 700; font-size: 13.5px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  white-space: nowrap; text-decoration: none; line-height: 1.2;
}
.btn:hover { background: var(--surface-2); border-color: var(--brand); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); border-color: var(--brand-600); }
.btn-leaf { background: var(--leaf); border-color: var(--leaf); color: #fff; }
.btn-leaf:hover { background: #357a3f; border-color: #357a3f; }
.btn-danger { color: var(--danger-ink); border-color: #e7b3b3; }
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--brand-50); border-color: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn-icon {
  font: inherit; border: 1px solid var(--border); background: var(--surface);
  width: 34px; height: 34px; border-radius: 9px; cursor: pointer; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center; color: var(--text-2);
}
.btn-icon:hover { border-color: var(--brand); color: var(--brand-700); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px;
}
.card + .card { margin-top: 16px; }
.grid > .card + .card, .stack > .card + .card { margin-top: 0; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { flex: 1; min-width: 160px; }
.card-sub { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.section-gap { margin-top: 16px; }

/* KPI */
.kpi { padding: 16px 18px; }
.kpi-label { font-size: 12.5px; color: var(--text-2); font-weight: 700; display: flex; gap: 6px; align-items: center; }
.kpi-value { font-size: 27px; font-weight: 800; color: var(--brand-900); margin-top: 4px; line-height: 1.1; }
.kpi-foot { font-size: 12px; color: var(--muted); margin-top: 6px; }
.kpi-accent { border-top: 4px solid var(--brand); }
.kpi-accent.leaf { border-top-color: var(--leaf); }
.kpi-accent.warn { border-top-color: var(--warn); }
.kpi-accent.danger { border-top-color: var(--danger); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 800; padding: 2px 8px; border-radius: 20px;
  background: var(--brand-50); color: var(--brand-800); white-space: nowrap;
}
.badge-ok { background: var(--ok-bg); color: var(--ok-ink); }
.badge-warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge-danger { background: var(--danger-bg); color: var(--danger-ink); }
.badge-muted { background: #eef0f3; color: var(--text-2); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: 0 0 10px; }

/* ---------- Tabs / segmented ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button {
  font: inherit; font-weight: 700; color: var(--text-2); background: none; border: none;
  padding: 10px 14px; cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tabs button.active { color: var(--brand-700); border-bottom-color: var(--brand); }
.seg { display: inline-flex; background: #e9eef5; border-radius: 9px; padding: 3px; gap: 2px; }
.seg button {
  font: inherit; font-weight: 700; font-size: 12.5px; border: none; background: transparent;
  padding: 5px 11px; border-radius: 7px; cursor: pointer; color: var(--text-2);
}
.seg button.active { background: var(--surface); color: var(--brand-800); box-shadow: var(--shadow); }

/* ---------- Formularios ---------- */
.filters {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
  margin-bottom: 14px;
}
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span, .field > label { font-size: 12px; font-weight: 700; color: var(--text-2); }
.field .hint { font-size: 11.5px; color: var(--muted); font-weight: 600; }
input, select, textarea {
  font: inherit; font-size: 14px; color: var(--text);
  border: 1px solid var(--border-strong); background: var(--surface);
  border-radius: 8px; padding: 7px 10px; min-width: 0; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-100); border-color: var(--brand); }
input[readonly] { background: var(--surface-2); color: var(--text-2); }
textarea { resize: vertical; min-height: 64px; }
input[type="checkbox"] { width: auto; accent-color: var(--brand); }
.form-grid { display: grid; gap: 12px 14px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .half { grid-column: span 2; }
.search { min-width: 220px; }
.req::after { content: " *"; color: var(--danger); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th {
  background: var(--surface-2); color: var(--text-2); font-weight: 800; font-size: 12px;
  position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
tbody tr:hover td { background: #f7f9fc; }
tfoot td { font-weight: 800; background: var(--brand-50); border-bottom: none; }
td .row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.table-scroll { max-height: 620px; overflow: auto; }
.group-row td { background: var(--brand-50); font-weight: 800; color: var(--brand-800); }
.empty {
  padding: 40px 20px; text-align: center; color: var(--muted);
  border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface);
}
.empty .big { font-size: 30px; margin-bottom: 6px; }

/* Editor de filas (aplicaciones con varios productos) */
.items-table input, .items-table select { padding: 6px 6px; font-size: 13px; }
.items-table td { padding: 4px 3px; }
.items-table th { padding: 7px 4px; font-size: 11.5px; }
.items-table .calc { background: var(--surface-2); font-weight: 700; color: var(--brand-900); }
.items-table td.ctrl { width: 36px; }
.items-table .prod-new { display: flex; gap: 4px; align-items: center; margin-top: 4px; }
.items-table .prod-new input { width: 120px; font-size: 12px; padding: 4px 6px; }
.items-table td.prod-cell { vertical-align: top; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 32, 52, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 100; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 760px;
}
.modal.wide { max-width: 1400px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1; color: var(--brand-900); }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 14px 14px; flex-wrap: wrap; }
.modal-foot .left { margin-right: auto; display: flex; gap: 8px; align-items: center; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--brand-900); color: #fff; padding: 11px 16px; border-radius: 10px;
  box-shadow: var(--shadow-lg); font-weight: 700; font-size: 13.5px; max-width: 380px;
  animation: toast-in .18s ease-out;
}
.toast.ok { background: #1f6b2c; }
.toast.err { background: #9b2c2c; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Gráficas ---------- */
.chart { width: 100%; min-height: 220px; position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { font-family: var(--font); }
.chart .tick { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .lbl { font-size: 11px; fill: var(--text-2); font-weight: 700; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .mark { transition: opacity .12s; }
.chart.dim .mark { opacity: .35; }
.chart.dim .mark.on { opacity: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 12.5px; color: var(--text-2); font-weight: 600; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-empty { display: flex; align-items: center; justify-content: center; min-height: 200px; color: var(--muted); font-weight: 600; }
.chart-tip {
  position: fixed; z-index: 300; pointer-events: none;
  background: #fff; color: var(--text); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg); border-radius: 9px; padding: 8px 11px;
  font-size: 12.5px; min-width: 140px; max-width: 280px;
}
.chart-tip .t { font-weight: 800; margin-bottom: 4px; color: var(--brand-900); }
.chart-tip .r { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.chart-tip .r .k { display: flex; gap: 6px; align-items: center; color: var(--text-2); }
.chart-tip .r .v { font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---------- Lotes ---------- */
.lote-card { position: relative; overflow: hidden; }
.lote-card .lote-bar { position: absolute; left: 0; top: 0; bottom: 0; width: 5px; }
.lote-title { display: flex; align-items: baseline; gap: 8px; }
.lote-title h3 { font-size: 17px; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stat { background: var(--surface-2); border-radius: 9px; padding: 8px 10px; }
.stat .l { font-size: 11.5px; color: var(--muted); font-weight: 700; }
.stat .v { font-size: 16px; font-weight: 800; color: var(--brand-900); font-variant-numeric: tabular-nums; }
.progress { height: 6px; background: #e9eef5; border-radius: 4px; overflow: hidden; margin-top: 4px; }
.progress > div { height: 100%; background: var(--leaf); border-radius: 4px; }

/* ---------- Recomendaciones ---------- */
.rec-card { border-left: 5px solid var(--brand); }
.rec-card.done { border-left-color: var(--ok); }
.rec-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.rec-head h3 { font-size: 16px; }
.rec-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.rec-cols.single { grid-template-columns: 1fr; }
.rec-cols.single .items { display: grid; grid-template-columns: 1fr 1fr; column-gap: 10px; }
.rec-group h4 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--brand-700); margin-bottom: 6px; }
.rec-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center;
  padding: 7px 8px; border-radius: 8px; border: 1px solid var(--border); margin-bottom: 6px; background: var(--surface);
}
.rec-item.aplicada { background: var(--ok-bg); border-color: #bfe3bf; }
.rec-item.omitida { opacity: .55; text-decoration: line-through; }
.rec-item .p { font-weight: 800; }
.rec-item .d { font-size: 12.5px; color: var(--text-2); }
.days { display: inline-flex; gap: 3px; flex-wrap: wrap; }
.day-chip {
  font: inherit; font-size: 11.5px; font-weight: 800; width: 28px; height: 26px; border-radius: 7px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); cursor: pointer;
}
.day-chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.day-chip.ro { cursor: default; width: 22px; height: 20px; font-size: 10.5px; border-radius: 5px; }

/* Dropzone */
.drop {
  border: 2px dashed var(--brand-100); border-radius: var(--radius); padding: 26px; text-align: center;
  background: var(--brand-50); color: var(--brand-800); font-weight: 700; cursor: pointer;
}
.drop:hover, .drop.over { border-color: var(--brand); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); font-weight: 700; }
.kv dd { margin: 0; font-weight: 700; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .app.menu-open .sidebar { transform: none; }
  .topbar .menu-toggle { display: inline-flex; }
  .topbar { padding: 12px 16px; }
  .content { padding: 16px 16px 50px; }
  .banner { margin: 12px 16px 0; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .rec-cols, .rec-cols.single .items { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid .half { grid-column: auto; }
  .topbar-actions .btn span.lbl { display: none; }
}

/* ---------- Impresión / PDF ---------- */
#print-root { display: none; }
@media print {
  @page { size: A4 landscape; margin: 12mm 10mm; }
  body { background: #fff; font-size: 11px; }
  body.printing .app, body.printing .modal-backdrop, body.printing .toasts { display: none !important; }
  body.printing #print-root { display: block; }
  .rep-page { page-break-after: always; }
  .rep-page:last-child { page-break-after: auto; }
  .avoid-break { break-inside: avoid; }
  .card { box-shadow: none; }
  th { position: static; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
/* Estilos del informe (también se usan en pantalla dentro de la vista previa) */
.report { color: var(--text); font-size: 12px; }
.report .rep-header { display: flex; align-items: center; gap: 18px; border-bottom: 3px solid var(--brand); padding-bottom: 10px; margin-bottom: 14px; }
.report .rep-header img { width: 150px; }
.report .rep-header .t { flex: 1; }
.report .rep-header h1 { font-size: 20px; color: var(--brand-900); }
.report .rep-header .s { color: var(--text-2); font-size: 12px; font-weight: 600; }
.report .rep-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.report .rep-kpi { border: 1px solid var(--border); border-radius: 9px; padding: 8px 12px; border-top: 3px solid var(--brand); }
.report .rep-kpi .l { font-size: 10.5px; color: var(--text-2); font-weight: 700; }
.report .rep-kpi .v { font-size: 18px; font-weight: 800; color: var(--brand-900); }
.report h2 { font-size: 14px; color: var(--brand-800); margin: 14px 0 8px; }
.report table { font-size: 10.5px; }
.report th, .report td { padding: 4px 6px; }
.report .rep-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.report .rep-chart { border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px; }
.report .rep-chart h3 { font-size: 12px; margin-bottom: 4px; color: var(--brand-900); }
.report .rep-foot { margin-top: 14px; font-size: 10px; color: var(--muted); display: flex; justify-content: space-between; }
.order-sheet .day-block { border: 1px solid var(--border); border-radius: 9px; padding: 8px 12px; margin-bottom: 10px; }
.order-sheet .check { display: inline-block; width: 14px; height: 14px; border: 1.5px solid var(--text-2); border-radius: 3px; vertical-align: middle; }
