:root {
  --bg: #f4f6f2;
  --card: #ffffff;
  --text: #1d2a1f;
  --muted: #6b7a6e;
  --line: #e2e8de;
  --primary: #2e7d43;
  --primary-dark: #235f34;
  --red: #c62828;
  --amber: #b26a00;
  --radius: 14px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  line-height: 1.45;
}
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 14px 60px;
}
h1 { font-size: 26px; margin: 8px 0; }
h2 { font-size: 18px; margin: 22px 0 10px; color: var(--muted); font-weight: 600; }
a { color: var(--primary-dark); text-decoration: none; }

/* Шапка */
.topbar {
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
  gap: 6px;
}
.brand { color: #fff; font-weight: 700; font-size: 18px; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  color: #eaf5ec;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 15px;
}
.topbar nav a.on, .topbar nav a:active { background: rgba(255,255,255,.18); color: #fff; }

/* Сообщения */
.flashes { max-width: 640px; margin: 10px auto 0; padding: 0 14px; }
.flash {
  background: #e3f2e6;
  border: 1px solid #bfe0c6;
  color: var(--primary-dark);
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 6px;
}

/* Карточки и списки */
.card {
  display: block;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin: 10px 0;
}
.card-alert { border-color: #f0c9a0; background: #fff8ef; }
.alert-row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

.list { margin: 8px 0; }
.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  margin-bottom: 8px;
  color: var(--text);
  min-height: 52px;
}
.row:active { background: #f0f4ee; }
.row-main { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-sub { color: var(--muted); font-size: 14px; white-space: nowrap; display: flex; align-items: center; gap: 6px; }

/* Блоки */
.blocks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.block-card { display: flex; align-items: center; gap: 10px; margin: 0; }
.block-label { flex: 1; font-size: 14px; color: var(--muted); }
.block-count { font-size: 22px; font-weight: 700; }
.block-code {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 6px;
  border-radius: 9px;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  background: #90a4ae;
}
.block-А  { background: #2e7d43; }
.block-А1 { background: #7cb342; }
.block-Б  { background: #f9a825; }
.block-С  { background: #0288d1; }
.block-Д  { background: #8d6e63; }

/* Метки */
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  background: #eceff1;
  color: #455a64;
}
.pill-red   { background: #fdecea; color: var(--red); }
.pill-amber { background: #fff3e0; color: var(--amber); }
.pill-green { background: #e3f2e6; color: var(--primary-dark); }
.pill-gray  { background: #eceff1; color: #607d8b; }
.pill-blue  { background: #e3f2fd; color: #0d47a1; }
.warn { color: var(--red); font-weight: 600; }
.muted { color: var(--muted); font-size: 15px; }
.center { text-align: center; }

/* Поиск и фильтры */
.searchbar { display: flex; gap: 8px; margin: 6px 0 12px; }
.searchbar input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 17px;
  background: var(--card);
}
.searchbar button {
  padding: 12px 18px;
  border: 0;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.chip {
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Кнопки */
.btn {
  display: inline-block;
  text-align: center;
  padding: 13px 18px;
  border-radius: var(--radius);
  border: 0;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-wide { display: block; width: 100%; margin: 14px 0; }
.btn-del {
  border: 0;
  background: none;
  color: #b0bec5;
  font-size: 16px;
  padding: 4px 6px;
  cursor: pointer;
}
.btn-del:active { color: var(--red); }
.inline { display: inline; }

/* Карточка животного */
.animal-head { padding: 16px; }
.animal-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.animal-title h1 { margin: 0; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin: 14px 0 0; }
.facts div { }
.facts dt { font-size: 13px; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 600; }

/* Формы */
.event-form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.event-form label { display: flex; flex-direction: column; gap: 5px; font-size: 14px; color: var(--muted); font-weight: 600; }
.event-form input, .event-form select {
  padding: 12px;
  font-size: 17px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  width: 100%;
}
.event-form .check { flex-direction: row; align-items: center; gap: 8px; font-size: 15px; }
.event-form .check input { width: 22px; height: 22px; }
.tf { display: flex; flex-direction: column; gap: 12px; border-left: 3px solid var(--line); padding-left: 12px; }

.add-event summary { list-style: none; }
.add-event summary::-webkit-details-marker { display: none; }
.add-event { border: 0; background: none; padding: 0; }

.event-row { cursor: default; }

/* Контрольный удой */
.milk-head {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  padding: 0 14px 4px 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.milk-head span { width: 62px; text-align: center; }
.milk-inputs { display: flex; gap: 6px; }
.milk-inputs input {
  width: 62px;
  min-width: 0;
  padding: 10px 4px;
  font-size: 16px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.yield-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.yield-grid label {
  min-width: 0;
}
.yield-grid input {
  width: 100% !important;
  min-width: 0;
  box-sizing: border-box;
  text-align: center;
  font-size: 16px;
}
.milk-history { display: flex; flex-wrap: wrap; gap: 10px 18px; }
.milk-item { display: flex; flex-direction: column; }
.milk-liters { font-weight: 700; font-size: 18px; }

/* Страница входа */
.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-box { width: 100%; max-width: 360px; padding: 24px; text-align: center; }
.login-box h1 { margin: 10px 0 18px; }
.login-box form { text-align: left; }
.login-logo { width: 84px; height: 84px; border-radius: 20px; }
.login-error { background: #fdecea; border-color: #f5c6c0; color: #c62828; }

@media (max-width: 420px) {
  .facts { grid-template-columns: 1fr; }
  .blocks { grid-template-columns: 1fr 1fr; }
}
