:root {
  --verde: #2e6b30;
  --verde-osc: #1f4d21;
  --verde-claro: #e3efe0;
  --amarillo: #f2b705;
  --amarillo-claro: #fff4d1;
  --rojo: #c0392b;
  --rojo-claro: #fbe3e0;
  --azul: #1f6fb2;
  --azul-claro: #e0eefa;
  --fondo: #f4f6f1;
  --carta: #ffffff;
  --texto: #1c281c;
  --suave: #5d6b5d;
  --borde: #d9dfd4;
  --radio: 14px;
  --sombra: 0 1px 3px rgba(0, 0, 0, .08);
  --tab-alto: 64px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  padding-bottom: calc(var(--tab-alto) + env(safe-area-inset-bottom));
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 1.4rem; margin: 0; }
h2 { font-size: .95rem; text-transform: uppercase; letter-spacing: .04em; color: var(--suave); margin: 24px 0 8px; }

/* ---- barra superior ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--verde); color: #fff;
}
.marca { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; }
.marca img { width: 30px; height: 30px; border-radius: 8px; }
.pill {
  border: 0; border-radius: 999px; padding: 6px 12px; font: inherit; font-size: .82rem; font-weight: 600;
  background: rgba(255, 255, 255, .18); color: #fff; cursor: pointer; white-space: nowrap;
}
.pill.verde { background: rgba(255, 255, 255, .18); }
.pill.amarillo { background: var(--amarillo); color: #3b2c00; }
.pill.rojo { background: var(--rojo); }
.pill.gris { background: rgba(0, 0, 0, .25); }
.pill.gira::before { content: "⟳ "; display: inline-block; animation: gira 1s linear infinite; }
@keyframes gira { to { transform: rotate(360deg); } }

main { max-width: 720px; margin: 0 auto; padding: 16px; outline: none; }

/* ---- barra de pestañas ---- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tab-alto) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--carta); border-top: 1px solid var(--borde);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .72rem; color: var(--suave); }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.activo { color: var(--verde); font-weight: 700; }

/* ---- encabezados ---- */
.encabezado { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.encabezado h1 { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.btn-icono { border: 0; background: var(--carta); width: 40px; height: 40px; border-radius: 50%; font-size: 1.6rem; line-height: 1; box-shadow: var(--sombra); cursor: pointer; color: var(--texto); }
.saludo { margin: 4px 0 12px; }
.ayuda { color: var(--suave); font-size: .9rem; margin: 6px 0 12px; }
.centro { text-align: center; }
.vacio { color: var(--suave); background: var(--carta); padding: 14px; border-radius: var(--radio); text-align: center; margin: 0; }

/* ---- avisos ---- */
.aviso { display: flex; flex-direction: column; gap: 10px; background: var(--verde-claro); border-radius: var(--radio); padding: 12px 14px; margin-bottom: 12px; font-size: .92rem; }
.aviso.info { background: var(--azul-claro); }
.aviso.amarillo { background: var(--amarillo-claro); }
.aviso.rojo { background: var(--rojo-claro); }

/* ---- botones ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 10px; padding: 10px 16px; min-height: 44px;
  background: var(--verde); color: #fff; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:active { background: var(--verde-osc); }
.btn.sec { background: var(--carta); color: var(--verde); box-shadow: inset 0 0 0 1.5px var(--verde); }
.btn.chico { padding: 6px 12px; min-height: 36px; font-size: .88rem; }
.btn.grande { width: 100%; min-height: 52px; font-size: 1.05rem; }
.fila-botones { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- estadísticas ---- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--carta); border-radius: var(--radio); padding: 12px 14px; box-shadow: var(--sombra); border-left: 5px solid var(--verde); }
.stat b { display: block; font-size: 1.8rem; line-height: 1.1; }
.stat b small { font-size: 1rem; color: var(--suave); font-weight: 500; }
.stat span { font-size: .85rem; color: var(--suave); }
.stat.rojo { border-color: var(--rojo); }
.stat.amarillo { border-color: var(--amarillo); }
.stat.azul { border-color: var(--azul); }

/* ---- acciones rápidas ---- */
.acciones { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-top: 14px; }
.accion {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center;
  background: var(--carta); border-radius: var(--radio); padding: 14px 8px; min-height: 88px;
  box-shadow: var(--sombra); font-weight: 600; font-size: .92rem;
}
.accion span { font-size: 1.8rem; }
.accion:active { background: var(--verde-claro); }

/* ---- listas ---- */
.lista { display: flex; flex-direction: column; background: var(--carta); border-radius: var(--radio); box-shadow: var(--sombra); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--borde); min-height: 56px; }
.item:last-child { border-bottom: 0; }
.item-ico { font-size: 1.4rem; }
.item-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.item-txt b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item-txt small, .item-txt span { color: var(--suave); font-size: .85rem; }
.item-lado { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.flecha { color: var(--suave); font-size: 1.4rem; }
.pend { color: var(--amarillo); font-size: 1.1rem; }
.stock { text-align: right; padding: 4px 10px; border-radius: 10px; }
.stock b { display: block; font-size: 1.2rem; }
.stock small { font-size: .75rem; }
.stock.rojo { background: var(--rojo-claro); color: var(--rojo); }
.stock.verde { background: var(--verde-claro); color: var(--verde); }

/* ---- insignias ---- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.badge.verde { background: var(--verde-claro); color: var(--verde); }
.badge.amarillo { background: var(--amarillo-claro); color: #7a5a00; }
.badge.rojo { background: var(--rojo-claro); color: var(--rojo); }
.badge.azul { background: var(--azul-claro); color: var(--azul); }

/* ---- tarjetas de equipos ---- */
.segmentado { display: flex; background: var(--borde); border-radius: 12px; padding: 3px; margin-bottom: 12px; }
.segmentado a { flex: 1; text-align: center; padding: 9px 4px; border-radius: 9px; font-weight: 600; font-size: .9rem; color: var(--suave); }
.segmentado a.activo { background: var(--carta); color: var(--texto); box-shadow: var(--sombra); }
.tarjetas { display: flex; flex-direction: column; gap: 10px; }
.tarjeta { display: flex; align-items: center; gap: 12px; background: var(--carta); border-radius: var(--radio); padding: 10px 12px; box-shadow: var(--sombra); }
.tarjeta img, .tarjeta-ico { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; flex: none; }
.tarjeta-ico { display: grid; place-items: center; background: var(--verde-claro); font-size: 1.8rem; }
.tarjeta-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tarjeta-txt small { color: var(--suave); }

/* ---- ficha de equipo ---- */
.ficha { background: var(--carta); border-radius: var(--radio); box-shadow: var(--sombra); overflow: hidden; }
.ficha img { width: 100%; max-height: 220px; object-fit: cover; display: block; }
.ficha-datos { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; }
dt { color: var(--suave); }
dd { margin: 0; font-weight: 600; }
.info { background: var(--carta); padding: 12px 14px; border-radius: var(--radio); margin-bottom: 12px; }
details.doc, details.bloque { background: var(--carta); border-radius: var(--radio); margin-bottom: 8px; box-shadow: var(--sombra); }
details.bloque { margin-top: 20px; }
details.doc summary, details.bloque summary { padding: 12px 14px; font-weight: 600; cursor: pointer; }
.doc-txt { padding: 0 14px 14px; white-space: pre-wrap; font-size: .92rem; }

/* ---- formularios ---- */
form { display: flex; flex-direction: column; gap: 12px; }
.campo { display: flex; flex-direction: column; gap: 4px; }
.campo > span { font-weight: 600; font-size: .9rem; }
.campo i { color: var(--rojo); font-style: normal; }
.campo small { color: var(--suave); font-size: .8rem; }
input, select, textarea {
  font: inherit; font-size: 16px; /* 16px evita el zoom automático en iPhone */
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1.5px solid var(--borde); border-radius: 10px; background: var(--carta); color: var(--texto);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--verde); box-shadow: 0 0 0 3px var(--verde-claro); }
textarea { resize: vertical; }
.fila-campos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 4px; }
.fila-campos label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .9rem; }
.error { background: var(--rojo-claro); color: var(--rojo); padding: 10px 12px; border-radius: 10px; margin: 0; font-weight: 600; }
.barra-guardar {
  position: sticky; bottom: calc(var(--tab-alto) + env(safe-area-inset-bottom));
  padding: 10px 0; background: linear-gradient(transparent, var(--fondo) 30%);
  margin-top: 8px;
}

/* ---- checklist ---- */
details.categoria { background: var(--carta); border-radius: var(--radio); box-shadow: var(--sombra); margin-bottom: 10px; overflow: hidden; }
details.categoria summary { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; font-weight: 700; cursor: pointer; }
details.categoria summary small { color: var(--suave); font-weight: 500; }
.todo-bueno { margin: 0 14px 8px; }
.check { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 6px 10px; padding: 10px 14px; border-top: 1px solid var(--borde); }
.check-txt { font-size: .95rem; }
.check-btns { display: flex; gap: 6px; }
.check-btns button {
  width: 46px; height: 42px; border-radius: 10px; border: 1.5px solid var(--borde);
  background: var(--carta); font: inherit; font-weight: 800; color: var(--suave); cursor: pointer;
}
.check-btns .b.sel { background: var(--verde); border-color: var(--verde); color: #fff; }
.check-btns .m.sel { background: var(--rojo); border-color: var(--rojo); color: #fff; }
.check-obs { display: none; grid-column: 1 / -1; min-height: 40px; }
.check[data-estado="Malo"] { background: var(--rojo-claro); }
.check[data-estado="Malo"] .check-obs { display: block; }

/* ---- aviso flotante ---- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-alto) + 16px + env(safe-area-inset-bottom)); z-index: 20;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .2s;
  background: var(--texto); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600;
  max-width: calc(100% - 32px); text-align: center;
}
#toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* ---- ficha: información y documentación ---- */
.ficha > a { display: block; }
.ficha-sinimg { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 120px; background: var(--verde-claro); }
.ficha-sinimg span { font-size: 2.6rem; }
.ficha-sinimg small { color: var(--suave); }
.falta { color: var(--suave); font-weight: 400; font-style: italic; }
.segmentado.arriba { margin-top: 18px; margin-bottom: 0; }
.vacio small { display: block; margin-top: 6px; font-size: .82rem; }
.doc-cuerpo { background: var(--carta); border-radius: var(--radio); box-shadow: var(--sombra); padding: 14px 16px; font-size: 1.02rem; line-height: 1.55; }
.doc-cuerpo p { margin: 0 0 10px; }
.doc-cuerpo p:last-child { margin-bottom: 0; }
.doc-cuerpo .vi { position: relative; padding-left: 18px; margin-bottom: 6px; }
.doc-cuerpo .vi::before { content: ""; position: absolute; left: 4px; top: .65em; width: 6px; height: 6px; border-radius: 50%; background: var(--verde); }
.doc-cuerpo .vi.sub { margin-left: 18px; color: #2c3a2c; }
.doc-cuerpo .vi.sub::before { background: none; border: 1.5px solid var(--verde); width: 5px; height: 5px; }
.doc-nav { display: flex; justify-content: space-between; gap: 8px; margin-top: 14px; }
.doc-nav .btn { flex: 1; font-size: .85rem; text-align: center; }
.progreso { height: 8px; background: var(--borde); border-radius: 99px; overflow: hidden; margin: 8px 0; }
.progreso div { height: 100%; width: 0; background: var(--verde); transition: width .2s; }
