/* Corrales — light blue/slate theme over Bootstrap 5.
   Loaded AFTER bootstrap.min.css: these rules refine Bootstrap defaults. */
:root {
  --ink: #22303f;
  --muted: #64748b;
  --surface: #f4f7fa;
  --card: #ffffff;
  --line: #dde5ee;
  --primary: #2b6cb0;
  --primary-dark: #235a94;
  --primary-soft: #e3edf7;
  --occupied: #c07818;   /* reserved: pens with cattle */
  --danger: #b23b3b;
  --ok: #2f7d4f;
  --sidebar: #1e2a38;
  --sidebar-ink: #c8d4e0;
  --radius: 10px;
}

body.app-body {
  background: var(--surface);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 1.3rem; font-weight: 650; margin: 0.2rem 0 1.1rem; letter-spacing: -0.01em; }
h2 { font-size: 0.85rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em;
     color: var(--muted); margin: 1.6rem 0 0.6rem; }
a { color: var(--primary); }

/* ---------- Sidebar ---------- */
/* NOTE: Bootstrap forces background-color:transparent!important on .offcanvas-lg
   at >=992px, so the dark background lives on .sidebar-inner, never on .sidebar. */
.sidebar { width: 248px; --bs-offcanvas-width: 264px; border: none; }
.sidebar-inner {
  display: flex; flex-direction: column; height: 100%; min-height: 100vh;
  padding: 0.9rem 0.8rem; overflow-y: auto; background: var(--sidebar);
}
.side-brand {
  color: #fff; text-decoration: none; padding: 0.4rem 0.5rem 0.9rem;
  display: flex; align-items: center; gap: 0.6rem;
  border-bottom: 1px solid #ffffff1a; margin-bottom: 0.6rem;
}
.side-brand .wordmark, .mobile-brand {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700; font-size: 1.3rem; letter-spacing: 0.03em; color: #fff;
}
.mobile-brand { font-size: 1.1rem; display: inline-flex; align-items: center; gap: 0.45rem; }
.logo { flex-shrink: 0; display: inline-block; vertical-align: middle; }
.side-nav { display: flex; flex-direction: column; gap: 1px; }
.side-group {
  color: #7e93a8; font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.12em; padding: 0.9rem 0.6rem 0.3rem;
}
.side-link {
  color: var(--sidebar-ink); text-decoration: none; font-size: 0.92rem;
  padding: 0.5rem 0.6rem; border-radius: 7px; display: block;
}
.side-link:hover { background: #ffffff12; color: #fff; }
.side-link.active { background: var(--primary); color: #fff; font-weight: 600; }
.side-footer {
  margin-top: auto; padding: 0.9rem 0.6rem 0.2rem; border-top: 1px solid #ffffff1a;
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
}
.side-user { color: #93a7ba; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; }
.side-logout {
  color: #fff; font-size: 0.82rem; font-weight: 600; text-decoration: none;
  border: 1px solid #ffffff4d; border-radius: 999px; padding: 0.3rem 0.85rem; white-space: nowrap;
}
.side-logout:hover { color: #fff; background: #ffffff1c; border-color: #fff; }

@media (min-width: 992px) {
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; }
  .main-content { margin-left: 248px; }
}

/* ---------- Mobile top bar ---------- */
.mobile-topbar {
  background: var(--sidebar); color: #fff; display: flex; align-items: center;
  justify-content: space-between; padding: 0.55rem 0.8rem; position: sticky; top: 0; z-index: 1040;
}
.mobile-brand { font-weight: 700; font-size: 1.05rem; }

/* ---------- Layout (full-width: no wasted space on large screens) ---------- */
.main-content { padding: 1.3rem 1.1rem 3rem; }
@media (min-width: 992px) { .main-content { padding: 1.7rem 2.2rem 3rem; } }
/* Only forms stay at a readable width; tables and grids use the full screen */
form.stack { max-width: 640px; }

/* ---------- Cards (refine Bootstrap's .card) ---------- */
.card {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; margin-bottom: 1rem; background: var(--card);
}
.cards-row { display: grid; gap: 0.7rem; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 720px) { .cards-row { grid-template-columns: repeat(4, 1fr); } }
.stat { text-align: center; padding: 0.9rem 0.4rem; }
.stat .num { font-size: 1.4rem; font-weight: 700; color: var(--primary); display: block; letter-spacing: -0.02em; }
.stat .lbl { font-size: 0.78rem; color: var(--muted); }

/* Summary strip (dashboard) */
.summary-strip {
  display: flex; flex-wrap: wrap; gap: 0; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem;
}
.summary-strip .item {
  flex: 1 1 140px; padding: 0.85rem 1.1rem; border-right: 1px solid var(--line);
  min-width: 130px;
}
.summary-strip .item:last-child { border-right: none; }
.summary-strip .num { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; display: block; }
.summary-strip .lbl { font-size: 0.78rem; color: var(--muted); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem; }
.table-wrap table { border-collapse: collapse; width: 100%; font-size: 0.92rem; margin: 0; }
.table-wrap th, .table-wrap td { text-align: left; padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table-wrap th { background: #f0f4f9; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.table-wrap tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; }

/* ---------- Forms ---------- */
form.stack label, .form-field label, .inline-form label {
  display: block; font-size: 0.82rem; font-weight: 600; margin: 0.7rem 0 0.25rem; color: var(--ink);
}
input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  width: 100%; min-height: 44px; padding: 0.5rem 0.75rem;
  border: 1px solid #c3cfdd; border-radius: 8px; font-size: 1rem;
  background: #fff; color: var(--ink);
}
textarea { min-height: 70px; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px #2b6cb033;
}
.inline-form { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: end; }
.inline-form > div { flex: 1 1 150px; }

/* ---------- Buttons (refine Bootstrap) ---------- */
.btn { border-radius: 8px; font-weight: 600; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn:not(.btn-sm) { min-height: 44px; }

/* Segmented sex toggle */
.seg { display: flex; gap: 0.4rem; }
.seg input { display: none; }
.seg label {
  flex: 1; text-align: center; border: 1px solid #c3cfdd; border-radius: 8px;
  padding: 0.7rem 0; cursor: pointer; font-weight: 600; margin: 0;
}
.seg input:checked + label { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- Pen board (signature element) ---------- */
.grid-pens { display: grid; gap: 0.65rem; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.pen-card {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card);
  padding: 0.75rem 0.85rem; display: block; text-decoration: none; color: inherit;
  border-left: 4px solid #cbd5e1;
}
a.pen-card:hover { border-color: var(--primary); border-left-color: var(--primary); color: inherit; box-shadow: 0 2px 8px #22303f14; }
.pen-card.empty { background: #f8fafc; color: var(--muted); }
.pen-card.occupied { border-left-color: var(--occupied); }
.pen-card .pen-name { font-weight: 700; }
.pen-card .pen-info { font-size: 0.8rem; color: var(--muted); line-height: 1.35; }
.pen-card .pen-heads { font-weight: 700; color: var(--ink); }

/* ---------- Misc ---------- */
.flash {
  background: var(--primary-soft); border: 1px solid var(--primary); color: var(--primary-dark);
  border-radius: 8px; padding: 0.6rem 0.9rem; margin-bottom: 1rem;
}
.flash-error { background: #f9ecec; border-color: var(--danger); color: var(--danger); }
.error { color: var(--danger); }
.muted { color: var(--muted); }
.badge { font-size: 0.72rem; font-weight: 700; border-radius: 999px; padding: 0.28em 0.7em; }
.badge-active { background: #e2f0e8; color: var(--ok); }
.badge-closed { background: #e9edf2; color: var(--muted); }
.badge-off { background: #eef1f5; color: var(--muted); }
.actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.right { text-align: right; }
.mt { margin-top: 1rem; }

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(165deg, #dbe7f3 0%, #f4f7fa 55%, #e8eef6 100%);
  padding: 1rem;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.login-card {
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 2.4rem 2.2rem; width: 100%; max-width: 420px;
  box-shadow: 0 18px 45px #1e2a3826;
}
.login-card .brand {
  margin: 0; text-align: center; font-size: 2rem; font-weight: 700; color: var(--primary);
  font-family: Georgia, "Times New Roman", serif; letter-spacing: 0.03em;
  display: flex; align-items: center; justify-content: center; gap: 0.6rem;
}
.login-card .tagline { text-align: center; color: var(--muted); margin: 0.25rem 0 1.5rem; font-size: 0.92rem; }
.login-card label { display: block; font-size: 0.85rem; font-weight: 600; margin: 1rem 0 0.3rem; color: var(--ink); }
.login-card input { min-height: 50px; font-size: 1.05rem; }
.login-card .btn { margin-top: 1.5rem; min-height: 50px; font-size: 1.05rem; }
.login-card .error {
  background: #f9ecec; border: 1px solid var(--danger); border-radius: 8px;
  padding: 0.55rem 0.8rem; font-size: 0.9rem;
}

/* ---------- Charts ---------- */
.chart-box { width: 100%; }
.chart-box canvas { width: 100%; height: 220px; }
