:root {
  color-scheme: light;
  --bg: #f6f7f2;
  --surface: #ffffff;
  --surface-2: #eef0ea;
  --text: #161a16;
  --muted: #6b7169;
  --border: #e3e6dd;
  --border-strong: #d3d7cb;

  --primary: #2f7d54;
  --primary-dark: #205c3d;
  --primary-soft: #e3f2e8;
  --on-primary: #ffffff;

  --danger: #c0453b;
  --danger-dark: #9c362d;
  --danger-soft: #fbe9e7;
  --warn: #b3791d;
  --warn-soft: #fbf0da;

  --radius-lg: 18px;
  --radius: 14px;
  --radius-sm: 10px;

  --shadow-sm: 0 1px 2px rgba(20, 26, 20, 0.05), 0 1px 1px rgba(20, 26, 20, 0.04);
  --shadow-md: 0 10px 28px -10px rgba(20, 26, 20, 0.18), 0 2px 6px rgba(20, 26, 20, 0.05);

  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #141712;
    --surface: #1c211b;
    --surface-2: #242a22;
    --text: #eef1ea;
    --muted: #93998f;
    --border: #2b3128;
    --border-strong: #3a4136;

    --primary: #4fae7c;
    --primary-dark: #79cd9d;
    --primary-soft: rgba(79, 174, 124, 0.16);
    --on-primary: #08150e;

    --danger: #e2695f;
    --danger-dark: #ee8a81;
    --danger-soft: rgba(226, 105, 95, 0.16);
    --warn: #d9a44b;
    --warn-soft: rgba(217, 164, 75, 0.16);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 28px -10px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-dark); }

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left));
}

/* --- Cabecera --- */
.topbar {
  background: var(--surface);
  color: var(--text);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 20px 12px;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand {
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.mainnav {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  font-size: 0.88rem;
  background: var(--surface-2);
  padding: 3px;
  border-radius: 999px;
}

.mainnav a, .linklike {
  color: var(--muted);
  text-decoration: none;
  background: none;
  border: none;
  font: inherit;
  cursor: pointer;
  padding: 7px 13px;
  border-radius: 999px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}

.mainnav a:hover, .linklike:hover { color: var(--text); background: rgba(0,0,0,0.04); text-decoration: none; }
.mainnav a.active { font-weight: 700; text-decoration: none; background: var(--primary-soft); color: var(--primary-dark); }

.inline { display: inline; }

h1 { font-size: 1.5rem; margin: 0 0 12px; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.08rem; margin: 22px 0 10px; font-weight: 700; }
h3 { font-size: 0.95rem; margin: 12px 0 6px; font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

.plant-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.plant-card a { color: var(--text); text-decoration: none; font-weight: 600; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.badge-ok { background: var(--primary-soft); color: var(--primary-dark); }
.badge-check_soon, .badge-check { background: var(--warn-soft); color: var(--warn); }
.badge-needs_attention, .badge-needs { background: var(--danger-soft); color: var(--danger); }

.section { margin-bottom: 26px; }

form.stacked label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  margin: 14px 0 6px;
}

form.stacked input,
form.stacked select,
form.stacked textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

form.stacked input:focus,
form.stacked select:focus,
form.stacked textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

textarea { resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.96rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s ease, transform 0.06s ease, box-shadow 0.15s ease;
}

.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn:active { transform: scale(0.98); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--border);
  box-shadow: none;
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--border-strong); }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-dark); }

.btn-big { width: 100%; padding: 16px; font-size: 1.05rem; margin: 10px 0; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.muted { color: var(--muted); font-size: 0.9rem; }

.errors, .notice, .notice-warn {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-size: 0.92rem;
  border: 1px solid transparent;
}
.errors { background: var(--danger-soft); color: var(--danger); }
.notice { background: var(--primary-soft); color: var(--primary-dark); }
.notice-warn { background: var(--warn-soft); color: var(--warn); }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th {
  text-align: left; padding: 10px 12px; color: var(--muted);
  font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
}
td { text-align: left; padding: 12px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }

.cal-table { width: 100%; border-collapse: separate; border-spacing: 3px; table-layout: fixed; }
.cal-table th { border: none; padding: 4px 2px; text-align: center; color: var(--muted); font-size: 0.7rem; }
.cal-table td {
  border: 1px solid var(--border);
  border-radius: 10px;
  vertical-align: top;
  height: 52px;
  padding: 4px 3px;
  font-size: 0.74rem;
  background: var(--surface);
  overflow: hidden;
}
.cal-day-num {
  font-weight: 700; text-decoration: none; color: inherit;
  display: block; font-size: 0.78rem;
}
.cal-today { background: var(--primary-soft); border-color: var(--primary); }
.cal-empty { background: transparent; border: 1px solid transparent; }

.cal-events { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 3px; }
.cal-chip {
  font-size: 0.7rem; line-height: 1;
  width: 17px; height: 17px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--surface-2);
}
.cal-chip-forecast { opacity: 0.7; }
.cal-more { font-size: 0.62rem; color: var(--muted); font-weight: 700; align-self: center; }

/* --- Cabecera llamativa de planta --- */
.plant-hero {
  display: flex;
  align-items: center;
  gap: 16px;
  background: linear-gradient(135deg, #3a8a5f, #1f5c3d);
  color: #ffffff;
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-md);
}
.plant-hero-icon {
  font-size: 2.1rem;
  width: 64px;
  height: 64px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 18px;
}
.plant-hero-body { min-width: 0; }
.plant-hero h1 { color: #fff; margin: 0 0 3px; }
.plant-hero-sub { color: rgba(255, 255, 255, 0.85); margin: 0 0 10px; font-size: 0.9rem; }
.plant-hero-sub em { font-style: italic; }
.plant-hero .badge { background: rgba(255, 255, 255, 0.22); color: #fff; }

.about-card { background: linear-gradient(180deg, var(--surface-2), var(--surface)); }

/* --- Ficha en tarjetas de información --- */
.info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 10px;
}
@media (min-width: 480px) {
  .info-grid { grid-template-columns: repeat(3, 1fr); }
}
.info-tile {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.info-icon { font-size: 1.1rem; }
.info-label { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 700; }
.info-value { font-size: 0.9rem; font-weight: 600; word-break: break-word; }

.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { margin-bottom: 8px; }

code.tagid {
  background: var(--surface-2);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* --- Navegación móvil --- */
body.has-nav { padding-bottom: 0; }
.container { padding-bottom: 24px; }

.bottomnav { display: none; }

@media (max-width: 720px) {
  .mainnav { display: none; }
  body.has-nav .container { padding-bottom: 88px; }

  .bottomnav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 20;
    padding: 6px 4px max(6px, env(safe-area-inset-bottom));
  }
  .bottomnav a, .bottomnav summary {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.66rem;
    font-weight: 600;
    padding: 4px 2px;
    list-style: none;
    cursor: pointer;
  }
  .bottomnav summary::-webkit-details-marker { display: none; }
  .bottomnav a.active { color: var(--primary-dark); }
  .bottomnav a.active .bn-icon { background: var(--primary-soft); }
  .bn-icon {
    font-size: 1.2rem; line-height: 1.6;
    width: 34px; height: 26px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 10px;
    transition: background 0.15s ease;
  }
  .bn-more { position: relative; flex: 1; }
  .bn-more[open] .bn-more-menu { display: flex; }
  .bn-more-menu {
    display: none;
    flex-direction: column;
    position: absolute;
    bottom: 62px;
    right: -4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 180px;
    overflow: hidden;
    padding: 6px;
  }
  .bn-more-menu a, .bn-more-menu .linklike {
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
    padding: 11px 12px;
    font-size: 0.9rem;
    font-weight: 500;
    width: 100%;
    text-align: left;
    border-radius: var(--radius-sm);
    color: var(--text);
  }
  .bn-more-menu a:hover, .bn-more-menu .linklike:hover { background: var(--surface-2); }
}

/* --- Flash messages --- */
.flash { padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 12px; font-size: 0.92rem; font-weight: 500; }
.flash-success { background: var(--primary-soft); color: var(--primary-dark); }
.flash-warning { background: var(--warn-soft); color: var(--warn); }
.flash-error { background: var(--danger-soft); color: var(--danger); }

/* --- Resumen del dashboard --- */
.summary-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}
.summary-chip {
  flex: 1;
  min-width: 120px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.summary-chip .num { font-size: 1.3rem; font-weight: 700; display: block; letter-spacing: -0.02em; }
.summary-chip .label { font-size: 0.72rem; color: var(--muted); font-weight: 600; }

/* --- Barra de filtros --- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.filter-bar input[type="text"],
.filter-bar select {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}
.filter-bar input[type="text"] { flex: 1 1 160px; }
.filter-bar input:focus, .filter-bar select:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}

/* --- Tarjeta de planta ampliada --- */
.plant-card-full {
  display: block;
  transition: box-shadow 0.15s ease;
  border-left: 4px solid var(--border);
}
.plant-card-full.status-needs_attention { border-left-color: var(--danger); }
.plant-card-full.status-check_soon { border-left-color: var(--warn); }
.plant-card-full.status-ok { border-left-color: var(--primary); }
.plant-card-full .row1 { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.pc-avatar {
  font-size: 1.3rem;
  width: 40px; height: 40px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2);
  border-radius: 50%;
}
.plant-card-full .row1 .pc-body { flex: 1; min-width: 0; }
.plant-card-full .meta { font-size: 0.82rem; color: var(--muted); margin-top: 3px; }
.plant-card-full .quick-actions { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.plant-card-full .quick-actions form { display: inline; }
.btn-sm { padding: 7px 12px; font-size: 0.8rem; border-radius: 999px; }

/* --- Estado vacío --- */
.empty-state { text-align: center; padding: 40px 20px; }
.empty-state .icon {
  font-size: 2rem;
  width: 64px; height: 64px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 12px;
  background: var(--surface-2);
  border-radius: 50%;
}

/* --- Botones grandes NFC --- */
.nfc-actions { display: grid; grid-template-columns: 1fr; gap: 10px; margin: 16px 0; }
.nfc-actions .btn { padding: 18px; font-size: 1.02rem; }

/* --- Chips de tipo de acción --- */
.action-type-picker { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 16px; }
.action-type-picker label {
  display: flex; align-items: center; gap: 6px;
  border: 1.5px solid var(--border); border-radius: 999px;
  padding: 9px 15px; cursor: pointer; font-size: 0.86rem; font-weight: 500;
  background: var(--surface);
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.action-type-picker input { display: none; }
.action-type-picker input:checked + span { font-weight: 700; }
.action-type-picker label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); }

/* --- Botonera de acciones rápidas --- */
.qa-title { margin: 14px 0 6px; font-weight: 600; }
.quick-action-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.qa-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 4px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.06s ease;
}
.qa-tile:hover { border-color: var(--primary); background: var(--primary-soft); text-decoration: none; }
.qa-tile:active { transform: scale(0.96); }
.qa-icon { font-size: 1.3rem; }
.qa-label { font-size: 0.66rem; font-weight: 600; text-align: center; color: var(--muted); }

/* --- Timeline de actividad --- */
.timeline-day { margin-bottom: 20px; }
.timeline-day h3 { color: var(--muted); font-weight: 700; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
.timeline-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.timeline-item:last-child { border-bottom: none; }
.timeline-item .t-icon {
  font-size: 1.05rem;
  width: 34px; height: 34px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2);
  border-radius: 50%;
}
.timeline-item .t-time { color: var(--muted); font-size: 0.78rem; white-space: nowrap; }

/* --- Consejos --- */
.tip-card h3 { margin-top: 0; }
.tip-general { color: var(--muted); font-size: 0.9rem; margin-bottom: 8px; }
.tip-specific { background: var(--primary-soft); color: var(--primary-dark); padding: 10px 12px; border-radius: var(--radius-sm); font-size: 0.9rem; }

/* --- Insights y estadísticas --- */
.insight-list { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 8px; }
.insight-list li {
  font-size: 0.88rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  line-height: 1.35;
}

/* --- Pistas de diagnóstico --- */
.diagnosis-card { border-left: 4px solid var(--warn); }
.diagnosis-item { margin-top: 10px; }
.diagnosis-item ul { margin: 4px 0 0; padding-left: 20px; font-size: 0.88rem; color: var(--muted); }

/* --- Chips de tendencia (fleet stats) --- */
.trend-up { color: var(--danger); }
.trend-down { color: var(--primary-dark); }

/* --- Fieldset de formularios largos --- */
fieldset {
  border: none;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 6px 16px 18px;
  margin: 16px 0;
}
legend {
  padding: 0;
  font-weight: 700;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary-dark);
  margin-bottom: 2px;
}

/* --- Administración --- */
.admin-shell h1 { display: flex; align-items: center; gap: 8px; }
.admin-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-bottom: 20px;
  font-size: 0.88rem;
  background: var(--surface-2);
  padding: 3px;
  border-radius: 999px;
}
.admin-nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 7px 14px;
  border-radius: 999px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}
.admin-nav a:hover { background: rgba(0,0,0,0.05); color: var(--text); }
.admin-nav a.active { font-weight: 700; background: var(--surface); color: var(--primary-dark); box-shadow: var(--shadow-sm); }
.admin-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.admin-table-wrap table { min-width: 640px; }
.admin-table-wrap tr:last-child td { border-bottom: none; }

.stat-grid { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; }
.stat-box {
  flex: 1; min-width: 130px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-box .num { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.stat-box .label { font-size: 0.75rem; color: var(--muted); font-weight: 600; }

.suggest-list {
  list-style: none; padding: 0; margin: 6px 0 0;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.suggest-list li button {
  width: 100%; text-align: left; padding: 11px 13px; background: var(--surface); border: none;
  border-bottom: 1px solid var(--border); cursor: pointer; font-size: 0.9rem; color: var(--text);
  font-family: inherit;
}
.suggest-list li:last-child button { border-bottom: none; }
.suggest-list li button:hover { background: var(--surface-2); }

.pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 0.7rem; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}

/* --- Modo riego --- */
.switch-toggle {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 999px;
  padding: 8px 14px 8px 8px; cursor: pointer; font: inherit; font-weight: 700; font-size: 0.88rem;
  color: var(--text);
}
.switch-track {
  width: 40px; height: 22px; border-radius: 999px; background: var(--border);
  position: relative; flex: none; transition: background 0.15s ease;
}
.switch-thumb {
  position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,0.25); transition: transform 0.15s ease;
}
.switch-toggle.on .switch-track { background: var(--primary); }
.switch-toggle.on .switch-thumb { transform: translateX(18px); }

.watering-mode-banner {
  background: var(--primary);
  color: #fff;
  padding: 10px 20px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  text-align: center;
}
.wmb-off { color: #fff; text-decoration: underline; font-weight: 700; }

/* --- Detalle y accesibilidad --- */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

details > summary { cursor: pointer; }
