:root {
  --verde: #2f5d34; --verde-2: #3f7a45; --verde-claro: #e7f0e4; --tierra: #7a5230; --tierra-claro: #f4ece3;
  --txt: #1d231c; --txt-2: #5b6558; --borde: #d6dccf; --fondo: #f6f7f3; --blanco: #fff;
  --rojo: #b3261e; --ambar: #b7791f; --azul: #1f6fb2;
  --r: 12px; --sombra: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--fondo); color: var(--txt); -webkit-text-size-adjust: 100%; }
body { font-size: 16px; line-height: 1.4; padding-bottom: env(safe-area-inset-bottom); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--verde); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

/* Barra superior */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top)); background: var(--verde); color: #fff; }
.brand { flex: 1; font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: 0; background: transparent; color: inherit; border-radius: 10px; cursor: pointer; }
.icon-btn:active { background: rgba(255,255,255,.15); }
.sync { display: inline-flex; align-items: center; gap: 6px; border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.08); color: #fff; border-radius: 999px; padding: 5px 11px; font-size: .82rem; cursor: pointer; }
.sync .dot { width: 9px; height: 9px; border-radius: 50%; background: #ccc; }
.sync[data-s="online"] .dot { background: #7ee07e; }
.sync[data-s="offline"] .dot { background: #f2b84b; }
.sync[data-s="syncing"] .dot { background: #8fd0ff; animation: pulse 1s infinite; }
.sync[data-s="error"] .dot { background: #ff7b72; }
@keyframes pulse { 50% { opacity: .3; } }

main { max-width: 980px; margin: 0 auto; padding: 14px 12px 90px; }
.wide main, main.wide { max-width: none; }

/* Tarjetas y listas */
.card { background: var(--blanco); border: 1px solid var(--borde); border-radius: var(--r); padding: 14px; margin-bottom: 12px; box-shadow: var(--sombra); }
.card > h2, .card > h3 { margin-bottom: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 560px) { .grid3 { grid-template-columns: 1fr 1fr; } }
.muted { color: var(--txt-2); font-size: .88rem; }
.small { font-size: .82rem; }
.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--blanco); border: 1px solid var(--borde); border-radius: var(--r); margin-bottom: 8px; text-decoration: none; color: inherit; box-shadow: var(--sombra); }
.item .num { flex: none; width: 46px; height: 46px; border-radius: 10px; background: var(--tierra-claro); color: var(--tierra); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1.1rem; }
.item .body { flex: 1; min-width: 0; }
.item .t { font-weight: 650; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.badge { font-size: .72rem; padding: 2px 8px; border-radius: 999px; background: #eef0ea; color: var(--txt-2); white-space: nowrap; }
.badge.ok { background: var(--verde-claro); color: var(--verde); }
.badge.warn { background: #fdf0d8; color: #8a5a00; }
.badge.pend { background: #e6f0fa; color: var(--azul); }
.empty { text-align: center; padding: 30px 10px; color: var(--txt-2); }

/* Formularios */
label.f { display: block; font-size: .8rem; font-weight: 600; color: var(--txt-2); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .02em; }
.fld { margin-bottom: 12px; }
input[type=text], input[type=number], input[type=date], input[type=url], input[type=password], input:not([type]), select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--borde); border-radius: 10px; background: #fff; min-height: 46px; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--verde-2); outline-offset: -1px; border-color: transparent; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--borde); background: #fff; font-weight: 600; cursor: pointer; text-decoration: none; color: var(--txt); }
.btn.primary { background: var(--verde); border-color: var(--verde); color: #fff; }
.btn.tierra { background: var(--tierra); border-color: var(--tierra); color: #fff; }
.btn.danger { color: var(--rojo); border-color: #eac3c0; }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: .88rem; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; }
.fab { position: fixed; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 15; border-radius: 999px; min-height: 56px; padding: 0 22px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }

/* Chips de selección rápida */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--borde); background: #fff; border-radius: 999px; padding: 8px 12px; min-height: 40px; font-size: .9rem; cursor: pointer; }
.chip.sel { background: var(--verde); color: #fff; border-color: var(--verde); }
.chips.sm .chip { padding: 5px 10px; min-height: 34px; font-size: .84rem; }
.sub { font-size: .75rem; color: var(--txt-2); margin: 8px 0 4px; font-weight: 600; }

/* Horizontes */
.hz { background: #fff; border: 1px solid var(--borde); border-radius: var(--r); margin-bottom: 10px; box-shadow: var(--sombra); overflow: hidden; }
.hz-head { display: flex; align-items: center; gap: 10px; padding: 12px; cursor: pointer; }
.hz-head .n { width: 40px; height: 40px; border-radius: 10px; background: var(--tierra); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; flex: none; }
.hz-head .s { flex: 1; min-width: 0; font-size: .88rem; }
.hz-head .s b { font-size: 1rem; }
.hz-body { padding: 4px 12px 14px; border-top: 1px dashed var(--borde); }
.hz:not(.open) .hz-body { display: none; }
.sect { border-top: 1px solid #eef0ea; padding-top: 10px; margin-top: 10px; }
.sect > h4 { margin: 0 0 6px; font-size: .9rem; color: var(--tierra); }
.munsell { display: grid; grid-template-columns: 52px 1fr; gap: 6px 8px; align-items: center; margin-bottom: 6px; }
.mlbl { font-size: .72rem; color: var(--txt-2); }
.sw { display: inline-block; width: 20px; height: 20px; border-radius: 4px; border: 1px solid rgba(0,0,0,.2); vertical-align: middle; }
.fmg { display: grid; grid-template-columns: 64px 1fr; gap: 6px 8px; align-items: center; }
.fmg > span { font-size: .85rem; color: var(--txt-2); font-weight: 600; }

/* Dictado */
.mic { background: var(--tierra); color: #fff; border: 0; }
.mic.on { background: var(--rojo); animation: pulse 1.2s infinite; }
.dict { background: var(--tierra-claro); border: 1px solid #e3d3c1; border-radius: 10px; padding: 10px; margin: 8px 0; font-size: .92rem; }
.dict .live { color: var(--txt-2); font-style: italic; }
.dict .ok { color: var(--verde); font-weight: 600; }

/* Fotos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.ph { position: relative; aspect-ratio: 3/4; border-radius: 10px; overflow: hidden; background: #e9ece4; border: 1px solid var(--borde); }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph .tag { position: absolute; left: 4px; bottom: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: .7rem; padding: 2px 6px; border-radius: 6px; }
.ph .star { position: absolute; right: 4px; top: 4px; background: var(--ambar); color: #fff; font-size: .7rem; padding: 2px 6px; border-radius: 6px; }

/* Mapa */
.map { position: relative; width: 100%; border-radius: 10px; overflow: hidden; background: #eef0ea; border: 1px solid var(--borde); }
.map svg { display: block; width: 100%; height: auto; touch-action: manipulation; }
.map.placing { outline: 3px solid var(--ambar); }

/* Tablas simples */
table.t { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.t th, table.t td { border-bottom: 1px solid #eceee8; padding: 6px 8px; text-align: left; vertical-align: top; }
table.t th { font-size: .75rem; color: var(--txt-2); text-transform: uppercase; background: #f7f8f5; position: sticky; top: 0; }
.scroll { overflow: auto; max-height: 60vh; border: 1px solid var(--borde); border-radius: 10px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 0 -12px 12px; padding: 0 12px; position: sticky; top: 56px; z-index: 10; background: var(--fondo); padding-top: 6px; padding-bottom: 6px; }
.tabs a { flex: none; padding: 8px 14px; border-radius: 999px; background: #fff; border: 1px solid var(--borde); text-decoration: none; color: var(--txt); font-size: .9rem; font-weight: 600; }
.tabs a.on { background: var(--tierra); color: #fff; border-color: var(--tierra); }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; transition: .25s; pointer-events: none; z-index: 50; max-width: 90vw; font-size: .92rem; }
.toast.show { opacity: .95; transform: translateX(-50%); }
.hidden { display: none !important; }
dialog { border: 0; border-radius: 14px; padding: 16px; max-width: 520px; width: calc(100% - 24px); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.4); }

/* Panel de dictado */
.vpanel { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; background: #fff; border-top: 3px solid var(--rojo); box-shadow: 0 -6px 24px rgba(0,0,0,.25); padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); display: grid; gap: 10px; }
.vp-head { display: flex; align-items: center; gap: 8px; }
.vp-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--rojo); animation: pulse 1s infinite; }
.vp-txt { max-height: 30vh; overflow: auto; font-size: 1rem; background: var(--tierra-claro); border-radius: 10px; padding: 10px; min-height: 60px; }
.vp-txt .live { color: var(--txt-2); font-style: italic; }
.vp-btns { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }
