:root {
  --ink: #14231c;
  --ink-2: #3c4b43;
  --muted: #6a7870;
  --paper: #fafbf7;
  --surface: #ffffff;
  --line: #dde5da;
  --meadow: #e6f0e4;
  --pasture: #2f7a4b;
  --pasture-d: #1e5a37;
  --forest: #12261b;
  --hay: #c9962b;
  --hay-bg: #f8efd5;
  --alert: #b8432f;
  --alert-bg: #f7e3de;
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --body: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 15px/1.55 var(--body);
  color: var(--ink);
  background: var(--paper);
}

h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: -.01em; margin: 0; line-height: 1.15; }
a { color: var(--pasture-d); }
.muted { color: var(--muted); }
.err { color: var(--alert); min-height: 1.3em; margin: .3rem 0; white-space: pre-line; font-size: 14px; }

:focus-visible { outline: 3px solid var(--hay); outline-offset: 2px; }

/* ---------- Botones ---------- */
.btn {
  background: var(--pasture); color: #fff; border: 1px solid var(--pasture); border-radius: 999px;
  padding: .55rem 1.15rem; font: 600 14px var(--body); cursor: pointer; transition: background .15s;
}
.btn:hover { background: var(--pasture-d); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.ghost { background: transparent; color: var(--pasture-d); border-color: var(--line); }
.btn.ghost:hover { background: var(--meadow); border-color: var(--meadow); }
.btn.danger { background: transparent; color: var(--alert); border-color: var(--line); }
.btn.danger:hover { background: var(--alert-bg); border-color: var(--alert-bg); }
.btn.small { padding: .28rem .8rem; font-size: 13px; font-weight: 500; }
.btn.block { width: 100%; padding: .7rem; }

/* ---------- Formularios ---------- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); }
input, select, textarea {
  display: block; width: 100%; margin-top: .3rem; padding: .55rem .7rem;
  font: 15px var(--body); color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--pasture); outline-offset: -1px; border-color: var(--pasture); }
input[type=checkbox] { width: 20px; height: 20px; margin-top: .6rem; accent-color: var(--pasture); }
input[type=file] { padding: .4rem; }
textarea { min-height: 84px; resize: vertical; }

/* ---------- Marca ---------- */
.mark {
  display: inline-block; width: 28px; height: 28px; flex: none;
  background: var(--pasture); border-radius: 60% 40% 55% 45% / 50% 60% 40% 50%;
  box-shadow: inset -6px -5px 0 rgba(0,0,0,.14);
}

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { position: relative; overflow: hidden; }
.login-art svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.login-quote { position: absolute; left: 3rem; top: 3rem; margin: 0; font: 700 clamp(26px, 3.2vw, 40px)/1.15 var(--display); color: var(--forest); max-width: 14em; }
.login-form { align-self: center; justify-self: center; width: min(380px, 88vw); display: grid; gap: .9rem; padding: 2rem 0; }
.login-form h1 { font-size: 32px; margin: .4rem 0 .6rem; }

/* ---------- Estructura ---------- */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { background: var(--forest); color: #e8f1e6; padding: 1.2rem .8rem; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: .6rem; font: 700 21px var(--display); padding: 0 .6rem 1.4rem; }
.sidebar nav { display: grid; gap: 2px; overflow: auto; flex: 1; align-content: start; }
.sidebar nav a { display: flex; align-items: center; gap: .7rem; color: #bcd0bf; text-decoration: none; padding: .55rem .7rem; border-radius: 10px; font-weight: 500; }
.sidebar nav a svg { width: 18px; height: 18px; flex: none; }
.sidebar nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar nav a.active { background: var(--paper); color: var(--forest); font-weight: 600; }
.owner-pick { margin: 0 .3rem .8rem; color: #bcd0bf; }
.owner-pick + .owner-pick { margin-bottom: 1rem; }
.owner-pick select { background: rgba(255,255,255,.08); color: #fff; border-color: rgba(255,255,255,.22); border-radius: 10px; }
.owner-pick select option { color: var(--ink); }
.filter-note { background: var(--hay-bg); color: #6b4a00; border-radius: 10px; padding: .5rem .8rem; margin: -.4rem 0 1.1rem; font-size: 14px; }
.owner-tag { display: block; color: var(--pasture-d) !important; font-weight: 600; font-size: 12.5px !important; margin-top: .15rem; }
.nav-sep { height: 1px; background: rgba(255,255,255,.12); margin: .6rem .7rem; }
.sidebar-foot { display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .8rem .4rem 0; border-top: 1px solid rgba(255,255,255,.14); font-size: 13px; color: #bcd0bf; }
.sidebar-foot .btn.ghost { color: #fff; border-color: rgba(255,255,255,.3); }
.sidebar-foot .btn.ghost:hover { background: rgba(255,255,255,.1); }

.content { min-width: 0; }
.topbar { display: none; align-items: center; gap: .75rem; padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); font-weight: 600; }
main { padding: 2rem 2.2rem 3rem; max-width: 1240px; }

.bar { display: flex; flex-wrap: wrap; align-items: center; gap: .8rem; margin-bottom: 1.3rem; }
.bar h2 { font-size: 32px; margin-right: auto; }
.bar input[type=search] { width: 250px; margin: 0; border-radius: 999px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 1.2rem 1.3rem; }
.panel h3 { font-size: 18px; margin-bottom: .2rem; }
.panel .sub { color: var(--muted); font-size: 13px; margin: 0 0 .8rem; }

/* ---------- Tabla ---------- */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; font-size: 13px; color: var(--muted); padding: .5rem .7rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: .65rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #f4f8f1; }
td.actions { white-space: nowrap; text-align: right; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.pill { display: inline-block; padding: .08rem .65rem; border-radius: 999px; background: var(--meadow); color: var(--pasture-d); font-size: 12.5px; font-weight: 600; }
.pill.warn { background: var(--hay-bg); color: #7a5600; }
.pill.bad { background: var(--alert-bg); color: var(--alert); }
.pill.off { background: #eceeea; color: var(--ink-2); }

/* ---------- Filtros (chips) ---------- */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1.2rem; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 999px; padding: .3rem .9rem; font: 500 13.5px var(--body); cursor: pointer; }
.chip:hover { background: var(--meadow); }
.chip[aria-pressed=true] { background: var(--forest); border-color: var(--forest); color: #fff; }

/* ---------- Galería de ganado ---------- */
.herd { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 1.1rem; }
.cow { display: block; width: 100%; text-align: left; padding: 0; border: 1px solid var(--line); background: var(--surface); border-radius: 18px 18px 18px 6px; overflow: hidden; cursor: pointer; font: inherit; color: inherit; transition: transform .15s, border-color .15s; }
.cow:hover { transform: translateY(-3px); border-color: var(--pasture); }
.cow-photo { aspect-ratio: 4 / 3; background: var(--meadow); position: relative; display: grid; place-items: center; overflow: hidden; }
.cow-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cow-photo .tagbig { font: 700 44px var(--display); color: rgba(30, 90, 55, .28); }
.cow-photo .pill { position: absolute; top: .6rem; left: .6rem; }
.cow-info { padding: .75rem .9rem .9rem; }
.cow-info strong { display: block; font: 700 18px var(--display); }
.cow-info span { color: var(--muted); font-size: 13px; }

/* ---------- Ficha de la res ---------- */
.back { margin-bottom: 1rem; }
.hero { display: grid; grid-template-columns: minmax(260px, 420px) 1fr; gap: 1.6rem; align-items: stretch; margin-bottom: 1.4rem; }
.hero-photo { border-radius: 24px 24px 24px 8px; overflow: hidden; background: var(--meadow); aspect-ratio: 4 / 3; display: grid; place-items: center; position: relative; border: 1px solid var(--line); }
.hero-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hero-photo .tagbig { font: 700 90px var(--display); color: rgba(30, 90, 55, .25); }
.hero-text h2 { font-size: clamp(34px, 5vw, 52px); }
.hero-text .tag { color: var(--muted); font-size: 16px; margin: .2rem 0 .8rem; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .9rem 1.4rem; margin: 1.1rem 0; }
.facts dt { font-size: 13px; color: var(--muted); }
.facts dd { margin: 0; font: 600 18px var(--display); }
.hero-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: auto; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.1rem; }
.cols .wide { grid-column: 1 / -1; }
.kin { display: flex; flex-wrap: wrap; gap: .6rem; }
.kin button { display: flex; align-items: center; gap: .6rem; background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: .25rem .9rem .25rem .25rem; cursor: pointer; font: 500 14px var(--body); color: var(--ink); }
.kin button:hover { border-color: var(--pasture); background: var(--meadow); }
.kin .avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--meadow); overflow: hidden; display: grid; place-items: center; font: 700 11px var(--display); color: var(--pasture-d); }
.kin .avatar img { width: 100%; height: 100%; object-fit: cover; }
.kin-label { font-size: 13px; color: var(--muted); margin: .9rem 0 .4rem; }
.kin-label:first-child { margin-top: 0; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 1rem; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 .9rem .9rem; }
.timeline li::before { content: ""; position: absolute; left: -1.42rem; top: .45rem; width: 10px; height: 10px; border-radius: 50%; background: var(--pasture); border: 2px solid var(--surface); }
.timeline li.enfermedad::before { background: var(--alert); }
.timeline li.pesaje::before { background: var(--hay); }
.timeline li.muerte::before { background: var(--ink); }
.death-note { background: var(--alert-bg); color: #7a2a1c; border-radius: 10px; padding: .6rem .85rem; margin: .2rem 0 .8rem; }
.timeline .when { font-size: 13px; color: var(--muted); }

/* ---------- Resumen ---------- */
.lead { display: grid; grid-template-columns: 1fr 280px; gap: 1.1rem; margin-bottom: 1.1rem; }
.lead-number { font: 700 clamp(44px, 6vw, 68px)/1 var(--display); color: var(--pasture-d); letter-spacing: -.02em; }
.lead-number small { font-size: .38em; color: var(--muted); font-weight: 500; letter-spacing: 0; margin-left: .2rem; }
.lead-side { display: grid; gap: 1.1rem; align-content: start; }
.fact-list { list-style: none; margin: 0; padding: 0; }
.fact-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.fact-list li:last-child { border-bottom: 0; }
.fact-list b { font-family: var(--display); font-size: 17px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.1rem; }
.ok { color: var(--pasture-d); }

/* ---------- Gráficos ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font: 12px var(--body); fill: var(--muted); }
.hbar { display: grid; gap: .55rem; }
.hbar-row { display: grid; grid-template-columns: minmax(90px, 32%) 1fr auto; gap: .7rem; align-items: center; font-size: 14px; }
.hbar-row .track { background: var(--meadow); border-radius: 0 6px 6px 0; height: 14px; }
.hbar-row .fill { background: var(--pasture); height: 100%; border-radius: 0 6px 6px 0; min-width: 2px; }
.hbar-row b { font-variant-numeric: tabular-nums; }
.tip { position: fixed; z-index: 30; pointer-events: none; background: var(--forest); color: #fff; padding: .35rem .65rem; border-radius: 8px; font-size: 13px; white-space: nowrap; transform: translate(-50%, -120%); }

/* ---------- Diálogo / toast ---------- */
dialog { border: 0; border-radius: 20px; padding: 1.6rem; width: min(660px, 94vw); box-shadow: 0 24px 70px rgba(10, 25, 15, .35); }
dialog::backdrop { background: rgba(14, 30, 20, .55); }
dialog h3 { font-size: 24px; margin-bottom: 1.1rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .95rem; }
.grid .full { grid-column: 1 / -1; }
.actions-row { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.1rem; }
.hint { font-size: 12.5px; font-weight: 400; color: var(--muted); }
.toast { position: fixed; bottom: 1.3rem; left: 50%; transform: translateX(-50%); background: var(--forest); color: #fff;
  padding: .65rem 1.2rem; border-radius: 999px; z-index: 40; }

/* ---------- Móvil ---------- */
@media (max-width: 820px) {
  .login { grid-template-columns: 1fr; }
  .login-art { height: 190px; }
  .login-quote { left: 1.4rem; top: 1.2rem; font-size: 22px; }
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 5; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .topbar { display: flex; position: sticky; top: 0; z-index: 4; }
  main { padding: 1.1rem 1rem 2.5rem; }
  .bar h2 { font-size: 26px; }
  .bar input[type=search] { width: 100%; order: 3; }
  .lead { grid-template-columns: 1fr; }
  .hero { grid-template-columns: 1fr; }
  .herd { grid-template-columns: repeat(2, 1fr); gap: .8rem; }
  .cols, .grid2 { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
