:root {
  --navy: #1F4E78; --navy-d: #143654; --ink: #16202b; --muted: #5d6875; --line: #d5dbe2; --bg: #eef1f5; --card: #fff;
  --ok: #1E9E3A; --danger: #C62828; --gen: #E8590C; --focus: #2b7de9;
  --r: 10px; --tap: 46px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); overscroll-behavior: none; }
body { font-size: 16px; }
html, body { overflow: hidden; overflow: clip; position: fixed; inset: 0; width: 100%; }
#app { height: 100%; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
button { font: inherit; color: inherit; cursor: pointer; }
h1 { font-size: 1.5rem; margin: 0; } h2 { font-size: 1.05rem; margin: 22px 0 10px; color: var(--muted); font-weight: 600; }
h3 { font-size: 1.08rem; margin: 0; } h4 { margin: 18px 0 6px; font-size: .92rem; color: var(--navy); text-transform: uppercase; letter-spacing: .03em; }
.muted { color: var(--muted); } .tiny { font-size: .8rem; } .c { text-align: center; } .pad { padding: 14px; }
.falta { color: var(--danger); }

.btn { min-height: var(--tap); padding: 0 16px; border-radius: var(--r); border: 1px solid var(--line); background: #fff; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.btn:active { transform: translateY(1px); filter: brightness(.95); }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.ok { background: #e7f6ea; border-color: #9fd3aa; color: #12631f; }
.btn.danger { color: var(--danger); border-color: #f0b4b4; }
.btn.ghost { background: transparent; }
.btn.big { min-height: 64px; font-size: 1.15rem; width: 100%; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .9rem; }
.btn.gen { background: var(--gen); color: #fff; border-color: var(--gen); letter-spacing: .02em; }
.btn.block { width: 100%; margin-top: 22px; min-height: 56px; }
.icon-btn { width: var(--tap); height: var(--tap); border-radius: var(--r); border: 1px solid var(--line); background: #fff; font-size: 1.25rem; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.inp { width: 100%; min-height: var(--tap); border: 1px solid #b9c3cf; border-radius: 8px; padding: 8px 10px; font: inherit; background: #fff; color: var(--ink); }
textarea.inp { min-height: 70px; resize: vertical; }
.inp:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
label { display: block; font-size: .88rem; color: var(--muted); margin-top: 10px; font-weight: 600; }
label .inp { margin-top: 4px; color: var(--ink); font-weight: 400; }
label.check, label.radio { display: flex; align-items: center; gap: 10px; color: var(--ink); min-height: var(--tap); margin-top: 22px; }
label.radio { margin-top: 0; }
input[type=checkbox], input[type=radio] { width: 24px; height: 24px; accent-color: var(--navy); }
.inl { display: flex; gap: 6px; margin-top: 4px; } .inl .inp { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; } .row-btns .btn { flex: 1 1 auto; }
.row-btns.small .btn { flex: 0 0 auto; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 6px 0 2px; scrollbar-width: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip { min-height: 38px; padding: 0 12px; border-radius: 19px; border: 1px solid var(--line); background: #fff; font-size: .9rem; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.chip i, .legend i, .resumen i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.dot { width: 14px; height: 14px; border-radius: 4px; border: 1.5px solid rgba(0,0,0,.35); display: inline-block; flex: none; }
.dot.lg { width: 18px; height: 18px; margin-right: 8px; vertical-align: -3px; }
.badge { background: #fde2e2; color: #9b1c1c; border-radius: 6px; padding: 1px 7px; font-size: .78rem; font-weight: 700; }

/* ---------- Inicio ---------- */
.home { max-width: 860px; margin: 0 auto; padding: max(18px, env(safe-area-inset-top)) 16px 40px; }
.home-h { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; }
.home-h p { margin: 2px 0 0; color: var(--muted); }
.cards { display: grid; gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.card.insp { display: flex; align-items: center; gap: 14px; cursor: pointer; }
.card.insp.last { border-color: var(--navy); box-shadow: 0 0 0 1px var(--navy) inset; }
.card.insp .ic { width: 64px; height: 52px; border-radius: 10px; background: var(--navy); color: #fff; font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: .95rem; flex: none; }
.card.insp .meta { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.card.insp .meta span { font-size: .88rem; }
.card.warn { background: #fff8e1; border-color: #f1d27a; margin: 10px 0; }
.home-f { margin-top: 26px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; font-size: .85rem; }
.folder { background: #fff; border: 1px solid var(--line); border-radius: 12px; margin: 10px 0; }
.folder summary { padding: 14px; font-weight: 700; cursor: pointer; list-style: none; }
.folder summary::-webkit-details-marker { display: none; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; padding: 0 12px 12px; }
.tile { min-height: 70px; border-radius: 10px; border: 1px solid var(--line); background: #f8fafc; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; padding: 8px 10px; text-align: left; }
.tile b { font-size: 1.05rem; } .tile span { font-size: .78rem; color: var(--muted); }
.tile.noplan { opacity: .65; border-style: dashed; }
.est-list { padding: 0 12px 10px; } .est-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid #eef1f4; }
.est-row .muted { flex: 1; font-size: .85rem; } .list-actions { display: grid; gap: 8px; }

/* ---------- Trabajo ---------- */
.work { height: 100%; display: flex; flex-direction: column; overflow: hidden; }
.bar { display: flex; align-items: center; gap: 10px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--navy); color: #fff; flex-wrap: wrap; }
.bar .icon-btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.bar .ttl { display: flex; flex-direction: column; min-width: 120px; flex: 1; } .bar .ttl b { font-size: 1.1rem; } .bar .ttl span { font-size: .78rem; opacity: .85; }
.tabs { display: flex; background: rgba(255,255,255,.12); border-radius: 10px; padding: 3px; }
.tabs button { border: 0; background: transparent; color: #dbe6f2; min-height: 40px; padding: 0 14px; border-radius: 8px; font-weight: 600; }
.tabs button.on { background: #fff; color: var(--navy); }
.body { flex: 1; display: flex; min-height: 0; }
.planpane { position: relative; flex: 1; min-width: 0; background: #e9edf2; }
.cv-wrap { position: absolute; inset: 0; } canvas { display: block; touch-action: none; }
.ptools { position: absolute; left: 10px; bottom: 44px; display: flex; gap: 6px; flex-wrap: wrap; }
.ptools .icon-btn, .ptools .btn { box-shadow: 0 1px 4px rgba(0,0,0,.18); }
.legend { position: absolute; left: 10px; right: 10px; bottom: 8px; display: flex; gap: 12px; font-size: .74rem; flex-wrap: wrap; color: #333; pointer-events: none; }
.legend span { display: inline-flex; align-items: center; gap: 4px; background: rgba(255,255,255,.85); padding: 2px 6px; border-radius: 5px; }
.mode-hint { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: #111c; color: #fff; padding: 8px 8px 8px 14px; border-radius: 10px; display: none; align-items: center; gap: 10px; font-weight: 600; max-width: 94%; }
.mode-hint.on { display: flex; } .mode-hint .btn { color: var(--ink); }
.side { width: 400px; flex: none; background: #fff; border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-h { padding: 10px 12px 6px; border-bottom: 1px solid var(--line); }
.side-b { padding: 12px 14px 40px; overflow-y: auto; flex: 1; min-height: 0; }
.side .grid2 { grid-template-columns: 1fr; }
.slist { overflow-y: auto; flex: 1; }
.srow { width: 100%; display: grid; grid-template-columns: 18px 86px 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center; text-align: left; border: 0; border-bottom: 1px solid #eef1f4; background: #fff; padding: 10px 12px; min-height: 56px; }
.srow .dot { grid-row: span 2; }
.srow .dot[style*="transparent"] { border: 1.5px dashed #b8c0ca; } .srow b { font-size: 1.02rem; } .srow .muted { font-size: .8rem; } .srow .st { grid-column: 2 / 4; font-size: .82rem; color: var(--muted); }
.srow.sel { background: #e8f0fa; }
.ent.act { border-color: var(--danger); } .card.ent { margin: 10px 0; } .card + .card { margin-top: 10px; }
.resumen { display: flex; flex-wrap: wrap; gap: 10px; font-size: .88rem; } .resumen span { display: inline-flex; align-items: center; gap: 5px; }
.pc { display: flex; align-items: center; gap: 8px; margin-top: 6px; } .pc span { flex: 1; font-size: .9rem; } .pc .inp { width: 130px; }
.rev { display: grid; grid-template-columns: 52px 1fr 1fr 100px 40px; gap: 4px; margin-bottom: 6px; } .rev .icon-btn { width: 40px; height: 46px; }

/* ---------- Hojas ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; pointer-events: none; overflow: hidden; overflow: clip; }
.sheet-bg { position: absolute; inset: 0; background: rgba(10,20,30,.35); opacity: 0; transition: opacity .18s; pointer-events: auto; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 92%; background: #fff; border-radius: 16px 16px 0 0; display: flex; flex-direction: column; transform: translateY(100%); transition: transform .2s ease-out; pointer-events: auto; padding-bottom: env(safe-area-inset-bottom); }
.sheet-wrap.on .sheet { transform: none; } .sheet-wrap.on .sheet-bg { opacity: 1; }
.sheet-h { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.sheet-h h3 { flex: 1; }
.sheet-b { padding: 6px 14px 18px; overflow-y: auto; flex: 1; min-height: 0; }
.sheet-f { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); } .sheet-f .btn { flex: 1; }
.sheet-wrap.small .sheet { left: 50%; right: auto; bottom: auto; top: 50%; width: min(440px, 92vw); border-radius: 14px; transform: translate(-50%, -40%); opacity: 0; transition: all .16s; }
.sheet-wrap.small.on .sheet { transform: translate(-50%, -50%); opacity: 1; }
@media (min-width: 900px) {
  .sheet-wrap.derecha .sheet-bg { background: rgba(10,20,30,.12); }
  .sheet-wrap.derecha .sheet { left: auto; right: 0; top: 0; bottom: 0; max-height: none; width: 460px; border-radius: 0; transform: translateX(100%); box-shadow: -6px 0 24px rgba(0,0,0,.15); }
  .sheet-wrap.derecha.on .sheet { transform: none; }
}
.estados { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; margin-top: 10px; }
.est { min-height: 48px; border-radius: 10px; border: 2px solid var(--c); background: #fff; font-weight: 700; font-size: .9rem; color: var(--ink); }
.est.on { background: var(--c); color: #fff; }
.motivo { margin-top: 12px; }
.reg { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-top: 8px; cursor: pointer; }
.reg.hl { border-left: 6px solid #f2c200; }
.reg-t { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; } .reg-m { font-size: .86rem; color: var(--muted); margin-top: 2px; }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.thumbs img { width: 64px; height: 48px; object-fit: cover; border-radius: 6px; background: #ddd; }
.thumbs.big img { width: 120px; height: 90px; }
.th { position: relative; } .th .x { position: absolute; top: -6px; right: -6px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: var(--danger); color: #fff; font-size: .8rem; }
.form .chips { margin-bottom: 2px; }
.dirs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 6px; }
.dir { min-height: 50px; font-size: 1.5rem; border-radius: 10px; border: 1px solid var(--line); background: #fff; }
.dir.on { background: #E01010; color: #fff; border-color: #E01010; } .dir.wide { grid-column: span 4; font-size: .95rem; font-weight: 600; }

/* ---------- Vista previa ---------- */
.sheet-wrap.preview .sheet { top: 0; max-height: none; border-radius: 0; background: #d9dee5; }
.pv-bar { display: flex; gap: 8px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--navy); flex-wrap: wrap; } .pv-bar .sp { flex: 1; }
.pv-scroll { overflow-y: auto; flex: 1; padding: 12px; }
.page { background: #fff; max-width: 820px; margin: 0 auto; padding: 22px 28px; box-shadow: 0 2px 12px rgba(0,0,0,.15); font-family: Arial, sans-serif; font-size: 13px; }
.page h3 { margin: 26px 0 10px; font-size: 14px; } .pv-sub { text-decoration: underline; color: #000; text-transform: none; letter-spacing: 0; font-size: 13px; margin: 20px 0 8px; }
.pv-hdr { display: grid; grid-template-columns: 130px 1fr 120px; border: 1px solid #000; margin-bottom: 14px; }
.pv-hdr > div { padding: 6px; border-right: 1px solid #000; } .pv-hdr > div:last-child { border: 0; font-size: 12px; }
.pv-hdr .l img { width: 110px; display: block; } .pv-hdr mark { font-size: 12px; } .pv-hdr .m { display: flex; flex-direction: column; justify-content: space-between; align-items: center; text-align: center; gap: 6px; }
.pv-t { width: 100%; border-collapse: collapse; margin: 6px 0 14px; font-family: Calibri, Arial, sans-serif; font-size: 12px; }
.pv-t th, .pv-t td { border: 1px solid #000; padding: 3px 4px; text-align: center; font-weight: 400; } .pv-t th { background: #fafafa; }
.pv-t td.hl { background: #ffff00; } .pv-t tr[data-edit] { cursor: pointer; } .pv-t tr[data-edit]:hover td { outline: 1px solid var(--focus); }
.pv-p td { padding: 3px 10px 3px 0; font-family: Calibri, Arial, sans-serif; }
.pv-plano { width: 100%; display: block; } .pv-crop { width: 85%; display: block; margin: 0 auto; }
.pv-foto { display: block; width: 72%; margin: 10px auto 4px; }
.pv-concl { font-family: Arial, sans-serif; font-size: 13px; margin-bottom: 10px; }

#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px); background: #16202b; color: #fff; padding: 12px 18px; border-radius: 10px; opacity: 0; transition: all .2s; z-index: 50; pointer-events: none; max-width: 92vw; font-weight: 600; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
#busy { position: fixed; inset: 0; background: rgba(255,255,255,.7); z-index: 60; display: none; align-items: center; justify-content: center; flex-direction: column; gap: 12px; font-weight: 600; }
#busy.on { display: flex; } .spin { width: 42px; height: 42px; border: 4px solid #c9d3df; border-top-color: var(--navy); border-radius: 50%; animation: sp 0.8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

/* ---------- Teléfono / pantalla angosta ---------- */
.only-narrow { display: none; }
@media (max-width: 899px) {
  .only-narrow { display: inline-block; }
  .bar .ttl { order: 1; } .bar #w-back { order: 0; } .bar .gen { order: 2; min-height: 40px; padding: 0 12px; font-size: .85rem; }
  .tabs { order: 3; width: 100%; } .tabs button { flex: 1; padding: 0 6px; }
  .body { position: relative; }
  .side { position: absolute; inset: 0; width: auto; border: 0; display: none; }
  .work[data-tab=spools] .side, .work[data-tab=entradas] .side, .work[data-tab=informe] .side { display: flex; }
  .grid2 { grid-template-columns: 1fr; }
  .rev { grid-template-columns: 44px 1fr 40px; } .rev [data-f=reviso], .rev [data-f=fecha] { grid-column: 2; }
  .ptools .btn.small { font-size: .82rem; padding: 0 8px; }
  .page { padding: 12px; } .pv-hdr { grid-template-columns: 80px 1fr 90px; } .pv-hdr .l img { width: 70px; }
}
