/* ============================================================
   MÓDULO HONGOS — Estilo Apple/Orgánico
   ============================================================ */

:root {
  --bg:       #f2f2f7;
  --bg2:      #ffffff;
  --bg3:      #f8f8fa;
  --border:   #e5e5ea;
  --border2:  #d1d1d6;

  --text:     #1c1c1e;
  --text2:    #3a3a3c;
  --text3:    #8e8e93;
  --text4:    #aeaeb2;

  --green:    #34c759;
  --green-bg: #34c75914;
  --blue:     #4a90d9;
  --blue-bg:  #4a90d912;
  --orange:   #ef6c54;
  --orange-bg:#ef6c5412;
  --red:      #ff3b30;
  --red-bg:   #ff3b3012;
  --amber:    #ff9f0a;

  --radius:   16px;
  --radius-sm:10px;
  --shadow:   0 2px 12px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.04);
  --shadow-md:0 4px 24px rgba(0,0,0,.08), 0 1px 4px rgba(0,0,0,.05);

  --font:     'DM Sans', system-ui, sans-serif;
  --font-mono:'DM Mono', monospace;
  --font-disp:'Playfair Display', Georgia, serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; -webkit-font-smoothing: antialiased; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
}

/* ── HEADER ── */
.header {
  background: rgba(255,255,255,.82);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 60px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 12px; }

.logo-mark { font-size: 1.6rem; line-height: 1; }

.site-title {
  font-family: var(--font-disp);
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -.01em;
}

.site-sub {
  font-size: 0.7rem;
  color: var(--text3);
  margin-top: 1px;
}

.header-right { display: flex; align-items: center; gap: 14px; }

.pill-status {
  display: flex; align-items: center; gap: 6px;
  background: var(--green-bg);
  border: 1px solid #34c75930;
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 500;
  color: #1a7a35;
}

.pill-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green);
  animation: blink 2s infinite;
}

.header-clock {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--text2);
  letter-spacing: .02em;
}

/* ── PAGE LAYOUT ── */
.page {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  display: flex; flex-direction: column; gap: 20px;
}

/* ── CARD BASE ── */
.card {
  background: var(--bg2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 20px;
  animation: fadeUp .4s ease both;
}

.card-top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 12px; flex-wrap: wrap;
}

.card-title {
  font-family: var(--font-disp);
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -.01em;
}

.card-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 14px;
}

/* ── SEGMENTED CONTROL (estilo iOS) ── */
.seg-control {
  display: flex;
  background: var(--bg);
  border-radius: 9px;
  padding: 2px;
  gap: 1px;
}

.seg-btn {
  background: none;
  border: none;
  border-radius: 7px;
  padding: 5px 14px;
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text3);
  cursor: pointer;
  transition: all .18s ease;
  white-space: nowrap;
}

.seg-btn.active {
  background: var(--bg2);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
}

/* ── CHART AREA ── */
.chart-area { position: relative; height: 220px; }
.chart-area-bolsa { height: 200px; }

/* ══ SECCIÓN AMBIENTE ══ */
.section-ambient {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 16px;
  animation: fadeUp .35s ease both;
}

/* CO2 Card */
.card-co2 {
  text-align: center;
  padding: 20px 16px 16px;
}

.co2-label {
  font-size: 0.7rem; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--text3); margin-bottom: 6px;
}

.co2-value {
  font-family: var(--font-mono);
  font-size: 2rem; font-weight: 500;
  color: var(--text); line-height: 1;
  margin-bottom: 14px;
}
.co2-value span { font-size: .9rem; color: var(--text3); margin-left: 2px; }

.co2-gauge-wrap { margin-bottom: 10px; }

.co2-gauge-track {
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 4px;
}

.co2-gauge-fill {
  height: 100%; width: 20%;
  border-radius: 3px;
  background: var(--green);
  transition: width .8s ease, background .8s ease;
}

.co2-gauge-labels {
  display: flex; justify-content: space-between;
  font-size: .6rem; color: var(--text4);
  font-family: var(--font-mono);
}

.co2-badge {
  display: inline-block;
  padding: 4px 14px;
  border-radius: 20px;
  font-size: .72rem; font-weight: 600;
  letter-spacing: .06em;
  background: var(--green-bg);
  color: #1a7a35;
  transition: all .3s;
}
.co2-badge.alto { background: var(--red-bg); color: var(--red); }

/* Stats card */
.card-stats { }

.stat-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--bg);
}
.stat-row:last-child { border-bottom: none; }

.stat-icon { font-size: .9rem; width: 20px; text-align: center; }
.stat-name { flex: 1; font-size: .82rem; color: var(--text2); }
.stat-val  { font-family: var(--font-mono); font-size: .82rem; font-weight: 500; color: var(--text); }

.stat-divider { height: 1px; background: var(--border); margin: 4px 0; }

.ambient-sidebar { display: flex; flex-direction: column; gap: 16px; }

/* ══ SECCIÓN SENSORES ══ */
.section-sensors { animation: fadeUp .4s .05s ease both; }

.sensors-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 10px;
}

.sensor-tile {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 6px 8px;
  text-align: center;
  transition: all .2s ease;
  cursor: default;
}

.sensor-tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border2);
}

.sensor-tile-num {
  font-size: .6rem; font-weight: 600;
  letter-spacing: .08em;
  color: var(--text4);
  margin-bottom: 4px;
}

.sensor-tile-val {
  font-family: var(--font-mono);
  font-size: 1.1rem; font-weight: 500;
  line-height: 1; margin-bottom: 2px;
}

.sensor-tile-unit {
  font-size: .6rem; color: var(--text4);
  font-family: var(--font-mono);
  margin-bottom: 5px;
}

.sensor-tile-bar {
  height: 3px; background: var(--bg);
  border-radius: 2px; overflow: hidden;
}

.sensor-tile-fill { height: 100%; border-radius: 2px; transition: width .8s ease; }

/* colores por rango */
.s-temp-low  .sensor-tile-val  { color: var(--blue); }
.s-temp-ok   .sensor-tile-val  { color: var(--green); }
.s-temp-high .sensor-tile-val  { color: var(--amber); }
.s-temp-alert .sensor-tile-val { color: var(--red); }
.s-hum-low   .sensor-tile-val  { color: #8e6fba; }
.s-hum-ok    .sensor-tile-val  { color: var(--green); }
.s-hum-high  .sensor-tile-val  { color: var(--blue); }

.s-temp-low   { border-top: 2px solid var(--blue); }
.s-temp-ok    { border-top: 2px solid var(--green); }
.s-temp-high  { border-top: 2px solid var(--amber); }
.s-temp-alert { border-top: 2px solid var(--red); }
.s-hum-low    { border-top: 2px solid #8e6fba; }
.s-hum-ok     { border-top: 2px solid var(--green); }
.s-hum-high   { border-top: 2px solid var(--blue); }

/* ══ SECCIÓN BOLSA ══ */
.section-bolsa {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
  animation: fadeUp .4s .1s ease both;
}

.card-bolsa { display: flex; flex-direction: column; }

.bolsa-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 14px; gap: 10px;
}

.bolsa-species { font-style: italic; color: var(--text3); font-size: .82rem; margin-top: 2px; }

.bolsa-select {
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 6px 10px;
  font-family: var(--font);
  font-size: .8rem;
  color: var(--text2);
  cursor: pointer;
  outline: none;
  transition: border-color .2s;
}
.bolsa-select:focus { border-color: var(--blue); }

.bolsa-img-wrap {
  flex: 1;
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg3);
  min-height: 220px;
  display: flex; align-items: center; justify-content: center;
}

.bolsa-img-bg {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, #e8f4e8 0%, var(--bg3) 70%);
  transition: background .5s;
}

.bolsa-img {
  position: relative; z-index: 1;
  max-height: 200px; max-width: 100%;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,.12));
  transition: opacity .3s;
}

/* Placeholder SVG bolsa cuando no hay imagen real */
.bolsa-img[src=""] { opacity: 0; }

.bolsa-badge {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  z-index: 2;
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 12px;
  font-size: .72rem; font-weight: 500;
  color: var(--text2);
}

/* Gráfica bolsa */
.bolsa-current-vals {
  display: flex; align-items: center; justify-content: center;
  gap: 0; margin-top: 14px;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.bcv-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 10px 0;
}

.bcv-divider { width: 1px; height: 36px; background: var(--border); }

.bcv-label { font-size: .68rem; color: var(--text3); margin-bottom: 2px; }

.bcv-val {
  font-family: var(--font-mono);
  font-size: 1.3rem; font-weight: 500;
}

.temp-color { color: var(--orange); }
.hum-color  { color: var(--blue); }

.chart-legend-inline {
  display: flex; align-items: center; gap: 5px;
  font-size: .72rem; color: var(--text3);
}

.legend-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block;
}

/* ══ SECCIÓN CONTROL ══ */
.section-control {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  animation: fadeUp .4s .15s ease both;
}

/* iOS Toggle */
.ctrl-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--bg);
}
.ctrl-row:last-child { border-bottom: none; }

.ctrl-left { display: flex; align-items: center; gap: 10px; }
.ctrl-emoji { font-size: 1.2rem; width: 28px; text-align: center; }
.ctrl-name  { font-size: .88rem; font-weight: 500; color: var(--text); }
.ctrl-sub   { font-size: .68rem; color: var(--text3); font-family: var(--font-mono); margin-top: 1px; }

.ios-toggle {
  position: relative; display: inline-block;
  width: 44px; height: 26px; cursor: pointer;
}

.ios-toggle input { opacity: 0; width: 0; height: 0; position: absolute; }

.ios-slider {
  position: absolute; inset: 0;
  background: #e5e5ea;
  border-radius: 13px;
  transition: background .25s ease;
}

.ios-slider::before {
  content: '';
  position: absolute;
  width: 20px; height: 20px;
  left: 3px; top: 3px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: transform .25s ease;
}

.ios-toggle input:checked + .ios-slider { background: var(--green); }
.ios-toggle input:checked + .ios-slider::before { transform: translateX(18px); }

/* Cámara */
.card-camera { }

.cam-preview-wrap {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg3);
  aspect-ratio: 4/3;
  margin-bottom: 10px;
  display: flex; align-items: center; justify-content: center;
}

.cam-preview {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.cam-preview[src=""] { display: none; }

.cam-no-img {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; color: var(--text4);
}
.cam-no-img span { font-size: 2rem; }
.cam-no-img p    { font-size: .78rem; }

.cam-date {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,.4));
  padding: 12px 10px 6px;
  font-size: .65rem; color: rgba(255,255,255,.8);
  font-family: var(--font-mono);
}

.cam-gallery {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px;
}

.cam-thumb {
  aspect-ratio: 1; object-fit: cover;
  border-radius: 6px; border: 1.5px solid transparent;
  cursor: pointer; transition: all .2s;
  width: 100%;
}
.cam-thumb:hover { border-color: var(--blue); transform: scale(1.04); }

/* Botones Apple */
.btn-apple-primary {
  background: var(--green);
  color: white; border: none;
  border-radius: 8px;
  padding: 6px 14px;
  font-family: var(--font); font-size: .8rem; font-weight: 500;
  cursor: pointer; transition: all .18s;
}
.btn-apple-primary:hover { background: #2db84e; box-shadow: 0 2px 10px rgba(52,199,89,.35); }

.btn-apple-secondary {
  background: var(--bg3);
  color: var(--text2); border: 1px solid var(--border2);
  border-radius: 8px; padding: 6px 12px;
  font-family: var(--font); font-size: .8rem; font-weight: 500;
  cursor: pointer; transition: all .18s;
}
.btn-apple-secondary:hover { border-color: var(--blue); color: var(--blue); }

.cam-actions { display: flex; gap: 8px; }

/* ── TOAST ── */
.toast-wrap {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}

.toast {
  background: rgba(28,28,30,.92);
  backdrop-filter: blur(12px);
  color: white;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: .78rem;
  max-width: 280px;
  animation: toastIn .25s ease, toastOut .25s ease 2.75s forwards;
}

/* ── ANIMACIONES ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes blink {
  0%,100% { opacity: 1; } 50% { opacity: .4; }
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
  to { opacity: 0; }
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ── RESPONSIVE ── */
@media (max-width: 1100px) {
  .section-ambient  { grid-template-columns: 1fr 260px; }
  .sensors-grid     { grid-template-columns: repeat(5, 1fr); }
  .section-bolsa    { grid-template-columns: 260px 1fr; }
}
@media (max-width: 820px) {
  .section-ambient  { grid-template-columns: 1fr; }
  .ambient-sidebar  { flex-direction: row; }
  .section-bolsa    { grid-template-columns: 1fr; }
  .section-control  { grid-template-columns: 1fr; }
  .sensors-grid     { grid-template-columns: repeat(3, 1fr); }
}

/* ── MODALES ── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(4px);
  align-items: center; justify-content: center;
}
.modal-overlay.active { display: flex; }

.modal {
  background: white;
  border-radius: 20px;
  padding: 32px;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,.15);
  animation: fadeUp .25s ease;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-sm { width: 360px; }
.modal-lg { width: 760px; }

.modal-close {
  position: absolute; top: 16px; right: 16px;
  background: var(--bg); border: none;
  width: 28px; height: 28px; border-radius: 50%;
  font-size: .8rem; cursor: pointer; color: var(--text3);
}
.modal-close:hover { background: var(--border); }

.modal-icon { font-size: 2rem; margin-bottom: 12px; }
.modal-title { font-family: var(--font-disp); font-size: 1.2rem; margin-bottom: 4px; }
.modal-sub { font-size: .8rem; color: var(--text3); margin-bottom: 20px; }

.modal-header-row {
  display: flex; align-items: center;
  justify-content: space-between; margin-bottom: 16px;
}

.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: .78rem; font-weight: 500;
  color: var(--text2); margin-bottom: 5px; }
.form-input {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border2); border-radius: 8px;
  font-family: var(--font); font-size: .88rem; color: var(--text);
  background: var(--bg3); outline: none; transition: border-color .2s;
}
.form-input:focus { border-color: var(--blue); background: white; }

.form-error {
  background: var(--red-bg); border: 1px solid #ff3b3030;
  border-radius: 8px; padding: 8px 12px;
  font-size: .78rem; color: var(--red); margin-bottom: 14px;
}

.btn-modal-primary {
  width: 100%; padding: 10px;
  background: var(--text); color: white;
  border: none; border-radius: 10px;
  font-family: var(--font); font-size: .9rem; font-weight: 500;
  cursor: pointer; transition: all .2s;
}
.btn-modal-primary:hover { background: #3a3a3c; }

.btn-header-login {
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: 8px; padding: 5px 12px;
  font-family: var(--font); font-size: .78rem; font-weight: 500;
  color: var(--text2); cursor: pointer; transition: all .2s;
}
.btn-header-login:hover { border-color: var(--blue); color: var(--blue); }

.control-warning {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px;
  font-size: .78rem; color: var(--text3); margin-bottom: 12px;
}

/* Galería */
.gallery-main {
  position: relative; border-radius: 12px; overflow: hidden;
  background: var(--bg3); aspect-ratio: 16/9;
  margin-bottom: 14px; display: flex;
  align-items: center; justify-content: center;
}
.gallery-main img {
  max-width: 100%; max-height: 100%; object-fit: contain;
}
.gallery-big-info {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,.5));
  padding: 12px; font-size: .7rem; color: white;
  font-family: var(--font-mono);
}
.gallery-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px;
}
.gallery-thumb {
  aspect-ratio: 1; object-fit: cover; border-radius: 8px;
  border: 2px solid transparent; cursor: pointer; transition: all .2s; width: 100%;
}
.gallery-thumb:hover, .gallery-thumb.active { border-color: var(--blue); }
.gallery-loading { color: var(--text3); font-size: .82rem; padding: 20px; }

.btn-sm { font-size: .75rem; padding: 5px 10px; }

/* ── PANEL ADMIN ── */
.btn-header-admin {
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: 8px; padding: 5px 12px;
  font-family: var(--font); font-size: .78rem; font-weight: 500;
  color: var(--text2); cursor: pointer; transition: all .2s;
  margin-right: 6px;
}
.btn-header-admin:hover { border-color: var(--orange); color: var(--orange); }

.admin-sensors-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 8px;
}

.admin-sensor-card {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 14px;
  transition: all .2s;
}

.admin-sensor-card.inactivo {
  opacity: .5;
}

.admin-sensor-info { display: flex; flex-direction: column; gap: 2px; }
.admin-sensor-name { font-size: .85rem; font-weight: 500; color: var(--text); }
.admin-sensor-tipo { font-size: .7rem; color: var(--text3); font-family: var(--font-mono); }

.card-download {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px;
  margin-top: 12px;
}
.download-icon { font-size: 1.6rem; }
.download-info { flex: 1; }
.download-title { font-size: .88rem; font-weight: 500; color: var(--text); }
.download-sub { font-size: .72rem; color: var(--text3); margin-top: 2px; }
