:root {
  --ink: #111214;
  --ink-2: #4a4d52;
  --ink-3: #8a8d93;
  --bg: #f4f4f2;
  --surface: #ffffff;
  --line: #e2e2de;
  --accent: #f5a700;
  --accent-ink: #1a1300;
  --accent-soft: #fff4d6;
  --danger: #c62828;
  --ok: #1f8a4c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { font: 16px/1.45 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
img { max-width: 100%; display: block; }
h1, h2, h3 { margin: 0; line-height: 1.15; letter-spacing: -.01em; }
.boot { height: 100vh; display: grid; place-items: center; background: var(--ink); }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--ink); color: #fff; min-height: 56px; }
.topbar .logo { height: 34px; width: auto; }
.topbar .title { font-weight: 700; font-size: 15px; letter-spacing: .02em; text-transform: uppercase; opacity: .9; }
.topbar .sp { flex: 1; }
.topbar nav { display: none; gap: 4px; }
.topbar nav a { text-decoration: none; padding: 8px 12px; border-radius: 10px; font-size: 14px; opacity: .8; }
.topbar nav a.on, .topbar nav a:hover { background: rgba(255,255,255,.12); opacity: 1; }
.topbar .who { font-size: 13px; opacity: .7; text-align: right; line-height: 1.2; }

.page { max-width: 1100px; margin: 0 auto; padding: 16px 16px calc(96px + var(--safe-b)); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 6px 0 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 26px; font-weight: 800; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 9px;
  text-decoration: none; font-size: 11px; color: var(--ink-3); font-weight: 600; }
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.on { color: var(--ink); }
.tabbar a.plus span.ic { background: var(--accent); color: var(--accent-ink); border-radius: 14px; width: 48px; height: 34px;
  display: grid; place-items: center; margin-top: -2px; }

@media (min-width: 860px) {
  .topbar nav { display: flex; }
  .tabbar { display: none; }
  .page { padding-bottom: 40px; }
}

/* ---------- Componentes ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 12px;
  padding: 12px 18px; font-weight: 700; cursor: pointer; background: var(--ink); color: #fff; min-height: 48px;
  text-decoration: none; transition: transform .08s, opacity .2s; }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.accent { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1.5px solid #f0c9c9; }
.btn.sm { min-height: 38px; padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn svg { width: 20px; height: 20px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 700; color: var(--ink-2); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.field > span em { font-style: normal; color: var(--ink-3); font-weight: 500; text-transform: none; letter-spacing: 0; }
.input, select.input, textarea.input { width: 100%; border: 1.5px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 12px 14px; min-height: 50px; outline: none; transition: border-color .15s, box-shadow .15s; }
.input:focus { border-color: var(--ink); box-shadow: 0 0 0 4px rgba(17,18,20,.08); }
textarea.input { min-height: 110px; resize: vertical; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700;
  background: #ececea; color: var(--ink-2); }
.badge.ok { background: #e3f4ea; color: var(--ok); }
.badge.off { background: #fbe9e9; color: var(--danger); }
.badge.warn { background: var(--accent-soft); color: #8a5d00; }

.inch-note { display: flex; align-items: center; gap: 10px; background: var(--accent-soft); color: #5c3f00; border: 1px solid #f3dc9c;
  padding: 10px 12px; border-radius: 12px; font-size: 14px; font-weight: 600; }
.inch-note svg { flex: 0 0 auto; width: 22px; height: 22px; }

#toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%) translateY(20px); z-index: 100;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 14px; opacity: 0;
  pointer-events: none; transition: .25s; max-width: calc(100% - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }

.empty-state { text-align: center; padding: 48px 16px; color: var(--ink-3); }
.empty-state svg { width: 56px; height: 56px; margin: 0 auto 10px; opacity: .5; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background:
  radial-gradient(circle at 50% 0%, #2a2b2f 0, #111214 60%); }
.login .card { width: 100%; max-width: 380px; padding: 28px 22px; }
.login-wrap { width: 100%; max-width: 380px; }
.login-logo { width: 170px; margin: 0 auto 22px; }
.login h1 { text-align: center; font-size: 22px; margin: 0 0 4px; font-weight: 800; }
.login p.sub { text-align: center; margin: 0 0 22px; color: var(--ink-3); font-size: 14px; }

/* ---------- Lista de registros ---------- */
.filters { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 14px; }
@media (min-width: 700px) { .filters { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1000px) { .filters { grid-template-columns: 2fr 1.3fr 1.3fr 1fr 1fr; } }
.filters .input { min-height: 44px; padding: 9px 12px; }
.reg-list { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 700px) { .reg-list { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1000px) { .reg-list { grid-template-columns: 1fr 1fr 1fr; } }
.reg { display: flex; gap: 12px; text-decoration: none; padding: 10px; align-items: stretch; }
.reg .thumb { width: 92px; flex: 0 0 92px; aspect-ratio: 3/4; border-radius: 10px; background: #e9e9e6 center/cover; }
.reg .info { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.reg .info h3 { font-size: 17px; font-weight: 800; text-transform: none; letter-spacing: 0; color: var(--ink); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reg .info .meta { font-size: 13px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reg .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.reg .chips span { font-size: 12px; font-weight: 700; background: #f1f1ee; border-radius: 8px; padding: 3px 7px; }

/* ---------- Asistente (wizard) ---------- */
.wiz { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); z-index: 40; }
.wiz-top { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--ink); color: #fff; min-height: 52px; }
.wiz-top .x { background: none; border: 0; color: #fff; width: 40px; height: 40px; display: grid; place-items: center; cursor: pointer; border-radius: 10px; }
.wiz-top .x svg { width: 22px; height: 22px; }
.wiz-top .st { flex: 1; min-width: 0; }
.wiz-top .st small { display: block; font-size: 11px; opacity: .6; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.wiz-top .st b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wiz-top .unit { font-size: 11px; font-weight: 800; background: var(--accent); color: var(--accent-ink); padding: 5px 8px; border-radius: 8px; letter-spacing: .04em; white-space: nowrap; }
.progress { height: 4px; background: #2b2c30; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .35s; }

.wiz-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.viewer { position: relative; flex: 0 0 44vh; min-height: 230px; background: #17181b; overflow: hidden; touch-action: none; }
.viewer canvas { display: block; }
.viewer .hint { position: absolute; left: 10px; bottom: 10px; font-size: 11px; font-weight: 700; color: var(--ink-2);
  background: rgba(255,255,255,.85); padding: 4px 8px; border-radius: 8px; pointer-events: none; display: flex; gap: 6px; align-items: center; }
.viewer .hint svg { width: 14px; height: 14px; }
.viewer .reset { position: absolute; right: 10px; bottom: 10px; border: 0; background: rgba(255,255,255,.9); border-radius: 10px;
  width: 38px; height: 38px; display: grid; place-items: center; cursor: pointer; box-shadow: var(--shadow); }
.viewer .reset svg { width: 18px; height: 18px; }
.g3d-labels { position: absolute; inset: 0; pointer-events: none; }
.g3d-label { background: var(--ink); color: #fff; border-radius: 8px; padding: 3px 7px; font-size: 11px; line-height: 1.15;
  display: flex; flex-direction: column; align-items: center; box-shadow: 0 2px 8px rgba(0,0,0,.25); white-space: nowrap; }
.g3d-label .t { font-size: 9px; opacity: .7; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.g3d-label .v { font-size: 14px; }
.g3d-label.active { background: var(--accent); color: var(--accent-ink); }
.g3d-label.active.empty .v { animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }

.panel { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px 16px 24px; background: var(--surface);
  border-radius: 18px 18px 0 0; margin-top: -14px; position: relative; z-index: 2; box-shadow: 0 -6px 20px rgba(0,0,0,.06); }
.panel h2 { font-size: 22px; font-weight: 800; margin-bottom: 6px; }
.panel p.instr { margin: 0 0 14px; color: var(--ink-2); font-size: 15px; }
.panel .tip { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; color: var(--ink-2); background: #f5f5f3;
  border-radius: 12px; padding: 10px 12px; margin-top: 12px; }
.panel .tip svg { width: 18px; height: 18px; flex: 0 0 auto; margin-top: 1px; color: var(--ink-3); }

.measure { display: flex; align-items: stretch; border: 2px solid var(--ink); border-radius: 14px; overflow: hidden; background: var(--surface); }
.measure input { flex: 1; min-width: 0; width: 100%; border: 0; outline: 0; font-size: 34px; font-weight: 800; padding: 10px 14px; letter-spacing: -.02em; background: transparent; }
.measure .u { display: grid; place-items: center; padding: 0 16px; background: var(--ink); color: #fff; font-weight: 800; font-size: 14px; letter-spacing: .05em; }
.measure.sm input { font-size: 22px; padding: 8px 10px; }
.measure.sm .u { padding: 0 10px; font-size: 12px; }
.measure:focus-within { box-shadow: 0 0 0 4px rgba(245,167,0,.35); border-color: var(--accent); }
.measure:focus-within .u { background: var(--accent); color: var(--accent-ink); }
.conv { font-size: 13px; color: var(--ink-3); margin-top: 6px; min-height: 18px; }
.conv.warn { color: #8a5d00; font-weight: 600; }
.fracs { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.fracs button { border: 1.5px solid var(--line); background: var(--surface); border-radius: 10px; padding: 6px 12px; font-weight: 700; cursor: pointer; font-size: 15px; }
.fracs button:active { background: var(--accent-soft); }

.stepper { display: flex; align-items: center; gap: 16px; justify-content: center; margin: 8px 0; }
.stepper button { width: 56px; height: 56px; border-radius: 16px; border: 2px solid var(--ink); background: var(--surface); font-size: 28px; font-weight: 800; cursor: pointer; }
.stepper output { font-size: 54px; font-weight: 900; min-width: 70px; text-align: center; }

.cen-list { display: grid; gap: 10px; }
.cen { border: 1.5px solid var(--line); border-radius: 14px; padding: 12px; transition: border-color .15s, background .15s; }
.cen.on { border-color: var(--accent); background: #fffbf0; }
.cen.off .row { display: none; }
.cen header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; gap: 8px; }
.cen header b { font-size: 15px; }
.cen .row label > span { display: block; font-size: 11px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; margin-bottom: 4px; letter-spacing: .04em; }
.cen .diff { font-size: 12px; margin-top: 6px; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--ink-2); cursor: pointer; user-select: none; }
.switch input { appearance: none; width: 40px; height: 24px; border-radius: 99px; background: #d6d6d2; position: relative; cursor: pointer; transition: .2s; margin: 0; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked { background: var(--ink); }
.switch input:checked::after { left: 19px; }

.photos { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.photos .ph { position: relative; aspect-ratio: 3/4; border-radius: 12px; background: #eee center/cover; overflow: hidden; }
.photos .ph button { position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; cursor: pointer; display: grid; place-items: center; }
.photos .add { aspect-ratio: 3/4; border: 2px dashed #c9c9c4; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; color: var(--ink-2); font-weight: 700; cursor: pointer; background: #fafaf8; font-size: 14px; text-align: center; padding: 8px; }
.photos .add svg { width: 36px; height: 36px; }

.summary { width: 100%; border-collapse: collapse; font-size: 14px; }
.summary th, .summary td { text-align: left; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.summary td.v { text-align: right; font-weight: 800; white-space: nowrap; }
.summary td.v.miss { color: var(--danger); }
.summary tr.sec th { padding-top: 16px; font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }

.wiz-foot { display: flex; gap: 10px; padding: 10px 16px calc(10px + var(--safe-b)); background: var(--surface); border-top: 1px solid var(--line); }
.wiz-foot .btn { flex: 1; }
.wiz-foot .btn.back { flex: 0 0 auto; width: 56px; padding: 0; }

@media (min-width: 860px) {
  .wiz-body { flex-direction: row; }
  .viewer { flex: 1 1 60%; height: auto; }
  .panel { flex: 0 0 420px; border-radius: 0; margin: 0; box-shadow: none; border-left: 1px solid var(--line); }
  .wiz-foot { justify-content: flex-end; }
  .wiz-foot .btn { flex: 0 0 auto; min-width: 160px; }
}

.done { text-align: center; padding: 40px 20px; }
.done .ok-ic { width: 84px; height: 84px; border-radius: 50%; background: #e3f4ea; color: var(--ok); display: grid; place-items: center; margin: 0 auto 18px; }
.done .ok-ic svg { width: 44px; height: 44px; }

/* ---------- Detalle ---------- */
.detail-grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .detail-grid { grid-template-columns: 1.15fr 1fr; } }
.detail-grid .viewer { flex: none; height: 420px; border-radius: var(--radius); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 15px; }
.kv dt { color: var(--ink-3); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding-top: 2px; }
.kv dd { margin: 0; font-weight: 600; }
.card h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin-bottom: 10px; font-weight: 800; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.gallery a { aspect-ratio: 3/4; border-radius: 12px; background: #eee center/cover; display: block; }
.notes { white-space: pre-wrap; font-size: 15px; background: #fafaf8; border-radius: 10px; padding: 12px; border: 1px solid var(--line); }

.lightbox { position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.92); display: grid; place-items: center; padding: 16px; }
.lightbox img { max-height: 100%; max-width: 100%; object-fit: contain; border-radius: 6px; }
.lightbox button { position: absolute; top: 14px; right: 14px; width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255,255,255,.15); color: #fff; font-size: 22px; cursor: pointer; }

/* ---------- Tabla usuarios ---------- */
.ulist { display: grid; gap: 10px; }
.urow { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.urow .av { width: 42px; height: 42px; border-radius: 12px; background: var(--ink); color: #fff; display: grid; place-items: center; font-weight: 800; flex: 0 0 auto; }
.urow .i { flex: 1; min-width: 0; }
.urow .i b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.urow .i small { color: var(--ink-3); }

.modal-bg { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); width: 100%; max-width: 480px; border-radius: 20px 20px 0 0; padding: 20px 16px calc(20px + var(--safe-b)); max-height: 92vh; overflow-y: auto; }
.modal h2 { font-size: 20px; margin-bottom: 14px; font-weight: 800; }
@media (min-width: 600px) { .modal-bg { align-items: center; } .modal { border-radius: 20px; } }

/* ---------- Impresión ---------- */
@media print {
  .topbar, .tabbar, .no-print, .viewer { display: none !important; }
  body { background: #fff; }
  .page { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
}

tr[data-focus] { cursor: pointer; }
tr[data-focus]:hover td { background: #fafaf8; }
tr.sel td { background: var(--accent-soft) !important; }

/* Etiquetas de cota desplazadas para no tapar la línea ni las flechas */
.g3d-anchor { width: 0; height: 0; position: relative; }
.g3d-label { position: absolute; left: 0; top: 0; }
.g3d-label.side-left { transform: translate(calc(-100% - 16px), -50%); }
.g3d-label.side-right { transform: translate(16px, -50%); }
.g3d-label.side-up { transform: translate(-50%, calc(-100% - 12px)); }
.g3d-label.side-down { transform: translate(-50%, 12px); }
.urow .av svg, .empty-state svg { width: 22px; height: 22px; }
.empty-state svg { width: 56px; height: 56px; }

/* Proveedores con enlace de acceso */
.prov { display: grid; gap: 10px; }
.prov.inactive { opacity: .65; }
.link-box { background: #f5f5f3; border: 1px dashed #d6d6d2; border-radius: 10px; padding: 8px 10px; overflow-x: auto; }
.link-box code { font-size: 12px; white-space: nowrap; color: var(--ink-2); }
.link-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.wa { background: #1fa855; }

/* Filtros compactos en móvil: fechas lado a lado */
.filters { grid-template-columns: 1fr 1fr; }
.filters > #q, .filters > select { grid-column: span 2; }
@media (min-width: 700px) { .filters > select { grid-column: auto; } }
@media (min-width: 1000px) { .filters > #q { grid-column: auto; } }
.empty-state .btn svg { width: 20px; height: 20px; margin: 0; opacity: 1; }

/* Paso de la foto: sin visor 3D, solo la cámara */
.wiz.no3d .viewer { display: none; }
.wiz.no3d .panel { margin-top: 0; border-radius: 0; box-shadow: none; flex: 1; width: 100%; max-width: 640px; margin-inline: auto; border-left: 0; }
.wiz.no3d .photos .add { aspect-ratio: 4/5; }
