/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green-dark: #2d5016;
  --green: #4a7c28;
  --green-light: #6fa03e;
  --green-pale: #e8f5d8;
  --brown: #8b6914;
  --brown-light: #d4a837;
  --bg: #f5f3ef;
  --bg-card: #ffffff;
  --text: #2c2c2c;
  --text-light: #6b6b6b;
  --border: #e0ddd6;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --sidebar-w: 240px;
  --topbar-h: 56px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Screens === */
.screen { display: none; }
.screen.active { display: block; }

/* === Auth === */
.auth-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: linear-gradient(135deg, var(--green-dark) 0%, var(--green) 50%, var(--brown) 100%);
}

.logo { text-align: center; margin-bottom: 2rem; }
.logo-icon { font-size: 4rem; margin-bottom: 0.5rem; }
.logo h1 { font-size: 2.5rem; color: #fff; font-weight: 800; }
.logo h1 span { color: var(--brown-light); }
.tagline { color: rgba(255,255,255,0.8); font-size: 1.1rem; }

.auth-form {
  background: var(--bg-card);
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
}

.auth-form h2 { margin-bottom: 1.5rem; color: var(--green-dark); }
.auth-switch { text-align: center; margin-top: 1rem; color: var(--text-light); font-size: 0.9rem; }
.hidden { display: none !important; }

.error-msg {
  background: #fde8e8;
  color: #c53030;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-top: 1rem;
  max-width: 400px;
  width: 100%;
  text-align: center;
}

/* === Forms === */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; margin-bottom: 0.25rem; font-size: 0.9rem; }

.input, .auth-form input, .auth-form textarea, .auth-form select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  transition: border-color 0.2s;
  background: #fff;
}

.input:focus, .auth-form input:focus {
  outline: none;
  border-color: var(--green);
}

.input-sm {
  padding: 0.4rem 0.6rem;
  border: 2px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  background: #fff;
}

.form-row { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.5rem; }

/* === Buttons === */
.btn {
  padding: 0.6rem 1.2rem;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.2s;
}
.btn:hover { border-color: var(--green); color: var(--green); }
.btn-primary {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}
.btn-primary:hover { background: var(--green-dark); border-color: var(--green-dark); color: #fff; }
.btn-full { width: 100%; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }

/* === Layout === */
#main-screen { display: none; }
#main-screen.active { display: grid; grid-template-columns: var(--sidebar-w) 1fr; grid-template-rows: var(--topbar-h) 1fr; min-height: 100vh; }

.top-bar {
  grid-column: 1 / -1;
  background: var(--green-dark);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  z-index: 10;
}
.top-bar h1 { font-size: 1.1rem; flex: 1; }
.top-right { display: flex; align-items: center; gap: 1rem; }
#user-name { font-size: 0.85rem; opacity: 0.9; }
#logout-btn { color: #fff; border-color: rgba(255,255,255,0.3); background: transparent; }
#logout-btn:hover { border-color: #fff; }
.menu-btn { display: none; background: none; border: none; color: #fff; font-size: 1.5rem; cursor: pointer; }

/* === Sidebar === */
.sidebar {
  background: #fff;
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.sidebar-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border);
}
.ranch-name { font-weight: 700; color: var(--green-dark); font-size: 1rem; }
.nav-list { list-style: none; padding: 0.5rem 0; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1.25rem;
  color: var(--text);
  font-weight: 500;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}
.nav-link:hover { background: var(--green-pale); text-decoration: none; }
.nav-link.active {
  background: var(--green-pale);
  color: var(--green-dark);
  border-left-color: var(--green);
  font-weight: 700;
}
.nav-icon { font-size: 1.1rem; width: 1.5rem; text-align: center; }

/* === Content === */
.content {
  padding: 1.5rem;
  overflow-y: auto;
  max-height: calc(100vh - var(--topbar-h));
}

.page { display: none; }
.page.active { display: block; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}
.page-header h2 { font-size: 1.5rem; color: var(--green-dark); }

/* === Stats Grid === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  text-align: center;
}
.stat-number { font-size: 2rem; font-weight: 800; color: var(--green-dark); }
.stat-label { color: var(--text-light); font-size: 0.85rem; margin-top: 0.25rem; }

/* === Dashboard Sections === */
.dashboard-sections {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
}
.dash-section {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.dash-section h3 { margin-bottom: 1rem; color: var(--green-dark); font-size: 1rem; }
.empty-state { color: var(--text-light); font-style: italic; padding: 1rem 0; }

/* === Card Grid === */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}
.animal-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border-left: 4px solid var(--green);
}
.animal-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.animal-card .card-name { font-weight: 700; font-size: 1.1rem; }
.animal-card .card-meta { color: var(--text-light); font-size: 0.85rem; margin-top: 0.25rem; }
.animal-card .card-status {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: 0.5rem;
}
.status-active { background: var(--green-pale); color: var(--green-dark); }
.status-sold { background: #fff3cd; color: #856404; }
.status-deceased { background: #f5f5f5; color: #6b6b6b; }

/* === Filters === */
.filters {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

/* === Records List === */
.records-list .record-item {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow);
}

/* === Settings === */
.settings-section {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}
.settings-section h3 { margin-bottom: 1rem; color: var(--green-dark); }

.type-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--green-pale);
  padding: 0.35rem 0.75rem;
  border-radius: 20px;
  font-size: 0.85rem;
  margin: 0.25rem;
}

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.2rem; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-light); }
.modal-body { padding: 1.5rem; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 0.75rem; }

/* === Mobile === */
@media (max-width: 768px) {
  #main-screen.active {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: block; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-sections { grid-template-columns: 1fr; }
}

/* === Loading Spinner === */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 3px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Toast === */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--green-dark);
  color: #fff;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } }
