/* Livestock Sync web — sunlight palette from the Android app (ui/Theme.kt). All text pairs ≥ 4.5:1. */
:root {
  --maroon: #6B1E24; --maroon-dark: #4E1418; --maroon-mid: #8A3239; --maroon-light: #F2E3E0;
  --tan: #C8A97E; --tan-light: #E8D9BF; --paper: #F3EBDD; --card: #FFFFFF; --ink: #111511; --ink-soft: #4A524C;
  --line: #D9CBB3; --red: #B3261E; --red-light: #FBE3E1; --amber: #7A4E00; --amber-light: #FFF0C7;
  --blue: #1F4E8C; --blue-light: #E1ECFA; --preg: #D0105C;
  --radius: 14px; --tap: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "DejaVu Sans", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--paper); color: var(--ink); font: 18px/1.4 var(--font); -webkit-text-size-adjust: 100%; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--maroon); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.splash { height: 100vh; display: grid; place-content: center; text-align: center; color: var(--maroon); font-weight: 800; font-size: 24px; }

/* ---------- shell */
.shell { display: grid; height: 100vh; height: 100dvh; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "top" "main" "nav"; }
.topbar { grid-area: top; background: var(--maroon-dark); color: #fff; display: flex; align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-t)) 16px 10px; min-height: 64px; }
.topbar .mark { width: 40px; height: 40px; flex: none; border-radius: 9px; }
.topbar h1 { font-size: 24px; font-weight: 800; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .back { background: none; border: 0; color: #fff; width: 48px; height: 48px; margin-left: -8px; display: grid; place-items: center; cursor: pointer; border-radius: 50%; }
.topbar .back svg { width: 30px; height: 30px; }
.topbar .act { background: none; border: 2px solid rgba(255,255,255,.7); color: #fff; min-height: 48px; padding: 0 16px; border-radius: 12px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.syncpill { display: inline-flex; align-items: center; gap: 8px; background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 999px;
  padding: 8px 14px; font-size: 15px; font-weight: 600; white-space: nowrap; cursor: pointer; min-height: 44px; }
.syncpill .dot { width: 10px; height: 10px; border-radius: 50%; background: #7BD88F; flex: none; }
.syncpill.offline .dot, .syncpill.error .dot { background: #FFC24B; }
.syncpill.syncing .dot { background: #fff; animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .3; } }
.demobadge { background: var(--tan); color: var(--ink); border-radius: 999px; padding: 6px 12px; font-size: 15px; font-weight: 800; white-space: nowrap; }

.main { grid-area: main; overflow: auto; -webkit-overflow-scrolling: touch; min-height: 0; }
.page { max-width: 1100px; margin: 0 auto; padding: 16px 16px 32px; }

.nav { grid-area: nav; display: flex; background: #fff; border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 68px;
  text-decoration: none; color: var(--ink-soft); font-size: 15px; font-weight: 700; }
.nav a .ic { width: 60px; height: 34px; display: grid; place-items: center; border-radius: 17px; }
.nav a svg { width: 26px; height: 26px; fill: currentColor; }
.nav a.sel { color: var(--maroon); }
.nav a.sel .ic { background: var(--maroon); color: #fff; }

@media (min-width: 900px) {
  .shell { grid-template-columns: 112px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "top top" "nav main"; }
  .nav { flex-direction: column; justify-content: flex-start; border-top: 0; border-right: 1px solid var(--line); padding: 12px 0; gap: 6px; }
  .nav a { flex: none; min-height: 84px; font-size: 15px; }
}

/* ---------- common blocks */
.card { background: var(--card); border-radius: var(--radius); padding: 18px; border: 1px solid var(--line); margin-bottom: 14px; min-width: 0; }
.card > h2, .sect { color: var(--maroon); font-size: 22px; font-weight: 800; margin-bottom: 10px; }
.sect { margin: 22px 0 8px; display: flex; align-items: center; gap: 10px; }
.sect .grow { flex: 1; }
.muted { color: var(--ink-soft); }
.empty { color: var(--ink-soft); padding: 6px 0 2px; }
.grid2 { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .grid2 { grid-template-columns: 1fr 1fr; } .grid2 > .span2 { grid-column: 1 / -1; } }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row-btns { display: flex; flex-wrap: wrap; gap: 10px; }
.row-btns > * { flex: 1 1 160px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); padding: 10px 20px; border-radius: 14px;
  border: 0; background: var(--tan); color: var(--ink); font-weight: 800; font-size: 18px; cursor: pointer; text-decoration: none; text-align: center; line-height: 1.2; }
.btn svg { width: 24px; height: 24px; fill: currentColor; flex: none; }
.btn.big { min-height: 64px; font-size: 20px; }
.btn.maroon { background: var(--maroon); color: #fff; }
.btn.mid { background: var(--maroon-mid); color: #fff; }
.btn.white { background: #fff; color: var(--maroon); }
.btn.outline { background: #fff; color: var(--maroon); border: 2px solid var(--maroon); }
.btn.ghost { background: transparent; color: var(--maroon); padding: 10px 12px; }
.btn.danger { background: #fff; color: var(--red); border: 2px solid var(--red); }
.btn:disabled { opacity: .55; cursor: default; }
.btn:focus-visible, .chip:focus-visible, .row:focus-visible, a:focus-visible, .legend button:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

.pill { display: inline-block; border-radius: 999px; padding: 4px 12px; font-size: 15px; font-weight: 700; background: var(--maroon-light); color: var(--maroon); white-space: nowrap; }
.pill.red { background: var(--red-light); color: var(--red); }
.pill.amber { background: var(--amber-light); color: var(--amber); }
.pill.gray { background: #E6E3DA; color: var(--ink-soft); }

.banner { border-radius: var(--radius); padding: 14px 16px; display: flex; gap: 12px; align-items: center; font-weight: 600; margin-bottom: 12px; }
.banner.ok { background: var(--maroon-light); color: var(--maroon); }
.banner.warn { background: var(--amber-light); color: var(--amber); }
.banner.info { background: var(--blue-light); color: var(--ink); }
.banner.err { background: var(--red-light); color: var(--red); }

/* ---------- Today */
.hero { background: var(--maroon-dark); color: #fff; padding: 20px 20px 22px; }
.hero .inner { max-width: 1100px; margin: 0 auto; }
.hero .wm { height: 22px; display: block; margin-bottom: 12px; }
.hero .date { color: var(--tan-light); font-weight: 600; font-size: 17px; }
.hero h2 { font-size: 34px; font-weight: 900; margin: 2px 0; }
.hero .btns { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.hero .btns .btn { flex: 1 1 200px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 16px 0 4px; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: var(--ink); display: flex; align-items: center; gap: 12px; min-height: 76px; }
.tile .n { font-size: 32px; font-weight: 900; color: var(--maroon); line-height: 1; }
.tile .t { font-weight: 600; line-height: 1.2; }
.due { display: flex; align-items: center; gap: 14px; background: #fff; border-radius: var(--radius); padding: 10px 16px; margin-bottom: 8px; border: 1px solid var(--line); }
.due.urgent { background: var(--amber-light); border-color: #EBD9A0; }
.due .n { font-size: 34px; font-weight: 900; color: var(--maroon); min-width: 40px; }
.due.urgent .n { color: var(--amber); }
.due .t { font-size: 19px; font-weight: 600; }

/* ---------- animal rows + badges */
.list { background: var(--paper); }
.row { display: flex; align-items: center; gap: 14px; padding: 10px 16px; min-height: 80px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); cursor: pointer; }
.row:hover { background: #EFE5D3; }
.row.sel { background: var(--tan-light); box-shadow: inset 5px 0 0 var(--maroon); }
.row .txt { flex: 1; min-width: 0; }
.row .title { display: block; font-size: 19px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .title .tag { font-weight: 900; }
.row .sub { font-size: 16px; color: var(--ink-soft); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row .trail { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.cardlist { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 8px; }
.cardlist .row:last-child { border-bottom: 0; }

.badge { position: relative; width: 52px; height: 52px; flex: none; }
.badge .dotc { width: 100%; height: 100%; border-radius: 50%; display: grid; place-items: center; font-weight: 900; font-size: 27px; line-height: 1; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.08); }
.badge .p { position: absolute; top: -4px; right: -6px; width: 24px; height: 24px; border-radius: 50%; background: var(--preg); color: #fff; font-weight: 900;
  font-size: 15px; display: grid; place-items: center; border: 2px solid #fff; }
.badge.lg { width: 72px; height: 72px; } .badge.lg .dotc { font-size: 38px; } .badge.lg .p { width: 30px; height: 30px; font-size: 18px; }
.badge.sm { width: 30px; height: 30px; } .badge.sm .dotc { font-size: 16px; border-width: 1.5px; }

/* ---------- cattle list controls */
.controls { padding: 12px 16px 4px; display: flex; flex-direction: column; gap: 10px; }
.search { position: relative; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 26px; height: 26px; fill: var(--ink-soft); pointer-events: none; }
.search input { width: 100%; min-height: 56px; border: 2px solid var(--line); border-radius: 14px; background: #fff; padding: 10px 48px 10px 50px; font-size: 19px; }
.search input:focus { border-color: var(--maroon); outline: none; }
.search .clear { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; border: 0; background: none; font-size: 26px; color: var(--ink-soft); cursor: pointer; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { min-height: 48px; padding: 8px 18px; border-radius: 12px; border: 2px solid var(--line); background: #fff; font-weight: 700; font-size: 17px; color: var(--ink-soft); cursor: pointer; white-space: nowrap; flex: none; }
.chip.sel { background: var(--maroon); border-color: var(--maroon); color: #fff; }
.filterline { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.filterbtn { display: inline-flex; align-items: center; gap: 8px; min-height: 48px; padding: 6px 14px; border-radius: 12px; border: 2px solid var(--ink-soft); background: #fff; font-weight: 700; cursor: pointer; }
.filterbtn.on { border-color: var(--maroon); }
.filterbtn .n { background: var(--maroon); color: #fff; border-radius: 50%; width: 26px; height: 26px; display: grid; place-items: center; font-size: 14px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 10px; }
.legend button { display: inline-flex; align-items: center; gap: 8px; min-height: 48px; padding: 4px 14px 4px 6px; border-radius: 24px; border: 2px solid transparent; background: transparent; font-weight: 700; font-size: 17px; cursor: pointer; color: var(--ink); }
.legend button.sel { background: var(--tan-light); }
.legend .pdot { width: 30px; height: 30px; border-radius: 50%; background: var(--preg); color: #fff; font-weight: 900; font-size: 16px; display: grid; place-items: center; border: 1.5px solid #fff; }

/* ---------- split (iPad landscape / laptop) */
.split { display: grid; grid-template-columns: minmax(380px, 440px) minmax(0, 1fr); height: 100%; }
.split > .pane { overflow: auto; min-height: 0; -webkit-overflow-scrolling: touch; }
.split > .pane.left { border-right: 1px solid var(--line); background: var(--paper); }
.split > .pane.right .page { padding-top: 0; }
.placeholder { height: 100%; display: grid; place-content: center; text-align: center; color: var(--ink-soft); padding: 24px; }
.placeholder img { width: 88px; height: 88px; margin: 0 auto 12px; opacity: .9; }

/* ---------- animal detail */
.ahead { display: flex; gap: 16px; align-items: center; padding: 16px 0 10px; }
.ahead .t1 { color: var(--maroon); font-weight: 800; font-size: 22px; }
.ahead .t0 { font-size: 26px; font-weight: 900; overflow-wrap: anywhere; line-height: 1.15; }
.ahead .t2 { color: var(--ink-soft); }
.dtabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 2px solid var(--line); margin: 0 -16px 16px; padding: 0 12px; position: sticky; top: 0; background: var(--paper); z-index: 2; scrollbar-width: none; }
.dtabs::-webkit-scrollbar { display: none; }
.dtabs a { padding: 14px 16px 12px; min-height: 52px; font-weight: 700; color: var(--ink-soft); text-decoration: none; border-bottom: 4px solid transparent; margin-bottom: -2px; white-space: nowrap; font-size: 18px; }
.dtabs a.sel { color: var(--maroon); border-bottom-color: var(--maroon); }
.kv { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 8px 14px; margin: 0; }
.kv dt { color: var(--ink-soft); font-size: 16px; padding-top: 1px; }
.kv dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; white-space: pre-line; }
.vals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.val { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.val .v { font-size: 26px; font-weight: 900; }
.val .l { color: var(--ink-soft); font-size: 15px; }
.lines { white-space: pre-line; }
.hist { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; }
.hist .d { color: var(--ink-soft); font-size: 16px; white-space: nowrap; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { color: var(--ink-soft); font-size: 15px; font-weight: 700; }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl .x { width: 48px; }
.iconbtn { width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; color: var(--ink-soft); cursor: pointer; display: grid; place-items: center; }
.iconbtn svg { width: 24px; height: 24px; fill: currentColor; }
.iconbtn:hover { background: var(--paper); color: var(--red); }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.photos button { padding: 0; border: 0; border-radius: 12px; overflow: hidden; aspect-ratio: 1; background: var(--tan-light); cursor: pointer; }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ev { border-bottom: 1px solid var(--line); padding: 10px 0; display: flex; gap: 12px; align-items: flex-start; }
.ev:last-child { border-bottom: 0; }
.ev .b { flex: 1; min-width: 0; }
.ev .h { font-weight: 700; }

/* ---------- forms + dialog */
.form { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .form.two { grid-template-columns: 1fr 1fr; } .form .full { grid-column: 1 / -1; } }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-weight: 700; font-size: 16px; color: var(--ink-soft); }
.field input, .field select, .field textarea { min-height: var(--tap); border: 2px solid var(--line); border-radius: 12px; background: #fff; padding: 10px 12px; font-size: 18px; width: 100%; }
.field textarea { min-height: 110px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--maroon); outline: none; }
.check { display: flex; align-items: center; gap: 12px; min-height: var(--tap); font-weight: 600; cursor: pointer; }
.check input { width: 28px; height: 28px; accent-color: var(--maroon); }
.formsect { color: var(--maroon); font-weight: 800; font-size: 20px; margin-top: 8px; }
.err { color: var(--red); font-weight: 700; }

dialog#dlg { border: 0; border-radius: 18px; padding: 0; width: min(640px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); background: var(--paper); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog#dlg::backdrop { background: rgba(30, 10, 12, .55); }
.dlg-h { background: var(--maroon-dark); color: #fff; padding: 16px 20px; font-size: 22px; font-weight: 800; position: sticky; top: 0; z-index: 1; }
.dlg-b { padding: 18px 20px; }
.dlg-f { display: flex; gap: 10px; padding: 0 20px 20px; flex-wrap: wrap; }
.dlg-f .btn { flex: 1 1 160px; }
dialog img.full { width: 100%; display: block; border-radius: 12px; }

#toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 12px 20px;
  border-radius: 12px; font-weight: 600; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- auth / setup */
.auth { min-height: 100vh; min-height: 100dvh; overflow: auto; display: grid; place-items: center; padding: 24px; background: var(--paper); }
.authbox { width: min(460px, 100%); }
.authbox .brand { text-align: center; margin-bottom: 20px; }
.authbox .brand img.m { width: 96px; height: 96px; }
.authbox .brand img.w { display: block; width: 260px; max-width: 80%; margin: 14px auto 0; }
.authbox .card { padding: 22px; }
.authbox h2 { color: var(--maroon); font-size: 26px; margin-bottom: 14px; }
.switch { text-align: center; margin-top: 14px; }
.linkbtn { background: none; border: 0; color: var(--maroon); font-weight: 800; text-decoration: underline; cursor: pointer; min-height: 44px; padding: 4px 8px; font-size: 18px; }

@media (max-width: 420px) {
  body { font-size: 17px; }
  .page { padding: 12px 12px 28px; }
  .row { padding: 10px 12px; gap: 12px; }
  .controls { padding: 10px 12px 4px; }
  .kv { grid-template-columns: minmax(96px, 36%) 1fr; }
  .topbar h1 { font-size: 22px; }
  .hero h2 { font-size: 30px; }
}

.placerow { flex-wrap: wrap; cursor: default; }
.placerow .trail { flex-direction: row; gap: 8px; }
@media (max-width: 520px) {
  .nav a { font-size: 13px; min-height: 64px; }
  .nav a .ic { width: 52px; height: 32px; }
  .placerow .trail { width: 100%; }
  .placerow .trail .btn { flex: 1; }
  .topbar { gap: 10px; padding-left: 12px; padding-right: 12px; }
  .topbar .mark { width: 36px; height: 36px; }
  .demobadge { font-size: 14px; padding: 5px 10px; }
  .page .row-btns.stack-phone > * { flex-basis: 100%; }
  .tbl th, .tbl td { padding: 10px 4px; }
}
.recbtns { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.recbtns .btn { padding: 10px 8px; }
.placerow .title { white-space: normal; }
@media (max-width: 520px) { .val .v { font-size: 22px; } }
@media (max-width: 520px) { .ahead .t0 { font-size: 21px; } .ahead .t1 { font-size: 19px; } }
