:root {
  --bg: #0b1220;
  --surface: #131c2e;
  --surface-2: #1a2539;
  --ink: #e7edf6;
  --muted: #8ba0bb;
  --brand: #0f2744;
  --accent: #ff6a2b;
  --accent-soft: rgba(255, 106, 43, .16);
  --line: #24334b;
  --good: #22b573;
  --warn: #f59e0b;
  --bad: #e11d48;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

body.hoja-abierta { overflow: hidden; }

button, input { font: inherit; }

::selection { background: var(--accent); color: #fff; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Login ---------- */
.login {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 22px calc(24px + var(--safe-bottom));
  background:
    radial-gradient(520px 340px at 50% -8%, rgba(255, 106, 43, .18), transparent 70%),
    radial-gradient(420px 300px at 90% 110%, rgba(15, 39, 68, .9), transparent 70%),
    var(--bg);
}

.login-caja {
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-form input {
  width: 100%;
  height: 54px;
  padding: 0 18px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 1.1rem;
  letter-spacing: .06em;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.login-form input::placeholder {
  color: var(--muted);
  letter-spacing: 0;
}

.login-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-primario {
  height: 54px;
  border: 0;
  border-radius: 13px;
  background: linear-gradient(180deg, #ff7a3d, #f55312);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: .01em;
  cursor: pointer;
  transition: filter .15s ease, transform .05s ease;
}

.btn-primario:hover { filter: brightness(1.06); }
.btn-primario:active { transform: translateY(1px); }

.login-error {
  margin: 2px 0 0;
  font-size: .84rem;
  color: #ff8fa3;
  text-align: center;
}

/* ---------- App ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
  background: rgba(11, 18, 32, .92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar-vendedor {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  font-size: .78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.btn-actualizar {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s ease;
}

.btn-actualizar:hover { border-color: #1a7f4b; }
.btn-actualizar:disabled { opacity: .55; cursor: default; }

.icono-excel { width: 17px; height: 17px; flex: none; }

@media (max-width: 480px) {
  .topbar-vendedor > #vendedor-cedula { display: none; }
  .btn-actualizar { padding: 0 10px; }
}

.icon-btn {
  width: 38px; height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  display: grid; place-items: center;
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease;
}

.icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.icon-btn svg { width: 18px; height: 18px; }

.buscador {
  position: sticky;
  top: calc(59px + env(safe-area-inset-top, 0px));
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 12px 14px 0;
  padding: 0 12px 0 15px;
  height: 48px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  transition: border-color .15s ease, box-shadow .15s ease;
}

.buscador:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.buscador > svg {
  flex: none;
  width: 19px; height: 19px;
  color: var(--muted);
}

.buscador input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: .96rem;
}

.buscador input::placeholder { color: var(--muted); }
.buscador input::-webkit-search-cancel-button { -webkit-appearance: none; }

.limpiar {
  flex: none;
  width: 26px; height: 26px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--ink);
  display: grid; place-items: center;
  cursor: pointer;
}

.limpiar svg { width: 13px; height: 13px; }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 14px;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  height: 34px;
  padding: 0 15px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: .84rem;
  cursor: pointer;
  transition: all .15s ease;
}

.chip:hover { border-color: #33507a; color: var(--ink); }

.chip.activo {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.contenido { padding: 0 14px calc(30px + var(--safe-bottom)); }

.resumen {
  margin: 0 0 10px;
  font-size: .78rem;
  color: var(--muted);
}

.grilla {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.tarjeta {
  display: flex;
  flex-direction: column;
  text-align: left;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s ease, transform .12s ease;
}

.tarjeta:hover { border-color: #35507a; transform: translateY(-2px); }
.tarjeta:active { transform: translateY(0); }

.tarjeta-arte {
  position: relative;
  aspect-ratio: 1 / 1;
}

.arte {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--color);
  background:
    radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--color) 26%, transparent), transparent 68%),
    var(--surface-2);
}

.arte svg {
  width: 72%;
  height: 72%;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .35));
}

.foto {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: var(--surface-2);
}

.stock {
  position: absolute;
  top: 8px;
  right: 8px;
  min-width: 26px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: .72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(6px);
}

.stock.con-stock { background: rgba(34, 181, 115, .18); color: #45d694; }
.stock.poco-stock { background: rgba(245, 158, 11, .18); color: #fbbf24; }
.stock.sin-stock { background: rgba(225, 29, 72, .18); color: #fb7185; }

.tarjeta-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 11px 12px;
}

.codigo {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: .68rem;
  letter-spacing: .04em;
  color: var(--accent);
}

.nombre {
  margin: 0;
  font-size: .86rem;
  font-weight: 600;
  line-height: 1.28;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.2em;
}

.marca {
  font-size: .72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.precio {
  margin-top: 3px;
  font-size: .94rem;
  font-weight: 700;
}

.vacio {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 64px 20px;
  color: var(--muted);
  text-align: center;
}

.vacio svg { width: 46px; height: 46px; opacity: .45; margin-bottom: 6px; }
.vacio p { margin: 0; font-weight: 600; color: var(--ink); }
.vacio span { font-size: .82rem; }

/* ---------- Hoja de detalle ---------- */
.hoja-fondo {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(3, 7, 15, .66);
  backdrop-filter: blur(3px);
  animation: aparecer .18s ease;
}

.hoja {
  position: fixed;
  z-index: 41;
  left: 0; right: 0; bottom: 0;
  max-height: 88dvh;
  overflow-y: auto;
  padding: 18px 20px calc(24px + var(--safe-bottom));
  border-radius: 22px 22px 0 0;
  border-top: 1px solid var(--line);
  background: var(--surface);
  animation: subir .24s cubic-bezier(.2, .8, .2, 1);
}

@media (min-width: 640px) {
  .hoja {
    left: 50%;
    right: auto;
    bottom: 50%;
    width: 420px;
    border-radius: 20px;
    border: 1px solid var(--line);
    transform: translate(-50%, 50%);
    animation: aparecer .18s ease;
  }
}

@keyframes subir {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes aparecer {
  from { opacity: 0; }
  to { opacity: 1; }
}

.hoja-cerrar {
  position: absolute;
  top: 14px; right: 14px;
  width: 34px; height: 34px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
  display: grid; place-items: center;
  cursor: pointer;
}

.hoja-cerrar:hover { color: var(--ink); }
.hoja-cerrar svg { width: 16px; height: 16px; }

.detalle-arte {
  position: relative;
  width: 100%;
  max-width: 190px;
  aspect-ratio: 1 / 1;
  margin: 4px auto 16px;
  border-radius: 18px;
  overflow: hidden;
}

.detalle-cab { text-align: center; margin-bottom: 14px; }

.detalle-cab .codigo { font-size: .78rem; }

.detalle-cab h2 {
  margin: 5px 0 3px;
  font-size: 1.22rem;
  line-height: 1.28;
}

.detalle-cab p {
  margin: 0;
  font-size: .84rem;
  color: var(--muted);
}

.detalle-precio {
  text-align: center;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -.02em;
  margin-bottom: 18px;
}

.detalle-precio small {
  display: block;
  margin-top: 2px;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

.detalle-datos {
  display: flex;
  flex-direction: column;
  margin: 0 0 18px;
  border-top: 1px solid var(--line);
}

.detalle-datos > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 2px;
  border-bottom: 1px solid var(--line);
}

.detalle-datos dt {
  font-size: .84rem;
  color: var(--muted);
}

.detalle-datos dd {
  margin: 0;
  font-size: .88rem;
  font-weight: 600;
}

.con-stock-texto { color: #45d694; }
.poco-stock-texto { color: #fbbf24; }
.sin-stock-texto { color: #fb7185; }

.btn-copiar {
  width: 100%;
  height: 50px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: .94rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease;
}

.btn-copiar:hover { border-color: var(--accent); color: var(--accent); }

.import-titulo {
  margin: 6px 26px 4px;
  font-size: 1.15rem;
  text-align: center;
}

.import-sub {
  margin: 0 0 14px;
  text-align: center;
  font-size: .85rem;
  color: var(--muted);
}

.import-lista {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  max-height: 230px;
  overflow-y: auto;
  border-top: 1px solid var(--line);
}

.import-lista li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
  font-size: .8rem;
}

.import-lista .cod {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--accent);
}

.import-lista .nom {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.import-lista .precio-mini {
  flex: none;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.import-aviso {
  margin: 0 0 12px;
  font-size: .78rem;
  color: var(--muted);
  text-align: center;
}

.import-error {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(225, 29, 72, .12);
  color: #fb7185;
  font-size: .8rem;
  line-height: 1.4;
  white-space: pre-line;
}

.import-acciones {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.aviso {
  position: fixed;
  left: 50%;
  bottom: calc(26px + var(--safe-bottom));
  z-index: 60;
  transform: translateX(-50%);
  padding: 11px 18px;
  border-radius: 999px;
  background: #e7edf6;
  color: #0b1220;
  font-size: .84rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
  animation: aparecer .15s ease;
}
