:root {
  --green-900: #1b4332;
  --green-700: #2d6a4f;
  --green-500: #40916c;
  --green-100: #d8f3dc;
  --lemon-500: #f4b400;
  --lemon-100: #fff3cd;
  --red-500: #d64545;
  --gray-900: #1f2933;
  --gray-600: #52606d;
  --gray-300: #cbd2d9;
  --gray-100: #f5f7f8;
  --white: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--gray-100);
  color: var(--gray-900);
}

a { color: var(--green-700); }

button {
  cursor: pointer;
  font-family: inherit;
}

/* ---------- Auth (login / setup) ---------- */

.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--green-900), var(--green-700));
  padding: 16px;
}

.auth-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
}

.auth-logo {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--green-700);
  margin-bottom: 16px;
}

.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form h1 { font-size: 1.1rem; margin: 0 0 4px; }
.auth-hint { font-size: 0.85rem; color: var(--gray-600); margin: -8px 0 4px; }

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--gray-600);
}

.auth-form input {
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 1rem;
}

.auth-form button {
  margin-top: 6px;
  background: var(--green-700);
  color: var(--white);
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 1rem;
  font-weight: 600;
}

.auth-form button:hover { background: var(--green-900); }

.auth-error { color: var(--red-500); font-size: 0.85rem; min-height: 1.1em; }

/* ---------- App shell ---------- */

.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 56px 1fr;
  grid-template-areas: "topbar topbar" "sidenav content";
  min-height: 100vh;
}

.topbar {
  grid-area: topbar;
  background: var(--green-900);
  color: var(--white);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title { font-weight: 700; flex: 1; }
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; }

.btn-link {
  background: none;
  border: none;
  color: var(--lemon-100);
  text-decoration: underline;
  font-size: 0.9rem;
  padding: 4px;
}

.hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--white);
  font-size: 1.3rem;
}

.sidenav {
  grid-area: sidenav;
  background: var(--white);
  border-right: 1px solid var(--gray-300);
  display: flex;
  flex-direction: column;
  padding: 12px 0;
}

.sidenav a {
  padding: 12px 20px;
  text-decoration: none;
  color: var(--gray-900);
  font-size: 0.95rem;
  border-left: 3px solid transparent;
}

.sidenav a:hover { background: var(--green-100); }
.sidenav a.active { border-left-color: var(--green-700); background: var(--green-100); font-weight: 600; }

.content {
  grid-area: content;
  padding: 20px;
  overflow-x: hidden;
  max-width: 100%;
}

.loading { color: var(--gray-600); }

/* ---------- Mobile: off-canvas sidenav ---------- */

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas: "topbar" "content";
  }
  .hamburger { display: block; }
  .sidenav {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    width: 240px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
    z-index: 30;
  }
  .sidenav.open { transform: translateX(0); }
  .content { padding: 14px; }
}

/* ---------- Reusable view components ---------- */

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

.view-header h1 { font-size: 1.3rem; margin: 0; }

.btn-primary {
  background: var(--green-700);
  color: var(--white);
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 0.9rem;
}
.btn-primary:hover { background: var(--green-900); }

.btn-secondary {
  background: var(--white);
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.85rem;
}

.btn-danger { color: var(--red-500); }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.kpi-card .kpi-label { font-size: 0.8rem; color: var(--gray-600); }
.kpi-card .kpi-value { font-size: 1.6rem; font-weight: 700; color: var(--green-900); margin-top: 4px; }

.progress-bar {
  background: var(--gray-300);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
  margin-top: 8px;
}
.progress-bar-fill { background: var(--lemon-500); height: 100%; }

.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.card h2 { font-size: 1rem; margin: 0 0 12px; }

.task-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.task-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--gray-100);
  font-size: 0.9rem;
}
.task-list li.overdue { background: #fdeaea; color: var(--red-500); font-weight: 600; }
.task-list li.soon { background: var(--lemon-100); }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; min-width: 560px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--gray-300); white-space: nowrap; }
th { color: var(--gray-600); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }
tr:hover td { background: var(--gray-100); }
td.actions { display: flex; gap: 8px; }
td.actions button { font-size: 0.8rem; padding: 6px 10px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.form-grid label, .form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--gray-600);
}

.form-grid input, .form-grid select, .form-grid textarea,
.form-field input, .form-field select, .form-field textarea {
  padding: 10px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
}

.form-actions { display: flex; gap: 10px; margin-top: 14px; }

.product-picker { display: flex; flex-direction: column; gap: 10px; }
.product-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.product-row select { flex: 2; min-width: 160px; }
.product-row input { flex: 1; min-width: 120px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-estrella { background: var(--lemon-100); color: #8a6100; }
.badge-activo { background: var(--green-100); color: var(--green-900); }
.badge-sin_produccion { background: var(--gray-300); color: var(--gray-900); }

.empty-state { color: var(--gray-600); font-style: italic; padding: 20px 0; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
  z-index: 40;
}

.modal {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 560px;
  margin-top: 30px;
}

.modal h2 { margin-top: 0; }
