/* Hutch & Hen — warm barn theme. Always light, even in OS dark mode. */
:root {
  color-scheme: light;
  --cream: #FFF9EC;
  --cream-dark: #F5EAD0;
  --barn: #B5452F;
  --barn-dark: #8E3524;
  --barn-pale: #F7DEd4;
  --straw: #E8A93D;
  --straw-dark: #C07F1A;
  --leaf: #7CB342;
  --leaf-dark: #5A8F2A;
  --leaf-pale: #E8F3D8;
  --sky: #4FA8DE;
  --sky-pale: #DFF1FB;
  --ink: #3A2E24;
  --ink-soft: #7A6A58;
  --card: #FFFFFF;
  --danger: #E05A4F;
  --money: #2E7D4F;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(120, 70, 30, 0.10);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--cream);
  color: var(--ink);
  color-scheme: light;
  padding-bottom: 78px;
}

/* Header */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: linear-gradient(135deg, var(--barn) 0%, #C65B41 100%);
  color: #fff;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { margin: 0; font-size: 1.4rem; letter-spacing: 0.5px; }
.tagline { margin: 0; font-size: 0.75rem; opacity: 0.92; }
.brand-mark { filter: drop-shadow(0 2px 2px rgba(0,0,0,0.15)); }

.pro-badge {
  background: var(--straw); color: var(--ink);
  font-weight: 800; font-size: 0.75rem; letter-spacing: 1px;
  padding: 5px 12px; border-radius: 999px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* Screens */
#app { max-width: 720px; margin: 0 auto; padding: 12px 14px 24px; }
.screen { display: none; }
.screen.active { display: block; }
h2 { font-size: 1.25rem; margin: 14px 4px 10px; color: var(--barn-dark); }
h3 { color: var(--barn-dark); }

/* Cards */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px;
  border: 1px solid #F0E2C8;
}

/* Buttons */
.btn {
  display: inline-block; border: none; border-radius: 999px;
  padding: 12px 22px; font-size: 1rem; font-weight: 700;
  cursor: pointer; text-align: center; text-decoration: none;
  transition: transform 0.05s ease;
  min-height: 48px;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--barn); color: #fff; }
.btn-gold { background: var(--straw); color: var(--ink); }
.btn-sky { background: var(--sky); color: #fff; }
.btn-leaf { background: var(--leaf); color: #fff; }
.btn-money { background: var(--money); color: #fff; }
.btn-outline { background: #fff; color: var(--barn-dark); border: 2px solid var(--barn); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 8px 16px; font-size: 0.85rem; min-height: 40px; }
.btn-block { display: block; width: 100%; margin-top: 10px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Bottom nav */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: #fff;
  border-top: 1px solid #EADFC2;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 12px rgba(120,70,30,0.08);
}
.nav-btn {
  flex: 1; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 0.7rem; color: var(--ink-soft); padding: 4px;
  border-radius: 12px; min-height: 56px; justify-content: center;
}
.nav-btn.active { color: var(--barn-dark); font-weight: 700; background: var(--barn-pale); }
.nav-ico { font-size: 1.4rem; }
.nav-cta .nav-ico {
  background: var(--straw); border-radius: 50%;
  width: 46px; height: 46px; display: flex; align-items: center; justify-content: center;
  margin-top: -18px; box-shadow: 0 2px 8px rgba(192,127,26,0.5); font-size: 1.5rem;
}

/* Tabs */
.tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.tab-btn {
  flex: 1; border: 2px solid #EFE0C2; background: #fff; color: var(--ink-soft);
  border-radius: 12px; padding: 10px 4px; font-size: 0.9rem; font-weight: 700; cursor: pointer;
  min-height: 48px;
}
.tab-btn.active { border-color: var(--barn); background: var(--barn-pale); color: var(--barn-dark); }

/* Stat grid */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat-grid.two { grid-template-columns: repeat(2, 1fr); }
.stat-box { background: #fff; border-radius: var(--radius); padding: 12px 6px; text-align: center; box-shadow: var(--shadow); border: 1px solid #F0E2C8; }
.stat-box .num { font-size: 1.4rem; font-weight: 800; color: var(--barn-dark); }
.stat-box .num.green { color: var(--money); }
.stat-box .num.red { color: var(--danger); }
.stat-box .lbl { font-size: 0.72rem; color: var(--ink-soft); margin-top: 2px; }

/* Lists */
.animal-row, .flock-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: #fff; border: 2px solid #EFE0C2; border-radius: 12px;
  padding: 12px; margin-bottom: 8px; cursor: pointer;
  font-size: 1rem; text-align: left; color: var(--ink);
  min-height: 60px;
}
.animal-row .a-ico, .flock-row .a-ico { font-size: 1.8rem; flex: 0 0 auto; }
.animal-row .a-main, .flock-row .a-main { flex: 1 1 auto; min-width: 0; }
.animal-row .a-name { font-weight: 700; }
.animal-row .a-sub, .flock-row .a-sub { font-size: 0.82rem; color: var(--ink-soft); }
.animal-row .a-chev { color: var(--ink-soft); flex: 0 0 auto; }

.badge {
  display: inline-block; font-size: 0.72rem; font-weight: 700;
  padding: 3px 10px; border-radius: 999px; white-space: nowrap;
}
.badge-live { background: var(--leaf-pale); color: var(--leaf-dark); }
.badge-out { background: #EFE0C2; color: var(--ink-soft); }
.badge-money { background: #DDF0E3; color: var(--money); }
.badge-cost { background: var(--barn-pale); color: var(--barn-dark); }

/* Forms */
.field { margin-bottom: 12px; }
.field label { display: block; font-weight: 700; font-size: 0.9rem; margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px; font-size: 1rem;
  border: 2px solid #E7D5B4; border-radius: 12px; background: #fff; color: var(--ink);
  font-family: inherit; min-height: 48px;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--barn); }
.field .hint { font-size: 0.78rem; color: var(--ink-soft); margin-top: 4px; }
.inline-form { display: flex; gap: 8px; margin-bottom: 8px; }
.inline-form input, .inline-form select { flex: 1; padding: 11px; border: 2px solid #E7D5B4; border-radius: 12px; font-size: 1rem; min-width: 0; min-height: 48px; }
.inline-form .btn { padding: 10px 16px; white-space: nowrap; }

/* Log rows */
.log-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 2px; border-bottom: 1px dashed #EADFC2; font-size: 0.9rem; }
.log-row:last-child { border-bottom: none; }

table.data { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.data th, table.data td { padding: 8px 6px; text-align: left; border-bottom: 1px solid #F0E2C8; }
table.data th { color: var(--barn-dark); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.5px; }
td.r, th.r { text-align: right; }
.pos { color: var(--money); font-weight: 700; }
.neg { color: var(--danger); font-weight: 700; }

/* Pedigree */
.ped { display: flex; flex-direction: column; gap: 8px; }
.ped-gen { display: flex; gap: 8px; }
.ped-gen .gen-label { flex: 0 0 86px; font-size: 0.75rem; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.5px; padding-top: 10px; }
.ped-node {
  flex: 1; background: var(--cream); border: 2px solid #EFE0C2; border-radius: 12px;
  padding: 8px 10px; font-size: 0.85rem; cursor: pointer; min-width: 0;
}
.ped-node .pn-name { font-weight: 700; }
.ped-node .pn-sub { font-size: 0.75rem; color: var(--ink-soft); }
.ped-node.unknown { opacity: 0.55; cursor: default; border-style: dashed; }

/* Quick-add menu */
.qa-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.qa-btn {
  border: 2px solid #EFE0C2; background: #fff; border-radius: 14px;
  padding: 16px 8px; font-size: 0.9rem; font-weight: 700; color: var(--ink);
  cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px;
  min-height: 84px; justify-content: center;
}
.qa-btn .qa-ico { font-size: 1.6rem; }
.qa-btn:active { border-color: var(--barn); background: var(--barn-pale); }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(58, 46, 36, 0.5);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--cream); border-radius: 20px 20px 0 0;
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
}
.modal h3 { margin-top: 0; }
.plan-card { border: 2px solid var(--straw); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; background: #fff; }
.plan-card .price { font-size: 1.4rem; font-weight: 800; }
.demo-note { font-size: 0.78rem; color: var(--ink-soft); background: #FFF3D6; border: 1px dashed var(--straw-dark); border-radius: 10px; padding: 8px 10px; margin: 10px 0; }

/* Photo */
.animal-photo { width: 96px; height: 96px; border-radius: 16px; object-fit: cover; border: 2px solid #EFE0C2; background: var(--cream-dark); }
.photo-placeholder { width: 96px; height: 96px; border-radius: 16px; background: var(--cream-dark); display: flex; align-items: center; justify-content: center; font-size: 2.4rem; border: 2px dashed #E0CFA8; }

/* Toast */
#toast-root { position: fixed; bottom: 92px; left: 0; right: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 0.9rem; box-shadow: var(--shadow); animation: toast-in 0.2s ease; max-width: 92vw; text-align: center; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

.empty { text-align: center; padding: 30px 10px; color: var(--ink-soft); }
.hidden { display: none !important; }
.small { font-size: 0.8rem; color: var(--ink-soft); }
.muted { color: var(--ink-soft); }
.divider { border: none; border-top: 1px solid #EADFC2; margin: 14px 0; }
canvas.chart { width: 100%; height: 200px; background: #fff; border-radius: 12px; border: 1px solid #EFE0C2; }

/* Offline strip (home) */
.offline-strip {
  background: #fff; border: 2px solid var(--leaf); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 12px; font-size: 0.85rem;
  box-shadow: var(--shadow); color: var(--ink);
}
.offline-strip span { color: var(--ink-soft); }

/* Feedback floating button — subtle, above the bottom nav */
.feedback-fab {
  position: fixed; right: 14px; bottom: 88px; z-index: 40;
  border: 2px solid #EFE0C2; background: #fff; color: var(--ink);
  border-radius: 999px; padding: 9px 15px; font-size: 0.85rem; font-weight: 700;
  box-shadow: var(--shadow); cursor: pointer; opacity: 0.94; min-height: 44px;
}
.feedback-fab:active { transform: scale(0.96); }

/* Undo toast (needs pointer events for the button) */
.toast.toast-undo { pointer-events: auto; display: flex; align-items: center; gap: 12px; }
.toast-btn {
  background: var(--straw); border: none; border-radius: 999px;
  padding: 8px 18px; font-weight: 800; font-size: 0.9rem; color: var(--ink);
  cursor: pointer; min-height: 40px;
}

/* Feedback photo preview */
.fb-photo-prev { position: relative; display: inline-block; margin-top: 8px; }
.fb-photo-prev img { width: 120px; height: 120px; object-fit: cover; border-radius: 12px; border: 2px solid #EFE0C2; }
.fb-photo-remove {
  position: absolute; top: -10px; right: -10px;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--danger); color: #fff; border: none;
  font-size: 0.85rem; font-weight: 800; cursor: pointer;
}

/* Batch weight inputs */
input[data-batch-w] { width: 92px; padding: 10px; border: 2px solid #E7D5B4; border-radius: 12px; font-size: 1rem; min-height: 48px; }

/* Print — only the print sheet shows */
#print-root { display: none; }
@media print {
  body.printing #app, body.printing .app-header, body.printing .bottom-nav,
  body.printing #modal-root, body.printing #toast-root,
  body.printing .feedback-fab, body.printing #feedback-fab { display: none !important; }
  body.printing { padding-bottom: 0; background: #fff; }
  body.printing #print-root { display: block; }
}
.print-sheet { color: #000; font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
.print-cagecard {
  border: 3px solid #000; border-radius: 12px; padding: 18px;
  max-width: 420px; margin: 0 auto; page-break-inside: avoid;
}
.pc-head { font-size: 1.6rem; font-weight: 800; margin-bottom: 10px; }
.pc-table { width: 100%; border-collapse: collapse; font-size: 1rem; }
.pc-table td { padding: 6px 4px; border-bottom: 1px solid #ccc; vertical-align: top; }
.pc-table td:first-child { color: #555; width: 34%; }
.pc-foot { margin-top: 12px; font-size: 0.8rem; color: #555; }
.print-pedigree h2 { margin: 0 0 4px; }
.pp-sub { margin: 0 0 12px; color: #333; }
.pp-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.pp-table th, .pp-table td { border: 1px solid #999; padding: 8px; text-align: left; vertical-align: top; }
.pp-table th { background: #eee; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.5px; }
.pp-unknown { color: #888; }

@media (min-width: 600px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 20px; }
  .qa-grid { grid-template-columns: 1fr 1fr 1fr; }
}
