:root {
  --espresso: #1a110c;
  --espresso-2: #241810;
  --espresso-3: #2f2017;
  --crema: #f4ead8;
  --crema-dim: rgba(244, 234, 216, .68);
  --line: rgba(244, 234, 216, .14);
  --oro: #d9a441;
  --verde-profundo: #10281b;
  --verde: #7fb08a;
  --tostado: #a85d1c;
  --error: #e5826b;
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --radius: 14px;
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Outfit', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--espresso); color: var(--crema); font: 400 15px/1.5 var(--font-body); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 500; margin: 0; letter-spacing: .1px; }
a { color: var(--oro); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--oro); outline-offset: 2px; }

/* Botones */
.btn { appearance: none; border: 1px solid var(--line); background: var(--espresso-3); color: var(--crema); padding: .55rem 1rem; border-radius: 999px; cursor: pointer; font-weight: 500; transition: transform .35s var(--spring), background .2s, border-color .2s; }
.btn:hover { transform: translateY(-1px) scale(1.03); border-color: rgba(244, 234, 216, .35); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--oro); color: var(--espresso); border-color: var(--oro); font-weight: 600; }
.btn.danger { background: var(--tostado); border-color: var(--tostado); color: var(--crema); }
.btn.ghost { background: transparent; }
.btn.small { padding: .3rem .75rem; font-size: .85rem; }
.btn.big { padding: .8rem 1.4rem; font-size: 1.05rem; width: 100%; margin-top: .6rem; }
.btn[disabled] { opacity: .55; cursor: wait; transform: none; }

.demo-pill { display: inline-block; background: rgba(217, 164, 65, .14); color: var(--oro); border: 1px solid rgba(217, 164, 65, .55); padding: .15rem .7rem; border-radius: 999px; font-size: .78rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: .72rem; color: var(--verde); margin: 0; }

/* Ingreso */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(1000px 500px at 80% -10%, rgba(16, 40, 27, .9), transparent 60%), radial-gradient(700px 400px at 0% 100%, rgba(168, 93, 28, .25), transparent 60%), var(--espresso); }
.login-card { width: min(420px, 100%); background: rgba(36, 24, 16, .86); border: 1px solid var(--line); border-radius: 22px; padding: 30px 28px; display: grid; gap: 8px; backdrop-filter: blur(6px); animation: rise .7s var(--spring) both; }
.login-card h1 { font-size: 2.1rem; line-height: 1.1; }
.login-card h1 span, .brand strong span { color: var(--oro); }
.login-card .bean { width: 54px; height: 54px; animation: wobble 1.2s var(--spring) .3s both; }
.lede { color: var(--crema-dim); margin: 0 0 6px; }
.login-card label { font-size: .85rem; margin-top: 8px; color: var(--crema-dim); }
.login-card label small { opacity: .75; }
input, select, textarea { width: 100%; background: var(--espresso); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .75rem; transition: border-color .2s, box-shadow .2s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--oro); box-shadow: 0 0 0 3px rgba(217, 164, 65, .2); }
.form-error { color: var(--error); margin: 4px 0 0; font-size: .9rem; }
.fine { color: var(--crema-dim); font-size: .78rem; margin: 6px 0 0; text-align: center; }

/* Cabecera */
.top { display: flex; align-items: center; gap: 14px; padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--espresso-2); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-size: 1.15rem; }
.brand svg { width: 28px; height: 28px; }
.tabs { display: flex; gap: 4px; margin-left: 8px; flex: 1; flex-wrap: wrap; }
.tabs button, .seg button { appearance: none; background: transparent; border: 0; color: var(--crema-dim); padding: .5rem .9rem; border-radius: 999px; cursor: pointer; font-weight: 500; transition: color .2s, background .2s, transform .35s var(--spring); }
.tabs button:hover, .seg button:hover { color: var(--crema); transform: translateY(-1px); }
.tabs button[aria-selected="true"], .seg button[aria-selected="true"] { background: var(--verde-profundo); color: var(--crema); box-shadow: inset 0 0 0 1px rgba(127, 176, 138, .5); }
.who { display: flex; align-items: center; gap: 10px; color: var(--crema-dim); font-size: .9rem; }

/* Vistas */
#app { height: 100%; display: flex; flex-direction: column; }
main { flex: 1; min-height: 0; }
.view { height: 100%; }
.map-view { display: grid; grid-template-columns: minmax(0, 1fr) 460px; }
.map-col { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: #0d0a07; }
.map-modes { position: absolute; z-index: 500; top: 12px; left: 56px; display: flex; align-items: center; gap: 4px; background: rgba(26, 17, 12, .88); border: 1px solid var(--line); border-radius: 999px; padding: 4px 6px 4px 14px; backdrop-filter: blur(4px); }
.map-modes span { font-size: .78rem; color: var(--crema-dim); margin-right: 4px; }
.map-modes button { background: transparent; border: 0; color: var(--crema-dim); padding: .3rem .8rem; border-radius: 999px; cursor: pointer; transition: transform .35s var(--spring), background .2s; }
.map-modes button[aria-pressed="true"] { background: var(--oro); color: var(--espresso); font-weight: 600; }
.legend { position: absolute; z-index: 500; left: 12px; bottom: 34px; background: rgba(26, 17, 12, .9); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: .82rem; max-width: 280px; }
.legend h4 { font-family: var(--font-body); font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; color: var(--crema-dim); margin-bottom: 6px; }
.legend .row { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
.legend .sw { width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(255, 255, 255, .35); flex: none; }
.legend .grad { height: 10px; width: 180px; border-radius: 6px; }
.legend .ends { display: flex; justify-content: space-between; color: var(--crema-dim); margin-top: 3px; }
.lot-tip { background: var(--espresso); color: var(--crema); border: 1px solid var(--oro); font-family: var(--font-body); }
.leaflet-container { font-family: var(--font-body); }

.side { border-left: 1px solid var(--line); background: var(--espresso-2); display: flex; flex-direction: column; min-height: 0; }
.seg { display: flex; gap: 4px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.panel { flex: 1; min-height: 0; overflow: auto; padding: 14px 16px 24px; display: flex; flex-direction: column; gap: 14px; }
.page { overflow: auto; padding: 22px clamp(16px, 4vw, 48px) 48px; }
.page > * { max-width: 1100px; margin-left: auto; margin-right: auto; }

/* Tarjetas */
.card { background: var(--espresso-3); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; animation: rise .5s var(--spring) both; }
.card h3 { font-size: 1.15rem; margin-bottom: 6px; }
.card h4 { font-family: var(--font-body); font-size: .74rem; text-transform: uppercase; letter-spacing: .1em; color: var(--verde); margin-bottom: 8px; }
.muted { color: var(--crema-dim); }
.small { font-size: .85rem; }
.lot-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.lot-head .code { font-family: var(--font-display); font-size: 1.9rem; color: var(--oro); line-height: 1; }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 10px 0; }
.kv div { background: var(--espresso); border-radius: 10px; padding: 8px 10px; }
.kv b { display: block; font-size: 1.05rem; font-weight: 600; }
.kv span { font-size: .72rem; color: var(--crema-dim); text-transform: uppercase; letter-spacing: .06em; }
.bar { display: flex; height: 12px; border-radius: 8px; overflow: hidden; margin: 8px 0 6px; border: 1px solid var(--line); }
.bar i { display: block; height: 100%; }
.var-list { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .86rem; }
.var-list .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }

.lot-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.lot-chip { appearance: none; background: var(--espresso); border: 1px solid var(--line); border-radius: 999px; padding: .25rem .8rem; cursor: pointer; font-weight: 500; transition: transform .35s var(--spring), border-color .2s; }
.lot-chip:hover { transform: translateY(-2px) scale(1.05); }
.lot-chip[aria-pressed="true"] { border-color: var(--oro); color: var(--oro); background: rgba(217, 164, 65, .1); }
.lot-chip .n { margin-left: 6px; font-size: .72rem; background: var(--tostado); color: var(--crema); border-radius: 999px; padding: 0 .4rem; }

/* Hallazgos */
.finding { display: grid; grid-template-columns: auto 1fr; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.finding:first-of-type { border-top: 0; }
.sev { font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; padding: .15rem .5rem; border-radius: 6px; height: fit-content; margin-top: 2px; }
.sev.error { background: rgba(229, 130, 107, .2); color: var(--error); }
.sev.alerta { background: rgba(217, 164, 65, .2); color: var(--oro); }
.sev.info { background: rgba(127, 176, 138, .2); color: var(--verde); }

/* Línea de tiempo */
.timeline { list-style: none; margin: 0; padding: 0 0 0 16px; border-left: 2px solid rgba(217, 164, 65, .35); display: grid; gap: 12px; }
.tl-item { position: relative; background: var(--espresso); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; animation: rise .5s var(--spring) both; }
.tl-item::before { content: ''; position: absolute; left: -24px; top: 16px; width: 12px; height: 12px; border-radius: 50%; background: var(--c, var(--oro)); border: 2px solid var(--espresso-2); }
.tl-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.tl-date { font-size: .8rem; color: var(--crema-dim); }
.chip { display: inline-block; font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; padding: .1rem .55rem; border-radius: 999px; background: color-mix(in srgb, var(--c, var(--oro)) 22%, transparent); color: var(--c, var(--oro)); }
.sealed-badge { color: var(--verde); font-size: .78rem; font-weight: 600; }
.tl-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.tl-who { font-size: .76rem; color: var(--crema-dim); margin-top: 4px; }
details.ref summary { cursor: pointer; color: var(--verde); font-weight: 500; }
details.ref ul { margin: 8px 0 0; padding-left: 18px; }

/* Chat */
.chat { display: flex; flex-direction: column; gap: 10px; min-height: 0; flex: 1; }
.chat-log { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 4px; min-height: 160px; }
.msg { max-width: 92%; padding: 10px 12px; border-radius: 14px; animation: rise .4s var(--spring) both; }
.msg.user { align-self: flex-end; background: var(--verde-profundo); border: 1px solid rgba(127, 176, 138, .4); }
.msg.agent { align-self: flex-start; background: var(--espresso-3); border: 1px solid var(--line); }
.msg p { margin: 0 0 6px; } .msg p:last-child { margin: 0; }
.msg ul { margin: 4px 0; padding-left: 18px; }
.msg .who-tag { display: block; font-size: .7rem; color: var(--verde); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 4px; }
.proposal { align-self: stretch; border: 1px dashed var(--oro); background: rgba(217, 164, 65, .08); border-radius: 12px; padding: 10px 12px; animation: rise .4s var(--spring) both; }
.proposal h4 { font-family: var(--font-body); font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; color: var(--oro); margin-bottom: 4px; }
.proposal dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 6px 0; font-size: .84rem; }
.proposal dt { color: var(--crema-dim); }
.proposal dd { margin: 0; }
.proposal .row { display: flex; gap: 8px; margin-top: 8px; }
.proposal.done { opacity: .6; border-style: solid; }
.chat-form { display: grid; gap: 8px; }
.chat-form .line { display: flex; gap: 8px; }
.chat-form textarea { resize: none; }
.typing { display: inline-flex; gap: 4px; } .typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--crema-dim); animation: blink 1s infinite; } .typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }

/* Capa blockchain */
.page h2 { font-size: 1.8rem; margin-bottom: 6px; }
.status-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 12px 0 18px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: .25rem .8rem; border-radius: 999px; border: 1px solid var(--line); font-size: .85rem; }
.pill.ok { border-color: rgba(127, 176, 138, .6); color: var(--verde); }
.pill.warn { border-color: rgba(217, 164, 65, .6); color: var(--oro); }
.seal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.seal-card { background: var(--espresso-3); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; animation: rise .5s var(--spring) both; }
.mono { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: .8rem; word-break: break-all; color: var(--crema-dim); }
.explainer { background: linear-gradient(135deg, rgba(16, 40, 27, .8), rgba(36, 24, 16, .9)); border: 1px solid rgba(127, 176, 138, .35); border-radius: var(--radius); padding: 14px 18px; }
table.audit { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.audit th, table.audit td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.audit th { color: var(--verde); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--espresso-3); }

/* Diálogos */
dialog.modal { border: 1px solid var(--line); border-radius: 18px; background: var(--espresso-2); color: var(--crema); padding: 0; width: min(520px, calc(100vw - 32px)); animation: pop .45s var(--spring) both; }
dialog.modal::backdrop { background: rgba(10, 6, 3, .72); backdrop-filter: blur(3px); }
.modal form { padding: 20px 22px; display: grid; gap: 12px; }
.modal-body { display: grid; gap: 10px; max-height: 62vh; overflow: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fields .wide { grid-column: 1 / -1; }
.fields label, .modal-body label { font-size: .8rem; color: var(--crema-dim); display: grid; gap: 4px; }
.check { display: flex; gap: 8px; align-items: center; padding: 6px 0; }
.check .mark { font-weight: 700; }
.check.ok .mark { color: var(--verde); } .check.bad .mark { color: var(--error); }
.warn-box { border: 1px solid rgba(217, 164, 65, .55); background: rgba(217, 164, 65, .08); border-radius: 10px; padding: 10px 12px; font-size: .88rem; }

.toasts { position: fixed; z-index: 2000; right: 16px; bottom: 16px; display: grid; gap: 8px; }
.toast { background: var(--espresso-3); border: 1px solid var(--line); border-left: 4px solid var(--verde); padding: 10px 14px; border-radius: 10px; max-width: 360px; animation: pop .45s var(--spring) both; }
.toast.error { border-left-color: var(--error); }
.toast.out { opacity: 0; transform: translateY(8px); transition: all .3s; }

.empty { text-align: center; color: var(--crema-dim); padding: 28px 10px; }

/* Pasaporte público */
.passport-body { min-height: 100%; background: radial-gradient(900px 420px at 85% -10%, rgba(16, 40, 27, .85), transparent 60%), var(--espresso); }
.passport { width: min(760px, 100%); margin: 0 auto; padding: 18px 16px 48px; display: grid; gap: 14px; }
.passport .hero h1 { font-size: clamp(2rem, 7vw, 2.8rem); color: var(--oro); margin: 2px 0; }
.pmap { height: 260px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: #0d0a07; }
.qr-box { display: grid; place-items: center; gap: 10px; }
.qr-box img { width: min(240px, 70vw); border-radius: 12px; border: 6px solid var(--crema); background: var(--crema); }
.qr-box .mono { text-align: center; }

/* Animaciones con resorte */
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.92); } to { opacity: 1; transform: none; } }
@keyframes wobble { 0% { transform: rotate(-30deg) scale(.6); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.timeline .tl-item:nth-child(2) { animation-delay: .04s; } .timeline .tl-item:nth-child(3) { animation-delay: .08s; } .timeline .tl-item:nth-child(4) { animation-delay: .12s; } .timeline .tl-item:nth-child(5) { animation-delay: .16s; } .timeline .tl-item:nth-child(n+6) { animation-delay: .2s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Responsive */
@media (max-width: 900px) {
  #app { height: auto; min-height: 100%; }
  .map-view { grid-template-columns: 1fr; grid-template-rows: 55vh auto; height: auto; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
  .panel { overflow: visible; }
  .view { height: auto; }
  .kv { grid-template-columns: repeat(2, 1fr); }
  .fields { grid-template-columns: 1fr; }
  .map-modes { left: 12px; top: 56px; }
  .top { padding: 10px 16px; gap: 10px; }
  .who { margin-left: auto; }
  .tabs { order: 5; flex: 1 1 100%; margin-left: 0; flex-wrap: nowrap; overflow-x: auto; }
  .tabs button { white-space: nowrap; }
}

/* Comité: formularios */
.modal.wide { width: min(760px, calc(100vw - 32px)); }
.pick { height: 280px; cursor: crosshair; }
.var-row { display: grid; grid-template-columns: 1fr 110px 40px; gap: 8px; margin: 6px 0; align-items: center; }
.var-rows { display: grid; }
.mini-list { margin: 8px 0; padding-left: 18px; font-size: .84rem; color: var(--crema-dim); }
.check input { width: auto; }
.modal-body .tl-actions { align-items: center; }
.agentes-off { border-style: dashed; border-color: rgba(217, 164, 65, .55); }
.agentes-off h3 { color: var(--oro); }
