/* ===================== AGROSOCIO :: tema verde/blanco mobile-first ===================== */
:root {
  --green-900: #14361f;
  --green-700: #1f6b3a;
  --green-600: #2e8b4f;
  --green-500: #38a169;
  --green-100: #e6f4ea;
  --green-050: #f3faf5;
  --ink: #16241b;
  --muted: #5b6b60;
  --line: #d7e6dc;
  --white: #ffffff;
  --bg: #f6faf7;
  --danger: #c0392b;
  --warn: #b7791f;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(20, 54, 31, 0.08);
  --tap: 48px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

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

.hidden { display: none !important; }

/* ===================== Layout general ===================== */
.app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--green-700);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  box-shadow: var(--shadow);
}
.topbar h1 { font-size: 20px; margin: 0; font-weight: 700; letter-spacing: .3px; }
.topbar .brand { display: flex; align-items: center; gap: 10px; }
.topbar .brand svg { width: 26px; height: 26px; }
.topbar .user { font-size: 14px; opacity: .9; display: flex; align-items: center; gap: 8px; }
.icon-btn {
  background: rgba(255,255,255,.15);
  border: 0;
  color: var(--white);
  width: 40px; height: 40px;
  border-radius: 12px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

main {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(96px + var(--safe-bottom));
}

h2.view-title { font-size: 22px; margin: 4px 0 14px; }

/* ===================== Tarjetas ===================== */
.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.card-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}
.card-row .title { font-weight: 600; font-size: 17px; }
.card-row .subtitle { color: var(--muted); font-size: 14px; margin-top: 2px; }

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--green-100);
  color: var(--green-700);
  white-space: nowrap;
}
.badge.alta { background: #fde8e6; color: var(--danger); }
.badge.media { background: #fdf2dc; color: var(--warn); }
.badge.baja { background: var(--green-100); color: var(--green-700); }
.badge.hecha { background: #e3e8e5; color: var(--muted); }
.badge.personal { background: #e7edf5; color: #355a8c; }
.badge.grupo { background: #eef0fb; color: #4a3a8c; }
.badge.warn { background: #fdf2dc; color: var(--warn); }
.badge.danger { background: #fde8e6; color: var(--danger); }

/* ===================== Dashboard ===================== */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat .num { font-size: 30px; font-weight: 800; color: var(--green-700); line-height: 1; }
.stat .lbl { color: var(--muted); font-size: 14px; margin-top: 6px; }
.section-title { font-size: 16px; font-weight: 700; margin: 18px 0 8px; color: var(--green-900); }
.list-empty { color: var(--muted); font-style: italic; padding: 8px 0; }

/* ===================== Botones ===================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: 14px;
  border: 0;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  background: var(--green-600);
  color: var(--white);
}
.btn:active { transform: translateY(1px); }
.btn.block { width: 100%; }
.btn.ghost { background: var(--green-100); color: var(--green-700); }
.btn.danger { background: var(--danger); }
.btn.small { min-height: 38px; font-size: 14px; padding: 0 14px; }

.fab {
  position: fixed;
  right: max(16px, calc((100vw - 720px) / 2 + 16px));
  bottom: calc(84px + var(--safe-bottom));
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--green-600);
  color: var(--white);
  border: 0;
  font-size: 30px;
  box-shadow: 0 6px 18px rgba(31, 107, 58, .4);
  cursor: pointer;
  z-index: 30;
}

/* ===================== Formularios ===================== */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; color: var(--green-900); }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--white);
}
.field textarea { min-height: 90px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--green-500);
  box-shadow: 0 0 0 3px var(--green-100);
}
.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.form-actions .btn { flex: 1; }

/* ===================== Buscador / filtros ===================== */
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; }
.toolbar input { flex: 1; min-height: 44px; padding: 0 14px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--white); }

/* ===================== Chat ===================== */
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.chat-head-actions { display: flex; gap: 8px; }
.icon-btn-green { width: 46px; height: 46px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--white); font-size: 20px; cursor: pointer; }
.icon-btn-green.active { background: var(--green-100); border-color: var(--green-500); }
.icon-btn-green.listening { background: var(--danger); color: #fff; border-color: var(--danger); animation: pulse 1s infinite; }
.icon-btn-green:disabled { opacity: .4; cursor: not-allowed; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }
.chat-log { display: flex; flex-direction: column; gap: 10px; padding-bottom: 108px; }
.msg { max-width: 85%; padding: 11px 14px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--green-600); color: var(--white); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--white); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg-author { font-size: 12px; font-weight: 700; color: var(--green-700); margin-bottom: 3px; }
.chat-form {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(76px + var(--safe-bottom));
  z-index: 22;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.chat-form textarea { flex: 1; min-height: 48px; max-height: 120px; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 14px; background: var(--white); }

/* ===================== Navegacion inferior ===================== */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 25;
  background: var(--white);
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-around;
  padding: 6px 4px calc(6px + var(--safe-bottom));
  max-width: 720px;
  margin: 0 auto;
}
.bottom-nav a {
  flex: 1;
  text-align: center;
  text-decoration: none;
  color: var(--muted);
  font-size: 11px;
  padding: 6px 2px;
  border-radius: 12px;
}
.bottom-nav a .ico { display: block; font-size: 22px; line-height: 1.1; }
.bottom-nav a.active { color: var(--green-700); font-weight: 700; }

/* Menu desplegable de modulos extra */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; display: flex; align-items: flex-end; }
.sheet {
  background: var(--white);
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(20px + var(--safe-bottom));
  max-height: 80vh;
  overflow-y: auto;
}
.sheet h3 { margin: 4px 0 12px; }
.sheet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.sheet-grid a {
  text-decoration: none;
  color: var(--ink);
  background: var(--green-050);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 8px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
}
.sheet-grid a .ico { display: block; font-size: 26px; margin-bottom: 6px; }

/* ===================== Login ===================== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { background: var(--white); border-radius: 22px; box-shadow: var(--shadow); padding: 28px 22px; width: 100%; max-width: 380px; }
.login-card .logo { text-align: center; margin-bottom: 18px; }
.login-card .logo svg { width: 64px; height: 64px; }
.login-card h1 { text-align: center; margin: 6px 0 2px; color: var(--green-700); }
.login-card p.sub { text-align: center; color: var(--muted); margin: 0 0 20px; }

/* ===================== Toast ===================== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--green-900);
  color: var(--white);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 60;
  box-shadow: var(--shadow);
  max-width: 90%;
}
.toast.error { background: var(--danger); }

/* ===================== Grupos ===================== */
.group-pin { margin: 10px 0; font-size: 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.group-pin strong { letter-spacing: 2px; font-size: 17px; color: var(--green-700); }
.group-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.member-list { margin: 0; padding-left: 18px; }
.member-list li { padding: 5px 0; }
.login-switch { text-align: center; margin-top: 16px; }
.login-switch a { color: var(--green-700); font-weight: 600; text-decoration: none; }
