/* =============================================
   FarmApp — main.css  (Phase 5: mobile polish)
   ============================================= */

/* ---- Base reset ---- */
*, *::before, *::after {
  box-sizing: border-box;
}

/* ---- Body ---- */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  background: #f2f2f2;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  /* dvh = dynamic viewport height (collapses with mobile browser toolbar) */
  min-height: 100dvh;
  min-height: 100vh; /* fallback */
  padding-top: 1.5rem;
  padding-bottom: 1.5rem;
  /* Safe-area insets: top for notch, bottom for home indicator */
  padding-top:    max(1.5rem, env(safe-area-inset-top,    0px));
  padding-bottom: max(1.5rem, env(safe-area-inset-bottom, 0px));
  padding-left:   env(safe-area-inset-left,  0px);
  padding-right:  env(safe-area-inset-right, 0px);
}

/* Extra bottom padding when the bottom nav is present */
body.has-bottom-nav {
  padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
}

/* ---- Form container ---- */
.form-container {
  background: #fff;
  padding: 2rem;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  width: 92%;
  max-width: 480px;
  margin: 0 auto;
}

/* Wide variant (view_animals table) */
.form-container--wide {
  max-width: 860px;
}

/* Tighter padding on small phones */
@media (max-width: 380px) {
  .form-container {
    padding: 1.25rem;
    border-radius: 12px;
  }
}

/* ---- Typography ---- */
h2 {
  text-align: center;
  margin: 0 0 1rem;
  font-size: 1.35rem;
  color: #1a1a1a;
}

label {
  display: block;
  margin: 12px 0 5px;
  font-weight: 600;
  font-size: 0.9rem;
  color: #333;
}

/* ---- Inputs ---- */
/* font-size: 16px prevents iOS auto-zoom on focus */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 12px;
  margin-bottom: 0.75rem;
  border: 1.5px solid #d0d0d0;
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  background: #fff;
  color: #1a1a1a;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  touch-action: manipulation;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: #2d2d30;
  box-shadow: 0 0 0 3px rgba(45, 45, 48, 0.15);
}

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

/* ---- Buttons ---- */
button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 14px;
  background: #2d2d30;
  color: #fff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 600;
  min-height: 48px;
  transition: background 0.15s, transform 0.1s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:hover,
.btn:hover {
  background: #1f1f21;
}

button:active,
.btn:active {
  background: #111;
  transform: scale(0.98);
}

button:focus-visible,
.btn:focus-visible {
  outline: 3px solid #2d2d30;
  outline-offset: 2px;
}

/* ---- Alerts ---- */
.error,
.success {
  padding: 11px 14px;
  margin-bottom: 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  line-height: 1.4;
}

.error {
  background: #f8d7da;
  color: #842029;
  border-left: 4px solid #f5c2c7;
}

.success {
  background: #d1e7dd;
  color: #0f5132;
  border-left: 4px solid #a3cfbb;
}

/* ---- Links ---- */
.form-links {
  text-align: center;
  margin-top: 1.25rem;
  font-size: 0.9rem;
}

.form-links a {
  color: #2d2d30;
  text-decoration: none;
  padding: 6px 2px;
  display: inline-block;
  min-height: 44px;
  line-height: 32px;
}

.form-links a:hover {
  text-decoration: underline;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: #2d2d30;
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  text-decoration: none;
  min-height: 48px;
  font-weight: 600;
}

.button-link:hover { background-color: #1f1f21; }
.button-link:active { background-color: #111; }

/* ---- Dashboard grid ---- */
.grid-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.875rem;
  justify-content: center;
  margin-top: 1.75rem;
}

.grid-buttons a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1rem 1.5rem;
  text-align: center;
  text-decoration: none;
  color: #fff;
  background-color: #2d2d30;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  min-width: 140px;
  min-height: 52px;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.grid-buttons a:hover  { background-color: #1f1f21; }
.grid-buttons a:active { background-color: #111; transform: scale(0.97); }

/* ---- Animal table ---- */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  font-size: 0.9rem;
}

th, td {
  padding: 10px 12px;
  border: 1px solid #e0e0e0;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f5f5f5;
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #555;
}

.actions a {
  margin-right: 10px;
  color: #2d2d30;
  text-decoration: none;
  font-weight: 600;
  display: inline-block;
  min-height: 44px;
  line-height: 44px;
}

/* ---- Responsive table: card layout on small screens ---- */
@media (max-width: 640px) {
  table, thead, tbody, th, td, tr { display: block; }

  thead { display: none; }

  tr {
    margin-bottom: 0.875rem;
    border: 1px solid #ddd;
    border-radius: 10px;
    padding: 0.625rem 0.75rem;
    background: #fafafa;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
  }

  td {
    border: none;
    padding: 5px 0;
    font-size: 0.9rem;
    display: flex;
    gap: 6px;
  }

  td::before {
    content: attr(data-label);
    font-weight: 700;
    color: #555;
    min-width: 72px;
    flex-shrink: 0;
  }
}

/* ---- Bottom navigation bar ---- */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: #2d2d30;
  display: flex;
  align-items: stretch;
  /* Safe-area bottom padding for iPhone home indicator */
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left:   env(safe-area-inset-left,   0px);
  padding-right:  env(safe-area-inset-right,  0px);
  box-shadow: 0 -2px 12px rgba(0,0,0,.25);
}

#bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 10px 4px;
  min-height: 56px;
  text-decoration: none;
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  transition: color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#bottom-nav a:hover  { color: rgba(255,255,255,.8); }
#bottom-nav a:active { background: rgba(255,255,255,.08); }

#bottom-nav a.nav-active {
  color: #fff;
}

#bottom-nav a.nav-active .nav-icon {
  /* Subtle indicator dot under active icon */
  position: relative;
}

#bottom-nav a.nav-active .nav-icon::after {
  content: '';
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #fff;
  margin: 2px auto 0;
}

.nav-icon {
  font-size: 1.35rem;
  line-height: 1;
  display: block;
}

.nav-label {
  display: block;
  font-size: 0.58rem;
}

/* ---- Loading spinner ---- */
.farm-loading {
  display: flex;
  justify-content: center;
  padding: 1.5rem 0;
}

.farm-loading::after {
  content: '';
  width: 28px;
  height: 28px;
  border: 3px solid #e0e0e0;
  border-top-color: #2d2d30;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---- Offline / sync notes ---- */
.offline-note {
  color: #c0392b;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  padding: 8px 10px;
  background: #fff5f5;
  border-radius: 6px;
  border-left: 3px solid #c0392b;
}

.sync-status {
  font-size: 0.78rem;
  color: #888;
  white-space: nowrap;
}

/* ---- Focus ring for keyboard users ---- */
a:focus-visible {
  outline: 3px solid #2d2d30;
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---- Utility ---- */
.text-center { text-align: center; }
.mt-1 { margin-top: 1rem; }

/* ---- Photo upload area ---- */
.photo-upload-area {
  margin-bottom: 0.75rem;
}

/* Hidden native file input — triggered by the styled label */
.photo-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

/* Styled upload button / drop zone */
.photo-upload-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 20px 12px;
  border: 2px dashed #c0c0c0;
  border-radius: 12px;
  background: #fafafa;
  color: #555;
  cursor: pointer;
  text-align: center;
  font-size: 0.9rem;
  transition: border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.photo-upload-label:hover,
.photo-upload-label:focus-within {
  border-color: #2d2d30;
  background: #f0f0f0;
}

.photo-upload-icon {
  font-size: 2rem;
  line-height: 1;
}

.photo-upload-hint {
  font-size: 0.78rem;
  color: #999;
}

/* Preview wrapper */
.photo-preview-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  margin-bottom: 0.5rem;
}

.photo-preview {
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  border-radius: 12px;
  border: 1.5px solid #e0e0e0;
}

/* ✕ remove button overlaid on preview */
.photo-remove-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 0.85rem;
  line-height: 1;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-remove-btn:hover {
  background: rgba(0,0,0,0.75);
}

/* ---- Animal thumbnail in table ---- */
.animal-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
  display: block;
}

.animal-thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background: #f0f0f0;
  font-size: 1.5rem;
}

.animal-photo-cell {
  text-align: center;
  vertical-align: middle;
}

/* On mobile card layout, photo goes full-width at top */
@media (max-width: 640px) {
  .animal-photo-cell {
    justify-content: flex-start;
    padding-bottom: 8px;
  }

  .animal-photo-cell::before {
    display: none;
  }

  .animal-thumb {
    width: 72px;
    height: 72px;
  }
}
