:root {
  --paper: #f3f5f1;
  --card: #ffffff;
  --ink: #17221c;
  --muted: #5b6a61;
  --faint: #8a978f;
  --line: rgba(23, 34, 28, 0.12);
  --line-strong: rgba(23, 34, 28, 0.24);
  --field: #24543a;
  --field-ink: #ffffff;
  --field-soft: #e3ece5;
  --accent-text: #24543a;
  --tag: #f5c518;
  --tag-edge: #d9a900;
  --tag-ink: #141414;
  --rust: #b3361e;
  --rust-soft: #f8e4de;
  --warn: #8a5a00;
  --warn-soft: #fbefcf;
  --ok: #2c6e45;
  --ok-soft: #e1efe5;
  --radius: 10px;
  --font: 'Barlow', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-tag: 'Barlow Condensed', 'Arial Narrow', system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --paper: #0f1512;
    --card: #17201b;
    --ink: #e6ede8;
    --muted: #a0b0a6;
    --faint: #7b8b81;
    --line: rgba(230, 237, 232, 0.12);
    --line-strong: rgba(230, 237, 232, 0.26);
    --field: #3d8a5c;
    --field-soft: #1f3327;
    --accent-text: #8fd3a7;
    --rust: #f08a73;
    --rust-soft: #3a1d17;
    --warn: #f2c66b;
    --warn-soft: #362a12;
    --ok: #8fd3a7;
    --ok-soft: #1c3124;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --paper: #0f1512;
  --card: #17201b;
  --ink: #e6ede8;
  --muted: #a0b0a6;
  --faint: #7b8b81;
  --line: rgba(230, 237, 232, 0.12);
  --line-strong: rgba(230, 237, 232, 0.26);
  --field: #3d8a5c;
  --field-soft: #1f3327;
  --accent-text: #8fd3a7;
  --rust: #f08a73;
  --rust-soft: #3a1d17;
  --warn: #f2c66b;
  --warn-soft: #362a12;
  --ok: #8fd3a7;
  --ok-soft: #1c3124;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-text); }
h1, h2, h3 { font-weight: 600; line-height: 1.2; margin: 0; }
p { margin: 0 0 0.75em; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
:focus-visible { outline: 3px solid var(--tag); outline-offset: 2px; border-radius: 4px; }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ── Shell ───────────────────────────────────────────────────────────── */
.shell { min-height: 100vh; }
.side { display: none; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  background: var(--field); color: var(--field-ink);
}
.topbar h1 { font-size: 20px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
main { padding: 16px 16px calc(96px + var(--safe-b)); max-width: 980px; margin: 0 auto; outline: none; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.bottomnav a, .bottomnav button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 0 8px; font: 500 12px var(--font); color: var(--faint); text-decoration: none;
  background: none; border: 0; cursor: pointer;
}
.bottomnav .ic { width: 24px; height: 24px; }
.bottomnav .on { color: var(--accent-text); }
.bottomnav .on .ic { stroke-width: 2.4; }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 236px 1fr; }
  .side {
    display: flex; flex-direction: column; gap: 4px;
    position: sticky; top: 0; height: 100vh; padding: 18px 12px;
    background: var(--card); border-right: 1px solid var(--line);
  }
  .brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: var(--ink); text-decoration: none; font: 600 20px var(--font); }
  .brand-mark { width: 22px; height: 26px; background: var(--tag); border: 1.5px solid var(--tag-edge); border-radius: 9px 9px 5px 5px; position: relative; }
  .brand-mark::before { content: ''; position: absolute; top: 4px; left: 50%; width: 5px; height: 5px; margin-left: -2.5px; border-radius: 50%; background: var(--card); }
  .side nav { display: flex; flex-direction: column; gap: 2px; }
  .side nav a { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
  .side nav a:hover { background: var(--paper); color: var(--ink); }
  .side nav a.on { background: var(--field-soft); color: var(--accent-text); }
  .topbar { background: var(--paper); color: var(--ink); padding: 22px 32px 6px; position: static; }
  .topbar h1 { font-size: 30px; }
  main { padding: 12px 32px 48px; margin: 0; }
  .bottomnav { display: none; }
}

.sync-pill {
  display: inline-flex; align-items: center; gap: 6px; border: 0; cursor: pointer;
  padding: 5px 10px; border-radius: 999px; font: 500 13px var(--font);
  background: rgba(255, 255, 255, 0.16); color: inherit;
}
.sync-pill .ic { width: 16px; height: 16px; }
.sync-pill.spin .ic { animation: spin 1.2s linear infinite; }
.sync-pill.warn, .sync-pill.danger { background: var(--warn-soft); color: var(--warn); }
.sync-pill.danger { background: var(--rust-soft); color: var(--rust); }
@media (min-width: 900px) {
  .sync-pill { background: var(--card); border: 1px solid var(--line); }
  .sync-pill.ok { color: var(--ok); }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Ear tag ─────────────────────────────────────────────────────────── */
.eartag {
  position: relative; display: inline-flex; flex-direction: column; align-items: center; justify-content: flex-end;
  flex: none; background: var(--tag); color: var(--tag-ink);
  border: 1.5px solid var(--tag-edge); border-radius: 14px 14px 8px 8px;
  font-family: var(--font-tag); line-height: 1;
  width: 54px; height: 58px; padding: 0 3px 6px;
}
.eartag::before {
  content: ''; position: absolute; top: 6px; left: 50%; width: 8px; height: 8px; margin-left: -4px;
  border-radius: 50%; background: var(--paper); box-shadow: inset 0 0 0 1.5px var(--tag-edge);
}
.eartag-head { font-size: 9px; font-weight: 500; letter-spacing: 0.02em; max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: clip; direction: rtl; opacity: 0.8; }
.eartag-tail { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; }
.eartag.sm { width: 44px; height: 48px; border-radius: 12px 12px 7px 7px; padding-bottom: 5px; }
.eartag.sm::before { top: 5px; width: 7px; height: 7px; margin-left: -3.5px; }
.eartag.sm .eartag-tail { font-size: 20px; }
.eartag.sm .eartag-head { display: none; }
.eartag.lg { width: 124px; height: 124px; border-radius: 26px 26px 14px 14px; padding: 0 8px 12px; border-width: 2px; }
.eartag.lg::before { top: 12px; width: 16px; height: 16px; margin-left: -8px; box-shadow: inset 0 0 0 2px var(--tag-edge); }
.eartag.lg .eartag-head { font-size: 15px; margin-bottom: 2px; }
.eartag.lg .eartag-tail { font-size: 46px; letter-spacing: -0.02em; }
.eartag.off { background: #d9d6cc; border-color: #b9b5a8; }
.eartag.danger { box-shadow: 0 0 0 3px var(--rust-soft), 0 0 0 4.5px var(--rust); }

/* ── Building blocks ─────────────────────────────────────────────────── */
.section { margin: 26px 0 0; }
.section-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.section-head h2 { font-size: 18px; flex: 1; }
.section-head a, .section-head button { font-size: 14px; }
.count { font: 600 14px var(--font); color: var(--muted); }

.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 14px; padding: 12px 14px; min-height: 64px;
  border-top: 1px solid var(--line); color: inherit; text-decoration: none; background: none; width: 100%; text-align: left; font: inherit;
}
.row:first-child { border-top: 0; }
a.row:hover, button.row:hover { background: var(--paper); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-sub { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; }
.row .chev { color: var(--faint); }
.row.done .row-title { color: var(--faint); text-decoration: line-through; }

.badge { display: inline-flex; align-items: center; gap: 4px; font: 600 13px var(--font); padding: 2px 9px; border-radius: 999px; background: var(--paper); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--rust-soft); color: var(--rust); }
.badge .ic { width: 14px; height: 14px; }

.banner { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); background: var(--warn-soft); color: var(--warn); margin-bottom: 14px; }
.banner.danger { background: var(--rust-soft); color: var(--rust); }
.banner strong { display: block; font-weight: 600; }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty h2 { font-size: 18px; color: var(--ink); margin-bottom: 6px; }
.empty .btn { margin-top: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: var(--radius);
  font: 600 15px var(--font); cursor: pointer; text-decoration: none;
  background: var(--card); color: var(--ink); border: 1px solid var(--line-strong);
}
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--field); color: var(--field-ink); border-color: var(--field); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--rust); border-color: var(--rust); }
.btn.ghost { border-color: transparent; background: none; }
.btn.block { width: 100%; }
.btn .ic { width: 18px; height: 18px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 50%; border: 0; background: none; color: inherit; cursor: pointer; }
.icon-btn:hover { background: var(--paper); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .grow { flex: 1; }

.fab {
  position: fixed; right: 16px; bottom: calc(76px + var(--safe-b)); z-index: 4;
  height: 56px; padding: 0 20px 0 16px; border-radius: 28px; border: 0;
  background: var(--field); color: var(--field-ink); font: 600 16px var(--font);
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer; text-decoration: none;
  box-shadow: 0 6px 18px rgba(23, 34, 28, 0.28);
}
@media (min-width: 900px) { .fab { position: static; box-shadow: none; height: 44px; border-radius: var(--radius); font-size: 15px; } }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; margin-bottom: 12px; scrollbar-width: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--line-strong); background: var(--card); color: var(--ink);
  font: 500 14px var(--font); cursor: pointer; white-space: nowrap;
}
.chip .n { color: var(--faint); font-weight: 600; }
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip.on .n { color: inherit; opacity: 0.7; }

.search { position: relative; margin-bottom: 12px; }
.search .ic { position: absolute; left: 14px; top: 50%; margin-top: -10px; color: var(--faint); }
.search input { padding-left: 44px; height: 52px; font-size: 18px; }

/* ── Forms ───────────────────────────────────────────────────────────── */
::placeholder { color: var(--faint); opacity: 1; }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: var(--card); color: var(--ink);
  font: 400 16px var(--font);
}
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
input[type='checkbox'] { width: 22px; min-height: 22px; height: 22px; accent-color: var(--field); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--field); box-shadow: 0 0 0 3px var(--field-soft); }
[aria-invalid='true'] { border-color: var(--rust); }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font: 600 14px var(--font); margin-bottom: 5px; }
.field .hint { font-size: 13px; color: var(--muted); margin-top: 4px; }
.field-err { color: var(--rust); font-size: 14px; margin-top: 4px; font-weight: 500; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.check { display: flex; align-items: center; gap: 12px; padding: 10px 0; font-weight: 500; cursor: pointer; }
.seg { display: flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.seg label { flex: 1; text-align: center; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 11px 6px; font-weight: 600; }
.seg label + label span { border-left: 1px solid var(--line-strong); }
.seg input:checked + span { background: var(--field); color: var(--field-ink); }
.seg input:focus-visible + span { outline: 3px solid var(--tag); outline-offset: -3px; }
.form-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; max-width: 640px; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }
.form-actions .btn { flex: 1; }
.preview { font-size: 14px; color: var(--accent-text); font-weight: 600; margin: -6px 0 14px; display: flex; gap: 6px; align-items: center; }
.preview .ic { width: 16px; height: 16px; }

/* ── Sheets (dialogs) ────────────────────────────────────────────────── */
dialog.sheet {
  border: 0; padding: 0; background: var(--card); color: var(--ink);
  width: 100%; max-width: 100%; max-height: 92vh; margin: auto auto 0; border-radius: 18px 18px 0 0;
}
dialog.sheet::backdrop { background: rgba(10, 16, 12, 0.5); }
.sheet-inner { display: flex; flex-direction: column; max-height: 92vh; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 10px 6px 18px; }
.sheet-head h2 { flex: 1; font-size: 20px; }
.sheet-body { padding: 8px 18px 4px; overflow-y: auto; }
.sheet-foot { display: flex; gap: 10px; padding: 12px 18px calc(14px + var(--safe-b)); border-top: 1px solid var(--line); }
.sheet-foot .btn { flex: 1; }
.lead { font-size: 17px; }
@media (min-width: 640px) {
  dialog.sheet { max-width: 520px; margin: auto; border-radius: 16px; }
  dialog.sheet.wide { max-width: 720px; }
  .sheet-foot { padding-bottom: 14px; }
}
.more-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 16px 16px calc(16px + var(--safe-b)); }
.more-grid a { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px 4px; border-radius: 12px; background: var(--paper); color: var(--ink); text-decoration: none; font-weight: 600; font-size: 14px; text-align: center; }
.more-grid .ic { width: 26px; height: 26px; color: var(--accent-text); }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translate(-50%, 20px); z-index: 50;
  display: flex; align-items: center; gap: 14px; max-width: calc(100% - 32px); width: max-content;
  padding: 12px 16px; border-radius: 12px; background: var(--ink); color: var(--paper);
  font-weight: 500; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast-btn { background: none; border: 0; color: var(--tag); font: 700 15px var(--font); cursor: pointer; padding: 4px; }
@media (min-width: 900px) { .toast { bottom: 24px; } }

/* ── Home ────────────────────────────────────────────────────────────── */
.finder { background: var(--field); margin: -16px -16px 0; padding: 4px 16px 18px; }
.finder .search { margin: 0; }
.finder input { border: 0; box-shadow: none; }
@media (min-width: 900px) { .finder { background: none; margin: 0; padding: 0; max-width: 560px; } .finder input { border: 1px solid var(--line-strong); } }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.quick a {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 4px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--ink); text-decoration: none; font-weight: 600; font-size: 14px; text-align: center;
}
.quick .ic { width: 26px; height: 26px; color: var(--accent-text); }
@media (min-width: 900px) { .quick { max-width: 640px; } }
.home-cols { display: grid; gap: 0 24px; }
@media (min-width: 1100px) { .home-cols { grid-template-columns: 1fr 1fr; } }

/* ── Animal page ─────────────────────────────────────────────────────── */
.hero { display: flex; gap: 18px; align-items: center; margin-bottom: 16px; }
.hero-info { flex: 1; min-width: 0; }
.hero-edit { align-self: flex-start; }
.hero-info h2 { font-size: 15px; font-weight: 500; color: var(--muted); word-break: break-all; }
.hero-info .facts { font-size: 18px; font-weight: 600; margin-top: 2px; }
.hero-info .badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.actions4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: 8px; margin-bottom: 18px; }
.actions4 a, .actions4 button {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 4px;
  border-radius: var(--radius); background: var(--card); border: 1px solid var(--line);
  color: var(--ink); text-decoration: none; font: 600 14px var(--font); cursor: pointer;
}
.actions4 .ic { width: 24px; height: 24px; color: var(--accent-text); }
.facts-list { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 0; }
.facts-list dt { color: var(--muted); }
.facts-list dd { margin: 0; font-weight: 500; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--line); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.photo .icon-btn { position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; background: rgba(0, 0, 0, 0.55); color: #fff; }
.photo-add { aspect-ratio: 1; border: 1.5px dashed var(--line-strong); border-radius: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; background: none; }
.lightbox { background: #000; }
.lightbox img { max-width: 100%; max-height: 80vh; display: block; margin: 0 auto; }
@media (min-width: 1000px) { .animal-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 28px; align-items: start; } }

/* ── Calendar ────────────────────────────────────────────────────────── */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.cal-head h2 { flex: 1; font-size: 20px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; }
.cal-dow { text-align: center; font-size: 12px; font-weight: 600; color: var(--faint); padding: 4px 0; }
.cal-day { aspect-ratio: 1; min-height: 40px; border: 0; border-radius: 8px; background: none; color: var(--ink); font: 500 15px var(--font); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
.cal-day.out { color: var(--faint); opacity: 0.5; }
.cal-day.today { box-shadow: inset 0 0 0 2px var(--field); }
.cal-day.sel { background: var(--field); color: var(--field-ink); }
.dots { display: flex; gap: 2px; height: 6px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.dot.calving { background: #c2577f; }
.dot.treatment { background: #3a78b5; }
.dot.reminder { background: #c9850f; }
.dot.sale { background: #2c6e45; }
.dot.event { background: var(--ink); }

/* ── Print (treatment register) ──────────────────────────────────────── */
.print-only { display: none; }
@media print {
  body { background: #fff; color: #000; }
  .side, .topbar, .bottomnav, .fab, .toolbar, .chips, .search, .no-print, .toast { display: none !important; }
  main { padding: 0; max-width: none; }
  .print-only { display: block; }
  .print-table { width: 100%; border-collapse: collapse; font-size: 11pt; }
  .print-table th, .print-table td { border: 1px solid #999; padding: 4px 6px; text-align: left; }
  .screen-only { display: none !important; }
}
@media (max-width: 599px) { .toolbar > .grow { flex-basis: 100%; } }

/* ── Phone polish ────────────────────────────────────────────────────── */
html { -webkit-tap-highlight-color: transparent; }
a, button, label, .chip, .row, input, select, textarea { touch-action: manipulation; }
.chip { height: 40px; }
.icon-btn { width: 44px; height: 44px; }
.back-btn { color: inherit; margin: -6px 0 -6px -10px; }
.back-btn .ic { width: 24px; height: 24px; }
@media (min-width: 900px) { .back-btn { margin-left: -12px; } }
/* Visible feedback on tap (phones have no hover). */
.row:active, .quick a:active, .actions4 > *:active, .more-grid a:active, .suggest-item:active { background: var(--field-soft); }
.btn:active, .fab:active, .chip:active { transform: scale(0.97); }
.bottomnav a:active, .bottomnav button:active { color: var(--accent-text); }
@media (prefers-reduced-motion: reduce) { .btn:active, .fab:active, .chip:active { transform: none; } }

/* Sheets: use the space that's really visible, scroll inside. */
dialog.sheet { max-height: calc(100dvh - env(safe-area-inset-top, 0px) - 8px); }
.sheet-inner { max-height: calc(100dvh - env(safe-area-inset-top, 0px) - 8px); }
dialog.sheet::before { content: ''; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: 8px auto 0; }
@media (min-width: 640px) { dialog.sheet::before { display: none; } }

/* Tappable suggestions under tag and medicine boxes. */
.suggest { margin-top: 6px; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; background: var(--card); }
.suggest-item { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 6px 12px; border: 0; border-top: 1px solid var(--line); background: none; color: var(--ink); font: 500 16px var(--font); text-align: left; cursor: pointer; }
.suggest-item:first-child { border-top: 0; }
.suggest-text { display: flex; flex-direction: column; min-width: 0; }
.suggest-text small { color: var(--muted); font-size: 13px; font-weight: 400; }
.eartag.xs { width: 34px; height: 38px; border-radius: 10px 10px 6px 6px; padding: 0 2px 4px; border-width: 1px; }
.eartag.xs::before { top: 4px; width: 5px; height: 5px; margin-left: -2.5px; }
.eartag.xs .eartag-tail { font-size: 15px; }
.eartag.xs .eartag-head { display: none; }
.kb-wrap { position: relative; display: block; }
.kb-wrap input { padding-right: 70px; }
.kb-wrap input::-webkit-search-cancel-button { display: none; }
.kb-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  height: 34px; min-width: 52px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--paper); color: var(--muted);
  font: 600 13px var(--font); cursor: pointer;
}
.sync-pill { min-height: 36px; padding: 6px 12px; }

/* On phones, messages sit above the add button rather than over it. */
@media (max-width: 899px) { .toast { bottom: calc(146px + var(--safe-b)); } }
/* Grid and flex children must be allowed to shrink on narrow phones. */
.grid2 > *, .toolbar > *, .row-main, .hero-info, .kb-wrap, .field { min-width: 0; }
.grid2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
input, select, textarea { min-width: 0; max-width: 100%; }
.seg label { position: relative; }
.seg input { left: 0; top: 0; width: 1px; height: 1px; min-height: 0; margin: 0; }
