:root {
  --primary: #1f4d31;
  --primary-light: #6da34d;
  --accent: #e2b453;
  --bg: #f5f7f2;
  --card-bg: #ffffff;
  --text-dark: #203126;
  --text-muted: #5e7063;
  --line: rgba(31, 77, 49, 0.1);
  --danger: #d32f2f;
  
  --sidebar-width: 280px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body { 
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; 
  background-color: var(--bg); 
  color: var(--text-dark); 
  line-height: 1.6;
}

/* LOGIN SCREEN */
.login-screen {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  display: flex; justify-content: center; align-items: center;
  z-index: 1000;
}
.login-card {
  background: white; padding: 3rem 2rem; border-radius: 20px;
  width: 90%; max-width: 400px; text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}
.login-logo { max-height: 60px; margin-bottom: 1rem; }
.login-card h1 { font-size: 1.8rem; margin-bottom: 0.5rem; color: var(--primary); }
.login-card p { color: var(--text-muted); margin-bottom: 2rem; }
#loginForm { display: flex; flex-direction: column; gap: 1rem; }

/* DASHBOARD LAYOUT */
.dashboard-layout { display: flex; min-height: 100vh; }

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-width);
  background: white;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: fixed; top: 0; bottom: 0; left: 0;
}
.sidebar-header {
  padding: 1.5rem; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.sidebar-header h2 { color: var(--primary); font-size: 1.4rem; font-weight: 800; }
.badge { background: var(--primary-light); color: white; padding: 0.2rem 0.5rem; border-radius: 6px; font-size: 0.75rem; font-weight: bold;}
.sidebar-nav { padding: 1.5rem 1rem; display: flex; flex-direction: column; gap: 0.5rem; flex-grow: 1;}
.nav-item {
  background: transparent; border: none; text-align: left;
  padding: 0.8rem 1rem; border-radius: 10px;
  font-size: 1rem; color: var(--text-muted); font-weight: 600;
  cursor: pointer; transition: all 0.2s; text-decoration: none; display: block;
}
.nav-item:hover { background: var(--bg); color: var(--primary); }
.nav-item.active { background: var(--primary-light); color: white; }
.text-danger { color: var(--danger); }
.text-danger:hover { background: #ffebee; color: var(--danger); }

/* MAIN CONTENT */
.main-content { margin-left: var(--sidebar-width); flex-grow: 1; display: flex; flex-direction: column; min-height: 100vh;}
.topbar {
  background: white; padding: 1.2rem 2.5rem;
  border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
}
.topbar h2 { font-size: 1.4rem; color: var(--text-dark); }
.content-area { padding: 2.5rem; max-width: 1200px; width: 100%; margin: 0 auto; }

.view-section { display: none; }
.view-section.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* COMPONENTS */
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.5rem; margin-bottom: 2rem;}
.metric-card {
  background: white; padding: 1.5rem; border-radius: 16px; border: 1px solid var(--line);
  box-shadow: 0 4px 15px rgba(0,0,0,0.02); display: flex; flex-direction: column; gap: 0.5rem;
}
.metric-card span { color: var(--text-muted); font-weight: 600; font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.5px;}
.metric-card strong { font-size: 2.5rem; color: var(--primary); font-weight: 800; line-height: 1;}

.text-blue strong { color: #1976d2; }
.text-green strong { color: #388e3c; }
.text-purple strong { color: #7b1fa2; }

.card { background: white; padding: 2rem; border-radius: 16px; border: 1px solid var(--line); box-shadow: 0 4px 15px rgba(0,0,0,0.02); margin-bottom: 2rem;}
.card-head { margin-bottom: 1.5rem; }
.card-head h3 { color: var(--primary); font-size: 1.3rem; margin-bottom: 0.3rem;}
.card-head p { color: var(--text-muted); font-size: 0.95rem; }
.card-head-inline { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.card-tools { display: flex; gap: 0.8rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.compact-grid { margin-top: 1.25rem; }
.subtle-status { color: var(--text-muted); margin-bottom: 1rem; }

/* FORMS */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
.filters-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; align-items: end; }
.form-group { display: flex; flex-direction: column; gap: 0.4rem; }
.form-group.full-width { grid-column: 1 / -1; }
.form-group label { font-size: 0.85rem; font-weight: 700; color: var(--text-dark); }
.helper-text { color: var(--text-muted); font-size: 0.8rem; }

input, select, textarea {
  padding: 0.8rem 1rem; border: 1px solid #ccc; border-radius: 10px;
  font-family: inherit; font-size: 0.95rem; background: #fafafa;
  transition: border-color 0.2s; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary-light); background: white;}

button { font-family: inherit; cursor: pointer; border: none; border-radius: 10px; font-weight: 700; transition: all 0.2s; }
.primary-button { background: var(--primary); color: white; padding: 0.8rem 1.5rem; font-size: 1rem;}
.primary-button:hover { background: var(--primary-light); }
.secondary-button { background: #edf4ed; color: var(--primary); }
.secondary-button:hover { background: #dfeedd; }
.icon-button { background: transparent; color: var(--text-muted); font-size: 1.2rem; padding: 0.4rem 0.7rem; }
.icon-button:hover { color: var(--primary); background: var(--bg); }

.status-message { font-size: 0.9rem; color: var(--danger); margin-top: 1rem; }
.status-message.success { color: var(--primary-light); }
.status-message.inline { margin-top: 0; margin-left: 1rem; }

hr { border: none; border-top: 1px solid var(--line); margin: 1rem 0; }

.photo-preview {
  width: 100%;
  max-width: 280px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
}

.photo-preview-empty {
  width: 100%;
  max-width: 280px;
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 1px dashed var(--line);
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 600;
  text-align: center;
  padding: 1rem;
}

/* HISTORY CONTROLS */
.chip-row { display: flex; flex-wrap: wrap; gap: 0.8rem; margin-top: 0.5rem;}
.chip-button { background: var(--bg); color: var(--text-dark); padding: 0.6rem 1.2rem; border: 1px solid var(--line); border-radius: 999px; font-size: 0.9rem;}
.chip-button:hover { background: var(--primary-light); color: white; border-color: var(--primary-light);}

.auth-inline {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
  align-items: center;
}

.auth-inline input {
  min-width: 180px;
}

/* PLANTS LIST */
.plants-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1.5rem; }
.plant-card { background: white; padding: 1.5rem; border-radius: 16px; border: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden; position: relative;}
.plant-card-id { position: absolute; top: 1.5rem; right: 1.5rem; background: rgba(0,0,0,0.6); color: white; padding: 0.2rem 0.6rem; border-radius: 6px; font-weight: 800; font-size: 0.8rem; z-index: 10; backdrop-filter: blur(4px);}
.plant-card-img { width: 100%; height: 180px; object-fit: cover; border-radius: 12px; margin-bottom: 1rem; }
.plant-card-img-placeholder { width: 100%; height: 180px; background: var(--bg); display: flex; align-items: center; justify-content: center; border-radius: 12px; margin-bottom: 1rem; color: var(--text-muted); font-weight: 700; border: 1px dashed var(--line); }
.plant-card h3 { color: var(--primary); margin-bottom: 0.8rem; font-size: 1.2rem; display: flex; justify-content: space-between; align-items: center;}
.plant-card h3 small { color: var(--text-muted); font-size: 0.85rem; font-weight: 500;}
.plant-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.tag { background: var(--bg); color: var(--text-dark); padding: 0.2rem 0.6rem; border-radius: 6px; font-size: 0.8rem; font-weight: 700;}
.tag.propagacion { background: #e3f2fd; color: #1565c0; }
.tag.disponible { background: #e8f5e9; color: #2e7d32; }
.tag.vendido { background: #f3e5f5; color: #7b1fa2; }
.plant-details { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.5rem; flex-grow: 1;}
.plant-links { display: flex; flex-wrap: wrap; gap: 1rem; border-top: 1px solid var(--line); padding-top: 1rem; }
.plant-links a, .btn-icon { color: var(--primary-light); text-decoration: none; font-weight: 700; font-size: 0.9rem; background: none; border: none; padding: 0; display: flex; align-items: center; gap: 0.3rem;}
.plant-links a:hover, .btn-icon:hover { text-decoration: underline; color: var(--primary); }
.btn-icon.text-danger { color: var(--danger); }
.btn-icon.text-danger:hover { color: #b71c1c; }

.plant-public-link {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-decoration: none;
  word-break: break-all;
}

.plant-public-link:hover {
  color: var(--primary);
  text-decoration: underline;
}

.species-grid-admin,
.budget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
}

.species-admin-card,
.budget-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.3rem;
  box-shadow: 0 4px 15px rgba(0,0,0,0.02);
}

.species-admin-card h3,
.budget-card h3 {
  color: var(--primary);
  font-size: 1.1rem;
  margin-bottom: 0.25rem;
}

.species-admin-card .scientific,
.budget-card .meta-note {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 0.85rem;
}

.species-admin-card .badge-row,
.budget-card .badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.9rem;
}

.info-list {
  display: grid;
  gap: 0.5rem;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.info-list strong {
  color: var(--text-dark);
}

.species-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}

.ghost-link {
  color: var(--primary-light);
  text-decoration: none;
  font-weight: 700;
}

.ghost-link:hover {
  color: var(--primary);
  text-decoration: underline;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 35, 26, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 1200;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  width: min(900px, 100%);
  max-height: calc(100vh - 3rem);
  overflow: auto;
}

.form-actions-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.budget-card .danger-text {
  color: var(--danger);
  font-weight: 700;
}

.budget-card .success-text {
  color: #2e7d32;
  font-weight: 700;
}

@media (max-width: 900px) {
  .dashboard-layout { flex-direction: column; }
  .sidebar { position: relative; width: 100%; height: auto; border-right: none; border-bottom: 1px solid var(--line); }
  .main-content { margin-left: 0; }
  .form-grid, .filters-grid { grid-template-columns: 1fr; }
  .card-head-inline,
  .card-tools,
  .form-actions-row { align-items: stretch; }
}
