/*
  TOTAAL – estilos base (mobile-first)
  - Paleta neutra y tipografía simple (sin “color palette” agresiva).
  - Componentes: header, drawer, cards, modal y controles del historial.
*/

:root{
  --bg: #f6f8f4;
  --card: #f8fbf7;
  --text: #1d1f1b;
  --muted: rgba(0,0,0,.55);
  --border: rgba(0,0,0,.10);
  --shadow: 0 8px 18px rgba(0,0,0,.06);
  --accent: #2AA84A;

  /* Barra de nivel (verde -> amarillo -> naranja -> rojo) */
  --g1:#2AA84A;
  --g2:#E9D436;
  --g3:#EB8C2E;
  --g4:#D9534F;
}

*{ box-sizing: border-box; }

body{
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app{
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header{
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.header-inner{
  width: 100%;
  padding: 10px 14px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 56px;
}

.logo img{
  height: 56px;
  width: auto;
  display: block;
}

/* Botón idioma */
.lang-btn{
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.65);
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  color: rgba(0,0,0,.75);
}
.lang-btn:hover{ background: rgba(255,255,255,.9); }
.lang-btn svg{ width: 18px; height: 18px; opacity: .85; }

/* Botón menú */
.menu-btn{
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.65);
  cursor: pointer;
  user-select: none;
}
.menu-btn:hover{ background: rgba(255,255,255,.9); }
.menu-btn svg{ width: 20px; height: 20px; opacity: .85; }

/* Drawer */
.drawer-overlay{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.25);
  display: none;
  z-index: 200; /* debajo del modal */
}
.drawer-overlay.show{ display: block; }

.drawer{
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: min(320px, 86vw);
  background: #ffffff;
  border-right: 1px solid var(--border);
  box-shadow: 14px 0 40px rgba(0,0,0,.12);
  transform: translateX(-105%);
  transition: transform 180ms ease;
  z-index: 201;
  display: flex;
  flex-direction: column;
}
.drawer.open{ transform: translateX(0); }

.drawer-header{
  height: 88px;
  display: flex;
  align-items: center;
  padding: 12px 14px;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.drawer-logo{
  height: 46px;
  width: auto;
  display: block;
}

.drawer-logo-fallback{
  font-weight: 900;
  letter-spacing: 2px;
  color: rgba(0,0,0,.70);
  font-size: 18px;
  display: none;
}

.drawer-nav{
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-item{
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-weight: 800;
  color: rgba(0,0,0,.75);
}
.nav-item:hover{
  background: rgba(0,0,0,.04);
  border-color: var(--border);
}
.nav-item.active{
  background: rgba(42,168,74,.10);
  border-color: rgba(42,168,74,.25);
  color: rgba(0,0,0,.82);
}

/* Estado deshabilitado: “feature en desarrollo” */
.nav-item:disabled,
.nav-item[aria-disabled="true"]{
  opacity: .45;
  cursor: not-allowed;
  background: transparent;
  border-color: transparent;
}
.nav-item:disabled:hover,
.nav-item[aria-disabled="true"]:hover{
  background: transparent;
  border-color: transparent;
}

.nav-item svg{ width: 18px; height: 18px; opacity: .85; }

.drawer-footer{
  margin-top: auto;
  padding: 12px 12px 16px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}

/* Main */
main{
  padding: 14px 16px 28px;
  flex: 1;
}

.last-update{
  font-size: 20px;
  font-weight: 800;
  letter-spacing: .2px;
  margin: 6px 0 14px;
}
.last-update span{
  font-weight: 500;
  color: rgba(0,0,0,.72);
  margin-left: 6px;
}

/* Cards */
.card{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 12px 0;
}
.card-top{
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}
.card-title{
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
}

.icon{
  width: 22px;
  height: 22px;
  opacity: .9;
  flex: 0 0 auto;
}

.bar{
  height: 14px;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border);
  background: linear-gradient(90deg, var(--g1), var(--g2), var(--g3), var(--g4));
}
.bar .mask{
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 50%;
  background: rgba(255,255,255,.82);
}

.level-row{
  margin-top: 10px;
  font-size: 16px;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.level-row .label{
  color: var(--muted);
  font-weight: 600;
}
.level-row .value{
  font-weight: 700;
  color: rgba(0,0,0,.80);
}

/* Recomendaciones */
.section-title{
  margin: 18px 0 8px;
  font-size: 20px;
  font-weight: 800;
}
.section-text{
  color: rgba(0,0,0,.70);
  line-height: 1.45;
  font-size: 16px;
  margin: 0 0 10px;
}

.link-btn{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: rgba(0,0,0,.70);
  font-weight: 700;
  cursor: pointer;
}
.link-btn:hover{
  background: rgba(0,0,0,.03);
  border-color: var(--border);
}

/* Error box */
.error-box{
  margin-top: 14px;
  padding: 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.55);
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.error-title{
  font-weight: 900;
  margin-bottom: 6px;
}
.primary-btn{
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(42,168,74,.12);
  color: rgba(0,0,0,.75);
  font-weight: 800;
  cursor: pointer;
}
.primary-btn:hover{ background: rgba(42,168,74,.18); }

/* Loading */
.spinner{
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(0,0,0,.12);
  border-top-color: rgba(0,0,0,.45);
  animation: spin 1s linear infinite;
  margin: 24px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Modal */
.overlay{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 999;
}
.overlay.show{ display: flex; }

.modal{
  width: min(420px, 100%);
  background: #eef2ea;
  border-radius: 18px;
  border: 1px solid rgba(0,0,0,.12);
  box-shadow: 0 20px 50px rgba(0,0,0,.18);
  padding: 18px 18px 14px;
}
.modal-title{
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 22px;
  font-weight: 900;
  margin: 2px 0 10px;
}
.modal-title svg{ width: 22px; height: 22px; }

.modal-text{
  color: rgba(0,0,0,.75);
  line-height: 1.45;
  font-size: 16px;
  margin: 0 0 14px;
  text-align: justify;
}

.modal-actions{
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.modal-ok{
  border: none;
  background: transparent;
  color: rgba(42,168,74,.95);
  font-weight: 900;
  cursor: pointer;
  padding: 10px 12px;
  border-radius: 10px;
}
.modal-ok:hover{
  background: rgba(42,168,74,.10);
}

/* Historial – controles de intervalo (columna) */
.history-controls{
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
  margin: 10px 0 14px;
}
.hc-row{
  display: flex;
  gap: 10px;
  align-items: center;
}
.history-controls label{
  font-weight: 800;
  color: rgba(0,0,0,.72);
  font-size: 14px;
  white-space: nowrap;
  width: 70px;
  flex: 0 0 auto;
}
.history-controls input[type="date"]{
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(0,0,0,.10);
  background: #fff;
  font-size: 14px;
}
.history-controls button{
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,.02);
  cursor: pointer;
  font-weight: 800;
  color: rgba(0,0,0,.72);
  white-space: nowrap;
}
.history-controls button:hover{
  background: rgba(0,0,0,.05);
}

.empty-note{
  color: rgba(0,0,0,.70);
  line-height: 1.45;
  font-size: 16px;
  margin: 0;
}

/* Espaciador */
.spacer{ height: 18px; }

/* Fallback si el logo no carga */
.logo-fallback{
  font-weight: 900;
  letter-spacing: 2px;
  font-size: 28px;
  color: rgba(0,0,0,.65);
  display: none;
}