
:root {
  --bg: #f4f6f3;
  --card: #ffffff;
  --text: #1f2a22;
  --muted: #68736b;
  --green: #1f5d38;
  --green-dark: #17472b;
  --green-soft: #e7f0e9;
  --border: #d9e0da;
  --danger: #a52a2a;
  --danger-soft: #fdeaea;
  --warning: #9a5600;
  --shadow: 0 2px 10px rgba(0,0,0,.07);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  padding-bottom: 86px;
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 10px;
  background: var(--green);
  color: #fff;
  font-weight: 700;
  padding: 12px 16px;
  cursor: pointer;
}

button:hover { background: var(--green-dark); }
button:disabled { opacity: .55; cursor: not-allowed; }

button.secondary {
  background: #e9eeea;
  color: var(--text);
  border: 1px solid var(--border);
}

button.secondary:hover { background: #dde5df; }

button.danger {
  background: var(--danger);
  color: white;
}

button.small-button {
  padding: 8px 11px;
  font-size: 14px;
}

input, select, textarea {
  width: 100%;
  border: 1px solid #bcc8bf;
  border-radius: 10px;
  padding: 12px;
  background: #fff;
  color: var(--text);
  min-height: 46px;
}

textarea {
  resize: vertical;
  min-height: 90px;
}

input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(31,93,56,.15);
  border-color: var(--green);
}

label {
  display: block;
  font-weight: 700;
  margin-bottom: 14px;
}

label input, label select, label textarea {
  margin-top: 6px;
  font-weight: 400;
}

h1, h2, h3 { margin-top: 0; }
h1 { font-size: 28px; }
h2 { font-size: 21px; margin-top: 24px; }
h3 { font-size: 17px; }

p { line-height: 1.45; }

.hidden, .hide { display: none !important; }

.muted, .small {
  color: var(--muted);
}

.small {
  display: block;
  font-size: 12px;
  margin-top: 2px;
}

.message {
  min-height: 20px;
  color: var(--danger);
  font-weight: 700;
}

/* LOGIN */
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.auth-card {
  width: min(470px, 100%);
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.auth-card h1 {
  color: var(--green);
  margin-bottom: 6px;
}

.auth-card button {
  width: 100%;
  margin-top: 8px;
}

/* HEADER */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  min-height: 64px;
  background: var(--green);
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
}

.topbar .small { color: rgba(255,255,255,.8); }

/* MAIN */
main {
  width: min(1000px, 100%);
  margin: 0 auto;
  padding: 18px;
}

main > section {
  padding-bottom: 30px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.section-heading h1 { margin: 0; }

.eyebrow {
  margin: 0 0 4px;
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  color: var(--muted);
}

/* LAYOUT */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 0 16px;
}

.quick-actions,
.filter-row,
.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0;
}

.inline-form > * {
  flex: 1 1 180px;
}

.inline-form button {
  flex: 0 0 auto;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-weight: 600;
}

.check-row input {
  width: 22px;
  height: 22px;
  min-height: auto;
  margin: 0;
  flex: 0 0 auto;
}

/* FILTERS */
.filter-button {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 9px 14px;
}

.filter-button.active {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

/* CARDS */
.card-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.animal-card,
.info-card,
.profile-card {
  width: 100%;
  text-align: left;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.animal-card {
  display: grid;
  gap: 4px;
}

.animal-card:hover {
  background: #f9fbf9;
  border-color: #aec4b4;
}

.info-card {
  display: grid;
  gap: 6px;
}

.info-card button {
  justify-self: start;
  margin-top: 4px;
}

.tag {
  font-size: 24px;
  font-weight: 900;
  color: var(--green-dark);
}

.animal-card small,
.info-card small,
.info-card span {
  color: var(--muted);
}

.alert {
  display: block;
  margin-top: 5px;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 800;
  font-size: 13px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 2px 20px;
}

.detail-grid p {
  margin: 8px 0;
}

.animal-photo {
  width: 100%;
  max-height: 330px;
  object-fit: cover;
  border-radius: 12px;
  margin-bottom: 12px;
}

.brand-photo {
  width: min(220px,100%);
  max-height: 180px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  margin: 8px 0;
}

.link-button {
  width: auto;
  display: inline-block;
  background: transparent;
  color: var(--green);
  border: 0;
  padding: 4px 3px;
  text-decoration: underline;
}

.link-button:hover {
  background: transparent;
  color: var(--green-dark);
}

.menu-list {
  display: grid;
  gap: 10px;
}

.menu-list button {
  min-height: 52px;
  text-align: left;
}

/* BOTTOM NAV */
.bottom-nav {
  position: fixed;
  z-index: 100;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4,1fr);
  min-height: 68px;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 10px rgba(0,0,0,.06);
}

.bottom-nav-button {
  border-radius: 0;
  background: #fff;
  color: var(--muted);
  padding: 10px 4px;
}

.bottom-nav-button:hover { background: #f4f7f4; }

.bottom-nav-button.active {
  color: var(--green);
  background: var(--green-soft);
}

/* TABLET/DESKTOP */
@media (min-width: 800px) {
  body { padding-bottom: 20px; }

  .bottom-nav {
    position: sticky;
    bottom: 0;
    width: min(650px, calc(100% - 40px));
    margin: 0 auto 18px;
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
  }

  main { padding-top: 24px; }
}

/* PHONE */
@media (max-width: 640px) {
  main { padding: 13px; }

  h1 { font-size: 24px; }

  .form-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .section-heading {
    align-items: flex-start;
  }

  .section-heading > button {
    padding: 9px 11px;
  }

  .quick-actions > button {
    flex: 1 1 calc(50% - 8px);
  }

  .tag { font-size: 26px; }

  input, select, textarea, button {
    min-height: 48px;
  }
}

/* PRINT SHIP LIST */
@media print {
  body {
    background: white;
    padding: 0;
  }

  .topbar,
  .bottom-nav,
  #shipAnimalSearch,
  #shipAnimalResults,
  #printShipListButton,
  #clearShipListButton,
  #confirmShipmentButton,
  #shipList .section-heading button {
    display: none !important;
  }

  main {
    width: 100%;
    padding: 0;
  }

  main > section {
    display: none !important;
  }

  #shipList {
    display: block !important;
  }

  .info-card {
    box-shadow: none;
    break-inside: avoid;
  }
}

/* --- T&E Cattle Books full feature additions --- */
.field-note {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.3;
}

.home-actions button {
  min-width: 130px;
}

.profile-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.status-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 900;
}

.status-on {
  background: var(--green-soft);
  color: var(--green-dark);
}

.status-off {
  background: #ececec;
  color: #555;
}

.withdrawal-card {
  border: 2px solid #b12626;
  background: #fff8f8;
}

.withdrawal-tag {
  color: #b12626 !important;
}

.family-links {
  display: grid;
  gap: 8px;
}

.family-link {
  width: 100%;
  text-align: left;
  background: var(--green-soft);
  color: var(--green-dark);
  border: 1px solid #bfd1c3;
}

.family-link:hover {
  background: #dceadf;
}

.deceased-link {
  background: #f2f2f2;
  color: #555;
  border-color: #d5d5d5;
}

.location-animal-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(100px, 1fr) minmax(100px, 1fr);
  align-items: center;
  gap: 12px;
  text-align: left;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.location-animal-row strong {
  color: var(--green-dark);
  font-size: 22px;
}

.location-animal-row span {
  color: var(--muted);
}

.inline-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.inline-actions button {
  min-height: 42px;
}

#treatmentAnimalBanner {
  margin-bottom: 16px;
}

#shipListSavedMessage {
  min-height: 20px;
  font-weight: 700;
}

@media (max-width: 640px) {
  .home-actions > button {
    flex: 1 1 calc(50% - 8px);
    min-width: 0;
  }

  .location-animal-row {
    grid-template-columns: 1fr 1fr;
  }

  .inline-actions button {
    flex: 1 1 120px;
  }
}

@media print {
  #saveShipListButton {
    display: none !important;
  }
}

/* --- Farm-owned Google Drive photos --- */
.profile-photo-grid {
  display: grid;
  grid-template-columns: minmax(0,2fr) minmax(180px,1fr);
  gap: 14px;
  margin-bottom: 16px;
}
.photo-card {
  display: grid;
  gap: 8px;
  align-content: start;
}
.photo-slot {
  min-height: 180px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: #f8faf8;
  color: var(--muted);
  overflow: hidden;
}
.photo-slot.small {
  min-height: 120px;
}
.photo-slot .animal-photo,
.photo-slot .brand-photo {
  margin: 0;
}
.photo-upload-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--green);
  color: var(--green-dark);
  background: #fff;
  font-weight: 800;
  cursor: pointer;
}
.photo-upload-label input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}
.photo-upload-label.disabled {
  opacity: .55;
  cursor: not-allowed;
}
.photo-error {
  padding: 12px;
  color: var(--danger);
  font-weight: 700;
  text-align: center;
}
#shipPenSelect {
  min-width: 220px;
}
@media (max-width: 700px) {
  .profile-photo-grid { grid-template-columns: 1fr; }
  .photo-slot { min-height: 150px; }
}
