/* Incidencias pedidos: pensado para usarse con una mano en el almacén */
:root {
  --ink: #13303d;
  --ink-soft: #4a6270;
  --paper: #ffffff;
  --ground: #eef2f3;
  --field: #f6f8f9;
  --line: #cbd5d9;
  --tape: #f5b700;
  --tape-dark: #d99f00;
  --ok: #1f7a4a;
  --ok-bg: #e5f3eb;
  --bad: #b42318;
  --bad-bg: #fcebe9;
  --warn-bg: #fff4d1;
  --t-no_entregado: #3f5a8a;
  --t-roto: #b42318;
  --t-mal_estado: #b3540a;
  --t-caducado: #6b3fa0;
  --radius: 10px;
  --font: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--ground);
}
a { color: var(--ink); text-underline-offset: 3px; }
h1 { font-size: 1.65rem; line-height: 1.15; margin: 0 0 .75rem; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; margin: 0 0 .75rem; }
p { margin: 0 0 .75rem; }
code { font-size: .9em; background: var(--field); padding: .1em .35em; border-radius: 4px; }
code.key { display: inline-block; word-break: break-all; user-select: all; }
:focus-visible { outline: 3px solid var(--tape); outline-offset: 2px; }

/* ---------- Barra superior ---------- */
.topbar {
  background: var(--ink);
  color: #fff;
  border-bottom: 5px solid var(--tape);
  padding-top: env(safe-area-inset-top);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 680px;
  margin: 0 auto;
  padding: .6rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.brand { color: #fff; text-decoration: none; font-weight: 700; display: flex; align-items: center; gap: .55rem; }
.brand img { border-radius: 6px; }
.menu { position: relative; }
.menu summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: .6rem;
  min-height: 44px;
  padding: 0 .25rem;
}
.menu summary::-webkit-details-marker { display: none; }
.menu-user { max-width: 9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .95rem; opacity: .9; }
.menu-icon, .menu-icon::before, .menu-icon::after {
  display: block; width: 22px; height: 2px; background: #fff; border-radius: 2px; position: relative;
}
.menu-icon::before, .menu-icon::after { content: ""; position: absolute; left: 0; }
.menu-icon::before { top: -7px; }
.menu-icon::after { top: 7px; }
.menu nav {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(19, 48, 61, .25);
  min-width: 14rem;
  padding: .4rem;
  display: flex;
  flex-direction: column;
}
.menu nav a, .menu nav .linklike {
  display: block;
  padding: .7rem .8rem;
  border-radius: 7px;
  text-decoration: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  width: 100%;
}
.menu nav a[aria-current="page"] { background: var(--ground); font-weight: 700; }
.menu nav a:hover, .menu nav .linklike:hover { background: var(--field); }
.menu nav form { border-top: 1px solid var(--line); margin-top: .3rem; padding-top: .3rem; }
.linklike { background: none; border: 0; cursor: pointer; }

/* ---------- Página ---------- */
.page {
  max-width: 680px;
  margin: 0 auto;
  padding: 1.25rem 1rem calc(3rem + env(safe-area-inset-bottom));
}
.page-title { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-title h1 { margin: 0; }
.lead { color: var(--ink-soft); }
.hint { color: var(--ink-soft); font-size: .9rem; display: block; margin-top: .3rem; }
.back { margin-bottom: .5rem; }
.back a::before { content: "‹ "; }
.panel { background: var(--paper); border-radius: var(--radius); padding: 1.1rem; margin-bottom: 1.25rem; }
.count { color: var(--ink-soft); font-size: .95rem; margin-bottom: .5rem; }

/* ---------- Avisos ---------- */
.notice { border-radius: var(--radius); padding: .8rem 1rem; margin-bottom: 1rem; border-left: 6px solid; }
.notice p:last-child, .notice ul { margin-bottom: 0; }
.notice ul { padding-left: 1.2rem; margin-top: .3rem; }
.notice-ok { background: var(--ok-bg); border-color: var(--ok); }
.notice-error { background: var(--bad-bg); border-color: var(--bad); }
.notice-warn { background: var(--warn-bg); border-color: var(--tape-dark); }

/* ---------- Formularios ---------- */
.form { display: flex; flex-direction: column; gap: 1rem; }
.group { border: 0; margin: 0; padding: 1.1rem; background: var(--paper); border-radius: var(--radius); display: flex; flex-direction: column; gap: 1rem; }
.group legend { float: left; width: 100%; font-weight: 700; font-size: 1.1rem; padding: 0; margin-bottom: .1rem; }
.group legend + * { clear: both; }
.field { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.field > span { font-weight: 700; font-size: .95rem; }
.field em { font-weight: 400; color: var(--ink-soft); }
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea {
  font: inherit;
  font-size: 18px; /* evita el zoom automático de iOS */
  color: var(--ink);
  background: var(--field);
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: .7rem .8rem;
  min-height: 52px;
  width: 100%;
}
input[type="date"] { min-width: 0; -webkit-appearance: none; appearance: none; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--ink); background: var(--paper); outline: none; }
.row-2, .row-3 { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 520px) {
  .row-2 { grid-template-columns: 1fr 1fr; }
  .row-3 { grid-template-columns: 2fr 1fr 1.3fr; }
}
.store-fixed { display: flex; flex-direction: column; padding: .8rem; background: var(--ground); border-radius: 8px; }
.store-fixed strong { font-size: 1.15rem; }
.store-fixed span { color: var(--ink-soft); }

.qty { display: grid; grid-template-columns: 7rem 1fr; gap: 1rem; align-items: end; }

/* Selector segmentado (unidades / cajas, rol) */
.segmented { display: flex; background: var(--field); border: 2px solid var(--line); border-radius: 8px; padding: 3px; min-height: 52px; }
.segmented label { flex: 1; display: flex; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { flex: 1; display: flex; align-items: center; justify-content: center; border-radius: 6px; cursor: pointer; font-weight: 700; color: var(--ink-soft); padding: 0 .5rem; }
.segmented input:checked + span { background: var(--ink); color: #fff; }
.segmented input:focus-visible + span { outline: 3px solid var(--tape); outline-offset: 1px; }

/* Tipo de incidencia: el control principal del formulario */
.tipos { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.tipo { display: flex; position: relative; }
.tipo input { position: absolute; opacity: 0; pointer-events: none; }
.tipo span {
  flex: 1;
  display: flex;
  align-items: center;
  min-height: 72px;
  padding: .6rem .9rem .6rem 1.2rem;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 1.1rem;
  cursor: pointer;
  background: var(--paper);
  position: relative;
  overflow: hidden;
  transition: background-color .12s, color .12s, border-color .12s;
}
.tipo span::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 8px; background: var(--c); }
.tipo input:checked + span { background: var(--c); border-color: var(--c); color: #fff; }
.tipo input:checked + span::after { content: "✓"; margin-left: auto; font-size: 1.3rem; }
.tipo input:focus-visible + span { outline: 3px solid var(--tape); outline-offset: 2px; }
.tipo-no_entregado { --c: var(--t-no_entregado); }
.tipo-roto { --c: var(--t-roto); }
.tipo-mal_estado { --c: var(--t-mal_estado); }
.tipo-caducado { --c: var(--t-caducado); }

/* Fotos */
.photo-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.thumbs { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.thumbs:empty { display: none; }
.thumbs li { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--ground); }
.thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-loading { display: flex; align-items: center; justify-content: center; color: var(--ink-soft); font-size: 1.5rem; }
.thumb-remove {
  position: absolute; top: 4px; right: 4px;
  width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: rgba(19, 48, 61, .85); color: #fff;
  font-size: 1.4rem; line-height: 1; cursor: pointer;
}

.check { display: flex; align-items: center; gap: .6rem; min-height: 44px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--ink); flex: none; }
.checks-list { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.checks-list legend { font-weight: 700; font-size: .95rem; margin-bottom: .2rem; padding: 0; }
.form-actions { display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap; }
.presets { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; color: var(--ink-soft); font-size: .95rem; }

/* ---------- Botones ---------- */
.btn {
  font: inherit;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: 52px;
  padding: 0 1.2rem;
  border-radius: var(--radius);
  border: 2px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--tape); border-color: var(--tape); }
.btn-primary:hover { background: var(--tape-dark); border-color: var(--tape-dark); }
.btn-secondary:hover { background: var(--field); }
.btn-small { min-height: 40px; padding: 0 .8rem; font-size: .92rem; border-width: 1.5px; }
.btn-block { width: 100%; }
.btn-send { min-height: 60px; font-size: 1.15rem; }
.btn[disabled] { opacity: .6; cursor: progress; }

/* ---------- Listas ---------- */
.list { list-style: none; margin: 0 0 1rem; padding: 0; background: var(--paper); border-radius: var(--radius); overflow: hidden; }
.list > li { border-top: 1px solid var(--line); position: relative; }
.list > li:first-child { border-top: 0; }
.list > li > a { display: block; padding: .85rem 1rem .85rem 1.25rem; text-decoration: none; }
.list > li > a:hover { background: var(--field); }
.item::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--c); }
.item-no_entregado { --c: var(--t-no_entregado); }
.item-roto { --c: var(--t-roto); }
.item-mal_estado { --c: var(--t-mal_estado); }
.item-caducado { --c: var(--t-caducado); }
.item-top { display: flex; align-items: center; gap: .5rem; margin-bottom: .25rem; }
.item-top time { margin-left: auto; color: var(--ink-soft); font-size: .88rem; white-space: nowrap; }
.item-main { font-weight: 700; font-size: 1.05rem; }
.item-main span { font-weight: 400; color: var(--ink-soft); }
.item-sub { color: var(--ink-soft); font-size: .93rem; }
.admin-list > li { display: flex; align-items: center; }
.admin-list > li > a { flex: 1; min-width: 0; padding-left: 1rem; }
.admin-list .item-action { padding-right: .8rem; }
.admin-list .is-off { opacity: .55; }

.chip { display: inline-block; font-size: .8rem; font-weight: 700; padding: .15rem .55rem; border-radius: 999px; color: #fff; background: var(--c); }
.chip-no_entregado { --c: var(--t-no_entregado); }
.chip-roto { --c: var(--t-roto); }
.chip-mal_estado { --c: var(--t-mal_estado); }
.chip-caducado { --c: var(--t-caducado); }
.estado { display: inline-block; font-size: .8rem; font-weight: 700; padding: .12rem .5rem; border-radius: 999px; border: 1.5px solid; }
.estado-enviada { color: var(--ok); }
.estado-error { color: var(--bad); }
.estado-pendiente { color: var(--ink-soft); }

.empty { background: var(--paper); border-radius: var(--radius); padding: 2rem 1.2rem; text-align: center; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.pager span { color: var(--ink-soft); font-size: .95rem; }

/* Filtros */
.filters { background: var(--paper); border-radius: var(--radius); margin-bottom: 1rem; }
.filters summary { padding: .9rem 1rem; cursor: pointer; font-weight: 700; min-height: 48px; }
.filters-form { padding: 0 1rem 1rem; display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.filters-form .wide, .filters-actions { grid-column: 1 / -1; }
.filters-actions { display: flex; align-items: center; gap: 1.2rem; }

/* ---------- Detalle de incidencia (como un albarán) ---------- */
.ticket { background: var(--paper); border-radius: var(--radius); overflow: hidden; }
.ticket-head { padding: 1.1rem 1.1rem .9rem; border-bottom: 2px dashed var(--line); }
.ticket-head h1 { margin: .5rem 0 .2rem; }
.ticket-head p { margin: 0; color: var(--ink-soft); }
.facts { margin: 0; padding: 1rem 1.1rem; display: grid; grid-template-columns: 1fr 1fr; gap: .9rem 1rem; }
.facts dt { font-size: .85rem; color: var(--ink-soft); }
.facts dd { margin: 0; font-weight: 700; overflow-wrap: anywhere; }
.facts .wide { grid-column: 1 / -1; }
.facts .wide dd { font-weight: 400; }
.gallery { list-style: none; margin: 0; padding: 0 1.1rem 1.1rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: .5rem; }
.gallery a { display: block; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--ground); }
.gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ticket > .hint { padding: 0 1.1rem 1rem; }
.sendbox { padding: 1rem 1.1rem 1.2rem; border-top: 2px dashed var(--line); }
.sendbox .estado { margin-bottom: .5rem; }
.sendbox-error { background: var(--bad-bg); }
.sendbox-enviada { background: var(--ok-bg); }

/* Login e instalación */
.login { max-width: 420px; margin: 2rem auto 0; background: var(--paper); border-radius: var(--radius); padding: 1.5rem 1.2rem; }
.checks { list-style: none; padding: 0; margin: 0 0 1rem; }
.checks li { padding: .2rem 0; }
.checks li::before { font-weight: 700; margin-right: .5rem; }
.checks .ok::before { content: "✓"; color: var(--ok); }
.checks .bad::before { content: "✗"; color: var(--bad); }
.checks .bad { color: var(--bad); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
