/* =====================================================================
   Conteo de Inventarios Semco - estilos (mobile first / PDA)
   ===================================================================== */

:root {
  --navy: #0f172a;
  --navy-2: #1e293b;
  --blue: #0066cc;
  --blue-dark: #004e99;
  --green: #12805c;
  --green-light: #e6f6ef;
  --red: #c0392b;
  --red-light: #fdecea;
  --amber: #b26a00;
  --amber-light: #fff4e0;
  --bg: #f1f4f9;
  --card: #ffffff;
  --line: #dbe2ec;
  --text: #16202e;
  --muted: #64748b;
  --radius: 14px;
  --tap: 56px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 16px;
  overscroll-behavior-y: none;
}

body { min-height: 100vh; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.error { color: var(--red); background: var(--red-light); padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.ok { color: var(--green); background: var(--green-light); padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.center { text-align: center; }
.right { text-align: right; }
.grow { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { height: 10px; }
.wrap-anywhere { overflow-wrap: anywhere; }

/* ---------------------------- LOGIN ---------------------------- */
.login {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #0f172a, #1e3a8a); padding: 20px; z-index: 50;
}
.login-card {
  background: #fff; border-radius: 18px; padding: 28px 22px; max-width: 420px; width: 100%;
  box-shadow: 0 20px 45px rgba(0,0,0,.28); text-align: center;
}
.brand {
  font-weight: 800; letter-spacing: 4px; color: var(--blue); font-size: 14px; margin-bottom: 10px;
}
.login-card h1 { font-size: 22px; margin: 0 0 8px; }
.login-card .btn { width: 100%; margin: 14px 0; }
.login-card .small { margin-top: 6px; }

/* ---------------------------- APPBAR ---------------------------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  background: var(--navy); color: #fff;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 8px;
}
.appbar-title { display: flex; flex-direction: column; line-height: 1.25; flex: 1; min-width: 0; }
.appbar-title strong { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appbar-title .small { color: #cbd5e1; }
.icon-btn {
  background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 10px;
  width: 42px; height: 42px; font-size: 20px; cursor: pointer; flex: none;
}
.icon-btn:active { background: rgba(255,255,255,.25); }

/* ---------------------------- VIEW ---------------------------- */
.view {
  flex: 1; padding: 14px 12px calc(env(safe-area-inset-bottom, 0px) + 92px);
  max-width: 900px; width: 100%; margin: 0 auto;
}
.view.no-bottom { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 20px); }
.view > .view-inner > :last-child { margin-bottom: 0; }

h2 { font-size: 18px; margin: 4px 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
p { margin: 0 0 10px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.card.tight { padding: 10px 12px; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }

/* ---------------------------- BOTONES ---------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: 12px; border: 1px solid transparent;
  font-size: 16px; font-weight: 600; cursor: pointer; background: var(--navy-2); color: #fff;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-lg { min-height: 60px; font-size: 17px; width: 100%; }
.btn-primary { background: var(--blue); }
.btn-primary:active { background: var(--blue-dark); }
.btn-success { background: var(--green); }
.btn-ghost { background: #fff; color: var(--text); border-color: var(--line); }
.btn-danger { background: var(--red); }
.btn-sm { min-height: 40px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

/* ---------------------------- LISTAS ---------------------------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; cursor: pointer; display: block; width: 100%; text-align: left;
  color: inherit; font-size: 15px;
}
.item:active { background: #f8fafc; }
.item-title { font-weight: 700; font-size: 16px; }
.item-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.item-right { text-align: right; }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: #eef2f7; color: var(--muted); text-transform: uppercase; letter-spacing: .3px;
}
.badge.abierta { background: var(--green-light); color: var(--green); }
.badge.en_proceso { background: var(--amber-light); color: var(--amber); }
.badge.cerrada { background: #eceff3; color: var(--muted); }
.badge.general { background: #e8f0fe; color: var(--blue-dark); }
.badge.ciclico { background: #f3e8ff; color: #6b21a8; }

.progress { height: 10px; background: #e8edf4; border-radius: 999px; overflow: hidden; margin: 8px 0 4px; }
.progress > span { display: block; height: 100%; background: var(--green); border-radius: 999px; transition: width .25s; }

.kv { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid #eef2f7; font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { font-weight: 600; text-align: right; overflow-wrap: anywhere; }

/* ---------------------------- FORMULARIOS ---------------------------- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 12px 0 6px; }
input[type=text], input[type=email], input[type=number], input[type=search], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--text);
  font-family: inherit;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }
.check { display: flex; align-items: center; gap: 10px; margin: 10px 0; font-size: 15px; font-weight: 500; color: var(--text); }
.check input { width: 22px; height: 22px; }

/* ---------------------------- CONTEO (PDA) ---------------------------- */
.steps { display: flex; gap: 6px; margin-bottom: 10px; }
.step {
  flex: 1; text-align: center; padding: 7px 4px; border-radius: 10px; font-size: 12px; font-weight: 700;
  background: #e8edf4; color: var(--muted); border: 1px solid transparent;
}
.step.active { background: var(--navy); color: #fff; }
.step.done { background: var(--green-light); color: var(--green); }

.ctx { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.ctx-item { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px; min-height: 62px; }
.ctx-item .k { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 700; }
.ctx-item .v { font-size: 14px; font-weight: 600; margin-top: 3px; overflow-wrap: anywhere; }

.scanbox {
  background: var(--navy); color: #fff; border-radius: var(--radius); padding: 18px 16px; text-align: center;
  margin-bottom: 12px; min-height: 118px; display: flex; flex-direction: column; justify-content: center; gap: 6px;
}
.scanbox .hint { font-size: 13px; color: #cbd5e1; }
.scanbox .code { font-size: 20px; font-weight: 700; letter-spacing: .5px; overflow-wrap: anywhere; }
.scanbox.ok { background: var(--green); }
.scanbox.err { background: var(--red); }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.key {
  min-height: 58px; font-size: 22px; font-weight: 700; border-radius: 12px; border: 1px solid var(--line);
  background: #fff; cursor: pointer; color: var(--text);
}
.key:active { background: #eef2f7; }
.key.fn { background: #eef2f7; font-size: 17px; }
.key.ok { background: var(--green); color: #fff; border-color: var(--green); }
.qty-display {
  background: #fff; border: 2px solid var(--blue); border-radius: 12px; padding: 14px;
  font-size: 36px; font-weight: 900; text-align: right; margin-bottom: 12px; font-variant-numeric: tabular-nums;
  min-height: 64px; display: flex; align-items: center; justify-content: flex-end;
}
.mode-toggle { display: flex; gap: 8px; margin-bottom: 10px; }
.mode-toggle .btn { flex: 1; }
.mode-toggle .btn.selected { background: var(--navy); color: #fff; }

/* Indicador de unidad de medida */
.um-badge {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: 8px 0 12px;
  background: #eef2f7;
  color: var(--muted);
}
.um-badge.um-uds { background: #dbeafe; color: #1e40af; }
.um-badge.um-kg { background: #ede9fe; color: #5b21b6; }
.um-badge.um-gr { background: #d1fae5; color: #065f46; }
.um-badge.um-lt { background: #ffedd5; color: #9a3412; }

/* Selector manual de unidad de medida */
.um-selector { display: flex; gap: 8px; margin-bottom: 10px; }
.um-btn {
  flex: 1;
  min-height: 54px;
  border-radius: 12px;
  border: 2px solid #dbe2ec;
  background: #fff;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: .3px;
  color: var(--muted);
}
.um-btn.selected { transform: scale(1.02); box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.um-btn.um-uds.selected { border-color: #1e40af; background: #dbeafe; color: #1e40af; }
.um-btn.um-kg.selected { border-color: #5b21b6; background: #ede9fe; color: #5b21b6; }
.um-btn.um-gr.selected { border-color: #065f46; background: #d1fae5; color: #065f46; }
.um-btn.um-lt.selected { border-color: #9a3412; background: #ffedd5; color: #9a3412; }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; gap: 8px; padding: 10px 12px calc(env(safe-area-inset-bottom, 0px) + 10px);
  background: rgba(255,255,255,.97); border-top: 1px solid var(--line); backdrop-filter: blur(6px);
}
.actionbar .btn { flex: 1; }

.list-scroll { max-height: 46vh; overflow: auto; -webkit-overflow-scrolling: touch; }
.count-row { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid #eef2f7; }
.count-row:last-child { border-bottom: 0; }
.count-row .grow { min-width: 0; }
.qty { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 17px; }
.qty.pos { color: var(--green); }
.qty.neg { color: var(--red); }

/* ---------------------------- MODAL / TOAST ---------------------------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 60;
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
}
.modal {
  background: #fff; width: 100%; max-width: 560px; border-radius: 18px 18px 0 0;
  padding: 16px 14px calc(env(safe-area-inset-bottom, 0px) + 16px); max-height: 92vh; overflow: auto;
}
.modal h3 { font-size: 17px; margin-bottom: 10px; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; }
.modal-actions .btn { flex: 1; }

#toast-root { position: fixed; left: 0; right: 0; bottom: 84px; z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--navy); color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px;
  max-width: 92%; box-shadow: 0 8px 22px rgba(0,0,0,.25); animation: toastIn .18s ease-out;
}
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }
.toast.warn { background: var(--amber); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------------------------- MENU ---------------------------- */
.menu-item { display: flex; align-items: center; gap: 12px; padding: 14px 4px; border-bottom: 1px solid #eef2f7; font-size: 16px; font-weight: 600; cursor: pointer; background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; color: inherit; }
.menu-item:last-child { border-bottom: 0; }
.menu-item .ic { font-size: 20px; width: 26px; text-align: center; }

.pill { display: inline-block; background: #eef2f7; border-radius: 8px; padding: 4px 8px; font-size: 12px; font-weight: 700; color: var(--muted); }
.pill.red { background: var(--red-light); color: var(--red); }
.pill.green { background: var(--green-light); color: var(--green); }
.pill.amber { background: var(--amber-light); color: var(--amber); }

.empty { text-align: center; padding: 30px 12px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 6px; border-bottom: 1px solid #eef2f7; vertical-align: top; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .3px; }

/* Selector de categoría de material (crear evento) */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 4px;
}
.cat-card {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 74px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: #fff;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  font-family: inherit;
  transition: border-color .15s, background .15s;
}
.cat-card .cat-icon { font-size: 26px; line-height: 1; flex: none; }
.cat-card .cat-name { font-size: 14px; font-weight: 800; line-height: 1.25; }
.cat-card.selected {
  border-color: var(--cat-color, var(--blue));
  background: var(--cat-color, var(--blue));
  color: #fff;
}
.cat-card:active { transform: translateY(1px); }

/* Checkmark de categoría seleccionada (permite elegir varias) */
.cat-card {
  position: relative;
}
.cat-check {
  position: absolute;
  top: 7px;
  right: 9px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: #fff;
  color: transparent;
  font-size: 12px;
  font-weight: 900;
  line-height: 17px;
  text-align: center;
  flex: none;
}
.cat-card.selected .cat-check {
  background: #fff;
  border-color: #fff;
  color: var(--cat-color, var(--blue));
}

@media (min-width: 560px) {
  .cat-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Etiqueta de categoría */
.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .3px;
  color: #fff;
}

/* Tablas responsive */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid #eef2f7; vertical-align: top; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .3px; background: #f8fafc; }
tr:hover td { background: #f8fafc; }

/* Destacados del dashboard */
.ctx-item .v.green { color: var(--green); }
.ctx-item .v.red { color: var(--red); }

/* Mejoras para el wizard de conteo */
.step { user-select: none; }
.search-results { max-height: 40vh; overflow: auto; }

@media (min-width: 720px) {
  .view { padding-bottom: 40px; }
  .ctx { grid-template-columns: repeat(4, 1fr); }
  .modal-back { align-items: center; padding: 20px; }
  .modal { border-radius: 18px; }
}
