/* ============================================================================
   CuraFauna — shared responsive layer
   ----------------------------------------------------------------------------
   Every app page carries its own copy of the base stylesheet inline. This file
   is linked AFTER that inline <style> on each page, so these rules win on equal
   specificity and one file controls the whole app's small-screen behaviour.

   Pairs with mobile-nav.js, which injects the menu button and backdrop and
   toggles .cf-nav-open on <body>.

   Breakpoints
     <= 1080px  tablet landscape — 4-up KPI rows go 2-up, side column stacks
     <=  900px  sidebar goes off-canvas behind a menu button
     <=  620px  phone — single column everywhere, secondary table columns hidden
   ========================================================================== */

/* ── Menu button (hidden on desktop, shown once the sidebar goes off-canvas) ── */
.cf-navtoggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-right: 12px;
  flex-shrink: 0;
  border: 1px solid var(--border, #E4E4E1);
  border-radius: 8px;
  background: var(--surface, #fff);
  color: var(--text-secondary, #4A4A47);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.cf-navtoggle:hover { background: #F0F0EE; }
.cf-navtoggle i { font-size: 19px; }

.cf-navtoggle:focus-visible {
  outline: 2px solid var(--teal, #0F6E56);
  outline-offset: 2px;
}

/* The topbar's first child is usually the title block; the button sits before it
   and must not be squeezed by the flex row. */
.topbar > .cf-navtoggle { order: -1; }

/* ── Close button inside the drawer (hidden until the drawer exists on screen) ── */
.cf-nav-close {
  display: none;
  position: absolute;
  top: 14px;
  right: 12px;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted, #8A8A86);
  cursor: pointer;
  padding: 0;
}

.cf-nav-close:hover { background: #F0F0EE; color: var(--text-secondary, #4A4A47); }
.cf-nav-close i { font-size: 18px; }

.cf-nav-close:focus-visible {
  outline: 2px solid var(--teal, #0F6E56);
  outline-offset: 2px;
}

/* ── Backdrop behind the open sidebar ── */
.cf-nav-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(20, 24, 22, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

/* ── Tablet landscape ───────────────────────────────────────────────────── */
@media (max-width: 1080px) {
  .kpi-row  { grid-template-columns: repeat(2, 1fr); }
  .two-col  { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: repeat(3, 1fr); }
}

/* ── Sidebar off-canvas ─────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .cf-navtoggle { display: inline-flex; }
  .cf-nav-close { display: inline-flex; }

  /* The drawer's own close button needs room beside the wordmark. */
  .logo { padding-right: 52px; }

  /* adoption.html shipped its own `.sidebar { display: none }` rule at 640px —
     restore it so the drawer works there too. */
  .sidebar {
    display: flex;
    transform: translateX(-100%);
    transition: transform 0.24s ease;
    will-change: transform;
    width: 264px;
    min-width: 264px;
  }

  body.cf-nav-open .sidebar {
    transform: translateX(0);
    box-shadow: 0 0 44px rgba(0, 0, 0, 0.20);
  }

  body.cf-nav-open .cf-nav-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  /* Stop the page scrolling underneath the open drawer. */
  body.cf-nav-open { overflow: hidden; }

  /* .main is a flex item of <body>. Flex items default to min-width:auto, so any
     wide child (a topbar button row, a settings card) stretches .main past the
     viewport instead of being constrained by it. min-width:0 lets it shrink, which
     is what makes the overflow-x containers below actually scroll. */
  .main,
  .main .topbar,
  .main .content,
  .main .content > *,
  .settings-body,
  .settings-card { min-width: 0; }

  .main { margin-left: 0; }

  .content { padding: 18px 16px; }
  .topbar  { padding: 12px 16px; }

  /* Long breadcrumbs and titles truncate rather than pushing the topbar wider. */
  .topbar > div:first-of-type { min-width: 0; }
  .breadcrumb { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Nav rows get finger-sized on touch. */
  .nav-item { padding: 11px 12px; font-size: 14px; }

  /* Wide tables scroll inside their card rather than pushing the page sideways. */
  .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { min-width: 560px; }

  .staff-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .cf-nav-backdrop { transition: none; }
}

/* ── Phone ──────────────────────────────────────────────────────────────── */
@media (max-width: 620px) {
  /* Four full-width KPI cards push the actual content a screen and a half down.
     Two-up keeps the whole summary above the fold on a phone. */
  .kpi-row  { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi      { padding: 12px 13px; }
  .kpi-label { font-size: 10px; margin-bottom: 6px; }
  .kpi-val  { font-size: 24px; }
  .kpi-sub  { font-size: 10px; margin-top: 4px; }

  .stat-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }

  /* Every two-up / three-up form row collapses. */
  .field-row,
  .field-row.three,
  .field-grid,
  .field-grid.three,
  .field-grid.full { grid-template-columns: 1fr; }

  .field.span2, .field.span3 { grid-column: span 1; }

  .content { padding: 14px 12px; gap: 12px; }
  .topbar  { padding: 11px 12px; }

  .page-title { font-size: 15px; }
  .page-sub   { font-size: 11px; }

  /* Topbar action buttons wrap under the title instead of overflowing. */
  .topbar { flex-wrap: wrap; gap: 8px; }
  .topbar-actions { width: 100%; display: flex; gap: 8px; }
  .topbar-actions .btn,
  .topbar-actions .btn-primary { flex: 1; justify-content: center; }

  /* Filter bars stack. */
  .filter-bar { flex-direction: column; align-items: stretch; gap: 8px; }
  .filter-bar .search-wrap,
  .filter-bar .search-input,
  .filter-bar .filter-select { width: 100%; }

  /* Animal profile header stacks photo above details. */
  .profile-header { flex-direction: column; align-items: flex-start; gap: 14px; }
  .meta-row { grid-template-columns: repeat(2, 1fr); gap: 12px; }

  /* Tabs scroll horizontally rather than wrapping into a broken block. */
  .tabs, .settings-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar, .settings-tabs::-webkit-scrollbar { display: none; }
  .tab, .s-tab { white-space: nowrap; flex-shrink: 0; }

  /* Vaccination rows on the animal profile are a 4-col grid — go 2-col. */
  .vacc-header { display: none; }
  .vacc-row { grid-template-columns: 1fr 1fr; row-gap: 4px; }

  /* Modals fill the screen instead of overflowing it. */
  .modal { width: calc(100vw - 24px); max-width: none; max-height: 88vh; overflow-y: auto; }
  .modal-actions { flex-direction: column-reverse; gap: 8px; }
  .modal-actions .btn, .modal-actions .btn-primary { width: 100%; justify-content: center; }

  /* Length-of-stay milestone labels collide at this width. */
  .stay-bar-marker-label { font-size: 9px; }

  /* Secondary table columns are hidden on phones — the full record is one tap
     away on the detail page, and a 7-column table is unreadable here.
     Column order is fixed by the page templates; see notes in each page. */

  /* animals.html — ANIMAL | SPECIES | SEX | AGE | INTAKE | DAYS | STATUS */
  .page-animals .table th:nth-child(3), .page-animals .table td:nth-child(3),
  .page-animals .table th:nth-child(4), .page-animals .table td:nth-child(4),
  .page-animals .table th:nth-child(5), .page-animals .table td:nth-child(5),
  .page-animals .table th:nth-child(6), .page-animals .table td:nth-child(6) { display: none; }

  /* vaccinations.html — ANIMAL | SPECIES | VACCINE | GIVEN | NEXT DUE | BY */
  .page-vaccinations .table th:nth-child(2), .page-vaccinations .table td:nth-child(2),
  .page-vaccinations .table th:nth-child(4), .page-vaccinations .table td:nth-child(4),
  .page-vaccinations .table th:nth-child(6), .page-vaccinations .table td:nth-child(6) { display: none; }

  /* adoptions.html — ADOPTER | ANIMAL | DATE | PROCESSED BY | NOTES */
  .page-adoptions .table th:nth-child(4), .page-adoptions .table td:nth-child(4),
  .page-adoptions .table th:nth-child(5), .page-adoptions .table td:nth-child(5) { display: none; }

  /* dashboard.html recent intakes — ANIMAL | SPECIES | INTAKE DATE | STATUS */
  .page-dashboard .table th:nth-child(3), .page-dashboard .table td:nth-child(3) { display: none; }

  /* With columns removed the remaining ones fit without sideways scrolling. */
  .page-animals .table,
  .page-vaccinations .table,
  .page-adoptions .table,
  .page-dashboard .table { min-width: 0; }
}

/* ── Login / set-password (no sidebar, just centred cards) ──────────────── */
@media (max-width: 620px) {
  body.page-auth { padding: 16px; }
  .page-auth .login-wrap { width: 100%; max-width: 100%; }
  .page-auth .card { width: 100%; max-width: 100%; }
}
