/* Estilos de la web de préstamos (derivados de la maqueta aprobada) */
:root {
    --ink: #1B1F27; --muted: #5B6577; --line: #DCE3EE;
    --bg: #F3F6FB; --surface: #FFFFFF;
    --tile-1: #E4EBF6; --tile-2: #CBD9F0; --tile-3: #98B0D0;
    --primary: #3F5F8F; --primary-hover: #34507A; --primary-soft: #E3EAF5;
    --ok: #2E7D4F; --ok-soft: #E3F2E8;
    --warn: #A15C00; --warn-soft: #FDF0DC;
    --danger: #B3261E; --danger-soft: #FBE5E3;
    --violet: #6A4C93; --violet-soft: #EEE8F6;
    --radius: 14px; --shadow: 0 1px 2px rgba(27,31,39,.06), 0 4px 16px rgba(27,31,39,.05);
    --nav-h: 68px;
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; }
  body { font-family: Inter, system-ui, sans-serif; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; -webkit-tap-highlight-color: transparent; }
  button { font: inherit; cursor: pointer; }
  input, select, textarea { font: inherit; color: inherit; }
  h1, h2, h3 { margin: 0; line-height: 1.2; }
  h1 { font-size: 1.35rem; font-weight: 700; }
  h2 { font-size: 1.05rem; font-weight: 600; }
  .muted { color: var(--muted); }
  .small { font-size: .85rem; }

  .azulejo {
    background-color: var(--tile-1);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64'%3E%3Cpath d='M0 0h32L0 32z' fill='%23CBD9F0'/%3E%3Cpath d='M64 64H32l32-32z' fill='%23CBD9F0'/%3E%3Cpath d='M32 0h32v32z' fill='%23B9CCEA' opacity='.7'/%3E%3Cpath d='M0 64V32l32 32z' fill='%23B9CCEA' opacity='.7'/%3E%3Crect x='24' y='24' width='16' height='16' transform='rotate(45 32 32)' fill='%23F3F6FB'/%3E%3C/svg%3E");
  }

  .app { min-height: 100vh; display: flex; flex-direction: column; }
  header.top { position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
  .top-inner { display: flex; align-items: center; gap: 12px; padding: 10px 16px; max-width: 1200px; margin: 0 auto; }
  .brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: inherit; text-decoration: none; }
  .brand img { height: 34px; width: auto; }
  .brand .t { font-weight: 600; font-size: .95rem; white-space: nowrap; }
  @media (max-width: 420px) { .brand .t { display: none; } }
  .spacer { flex: 1; }
  .role-switch { display: flex; background: var(--primary-soft); border-radius: 999px; padding: 3px; font-size: .8rem; }
  .role-switch button { border: 0; background: transparent; padding: 6px 12px; border-radius: 999px; color: var(--primary); font-weight: 600; }
  .role-switch button.on { background: var(--primary); color: #fff; }
  .avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: .85rem; flex: none; }
  .avatar.soft { background: var(--tile-3); }

  .layout { flex: 1; display: flex; max-width: 1200px; width: 100%; margin: 0 auto; }
  nav.side { display: none; }
  main { flex: 1; min-width: 0; padding: 16px 16px calc(var(--nav-h) + 24px); }
  nav.bottom { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; height: var(--nav-h); background: var(--surface); border-top: 1px solid var(--line); display: flex; padding-bottom: env(safe-area-inset-bottom); }
  nav.bottom a, nav.side a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 500; position: relative; }
  nav a.on { color: var(--primary); }
  nav a svg { width: 24px; height: 24px; }
  nav a .dot { position: absolute; top: 8px; left: calc(50% + 6px); background: var(--danger); color: #fff; font-size: .65rem; border-radius: 999px; padding: 0 5px; font-weight: 700; }
  @media (min-width: 900px) {
    nav.bottom { display: none; }
    nav.side { display: flex; flex-direction: column; gap: 4px; width: 220px; padding: 20px 12px; position: sticky; top: 58px; height: calc(100vh - 58px); }
    nav.side a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 14px; border-radius: 10px; font-size: .92rem; }
    nav.side a.on { background: var(--primary-soft); }
    nav.side a .dot { position: static; margin-left: auto; }
    main { padding: 24px 24px 40px; }
  }

  .card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
  .stack > * + * { margin-top: 12px; }
  .row { display: flex; align-items: center; gap: 10px; }
  .wrap { flex-wrap: wrap; }
  .btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 10px; padding: 12px 18px; font-weight: 600; background: var(--primary); color: #fff; min-height: 46px; text-decoration: none; }
  .btn:hover { background: var(--primary-hover); }
  .btn.ghost { background: var(--primary-soft); color: var(--primary); }
  .btn.danger { background: var(--danger-soft); color: var(--danger); }
  .btn.violet { background: var(--violet-soft); color: var(--violet); }
  .btn.block { width: 100%; }
  .btn.sm { min-height: 38px; padding: 8px 12px; font-size: .88rem; }
  .btn[disabled] { opacity: .45; pointer-events: none; }
  .btn svg { width: 20px; height: 20px; }
  .badge { display: inline-flex; align-items: center; gap: 5px; font-size: .75rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
  .badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
  .b-ok { background: var(--ok-soft); color: var(--ok); }
  .b-warn { background: var(--warn-soft); color: var(--warn); }
  .b-danger { background: var(--danger-soft); color: var(--danger); }
  .b-info { background: var(--primary-soft); color: var(--primary); }
  .b-violet { background: var(--violet-soft); color: var(--violet); }

  .search { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; height: 48px; }
  .search input { border: 0; outline: 0; flex: 1; background: transparent; min-width: 0; }
  .search svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
  .search a { display: grid; place-items: center; color: var(--primary); }
  .chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
  /* Con ratón no se puede deslizar la fila: en el PC las píldoras pasan a varias líneas y se ven todas */
  @media (hover: hover) and (pointer: fine) { .chips { flex-wrap: wrap; overflow-x: visible; } }
  .chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 14px; font-size: .85rem; white-space: nowrap; color: var(--ink); display: inline-flex; align-items: center; gap: 6px; }
  .chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
  .chip .x { border: 0; background: none; padding: 0 0 0 2px; color: var(--muted); font-size: 1rem; line-height: 1; }

  .grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
  @media (min-width: 640px) { .grid { grid-template-columns: repeat(3, minmax(0,1fr)); } }
  @media (min-width: 1100px) { .grid { grid-template-columns: repeat(4, minmax(0,1fr)); } }
  .item { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; text-decoration: none; color: inherit; display: flex; flex-direction: column; }
  .item .info { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
  .item .name { font-weight: 600; font-size: .92rem; overflow-wrap: anywhere; }
  .item .id { font-size: .75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
  .ph { aspect-ratio: 1; display: grid; place-items: center; position: relative; }
  .ph span { font-size: .7rem; font-weight: 700; letter-spacing: .08em; color: var(--primary); background: rgba(255,255,255,.85); padding: 4px 8px; border-radius: 6px; }

  .list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
  .li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); text-decoration: none; color: inherit; }
  .li:first-child { border-top: 0; }
  .li .thumb { width: 48px; height: 48px; border-radius: 10px; flex: none; }
  .li .grow { flex: 1; min-width: 0; }
  .li .title { font-weight: 600; overflow-wrap: anywhere; }

  label.f { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; }
  .input { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: var(--surface); min-height: 46px; }
  .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .two > *, .three > * { min-width: 0; }
  .hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }

  .steps { display: flex; gap: 6px; }
  .steps div { flex: 1; height: 4px; border-radius: 4px; background: var(--line); }
  .steps div.on { background: var(--primary); }

  .scanner { position: relative; background: #11151C; border-radius: var(--radius); aspect-ratio: 4/3; max-height: 40vh; width: 100%; overflow: hidden; display: grid; place-items: center; }
  .scanner .frame { width: 72%; height: 38%; border: 3px solid rgba(255,255,255,.9); border-radius: 12px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); }
  .scanner .laser { position: absolute; left: 16%; right: 16%; height: 2px; background: #FF5A5A; top: 50%; animation: laser 1.6s ease-in-out infinite; }
  @keyframes laser { 0%,100% { transform: translateY(-40px); } 50% { transform: translateY(40px); } }
  .scanner .hintcam { position: absolute; bottom: 12px; left: 12px; right: 12px; text-align: center; color: #fff; font-size: .85rem; }
  .flash { animation: flash .6s; }
  @keyframes flash { from { background: var(--ok-soft); } to { background: transparent; } }

  .hero { border-radius: var(--radius); padding: 18px; }
  .stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
  @media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
  .stat { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; text-decoration: none; color: inherit; }
  .stat b { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
  .detail { display: grid; gap: 16px; }
  @media (min-width: 800px) { .detail { grid-template-columns: 1fr 1fr; align-items: start; } }
  .detail .ph { border-radius: var(--radius); }
  .callout { border-radius: 12px; padding: 12px 14px; font-size: .9rem; }
  .callout.ok { background: var(--ok-soft); }
  .callout.warn { background: var(--warn-soft); }
  .callout.violet { background: var(--violet-soft); }
  .callout.info { background: var(--primary-soft); }
  .callout.danger { background: var(--danger-soft); }
  .sticky-bar { position: sticky; bottom: calc(var(--nav-h) + 8px); z-index: 10; }
  @media (min-width: 900px) { .sticky-bar { bottom: 16px; } }

  .toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: .9rem; z-index: 50; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
  .note { font-size: .8rem; color: var(--muted); border-left: 3px solid var(--tile-3); padding-left: 10px; }

  .login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
  .login .box { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); padding: 32px 24px; width: 100%; max-width: 400px; text-align: center; }
  .gbtn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 12px; font-weight: 600; min-height: 48px; }

  /* ---------- Hoja de etiquetas A4: 4 × 27 de 50 × 10 mm ---------- */
  .hoja-wrap { width: 100%; max-width: 620px; aspect-ratio: 210 / 297; position: relative; overflow: hidden; background: #fff; box-shadow: var(--shadow); border-radius: 4px; margin: 0 auto; }
  .hoja { position: absolute; top: 0; left: 0; width: 210mm; height: 297mm; transform-origin: top left; background: #fff;
    padding: 13.5mm 5mm; display: grid; grid-template-columns: repeat(4, 50mm); grid-auto-rows: 10mm; }
  .eti { width: 50mm; height: 10mm; display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; }
  .hoja.cortes .eti { outline: .1mm dashed #B9C2D0; outline-offset: -.05mm; }
  .eti svg { width: 44mm; height: 6.2mm; display: block; }
  .eti .cod { font: 600 2.6mm/1 Inter, Arial, sans-serif; letter-spacing: .3mm; margin-top: .6mm; color: #000; }
  .eti.vacia { background: repeating-linear-gradient(45deg, #F3F6FB 0 2mm, #fff 2mm 4mm); }
  .eti.vacia * { display: none; }

  #printArea { display: none; }
  @media print {
    @page { size: A4; margin: 0; }
    html, body { background: #fff; }
    #root > .app > header, nav, main > .stack > *:not(#printArea) { display: none !important; }
    .layout, main, main > .stack { display: block; padding: 0 !important; margin: 0 !important; max-width: none; }
    #printArea { display: block; }
    #printArea .hoja { position: relative; transform: none; break-after: page; }
    #printArea .hoja:last-child { break-after: auto; }
    .hoja.cortes .eti { outline-color: #CCC; }
    .eti.vacia { background: none; }
  }


/* Fotos reales sobre el fondo de azulejo */
.ph { overflow: hidden; }
.ph img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.detail .ph img { object-fit: contain; background: #fff; }
a.avatar { color: #fff; }


/* Escáner con cámara */
.camara { position: relative; background: #11151C; border-radius: var(--radius); overflow: hidden; min-height: 200px; display: grid; place-items: center; }
.camara #camaraVideo { width: 100%; height: 46vh; max-height: 360px; display: block; object-fit: cover; }
.camara-off { text-align: center; padding: 24px; }
.camara-marco { position: absolute; left: 7.5%; right: 7.5%; top: 25%; bottom: 25%; border: 3px solid rgba(255,255,255,.9); border-radius: 12px; pointer-events: none; box-shadow: 0 0 0 999px rgba(0,0,0,.25); }
.camara-marco.leido { animation: camaraLeido .6s ease-out; }
.camara-marco.apunta { border-color: #3BD16F; }
.camara-mira { position: absolute; left: 4%; right: 4%; top: 50%; height: 2px; margin-top: -1px; background: rgba(255,59,48,.85); box-shadow: 0 0 6px rgba(255,59,48,.8); }
.camara-apunta { position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: 92%; border: 0; border-radius: 999px; padding: 8px 14px; font: inherit; font-size: 13px; font-weight: 600; background: rgba(17,21,28,.75); color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.camara-apunta.on { background: #3BD16F; color: #0B2A16; font-size: 15px; padding: 10px 18px; }
@keyframes camaraLeido { from { border-color: #3BD16F; box-shadow: 0 0 0 999px rgba(59,209,111,.35); } }
.camara-botones { position: absolute; top: 10px; right: 10px; left: 10px; display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.camara-botones [hidden] { display: none; }
.camara-botones .btn.activo { background: #FFD54A; color: #11151C; }
.camara-info { position: absolute; left: 10px; bottom: 6px; font-size: 11px; color: rgba(255,255,255,.7); pointer-events: none; }
.foto-alta { border-radius: var(--radius); aspect-ratio: 4/3; max-height: 40vh; width: 100%; position: relative; overflow: hidden; display: grid; place-items: center; }
.foto-alta img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #fff; }
.foto-alta label { position: relative; z-index: 1; }
.foto-alta > .row { align-self: end; margin-bottom: 12px; flex-wrap: wrap; justify-content: center; }
/* Marca del entorno de pruebas */
.marca-pruebas { position: fixed; top: 0; left: 50%; transform: translateX(-50%); z-index: 101; pointer-events: none; background: #E8590C; color: #fff; font: 700 10px/1 Inter, system-ui, sans-serif; letter-spacing: .12em; padding: 3px 10px 4px; border-radius: 0 0 6px 6px; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
/* Estado de la conexión y de los datos */
#progreso { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 100; pointer-events: none; opacity: 0; transition: opacity .2s; background: linear-gradient(90deg, transparent, var(--primary), transparent); background-size: 50% 100%; background-repeat: no-repeat; }
#progreso.on { opacity: 1; animation: progreso 1.1s linear infinite; }
@keyframes progreso { from { background-position: -50% 0; } to { background-position: 150% 0; } }
.aviso-nuevos { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 60; border: 0; border-radius: 999px; padding: 10px 16px; background: var(--primary); color: #fff; font: inherit; font-weight: 600; font-size: .9rem; box-shadow: 0 4px 16px rgba(0,0,0,.2); cursor: pointer; white-space: nowrap; }
@media (min-width: 900px) { .aviso-nuevos { bottom: 24px; } }
.aviso-red { position: fixed; top: 0; left: 0; right: 0; z-index: 90; background: var(--warn-soft); color: var(--ink); text-align: center; font-size: .85rem; padding: 8px 16px; }
.li.esq { pointer-events: none; }
.esq-b { height: 12px; border-radius: 6px; background: linear-gradient(90deg, #e9edf3 25%, #f4f6f9 50%, #e9edf3 75%); background-size: 200% 100%; animation: esq 1.2s ease-in-out infinite; }
@keyframes esq { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.ph img { animation: aparecer .25s ease-out; }
@keyframes aparecer { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { #progreso.on, .esq-b, .ph img { animation: none; } }
/* Cámara para hacer fotos dentro de la web (ordenadores, donde el navegador no abre la cámara del sistema) */
.cam-foto { position: fixed; inset: 0; z-index: 1000; background: #000; display: flex; flex-direction: column; }
.cam-foto video { flex: 1; min-height: 0; width: 100%; object-fit: contain; background: #000; }
.cam-foto-info { position: absolute; top: 12px; left: 12px; right: 12px; color: #fff; text-shadow: 0 1px 3px #000; }
.cam-foto-botones { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: #11151C; }
.cam-foto-botones .btn.ghost { background: #fff; }

/* Ayuda */
.ayuda-btn { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--line); color: var(--primary); font-weight: 700; text-decoration: none; background: var(--surface); flex: none; }
.ayuda details > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: 10px; }
.ayuda details > summary::-webkit-details-marker { display: none; }
.ayuda details > summary::after { content: "+"; color: var(--primary); font-weight: 700; }
.ayuda details[open] > summary::after { content: "–"; }
.ayuda ul, .ayuda ol { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.ayuda p { margin: 0; }
.ayuda .badge { vertical-align: middle; }
a.chip { text-decoration: none; }
