:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #2b2620;
  --muted: #7a7266;
  --accent: #2f6b3a;
  --accent-ink: #ffffff;
  --line: #e4ded3;
  --warn: #a0522d;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand-title { font-size: 1.15rem; font-weight: 700; }
.brand-sub { font-size: 0.78rem; color: var(--muted); display: block; }
.nav { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.nav a { color: var(--ink); text-decoration: none; font-weight: 500; }
.nav a:hover { text-decoration: underline; }
.inline { display: inline; }

.content { padding: 16px; max-width: 980px; margin: 0 auto; }

.flashes { max-width: 980px; margin: 0 auto; padding: 0 16px; }
.flash { padding: 8px 12px; border-radius: 6px; margin: 8px 0; }
.flash.ok { background: #e6f2e9; color: #1c4a26; }
.flash.err { background: #fbe9e2; color: #7c2d12; }

.flock-tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.tab {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  text-decoration: none;
  color: var(--ink);
  font-weight: 500;
}
.tab.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  text-decoration: none;
  color: var(--ink);
  display: flex;
  flex-direction: column;
}
.card-photo { aspect-ratio: 1; background: #eae5da; display: flex; align-items: center; justify-content: center; }
.card-photo img { width: 100%; height: 100%; object-fit: cover; }
.no-photo { font-size: 2.4rem; opacity: 0.5; }
.card-body { padding: 8px 10px; }
.card-name { font-weight: 700; }
.card-meta { font-size: 0.78rem; color: var(--muted); }
.card-last { font-size: 0.74rem; color: var(--muted); margin-top: 2px; }

.sheep-header { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sheep-name { margin: 0; font-size: 1.6rem; }
.sheep-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.8rem;
}
.pill-warn { background: #fbe9e2; color: var(--warn); border-color: #eac3b0; }

.slots { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 12px 0; }
.slot { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px; text-align: center; }
.slot-label { font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; }
.slot-photo { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; }
.slot-empty { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); background: #eae5da; border-radius: 6px; }

.photo-form { margin-top: 8px; display: flex; gap: 6px; justify-content: center; }
.file-btn {
  display: inline-block;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  cursor: pointer;
  font-size: 0.8rem;
}
.file-btn.cam { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin: 8px 0; }
.gallery-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; }

.record { display: grid; grid-template-columns: 130px 1fr; gap: 4px 12px; margin: 8px 0; }
.record dt { color: var(--muted); font-weight: 500; }
.record dd { margin: 0; }
.notes { color: var(--muted); }

.lambs li, .breeding-list li { padding: 3px 0; }

.actions { list-style: none; padding: 0; margin: 8px 0; }
.actions li {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.action-type { font-weight: 600; }
.action-date { color: var(--muted); font-size: 0.85rem; }
.action-value { background: #eef3ea; padding: 1px 7px; border-radius: 999px; font-size: 0.82rem; }
.action-note { color: var(--muted); font-size: 0.88rem; }

details.add-action { margin: 14px 0; }
details.add-action summary { cursor: pointer; color: var(--accent); font-weight: 600; }
details[open] summary { margin-bottom: 10px; }

.form { display: flex; flex-direction: column; gap: 10px; max-width: 480px; }
.form label { display: flex; flex-direction: column; gap: 3px; font-size: 0.88rem; color: var(--muted); }
.form input, .form select, .form textarea {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 1rem;
  color: var(--ink);
  background: var(--card);
}
.form-actions { display: flex; gap: 10px; }

.btn, .btn-accent, .btn-ghost {
  display: inline-block;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--line);
  text-decoration: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  background: var(--card);
  color: var(--ink);
}
.btn-accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-ghost { background: transparent; }
button.btn-accent, button.btn-ghost { font-family: inherit; }

.login-box { max-width: 360px; margin: 40px auto; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 20px; }
.empty { color: var(--muted); }

.view-toggle { margin-left: auto; display: inline-flex; gap: 4px; }

.col-picker { margin: 4px 0 14px; }
.col-picker summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.col-form { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin-top: 8px; }
.col-check { display: inline-flex; align-items: center; gap: 4px; font-size: 0.86rem; color: var(--ink); }
.col-check input { width: 15px; height: 15px; }
.col-form .btn-accent { margin-left: 4px; }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.sheep-table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
.sheep-table th, .sheep-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.sheep-table th { position: sticky; top: 0; background: #f3efe7; font-weight: 600; color: var(--muted); }
.sheep-table tbody tr:hover { background: #faf7f0; }
.td-photo img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; display: block; }
.td-photo .no-photo { font-size: 1.2rem; opacity: 0.5; }
.td-name a { font-weight: 600; color: var(--ink); text-decoration: none; }
.td-name a:hover { text-decoration: underline; }

@media (max-width: 600px) {
  .record { grid-template-columns: 1fr; }
  .record dt { margin-top: 6px; }
  .brand-sub { display: none; }
  .view-toggle { margin-left: 0; width: 100%; }
  .view-toggle .tab { flex: 1; text-align: center; }
}
