:root {
  --bg: #f7f3ec;
  --surface: #fffdf9;
  --ink: #2b2320;
  --muted: #6f655c;
  --line: #e2d9ca;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --accent-soft: #e3eee9;
  --bad: #a8261c;
  --bad-soft: #f9e6e3;
  --warn-soft: #f6ecd2;
  --warn-ink: #5e4708;
  --radius: 14px;
  --tap: 46px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a17;
    --surface: #27241f;
    --ink: #f1ebe0;
    --muted: #a99f92;
    --line: #3b362e;
    --accent: #5fa893;
    --accent-ink: #10201b;
    --accent-soft: #24372f;
    --bad: #ef8d84;
    --bad-soft: #3d2320;
    --warn-soft: #3a3019;
    --warn-ink: #eed9a0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Hebrew", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
a { color: inherit; }
h1, h2, p, ul, dl, dd { margin: 0; padding: 0; }
ul { list-style: none; }
.boot { padding: 40vh 16px; text-align: center; color: var(--muted); }
.icon { display: inline-flex; width: 22px; height: 22px; flex: none; }
.icon svg { width: 100%; height: 100%; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }

/* ---------- layout ---------- */
.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px calc(84px + env(safe-area-inset-bottom));
}
.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 -16px 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.bar h1 { flex: 1; font-size: 20px; font-weight: 700; line-height: 1.2; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  width: var(--tap); height: var(--tap); margin-inline-start: -10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: 0; color: inherit; cursor: pointer; border-radius: 50%;
}
.tabs {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; max-width: 214px; min-height: 58px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 13px; color: var(--muted); text-decoration: none;
}
.tab.active { color: var(--accent); font-weight: 700; }
.notice {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 14px; padding: 10px 12px; border-radius: var(--radius);
  background: var(--warn-soft); color: var(--warn-ink); font-size: 15px;
}
.notice .btn { flex: none; border-color: currentColor; color: inherit; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 8px 16px;
  border: 1px solid transparent; border-radius: 12px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:disabled { opacity: .55; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.danger { background: var(--bad); color: var(--surface); }
.btn.danger-ghost { background: transparent; border-color: var(--line); color: var(--bad); }
.btn.link { background: none; color: var(--accent); min-height: 40px; text-decoration: underline; font-weight: 500; }
.btn.small { min-height: 38px; padding: 4px 12px; font-size: 15px; }
.btn.small .icon { width: 18px; height: 18px; }
.btn.wide { width: 100%; }
.btn.big { min-height: 54px; font-size: 17px; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}

/* ---------- home ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.stat {
  display: flex; flex-direction: column; align-items: center; padding: 10px 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none;
}
.stat strong { font-size: 26px; line-height: 1.15; }
.stat span { font-size: 13px; color: var(--muted); }
.stat.bad strong { color: var(--bad); }
.group { margin-bottom: 18px; }
.group h2 { font-size: 15px; color: var(--muted); font-weight: 700; margin-bottom: 8px; }
.reminders { display: flex; flex-direction: column; gap: 8px; }
.reminder { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.reminder-main { display: flex; gap: 10px; align-items: flex-start; text-decoration: none; }
.reminder-text { display: flex; flex-direction: column; min-width: 0; }
.due { font-size: 14px; color: var(--muted); }
.due.overdue { color: var(--bad); font-weight: 600; }
.reminder-actions { display: flex; gap: 8px; margin-top: 8px; justify-content: flex-end; }
.reminder.on-card { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; }
.reminder.on-card .reminder-actions { margin-top: 0; flex: none; }
.avatar {
  width: 46px; height: 46px; flex: none; border-radius: 50%; object-fit: cover;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 19px;
}
.empty { text-align: center; padding: 40px 16px; color: var(--muted); display: flex; flex-direction: column; gap: 14px; align-items: center; }
.empty-line { color: var(--muted); padding: 14px 2px; }

/* ---------- list ---------- */
.search {
  display: flex; align-items: center; gap: 8px; padding: 0 12px; min-height: 48px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; color: var(--muted);
}
.search input { flex: 1; min-width: 0; border: 0; background: none; font: inherit; color: var(--ink); height: 46px; outline: none; }
.search:focus-within { outline: 3px solid var(--accent); outline-offset: 1px; }
.filters { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 6px; margin: 8px 0; }
.filters select, .toggle {
  width: 100%; min-height: 42px; padding: 4px 8px; font: inherit; font-size: 14px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink);
}
.toggle { cursor: pointer; }
.toggle.on { background: var(--bad); border-color: var(--bad); color: var(--surface); font-weight: 700; }
.count { font-size: 14px; color: var(--muted); margin: 6px 2px; }
.rows { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.rows:empty { display: none; }
.rows li + li { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; text-decoration: none; min-height: 64px; }
.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-text > span { font-size: 14px; color: var(--muted); }
.chip-no { font-size: 13px; }
.badge {
  flex: none; font-size: 13px; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap;
}
.badge.bad { background: var(--bad-soft); color: var(--bad); font-weight: 700; }
.sentinel { height: 1px; }

/* ---------- horse card ---------- */
.hero {
  position: relative; margin-bottom: 14px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.hero-img { display: block; width: 100%; max-height: 300px; object-fit: cover; }
.hero-line { padding: 10px 12px 0; font-weight: 600; }
.hero-chip { padding: 0 12px 10px; font-size: 14px; color: var(--muted); }
.hero-line:last-child { padding-bottom: 10px; }
.photo-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 6px 12px; cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--accent);
}
.hero:not(.no-photo) .photo-btn {
  position: absolute; top: 8px; inset-inline-end: 8px; background: rgba(20, 16, 12, .62); color: #fff; border-radius: 999px;
}
/* Not display:none: some phones will not open the picker for a hidden file input. */
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.quick { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; margin-bottom: 14px; }
.quick .btn { padding-inline: 6px; }
.tabs-inline {
  display: flex; gap: 4px; margin-bottom: 12px; padding: 3px;
  background: var(--line); border-radius: 12px; overflow-x: auto;
}
.tabs-inline button {
  flex: 1 0 auto; min-height: 40px; padding: 4px 10px; border: 0; border-radius: 9px;
  background: none; font: inherit; font-size: 14px; color: var(--ink); cursor: pointer; white-space: nowrap;
}
.tabs-inline button.on { background: var(--surface); font-weight: 700; }
.records { display: flex; flex-direction: column; gap: 8px; }
.record { display: block; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; }
.record-top { display: flex; justify-content: space-between; gap: 10px; }
.record-date { flex: none; font-size: 14px; color: var(--muted); }
.record p { font-size: 15px; }
.record .next { color: var(--accent); font-weight: 600; }
.record .by { font-size: 13px; color: var(--muted); margin-top: 2px; }
.pre { white-space: pre-wrap; }
.details dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; padding: 12px; margin-bottom: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.details dt { color: var(--muted); font-size: 14px; }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 4px; position: relative; }
.field > label { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 14px; font-weight: 600; }
.field small, .hint { font-size: 13px; color: var(--muted); }
.field small.linked { color: var(--accent); font-weight: 600; }
.next-hint:empty { display: none; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="number"], textarea, .field select {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  /* 16px keeps iPhone from zooming the page on focus */
  font: inherit; font-size: 16px;
}
input[type="date"] { min-width: 0; -webkit-appearance: none; appearance: none; text-align: start; }
textarea { resize: vertical; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg input { position: absolute; opacity: 0; width: 0; height: 0; }
.seg label {
  flex: 1 0 auto; min-height: 42px; padding: 8px 12px; text-align: center; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; font-size: 15px;
}
.seg input:checked + label { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.seg input:focus-visible + label { outline: 3px solid var(--accent); outline-offset: 2px; }
.quick-dates { display: flex; flex-wrap: wrap; gap: 6px; }
.form-error { padding: 8px 12px; background: var(--bad-soft); color: var(--bad); border-radius: 10px; font-weight: 600; }
.picker {
  position: absolute; top: 100%; inset-inline: 0; z-index: 6; max-height: 260px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
}
.picker button { width: 100%; min-height: 44px; padding: 8px 12px; text-align: start; background: none; border: 0; font: inherit; color: inherit; cursor: pointer; }
.picker li + li { border-top: 1px solid var(--line); }
.with-button { display: flex; gap: 8px; align-items: stretch; }
.with-button input { flex: 1; }

/* ---------- more ---------- */
.card {
  display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; padding: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.card h2 { font-size: 17px; }
.card.backup { border: 2px solid var(--accent); }
.card.bad { border-color: var(--bad); }
.menu { display: flex; flex-direction: column; margin-bottom: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.menu a { display: flex; justify-content: space-between; align-items: center; min-height: 52px; padding: 8px 14px; text-decoration: none; }
.menu a + a { border-top: 1px solid var(--line); }
.menu .icon { color: var(--muted); width: 18px; height: 18px; }
.file-btn { position: relative; cursor: pointer; }
.trash { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.trash-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; }
.trash-row + .trash-row { border-top: 1px solid var(--line); }

/* ---------- overlay ---------- */
#toast {
  position: fixed; inset-inline: 16px; bottom: calc(70px + env(safe-area-inset-bottom)); z-index: 30;
  display: none; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 608px; margin-inline: auto; padding: 12px 14px;
  background: var(--ink); color: var(--bg); border-radius: 12px; font-size: 15px;
}
#toast.show { display: flex; }
.toast-action { flex: none; min-height: 34px; padding: 2px 8px; background: none; border: 0; color: inherit; font: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; }
.overlay {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(0, 0, 0, .5);
}
.dialog {
  width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto; padding: 18px;
  background: var(--surface); color: var(--ink); border-radius: 16px; outline: none;
}
.dialog h2 { font-size: 19px; margin-bottom: 8px; }
.dialog-body { margin-bottom: 14px; }
.dialog-actions { display: flex; flex-direction: column; gap: 8px; }

/* ---------- install first ---------- */
.welcome {
  max-width: 420px; margin: 0 auto; padding: calc(36px + env(safe-area-inset-top)) 16px 32px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.welcome h1 { font-size: 26px; }
.welcome-icon { border-radius: 18px; }
.welcome ol { margin: 4px 0; padding-inline-start: 22px; align-self: stretch; }
.welcome li { margin-bottom: 6px; }
.welcome .card { align-self: stretch; }
