:root {
  --bg: #F6F4EC;
  --surface: #FFFFFF;
  --surface-2: #EFEBDE;
  --border: #DDD6C3;
  --text: #23281F;
  --text-dim: #6F7566;
  --primary: #2E5C4C;
  --primary-dark: #1F4436;
  --primary-tint: #E3EBE4;
  --accent: #A9702F;
  --accent-tint: #F2E7D6;
  --good: #3D7A48;
  --warn: #A9702F;
  --bad: #9C3B33;
  --bad-tint: #F3E2DF;
  --radius: 10px;
  --radius-sm: 7px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

#app { display: flex; flex-direction: column; min-height: 100vh; }

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

/* ---------- Header ---------- */
header.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 15px 16px;
  display: flex; align-items: center; justify-content: space-between;
}
header.topbar h1 {
  font-family: var(--font-display);
  font-size: 19px; margin: 0; font-weight: 600; letter-spacing: -0.01em;
  color: var(--primary-dark);
}
header.topbar .icon-btn {
  background: none; border: none; color: var(--text-dim);
  padding: 6px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
}
header.topbar .icon-btn:hover { background: var(--surface-2); }
header.topbar .icon-btn svg { width: 19px; height: 19px; }
header.topbar .icon-btn.notif-on { color: var(--accent); }

main { flex: 1; padding: 14px 14px calc(92px + var(--safe-bottom)); max-width: 720px; margin: 0 auto; width: 100%; }

/* ---------- Bottom tab bar ---------- */
nav.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-bottom);
}
nav.tabbar button {
  flex: 1; background: none; border: none; color: var(--text-dim);
  padding: 10px 2px 8px; font-size: 10.5px; font-weight: 500; display: flex; flex-direction: column;
  align-items: center; gap: 4px; cursor: pointer; font-family: var(--font-body);
}
nav.tabbar button svg { width: 21px; height: 21px; }
nav.tabbar button.active { color: var(--primary); }
nav.tabbar button.active svg { color: var(--primary); }

/* ---------- Cards / rows ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 15px;
  margin-bottom: 10px;
}
.card h3 {
  margin: 0 0 3px; font-size: 15.5px; font-weight: 600;
  font-family: var(--font-display); color: var(--text);
}
.card .meta { color: var(--text-dim); font-size: 13px; line-height: 1.5; }
.card .row { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }

/* ---------- Dashboard stat strip ---------- */
.stat-grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 20px; overflow: hidden;
}
.stat-box {
  padding: 16px 12px; text-align: center;
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.stat-box:nth-child(2n) { border-right: none; }
.stat-box:nth-child(3), .stat-box:nth-child(4) { border-bottom: none; }
.stat-box .num {
  font-family: var(--font-display); font-size: 27px; font-weight: 600; color: var(--primary-dark);
  font-variant-numeric: tabular-nums;
}
.stat-box .label { font-size: 12px; color: var(--text-dim); margin-top: 3px; }

h2.section-title {
  font-size: 13.5px; color: var(--text-dim); font-weight: 600;
  margin: 20px 0 9px; font-family: var(--font-body);
}
h2.section-title:first-child { margin-top: 0; }

/* ---------- Status pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; padding: 3px 9px 3px 7px; border-radius: 999px;
  font-weight: 600; white-space: nowrap;
}
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.pill.active { background: var(--primary-tint); color: var(--primary); }
.pill.sold { background: var(--surface-2); color: var(--text-dim); }
.pill.deceased { background: var(--bad-tint); color: var(--bad); }
.pill.given_away { background: var(--accent-tint); color: var(--accent); }
.pill.warn { background: var(--accent-tint); color: var(--accent); }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: 18px; bottom: calc(76px + var(--safe-bottom));
  width: 50px; height: 50px; border-radius: var(--radius);
  background: var(--primary); color: #fff; border: none;
  font-size: 24px; font-weight: 400; line-height: 1;
  box-shadow: 0 4px 12px rgba(31,68,54,.28);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  z-index: 15;
}
.fab:hover { background: var(--primary-dark); }

/* ---------- Search ---------- */
.search-bar { margin-bottom: 12px; }
.search-bar input {
  width: 100%; padding: 11px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 15px; font-family: var(--font-body);
}
.search-bar input::placeholder { color: var(--text-dim); }
.search-bar input:focus { border-color: var(--primary); }

.empty-state {
  text-align: center; color: var(--text-dim); padding: 44px 16px; font-size: 14px;
  border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface);
}

/* ---------- Modal / form sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(35,40,31,.45);
  z-index: 30; display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--surface); width: 100%; max-width: 720px;
  border-radius: 16px 16px 0 0; max-height: 92vh; overflow-y: auto;
  padding: 18px 18px calc(20px + var(--safe-bottom));
  animation: slideup .18s ease-out;
}
@keyframes slideup { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.sheet-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.sheet-header h2 {
  font-size: 18px; margin: 0; font-family: var(--font-display); font-weight: 600; color: var(--primary-dark);
}
.sheet-header button {
  background: none; border: none; color: var(--text-dim); font-size: 20px; cursor: pointer;
  width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.sheet-header button:hover { background: var(--surface-2); }

label.field { display: block; margin-bottom: 13px; }
label.field span { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 5px; font-weight: 500; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 15px; font-family: var(--font-body);
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { min-height: 70px; resize: vertical; }

.btn {
  display: inline-block; width: 100%; padding: 12px; border-radius: var(--radius-sm);
  border: 1px solid transparent; font-size: 14.5px; font-weight: 600; cursor: pointer; text-align: center;
  font-family: var(--font-body);
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: var(--bad-tint); color: var(--bad); margin-top: 8px; }
.btn.ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn-row { display: flex; gap: 10px; margin-top: 16px; }
.btn-row .btn { flex: 1; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: var(--bg);
}
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 34px 26px; width: 100%; max-width: 340px; text-align: center;
}
.login-card .logo {
  width: 52px; height: 52px; margin: 0 auto 14px; color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  background: var(--primary-tint); border-radius: var(--radius);
}
.login-card .logo svg { width: 28px; height: 28px; }
.login-card h1 {
  font-family: var(--font-display); font-size: 20px; margin: 0 0 20px; font-weight: 600; color: var(--primary-dark);
}
.login-card input { margin-bottom: 12px; text-align: center; }
.error-text { color: var(--bad); font-size: 13px; margin: -4px 0 10px; }

.toast {
  position: fixed; bottom: calc(90px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--primary-dark); border: 1px solid var(--primary-dark); color: #fff;
  padding: 10px 18px; border-radius: var(--radius-sm); font-size: 13.5px; z-index: 40;
}

/* ---------- Print - cage QR label ---------- */
@media print {
  body * { visibility: hidden; }
  .print-label, .print-label * { visibility: visible; }
  .print-label {
    position: fixed; top: 0; left: 0; right: 0;
    margin: 40px auto; width: 300px;
  }
}
