:root {
  /* Critter Outlaws brand: red + black, sampled from the official logo (#F10816). */
  --red: #c8102e;        /* buttons and fills; white text 5.9:1 */
  --red-bright: #f10816; /* logo red: accents, borders, focus rings (non-text) */
  --red-dark: #8b0a1a;   /* banners, danger; white text 9.6:1 */
  --red-tint: #fde8ea;
  --black: #111111;
  --black-2: #1d1d1d;
  --black-3: #2a2a2a;
  --on-dark: #ffffff;
  --on-dark-soft: #cfcfcf; /* 12:1 on --black */
  --paper: #f5f5f5;
  --paper-2: #e8e8e8;
  --card: #ffffff;
  --ink: #111111;
  --ink-soft: #4a4a4a;   /* 8.4:1 on --paper */
  --line: #dcdcdc;
  --danger: #8b0a1a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 22px rgba(0, 0, 0, 0.06);
  --sans: "Segoe UI", Roboto, system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --display: "Arial Black", "Segoe UI Black", Roboto, system-ui, sans-serif;
  --tabh: 64px;
  --toph: 64px;
  color-scheme: light;
}

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

html, body { margin: 0; padding: 0; }
body {
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
}

img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
p { margin: 0; }

:focus-visible {
  outline: 3px solid var(--red-bright);
  outline-offset: 2px;
}
h1:focus { outline: none; }
h1:focus-visible { outline: 3px solid var(--red-bright); outline-offset: 3px; }

h1, h2, h3 {
  font-family: var(--sans);
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.2;
  color: var(--ink);
}
h2 { font-size: 1.15rem; margin: 0.2rem 0; }
h3 { font-size: 1.02rem; margin: 0.15rem 0; }

.shell { min-height: 100dvh; }

.topbar {
  background: var(--black);
  color: var(--on-dark);
  border-bottom: 3px solid var(--red-bright);
  padding: 0 0.9rem;
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-height: calc(var(--toph) - 3px);
  color: inherit;
  text-decoration: none;
}
.brand img { width: auto; height: 50px; display: block; }
.brand-name { display: block; font-family: var(--display); font-weight: 900; font-size: 1.2rem; line-height: 1.05; letter-spacing: 0.01em; text-transform: uppercase; }
.brand-sub {
  display: block;
  color: var(--on-dark-soft);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sync-banner {
  background: var(--red-dark);
  color: var(--on-dark);
  position: sticky;
  top: var(--toph);
  z-index: 29;
}
.sync-banner p { margin: 0; padding: 0.6rem 0.9rem; font-size: 0.92rem; }
.sync-banner a { color: var(--on-dark); font-weight: 800; text-decoration: underline; text-underline-offset: 2px; }

.sidebar {
  display: none;
  background: var(--black);
  color: var(--on-dark-soft);
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--black);
  color: var(--on-dark-soft);
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 3px solid var(--red-bright);
}

.nav-link {
  min-height: 48px;
  color: inherit;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  background: transparent;
  border: 0;
  font-family: inherit;
}
.tabbar .nav-link {
  flex-direction: column;
  min-height: var(--tabh);
  font-size: 0.72rem;
  padding: 0.35rem 0.15rem 0.4rem;
}
.tabbar .nav-link { position: relative; font-weight: 700; }
.tabbar .nav-link.is-active,
.sidebar .nav-link.is-active { color: var(--on-dark); }
.tabbar .nav-link.is-active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 22%;
  right: 22%;
  height: 4px;
  border-radius: 0 0 4px 4px;
  background: var(--red-bright);
}
.tabbar .nav-link.is-active .icon { color: var(--red-bright); }
.icon { width: 22px; height: 22px; flex: 0 0 auto; }

main {
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 1rem 1rem calc(var(--tabh) + env(safe-area-inset-bottom) + 1.25rem);
}

.stack { display: grid; gap: 0.9rem; align-content: start; }
.stack.tight { gap: 0.55rem; }
.page-head { display: grid; gap: 0.45rem; }
.page-head h1 { font-family: var(--display); font-weight: 900; font-size: 1.8rem; margin: 0; text-transform: uppercase; letter-spacing: 0; }
.eyebrow {
  margin: 0;
  color: var(--red);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.lede { color: var(--ink-soft); }
.muted, .hint { color: var(--ink-soft); }
.hint { font-size: 0.9rem; }
.preserve { white-space: pre-wrap; overflow-wrap: anywhere; }

.card, .empty {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.95rem 1rem;
  box-shadow: var(--shadow);
}
.card > h2:first-child, .empty > h2:first-child { padding-bottom: 0.35rem; border-bottom: 3px solid var(--red-bright); display: inline-block; }
.empty { display: grid; gap: 0.55rem; }
.empty h2, .card h2:first-child { margin-top: 0; }

.callout {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 6px solid var(--black);
  border-radius: 12px;
  padding: 1rem;
}
.callout-danger, .card.callout-danger {
  background: var(--red-tint);
  border: 1px solid #f3b8bf;
  border-left: 6px solid var(--red-bright);
  box-shadow: none;
}

.btn {
  min-height: 48px;
  padding: 0.65rem 1rem;
  border-radius: 10px;
  border: 2px solid var(--black);
  background: var(--card);
  color: var(--ink);
  font-weight: 800;
  letter-spacing: 0.01em;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  text-align: center;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--red); border-color: var(--red); color: var(--on-dark); }
.btn-primary:active { background: var(--red-dark); border-color: var(--red-dark); }
.btn-dark { background: var(--black); border-color: var(--black); color: var(--on-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--on-dark); }
.btn-ghost { background: transparent; }
.btn-small { min-height: 40px; padding: 0.35rem 0.75rem; font-size: 0.92rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.form-actions { display: flex; flex-direction: column; gap: 0.5rem; }
.form-actions .btn { width: 100%; }
.row-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.row-actions .btn { flex: 1 1 8rem; }

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--red);
  font-weight: 800;
  text-decoration: none;
}

.section-head { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; }
.section-head h2 { margin: 0; }

.stat-grid, .action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-height: 96px;
  padding: 0.85rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 4px solid var(--red-bright);
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
}
.stat b {
  font-family: var(--display);
  color: var(--red);
  font-size: 1.9rem;
  font-weight: 900;
  line-height: 1;
}
.stat span, .stat small { color: var(--ink-soft); }
.stat small { font-size: 0.78rem; }

.stack-list { display: grid; gap: 0.55rem; }
.record {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  padding: 0.85rem 0.95rem;
  min-height: 48px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--black);
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
}
.record:active { background: var(--red-tint); border-left-color: var(--red-bright); }
.record-title { font-weight: 800; }
.record-meta { color: var(--ink-soft); font-size: 0.92rem; overflow-wrap: anywhere; }

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0.05rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 750;
  background: var(--paper-2);
  color: var(--ink);
}
.chip-lead, .chip-due, .chip-upcoming { background: #fff1cc; color: #6b4a00; }
.chip-scheduled { background: #e4ebf3; color: #243e5c; }
.chip-in-progress, .chip-active { background: #e3f0e7; color: #1d5a38; }
.chip-completed, .chip-logged { background: #e7eee8; color: #234232; }
.chip-cancelled, .chip-expired, .chip-closed, .chip-void, .chip-unknown { background: #eeeae4; color: #5c564c; }
.chip-overdue { background: var(--red); color: var(--on-dark); }

.filters { display: flex; gap: 0.45rem; overflow-x: auto; padding-bottom: 0.15rem; }
.filter-btn {
  flex: 0 0 auto;
  min-height: 44px;
  border-radius: 999px;
  border: 2px solid var(--black);
  background: var(--card);
  padding: 0.35rem 0.85rem;
  font: inherit;
  font-weight: 700;
  color: var(--ink);
}
.filter-btn[aria-pressed="true"] {
  background: var(--black);
  border-color: var(--black);
  color: var(--on-dark);
}

.search, input, select, textarea {
  width: 100%;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid #9a9a9a;
  background: white;
  padding: 0.65rem 0.75rem;
}
input:focus, select:focus, textarea:focus { border-color: var(--black); }
textarea { min-height: 7rem; resize: vertical; line-height: 1.4; }
.search { background: white; }

.field { display: grid; gap: 0.35rem; }
.field-label { font-weight: 800; }
.req {
  margin-left: 0.45rem;
  color: var(--red);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.form-errors {
  background: var(--red-tint);
  border: 1px solid #f3b8bf;
  color: var(--danger);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
}
.form-errors p { margin: 0.15rem 0; }

fieldset.card { margin: 0; }
legend { font-weight: 750; padding: 0 0.3rem; }

.repeat-block { display: grid; gap: 0.7rem; }
.repeat-row, .repeat-card {
  display: grid;
  gap: 0.45rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
}
.repeat-row { grid-template-columns: 7.2rem minmax(0, 1fr) auto; align-items: center; }
.addr-grid { display: grid; grid-template-columns: minmax(0, 1fr) 4.5rem 6rem; gap: 0.45rem; }
.check-row { display: flex; gap: 0.7rem; align-items: flex-start; }
.check-row input { width: 1.35rem; min-height: 1.35rem; height: 1.35rem; margin-top: 0.15rem; }

.facts { display: grid; grid-template-columns: 7.2rem minmax(0, 1fr); gap: 0.45rem 0.75rem; margin: 0; }
.facts dt { color: var(--ink-soft); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.plain-list { margin: 0; padding-left: 1.1rem; display: grid; gap: 0.25rem; }

.bars { display: grid; gap: 0.45rem; }
.bar-row { display: grid; grid-template-columns: 6.5rem minmax(0, 1fr) auto; gap: 0.5rem; align-items: center; min-height: 32px; }
.bar-track { background: var(--paper-2); border-radius: 999px; height: 12px; overflow: hidden; }
.bar-fill { background: var(--red); height: 100%; min-width: 4px; border-radius: inherit; }
.bar-value { font-variant-numeric: tabular-nums; font-weight: 750; }
.pipeline { list-style: none; padding: 0; margin: 0; }
.pipeline li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  min-height: 48px;
  border-top: 1px solid var(--line);
}
.pipeline a { color: var(--red); font-weight: 800; text-decoration: none; }
.steps { margin: 0; padding-left: 1.2rem; display: grid; gap: 0.4rem; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.6rem; }
.photo-tile, .photo-open {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}
.photo-open img, .photo-tile img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 12px;
  background: var(--paper-2);
}
.photo-tile.is-removed img { opacity: 0.35; }
.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
}
label.btn { position: relative; }

.modal-backdrop, .sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0.75rem;
}
.sheet-backdrop { z-index: 55; padding: 0; }
.modal, .lightbox {
  width: min(560px, 100%);
  background: var(--card);
  color: var(--ink);
  border-radius: 14px;
  border-top: 4px solid var(--red-bright);
  padding: 1rem;
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.75rem;
}
.modal h2, .sheet h2 { margin: 0; }
.lightbox img { width: 100%; max-height: 70dvh; object-fit: contain; border-radius: 12px; background: var(--black); }
.sheet {
  width: min(640px, 100%);
  background: var(--card);
  color: var(--ink);
  border-radius: 18px 18px 0 0;
  padding: 0.85rem 0.85rem calc(0.9rem + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.sheet-link {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.35rem 0.7rem;
  border-radius: 12px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 700;
}
.sheet-link.is-active { background: var(--red-tint); color: var(--danger); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabh) + env(safe-area-inset-bottom) + 12px);
  transform: translateX(-50%);
  z-index: 70;
  width: max-content;
  max-width: calc(100% - 1.5rem);
  background: var(--black);
  color: var(--on-dark);
  border: 2px solid var(--red-bright);
  border-radius: 999px;
  padding: 0.75rem 1rem;
  text-align: center;
}
.noscript {
  display: block;
  background: var(--red-tint);
  border: 1px solid #f3b8bf;
  border-radius: 12px;
  padding: 0.8rem;
}

@media (max-width: 560px) {
  .repeat-row { grid-template-columns: 1fr; }
}
@media (max-width: 380px) {
  .addr-grid { grid-template-columns: 1fr 1fr; }
  .addr-grid .span-2 { grid-column: 1 / -1; }
  .facts { grid-template-columns: 1fr; }
  .facts dd { margin-bottom: 0.35rem; }
  .bar-row { grid-template-columns: 5.2rem minmax(0, 1fr) auto; }
}

@media (min-width: 720px) {
  .form-actions { flex-direction: row; justify-content: flex-end; }
  .form-actions .btn { width: auto; min-width: 9rem; }
  .row-actions .btn { flex: 0 0 auto; }
  .action-grid { grid-template-columns: repeat(3, 1fr); }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .modal-backdrop { align-items: center; }
}

@media (min-width: 960px) {
  .shell {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    grid-template-areas:
      "side top"
      "side banner"
      "side main";
    align-items: start;
  }
  .sidebar {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    grid-area: side;
    position: sticky;
    top: 0;
    min-height: 100dvh;
    padding: 0.85rem 0.7rem;
  }
  .sidebar-label {
    margin: 0.4rem 0.85rem 0.35rem;
    color: var(--red-bright);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }
  .sidebar .nav-link {
    justify-content: flex-start;
    gap: 0.7rem;
    min-height: 48px;
    padding: 0 0.8rem;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 650;
  }
  .sidebar .nav-link.is-active { background: var(--red); }
  .sidebar .nav-link:not(.is-active):hover { background: var(--black-3); color: var(--on-dark); }
  .topbar { grid-area: top; }
  .sync-banner { grid-area: banner; top: var(--toph); }
  main { grid-area: main; padding: 1.25rem 1.5rem 3rem; }
  .tabbar { display: none; }
  .toast { bottom: 1.25rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
