/* styles.css: how Tally Book looks.
   Big text and big buttons so it is easy to use outside, in the sun, with gloves.
   Colors are set once here as "variables" and reused everywhere. */

:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --ink: #1d261d;
  --muted: #5f6b5f;
  --line: #e2ddd1;
  --brand: #2f5d3a;
  --brand-ink: #ffffff;
  --brand-soft: #e3eee3;
  --red: #b42318;   --red-soft: #fde8e6;
  --amber: #a15c07; --amber-soft: #fdf0d8;
  --green: #1f7a3a; --green-soft: #e1f3e6;
  --blue: #1d5fa8;  --blue-soft: #e2edf9;
  --gray-soft: #ecebe7;
  --radius: 14px;
  --tabs-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141a15; --card: #1e2620; --ink: #eef2ec; --muted: #a3aea3;
    --line: #313b33; --brand: #4f8f5f; --brand-soft: #24362a;
    --red: #ff8a7f; --red-soft: #3a1f1c; --amber: #f2b558; --amber-soft: #3a2d15;
    --green: #7fd398; --green-soft: #1d3324; --blue: #8cbcf0; --blue-soft: #1b2b3d; --gray-soft: #2a302b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
}
body.has-selbar { padding-bottom: calc(var(--tabs-h) + 150px + env(safe-area-inset-bottom)); }
a { color: var(--brand); }
h2 { font-size: 1.1rem; margin: 22px 4px 8px; display: flex; align-items: center; gap: 8px; }
h2 .more { margin-left: auto; font-size: .9rem; font-weight: 500; }
h3 { font-size: 1rem; margin: 4px 0 8px; }
.count { background: var(--gray-soft); border-radius: 99px; padding: 0 9px; font-size: .85rem; font-weight: 600; }
.muted { color: var(--muted); }
.center { text-align: center; }
.pad { padding: 14px; margin: 0; }
.red-t { color: var(--red); font-weight: 600; }
.amber-t { color: var(--amber); }
[hidden] { display: none !important; }

/* ---------- Header ---------- */
#top {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: 90px 1fr 90px; align-items: center;
  background: var(--brand); color: var(--brand-ink);
  padding: calc(env(safe-area-inset-top) + 8px) 8px 8px; min-height: 52px;
}
#top h1 { margin: 0; font-size: 1.15rem; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hside.right { text-align: right; }
.hbtn {
  background: rgba(255,255,255,.16); color: inherit; border: 0; border-radius: 10px;
  padding: 8px 12px; font: inherit; font-size: .95rem; text-decoration: none; display: inline-block; cursor: pointer;
}

main { max-width: 720px; margin: 0 auto; padding: 12px 16px; }

/* ---------- Bottom tabs ---------- */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs a {
  height: var(--tabs-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: .75rem; color: var(--muted); text-decoration: none; gap: 2px;
}
#tabs a span { font-size: 1.4rem; line-height: 1; }
#tabs a.on { color: var(--brand); font-weight: 700; }
#tabs a.addtab span { background: var(--brand); color: #fff; border-radius: 50%; width: 34px; height: 34px; display: grid; place-items: center; font-size: 1.3rem; }

/* ---------- Cards, buttons ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
.card.list { padding: 0; overflow: hidden; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { color: var(--red); border-color: var(--red); background: transparent; }
.btn.big { width: 100%; min-height: 54px; font-size: 1.05rem; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn:disabled { opacity: .45; }
.linkbtn { background: none; border: 0; color: var(--brand); font: inherit; font-weight: 600; padding: 4px; cursor: pointer; }
.chip { border: 0; background: var(--brand-soft); color: var(--brand); border-radius: 99px; padding: 8px 14px; font: inherit; font-weight: 600; margin-top: 8px; }
.quick { display: grid; gap: 10px; margin: 14px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }

/* ---------- Ear tag chip ---------- */
.tag {
  display: inline-grid; place-items: center; min-width: 52px; height: 40px; padding: 0 8px;
  border-radius: 10px 10px 16px 16px; font-weight: 800; font-size: 1.05rem; letter-spacing: .3px;
  border: 2px solid rgba(0,0,0,.18); color: #111; background: #d9d6cf; flex-shrink: 0;
}
.tag.sm { min-width: 40px; height: 28px; font-size: .85rem; border-radius: 7px 7px 11px 11px; }
.tag.big { min-width: 84px; height: 62px; font-size: 1.7rem; border-radius: 14px 14px 24px 24px; }
.tag-yellow { background: #f6d433; }
.tag-orange { background: #f39a2b; }
.tag-green  { background: #3fae5a; color: #fff; }
.tag-white  { background: #ffffff; }
.tag-red    { background: #d93a2e; color: #fff; }
.tag-blue   { background: #2f76d2; color: #fff; }
.tag-pink   { background: #f39bc3; }
.tag-purple { background: #8a54c9; color: #fff; }
.tag-black  { background: #222; color: #fff; border-color: #555; }

/* ---------- Home ---------- */
.hello { color: var(--muted); margin: 4px 4px 10px; }
.bigsearch { display: flex; gap: 8px; margin-bottom: 14px; }
.bigsearch input { flex: 1; font-size: 1.1rem; min-height: 54px; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 10px;
  text-decoration: none; color: var(--ink); display: flex; flex-direction: column; min-width: 0;
}
.tile b { font-size: 1.45rem; line-height: 1.2; overflow-wrap: anywhere; }
.tile span { font-size: .85rem; color: var(--muted); }
.tile.total { grid-column: span 3; background: var(--brand); color: #fff; border-color: var(--brand); flex-direction: row; align-items: baseline; gap: 10px; }
.tile.total b { font-size: 2rem; }
.tile.total span { color: rgba(255,255,255,.85); font-size: 1rem; }
.alerts { display: grid; gap: 8px; }
.alert {
  display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: var(--radius);
  text-decoration: none; color: var(--ink); margin: 8px 0; border: 1px solid transparent;
}
.alerts .alert { margin: 0; }
.alert > b { font-size: 1.25rem; min-width: 28px; flex-shrink: 0; }
.alert > span { flex: 1; min-width: 0; }
.alert.red { background: var(--red-soft); border-color: color-mix(in srgb, var(--red) 35%, transparent); }
.alert.red > b { color: var(--red); }
.alert.amber { background: var(--amber-soft); } .alert.amber > b { color: var(--amber); }
.alert.green { background: var(--green-soft); } .alert.green > b { color: var(--green); }
.alert.blue { background: var(--blue-soft); } .alert.blue > b { color: var(--blue); }
.alert.gray { background: var(--gray-soft); }
.alert:not(.red):not(.amber):not(.green):not(.blue):not(.gray) > b { font-size: 1rem; }
.welcome p { color: var(--muted); }
.welcome .btn { margin-top: 10px; }

/* ---------- Lists ---------- */
.row {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; min-height: 62px;
  border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink);
}
.list > :last-child, .list > :last-child .row { border-bottom: 0; }
.row.sel { cursor: pointer; }
.row.sel input { width: 24px; height: 24px; accent-color: var(--brand); flex-shrink: 0; }
.rmain { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rmain small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rbadges { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.badge { font-size: .75rem; font-weight: 700; padding: 3px 8px; border-radius: 99px; white-space: nowrap; }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.gray { background: var(--gray-soft); color: var(--muted); }
.due { display: flex; flex-direction: column; align-items: flex-end; }
.due small { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.calverow { display: flex; align-items: center; border-bottom: 1px solid var(--line); padding-right: 10px; }
.calverow .row { flex: 1; border: 0; min-width: 0; }
.calverow:last-child { border-bottom: 0; }

.herdtools { position: sticky; top: calc(52px + env(safe-area-inset-top)); z-index: 5; background: var(--bg); padding: 4px 0 2px; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 6px; margin-top: 8px; }
.filters select { min-height: 42px; font-size: .95rem; }
.countline { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: .9rem; margin: 8px 4px 0; }

#selbar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); z-index: 9;
  background: var(--card); border-top: 2px solid var(--brand); padding: 8px 12px 10px; box-shadow: 0 -6px 20px rgba(0,0,0,.08);
}
.selcount { font-weight: 700; margin-bottom: 6px; }
.selactions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.selactions .btn { min-height: 42px; padding: 6px; font-size: .9rem; }

.logrow { padding: 10px 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; }
.logrow a { color: var(--ink); text-decoration: none; }
.logrow small { color: var(--muted); }
.day { margin: 0; padding: 12px 14px 6px; background: var(--gray-soft); font-size: .9rem; }
.menu a { display: flex; align-items: center; gap: 12px; padding: 16px; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; font-weight: 600; }
.menu a span { font-size: 1.3rem; }

/* ---------- Animal page ---------- */
.hero { display: flex; gap: 14px; align-items: center; margin-bottom: 6px; }
.hero.small { margin-bottom: 12px; }
.photo {
  width: 128px; height: 128px; border-radius: var(--radius); overflow: hidden; flex-shrink: 0; position: relative;
  background: var(--card); border: 2px dashed var(--line); display: grid; place-items: center; cursor: pointer;
}
.photo img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.ph-empty { text-align: center; color: var(--muted); font-size: .85rem; }
.hero-text h2 { margin: 8px 0 2px; font-size: 1.4rem; }
.hero-text p { margin: 0; color: var(--muted); }
.notes { white-space: pre-wrap; }
.acts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.act {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; min-height: 70px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--ink); font-size: .82rem; font-weight: 600; text-align: center; padding: 6px 2px;
}
.act span { font-size: 1.45rem; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.facts div { display: flex; flex-direction: column; min-width: 0; }
.facts span { font-size: .8rem; color: var(--muted); }
.facts b { font-weight: 600; overflow-wrap: anywhere; }
.summary { margin: 0 0 10px; color: var(--muted); }
.summary b { color: var(--ink); }
p.summary.card { margin: 10px 0; }
.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th { text-align: left; font-size: .78rem; color: var(--muted); font-weight: 600; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 7px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl a { text-decoration: none; color: var(--ink); display: inline-flex; align-items: center; gap: 4px; }
.evrow { display: flex; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.evrow > div { display: flex; flex-direction: column; min-width: 0; }
.evrow small { color: var(--muted); }
.evrow em { color: var(--muted); font-size: .92rem; }
.ev-ic { font-size: 1.2rem; width: 26px; text-align: center; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form.card h3 { margin-top: 6px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.lbl { font-weight: 600; font-size: .95rem; }
.hint { color: var(--muted); font-size: .85rem; margin: 0; }
input, select, textarea {
  font: inherit; font-size: 17px; /* 16px+ stops iPhone zooming in */
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
}
input[type=date] { -webkit-appearance: none; appearance: none; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
.unitbox { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.unitbox:focus-within { outline: 2px solid var(--brand); }
.unitbox input { border: 0; outline: 0 !important; background: transparent; }
.unitbox span { padding: 0 12px; color: var(--muted); font-weight: 600; }
.unitbox .pre { padding: 0 0 0 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { flex: 1 1 auto; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.seg span {
  display: grid; place-items: center; min-height: 46px; padding: 6px 12px; border-radius: 10px; text-align: center;
  border: 1px solid var(--line); background: var(--card); font-weight: 600; cursor: pointer; white-space: nowrap;
}
.seg input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
fieldset.sub { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin: 0; display: flex; flex-direction: column; gap: 14px; background: color-mix(in srgb, var(--card) 60%, transparent); }
legend { font-weight: 700; padding: 0 6px; }
.calc { font-size: 1.05rem; }
.calc:empty { display: none; }
.calc { background: var(--brand-soft); border-radius: 10px; padding: 12px; }
.bulkrows { display: flex; flex-direction: column; gap: 8px; }
.brow { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.bhead { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.bfields { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.bfields .lbl { font-size: .8rem; }
#ownerlist { display: flex; flex-direction: column; gap: 8px; }
#setup input + input { margin-top: 8px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 18px); transform: translate(-50%, 20px);
  background: #1d261d; color: #fff; padding: 12px 18px; border-radius: 12px; opacity: 0; pointer-events: none;
  transition: .2s; z-index: 30; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 380px) {
  .acts { grid-template-columns: repeat(3, 1fr); }
  .photo { width: 104px; height: 104px; }
}
@media (min-width: 640px) {
  .tiles { grid-template-columns: repeat(6, 1fr); }
  .tile.total { grid-column: span 6; }
}

/* ---------- Login and sync ---------- */
.logo { display: block; margin: 6px auto 0; border-radius: 20px; }
.center-h { justify-content: center; margin: 4px 0; }
.syncline { font-size: .85rem; }
.syncline:empty { display: none; }
