:root {
  --brand: #1769d1;
  --brand-700: #0f4fa8;
  --brand-900: #0b3a80;
  --sky: #3b9cf7;
  --aqua: #a8fbf6;
  --tint: #eaf3ff;
  --bg: #f2f5f9;
  --card: #ffffff;
  --text: #10233a;
  --muted: #5d7187;
  --line: #e1e8f0;
  --sale: #e03131;
  --red: #d63a3a;
  --red-bg: #fdeaea;
  --amber: #a86200;
  --amber-bg: #fff3d9;
  --green: #12805a;
  --green-bg: #e2f6ee;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 35, 58, 0.05), 0 6px 18px -10px rgba(16, 35, 58, 0.18);
  --tabs-h: 64px;
  --pad: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-size: 0.9rem; }
.hint { color: var(--muted); font-size: 0.82rem; margin-top: -4px; }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }

/* ---------- botones y formularios ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px;
  border: 1px solid var(--line); border-radius: 12px;
  background: #fff; color: var(--text); font-weight: 650; text-decoration: none; white-space: nowrap;
  transition: background 0.15s, transform 0.05s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 6px 14px -8px var(--brand); }
.btn.primary:hover { background: var(--brand-700); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn.ghost:hover { background: var(--tint); }
.btn.in { background: var(--green-bg); border-color: transparent; color: var(--green); }
.btn.out { background: var(--red-bg); border-color: transparent; color: var(--red); }
.btn.danger-text { border-color: transparent; background: transparent; color: var(--red); }
.btn.small { min-height: 38px; padding: 0 14px; font-size: 0.9rem; border-radius: 10px; }
.btn.block { width: 100%; }
.icon-btn { width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--bg); font-size: 1rem; flex: none; }

label { display: block; font-size: 0.86rem; font-weight: 600; color: var(--muted); }
form input:not([type=checkbox]):not([type=file]), form select, form textarea {
  display: block; width: 100%; margin-top: 6px; min-height: 48px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--text); font-weight: 400;
}
textarea { resize: vertical; }
form input:focus, form select:focus, form textarea:focus {
  outline: 3px solid color-mix(in srgb, var(--sky) 40%, transparent); outline-offset: 0; border-color: var(--sky);
}
.btn:focus-visible, .card:focus-visible, .tab:focus-visible, .chip:focus-visible, .stat:focus-visible, .top-btn:focus-visible, .top-avatar:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--sky) 55%, transparent); outline-offset: 2px;
}
form { display: grid; gap: 14px; }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.check { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 500; font-size: 1rem; }
.check input { width: 22px; height: 22px; accent-color: var(--brand); }
.form-error { color: var(--red); background: var(--red-bg); padding: 10px 12px; border-radius: 10px; font-size: 0.92rem; }

/* ---------- acceso ---------- */
.auth {
  min-height: 100dvh; display: grid; place-items: center; padding: 20px;
  background:
    radial-gradient(900px 500px at 100% 0%, rgba(168, 251, 246, 0.55), transparent 60%),
    linear-gradient(160deg, #0f4fa8 0%, #1769d1 45%, #3b9cf7 100%);
}
.auth-card {
  width: 100%; max-width: 400px; padding: 30px 24px 22px; background: #fff; border-radius: 26px;
  box-shadow: 0 30px 60px -25px rgba(6, 30, 70, 0.6);
}
.auth-logo { width: 180px; max-width: 66%; margin: 0 auto 2px; display: block; }
.auth-card h1 { text-align: center; font-size: 1.2rem; color: var(--brand-700); }
.auth-card .muted { text-align: center; }

/* ---------- cabecera ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  padding: calc(12px + var(--safe-t)) 16px 14px;
  color: #fff;
  background:
    radial-gradient(520px 220px at 100% 0%, rgba(168, 251, 246, 0.35), transparent 65%),
    linear-gradient(120deg, var(--brand-700) 0%, var(--brand) 50%, #2f93f0 100%);
  box-shadow: 0 6px 18px -12px rgba(11, 58, 128, 0.7);
}
.top-row { display: flex; align-items: center; gap: 12px; max-width: 1180px; margin: 0 auto; }
.top-logo { width: 42px; height: 42px; border-radius: 12px; background: #fff; box-shadow: 0 2px 8px rgba(6, 30, 70, 0.25); }
.top-title { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; margin-right: auto; }
.top-title strong { letter-spacing: 0.08em; font-size: 1.08rem; }
.top-title span { font-size: 0.8rem; opacity: 0.85; }
.top-btn {
  min-height: 38px; padding: 0 14px; border-radius: 99px; border: 1px solid rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.14); color: #fff; font-weight: 650; font-size: 0.9rem; white-space: nowrap;
}
.top-avatar {
  width: 40px; height: 40px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.18); color: #fff; font-weight: 700;
}
.net { padding: 5px 10px; border-radius: 99px; background: var(--amber-bg); color: var(--amber); font-size: 0.78rem; font-weight: 700; white-space: nowrap; }
.top-search {
  display: flex; align-items: center; gap: 10px; max-width: 1180px; margin: 12px auto 0; padding: 0 16px; height: 50px;
  background: #fff; border-radius: 99px; color: var(--brand); box-shadow: 0 4px 14px -6px rgba(6, 30, 70, 0.45);
}
.top-search svg { width: 22px; height: 22px; flex: none; }
.top-search input {
  flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 1rem; font-weight: 400;
}
.top-search:focus-within { outline: 3px solid rgba(168, 251, 246, 0.9); }

/* ---------- navegación ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -6px 18px -14px rgba(16, 35, 58, 0.35);
}
.shell.guest .tabs { display: none; }
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: none; color: #7c8da0; font-size: 0.72rem; font-weight: 600;
}
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--brand); }
.tab.active svg { stroke-width: 2.2; }

main { padding: 16px 16px calc(var(--tabs-h) + var(--safe-b) + 28px); max-width: 1212px; margin: 0 auto; }
.shell.guest main { padding-bottom: calc(var(--safe-b) + 32px); }
.page-title { font-size: 1.3rem; margin-bottom: 14px; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.toolbar .page-title { margin: 0; flex: 1; }
.panel { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.panel h3 { font-size: 1rem; margin-bottom: 6px; }
.panel .muted { margin-bottom: 12px; }

/* ---------- inventario ---------- */
.stats { display: flex; gap: 10px; overflow-x: auto; margin: 0 -16px 14px; padding: 0 16px 4px; scrollbar-width: none; }
.stats::-webkit-scrollbar { display: none; }
.stat {
  flex: 1 0 auto; min-width: 128px; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  padding: 12px 14px; background: var(--card); border: 1px solid transparent; border-radius: 14px; box-shadow: var(--shadow);
}
.stat strong { font-size: 1.35rem; line-height: 1.15; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat span { font-size: 0.78rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.stat.alert strong { color: var(--red); }
.stat.warn strong { color: var(--amber); }
.stat.on { border-color: var(--brand); background: var(--tint); }

.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px; padding: 0 16px 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips:empty { display: none; }
.chip { flex: none; min-height: 38px; padding: 0 16px; border-radius: 99px; border: 1px solid var(--line); background: #fff; font-weight: 600; font-size: 0.88rem; color: var(--muted); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }

.list-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 38px; margin-bottom: 10px; }
.list-head h2 { font-size: 0.95rem; color: var(--muted); font-weight: 600; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 12px; }
.card {
  display: flex; flex-direction: column; width: 100%; padding: 0; text-align: left; overflow: hidden;
  background: var(--card); border: 0; border-radius: var(--radius); box-shadow: var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgba(16, 35, 58, 0.06), 0 14px 26px -14px rgba(16, 35, 58, 0.35); }
.card-img { position: relative; display: grid; place-items: center; width: 100%; aspect-ratio: 5 / 4; background: #f6f9fc; }
.card-img img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card { height: 100%; }
.card-img { flex: none; }
.card-info { flex: 1; }
.ph { width: 34%; height: 34%; color: #bfd0e2; }
.tag {
  position: absolute; top: 10px; left: 10px; padding: 3px 9px; border-radius: 99px;
  background: var(--sale); color: #fff; font-size: 0.78rem; font-weight: 750; letter-spacing: 0.01em;
}
.tag.big { top: 14px; left: 14px; font-size: 0.95rem; padding: 5px 12px; }
.card-info { display: flex; flex-direction: column; gap: 3px; padding: 10px 12px 13px; min-width: 0; }
.card-price { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 7px; min-height: 1.5em; }
.card-price b { font-size: 1.08rem; font-variant-numeric: tabular-nums; }
.card-price b.sale { color: var(--sale); }
.card-price s { color: var(--muted); font-size: 0.8rem; }
.card-name { font-size: 0.92rem; font-weight: 600; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; min-height: 2.6em; }
.card-meta { font-size: 0.75rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta:empty { display: none; }
.avail { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; font-weight: 700; margin-top: 3px; }
.avail::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.avail.ok { color: var(--green); }
.avail.low { color: var(--amber); }
.avail.out { color: var(--red); }
.badges { display: flex; flex-wrap: wrap; gap: 5px; }
.badges:empty { display: none; }
.badge { padding: 2px 8px; border-radius: 99px; font-size: 0.72rem; font-weight: 700; }
.badge.out { background: var(--red-bg); color: var(--red); }
.badge.low, .badge.warn { background: var(--amber-bg); color: var(--amber); }
.empty { grid-column: 1 / -1; padding: 56px 20px; text-align: center; color: var(--muted); background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- hoja / diálogo ---------- */
dialog#sheet {
  width: 100%; max-width: 620px; max-height: 94dvh; margin: auto auto 0; padding: var(--pad) var(--pad) calc(22px + var(--safe-b));
  border: 0; border-radius: 24px 24px 0 0; background: #fff; color: var(--text); overflow-y: auto;
}
dialog#sheet::backdrop { background: rgba(8, 28, 56, 0.55); }
dialog#sheet > * + * { margin-top: 16px; }
.sheet-head { display: flex; align-items: flex-start; gap: 10px; }
.sheet-head h2 { flex: 1; font-size: 1.2rem; overflow-wrap: anywhere; padding-top: 6px; }
dialog h3 { font-size: 0.82rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

.hero {
  position: relative; display: grid; place-items: center; height: min(300px, 42dvh);
  margin: calc(var(--pad) * -1) calc(var(--pad) * -1) 0; background: #f6f9fc;
}
.hero { overflow: hidden; }
.hero img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.hero .ph { width: 96px; height: 96px; }
.hero-close { position: absolute; top: 12px; right: 12px; background: #fff; box-shadow: 0 2px 10px rgba(16, 35, 58, 0.2); }
.detail-head { display: flex; flex-direction: column; gap: 6px; }
.eyebrow { font-size: 0.76rem; font-weight: 700; color: var(--brand); text-transform: uppercase; letter-spacing: 0.06em; }
.detail-head h2 { font-size: 1.3rem; line-height: 1.25; overflow-wrap: anywhere; }
.price-big { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.price-big strong { font-size: 2rem; line-height: 1.1; color: var(--brand-700); font-variant-numeric: tabular-nums; }
.price-big s { color: var(--muted); font-size: 1rem; }
.price-big em { font-style: normal; font-weight: 700; font-size: 0.8rem; color: var(--sale); background: #fdecec; padding: 3px 9px; border-radius: 99px; }
.detail-avail { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.detail-avail .avail { font-size: 0.95rem; margin: 0; padding: 6px 12px; border-radius: 99px; background: var(--bg); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .btn { flex: 1; }
.actions.end { justify-content: flex-end; }
.actions.end .btn { flex: none; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px 16px; margin-bottom: 0; padding: 14px; border-radius: 14px; background: var(--bg); }
.fields:not(:has(div)) { display: none; }
.fields dt { font-size: 0.74rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.fields dd { margin: 0; overflow-wrap: anywhere; }
.pricing { display: grid; grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)); gap: 8px; }
.pricing > div { display: flex; flex-direction: column; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.pricing span { font-size: 0.72rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.pricing strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.pricing .pos { color: var(--green); }
.pricing .neg { color: var(--red); }

.photo-zone { display: flex; align-items: center; gap: 14px; }
.photo-frame {
  flex: none; width: 132px; height: 132px; border-radius: 18px; overflow: hidden; cursor: pointer;
  display: grid; place-items: center; background: var(--tint); border: 2px dashed #a9cdf3;
}
.photo-frame img { width: 100%; height: 100%; object-fit: cover; }
.photo-frame:has(img:not([hidden])) { border: 1px solid var(--line); }
.photo-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--brand); font-size: 0.85rem; }
.photo-empty svg { width: 34px; height: 34px; }
.photo-btns { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.photo-btns label { color: var(--text); }

/* ---------- listas ---------- */
.moves, .people { list-style: none; margin: 0; padding: 0; }
.moves li, .people li { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.moves li:last-child, .people li:last-child { border-bottom: 0; }
.mv { flex: none; min-width: 64px; padding: 6px 8px; border-radius: 10px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.mv.entrada { background: var(--green-bg); color: var(--green); }
.mv.salida { background: var(--red-bg); color: var(--red); }
.mv.ajuste { background: var(--tint); color: var(--brand-700); }
.mv-body { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 0.9rem; overflow-wrap: anywhere; }
.avatar { flex: none; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--tint); color: var(--brand-700); font-weight: 700; }
.people li.off { opacity: 0.55; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + var(--safe-b) + 16px); z-index: 99;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 12px; background: #10233a; color: #fff; font-weight: 600; font-size: 0.92rem;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--red); }

/* ---------- tablet y escritorio ---------- */
@media (min-width: 700px) {
  :root { --pad: 24px; }
  .top { padding-left: 24px; padding-right: 24px; }
  main { padding-left: 24px; padding-right: 24px; }
  .stats, .chips { margin-left: 0; margin-right: 0; padding-left: 0; padding-right: 0; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
  dialog#sheet { margin: auto; border-radius: 24px; }
}
@media (min-width: 1000px) {
  .shell:not(.guest) { padding-left: 92px; }
  .tabs {
    top: 0; right: auto; width: 92px; height: auto; flex-direction: column; justify-content: center; gap: 8px;
    padding: 16px 8px; border-top: 0; border-right: 1px solid var(--line); box-shadow: none;
  }
  .tab { flex: none; height: 70px; border-radius: 14px; }
  .tab.active { background: var(--tint); }
  main { padding-top: 24px; padding-bottom: 40px; }
  #toast { bottom: 28px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
