/* ============================================================
   SEMAR · Reposición y Picking — Stylesheet
   Paleta de marca:
     #87c329 primario (verde SEMAR)
     #76ab1f primario hover
     #003399 secundario (azul oscuro)
     #333    texto
     #d7d7d7 bordes
     #fafafa background app
   ============================================================ */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  color: #333;
  background: #fafafa;
}

a { color: #003399; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ Topbar / Header ============ */
.topbar {
  background: #87c329;
  color: white;
  padding: 0.7em 1em;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}
.topbar .brand {
  font-weight: 700;
  font-size: 1.05em;
  letter-spacing: 0.02em;
}
.topbar nav a {
  color: white;
  font-weight: 600;
  padding: 0.3em 0.8em;
  border-radius: 0.3em;
}
.topbar nav a:hover {
  background: rgba(255,255,255,0.15);
  text-decoration: none;
}

/* ============ Container ============ */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1em;
}

/* ============ Footer ============ */
.foot {
  text-align: center;
  color: #888;
  font-size: 0.85em;
  padding: 2em 1em;
  border-top: 1px solid #d7d7d7;
  margin-top: 3em;
}

/* ============ Typography ============ */
h1 { color: #333; margin: 0.5em 0; font-size: 1.5em; }
h2 { color: #333; margin: 0.8em 0 0.5em; font-size: 1.15em; border-left: 4px solid #87c329; padding-left: 0.5em; }
.muted { color: #666; font-size: 0.92em; }

/* ============ Cards ============ */
.card {
  background: white;
  padding: 1em 1.2em;
  margin-bottom: 1em;
  border-radius: 0.5em;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  border: 1px solid #ececec;
}
.card.hoy {
  border-left: 4px solid #87c329;
  background: linear-gradient(to right, #f5fce8 0%, white 30%);
}

/* ============ Tablas ============ */
table.grid {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5em;
}
table.grid th {
  background: #f5f6f9;
  color: #333;
  text-align: left;
  padding: 0.6em 0.5em;
  border-bottom: 2px solid #d7d7d7;
  font-size: 0.92em;
  font-weight: 600;
}
table.grid td {
  padding: 0.6em 0.5em;
  border-bottom: 1px solid #ececec;
}
table.grid tr:hover { background: #fafafa; }
table.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
tr.off { opacity: 0.5; }
tr.off td { color: #888; }

/* ============ Forms / Inputs ============ */
.row { display: flex; gap: 0.5em; flex-wrap: wrap; align-items: center; margin: 1em 0 0.5em; }
input, select {
  padding: 0.55em 0.7em;
  border: 1px solid #d7d7d7;
  border-radius: 0.3em;
  font-size: 1em;
  background: white;
  color: #333;
}
input:focus, select:focus {
  outline: none;
  border-color: #87c329;
  box-shadow: 0 0 0 3px rgba(135,195,41,0.2);
}

/* ============ Botones ============ */
.btn {
  display: inline-block;
  padding: 0.55em 1.1em;
  font-size: 1em;
  border: 1px solid #d7d7d7;
  background: white;
  color: #333;
  cursor: pointer;
  border-radius: 0.3em;
  text-decoration: none;
  min-height: 44px;  /* tap target */
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #f5f6f9; border-color: #b5b5b5; }
.btn.primary {
  background: #87c329;
  color: white;
  border-color: #87c329;
  font-weight: 600;
}
.btn.primary:hover {
  background: #76ab1f;
  border-color: #76ab1f;
}
.btn.small {
  padding: 0.3em 0.7em;
  font-size: 0.88em;
  min-height: 36px;
}

/* ============ Operador checkbox button ============ */
button.chk {
  font-size: 1.3em;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid #d7d7d7;
  background: white;
  color: #999;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
button.chk:hover { border-color: #87c329; color: #87c329; }
tr.done button.chk {
  background: #87c329;
  border-color: #87c329;
  color: white;
}

/* ============ Barra de progreso ============ */
.bar {
  height: 10px;
  background: #ececec;
  border-radius: 5px;
  overflow: hidden;
  margin-top: 0.4em;
}
.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #87c329, #76ab1f);
  transition: width 0.3s;
}

/* ============ Filas en estado preparado ============ */
tr.done td { color: #2e7d32; }

/* ============ ABC pills (Fase 1) ============ */
.abc {
  display: inline-block;
  padding: 0.2em 0.7em;
  border-radius: 0.6em;
  font-size: 0.9em;
  font-weight: bold;
  letter-spacing: 0.03em;
}
.abc-a { background: #c0392b; color: white; }
.abc-b { background: #f39c12; color: white; }
.abc-c { background: #95a5a6; color: white; }

/* ============ Tiers (Fase 1) ============ */
details.tier-urgente, details.tier-normal, details.tier-planificado, details.tier-sin {
  margin: 1em 0;
  padding: 0.7em 0.8em;
  border-radius: 0.5em;
  border-left: 5px solid;
  background: white;
}
details.tier-urgente     { border-color: #c0392b; background: #fdf2f0; }
details.tier-normal      { border-color: #f39c12; background: #fef9e7; }
details.tier-planificado { border-color: #87c329; background: #f4fbe8; }
details.tier-sin         { border-color: #95a5a6; }
details summary {
  cursor: pointer;
  padding: 0.4em 0;
  font-size: 1.05em;
  user-select: none;
}
details[open] summary { margin-bottom: 0.5em; }

/* ============ Parcial form (Fase 2) ============ */
details.parcial-form summary {
  display: inline-block;
  padding: 0.2em 0.6em;
  background: #f5f6f9;
  border: 1px solid #d7d7d7;
  border-radius: 0.3em;
  cursor: pointer;
  font-size: 0.85em;
}
details.parcial-form summary::-webkit-details-marker { display: none; }
details.parcial-form summary::marker { content: ""; }
details.parcial-form form {
  display: inline-block;
  margin-left: 0.5em;
  padding: 0.4em 0.5em;
  background: #fff8e1;
  border-radius: 0.3em;
}
details.parcial-form input[type="number"] { width: 4em; padding: 0.2em 0.4em; }
.parcial-tag {
  display: inline-block;
  padding: 0.1em 0.5em;
  background: #fff3cd;
  border-radius: 0.3em;
  font-size: 0.85em;
  color: #856404;
  font-weight: 600;
}

/* ============ Caso vacío "Hoy descansás" ============ */
.hoy-descansas {
  text-align: center;
  padding: 3em 1em;
  background: white;
  border-radius: 0.6em;
  border: 1px dashed #d7d7d7;
}
.hoy-descansas .big-emoji { font-size: 5em; margin: 0; line-height: 1; }
.hoy-descansas .big-text {
  font-size: 1.8em;
  font-weight: 700;
  margin: 0.4em 0;
  color: #87c329;
}

/* ============ Header sticky del operador ============ */
.operador-header {
  position: sticky;
  top: 0;
  background: white;
  z-index: 10;
  padding: 0.6em 0;
  margin-bottom: 1em;
  border-bottom: 3px solid #87c329;
}
.operador-header h1 { margin: 0.2em 0; }

/* ============ Indicador de faltante de origen ============ */
tr.falta-origen { background: #fff5f5; }
tr.falta-origen td:first-child { border-left: 3px solid #c0392b; }

/* ============ Badges OK / ⚠ FALTA ============ */
.badge {
  display: inline-block;
  padding: 0.15em 0.6em;
  border-radius: 0.5em;
  font-size: 0.85em;
  font-weight: 700;
}
.badge.ok   { background: #d4edda; color: #155724; }
.badge.warn { background: #f8d7da; color: #721c24; }

/* ============================================================
   Mobile-first refinements (max-width: 767px)
   ============================================================ */
@media (max-width: 767px) {
  .container { padding: 0.6em; }
  h1 { font-size: 1.3em; }
  h2 { font-size: 1.05em; }

  .topbar { padding: 0.5em 0.8em; flex-wrap: wrap; }
  .topbar .brand { font-size: 0.95em; }

  /* Tablas con scroll horizontal en mobile (excepto las del operador
     que usan tier sections — ahí preferimos vertical) */
  .card > table.grid {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  details.tier-urgente table.grid,
  details.tier-normal table.grid,
  details.tier-planificado table.grid,
  details.tier-sin table.grid {
    white-space: normal;
    font-size: 0.9em;
  }

  /* Inputs y botones más grandes en mobile */
  input, select, .btn {
    font-size: 1em;
    padding: 0.65em 0.8em;
  }

  /* Tap targets más grandes */
  button.chk { width: 48px; height: 48px; font-size: 1.5em; }

  /* Forms en columna */
  .row { flex-direction: column; align-items: stretch; }
  .row input, .row select, .row button { width: 100%; }

  /* Cards menos padding */
  .card { padding: 0.8em; }

  .hoy-descansas { padding: 2em 0.5em; }
  .hoy-descansas .big-emoji { font-size: 4em; }
  .hoy-descansas .big-text { font-size: 1.4em; }
}

/* ============================================================
   Desktop (>=768px)
   ============================================================ */
@media (min-width: 768px) {
  .container { padding: 1.5em 2em; }
}

/* ========== Banner de error (Fase 4) ========== */
.banner.error {
  background: #f8d7da;
  border-left: 5px solid #c0392b;
  color: #721c24;
  padding: 0.8em 1em;
  margin: 0.5em 0 1em;
  border-radius: 0.3em;
}
.banner.error code {
  background: rgba(0,0,0,0.05);
  padding: 0.1em 0.3em;
  border-radius: 0.2em;
  font-size: 0.9em;
}
.banner.error a { color: #721c24; font-weight: 600; }

/* ========== Vendedor login (v1.1) ========== */
.vendedor-login {
  max-width: 360px;
  margin: 2em auto;
  text-align: center;
  padding: 1.5em;
}
.brand-large { margin-bottom: 2em; }
.brand-icon {
  display: inline-block;
  width: 80px; height: 80px;
  border-radius: 16px;
  background: #87c329;
  color: white;
  font-size: 32px;
  font-weight: 700;
  line-height: 80px;
  margin-bottom: 0.5em;
}
.login-form { display: flex; flex-direction: column; gap: 0.7em; }
.login-form input { font-size: 1.1em; padding: 0.8em; }
.login-form .btn { padding: 0.9em; font-size: 1.1em; }

/* Header vendedor */
.vendedor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5em 0;
  border-bottom: 2px solid #87c329;
  margin-bottom: 1em;
  position: sticky; top: 0; background: white; z-index: 10;
}

/* ========== Vendedor home (v1.1) ========== */
.search-form { display: flex; gap: 0.5em; margin: 0.5em 0; }
.search-form input { flex: 1; padding: 0.7em; font-size: 1em; }
.search-results { margin-top: 1em; display: flex; flex-direction: column; gap: 0.3em; }
.result-row {
  display: block;
  padding: 0.6em 0.7em;
  border: 1px solid #d7d7d7;
  border-radius: 0.3em;
  background: white;
  color: #333;
  text-decoration: none;
}
.result-row:hover { border-color: #87c329; background: #f4fbe8; text-decoration: none; }
.result-row .stock { float: right; color: #2e7d32; font-weight: 600; font-size: 0.9em; }
.pedidos-lista { list-style: none; padding: 0; margin: 0; }
.pedidos-lista li.pedido {
  padding: 0.7em;
  border-left: 4px solid #d7d7d7;
  background: #fafafa;
  margin-bottom: 0.4em;
  border-radius: 0.2em;
}
.pedidos-lista li.pedido-resuelto_match,
.pedidos-lista li.pedido-resuelto_nueva { border-left-color: #87c329; }
.pedidos-lista li.pedido-rechazado { border-left-color: #c0392b; background: #fdedec; }
.pedidos-lista li.pedido-pendiente { border-left-color: #f39c12; background: #fef9e7; }
.pedidos-lista .estado { font-weight: 600; font-size: 0.85em; }

/* ========== Pedido form (v1.1) ========== */
.pedido-form { display: flex; flex-direction: column; gap: 0.7em; margin-top: 1em; }
.pedido-form label { display: flex; flex-direction: column; gap: 0.3em; font-size: 0.95em; }
.pedido-form input[type="number"] { width: 5em; }
.pedido-form textarea { min-height: 60px; padding: 0.5em; resize: vertical; }
.banner.matching {
  background: #fef9e7;
  border-left: 5px solid #f39c12;
  color: #7a5c00;
  padding: 0.7em 1em;
  margin: 1em 0;
  border-radius: 0.3em;
}

/* ========== Pedidos vendedor (v1.1, vista operador) ========== */
details.pedidos-vendedor {
  margin: 1em 0;
  padding: 0.7em 0.8em;
  border-radius: 0.5em;
  border-left: 5px solid #f39c12;
  background: #fffbf0;
}
details.pedidos-vendedor summary {
  font-weight: 700;
  color: #7a5c00;
  cursor: pointer;
}
.banner.ok {
  background: #d4edda;
  border-left: 5px solid #2e7d32;
  color: #155724;
  padding: 0.7em 1em;
  margin: 0.5em 0 1em;
  border-radius: 0.3em;
}
tr.pedido-resuelto_match td,
tr.pedido-resuelto_nueva td { color: #2e7d32; }
tr.pedido-rechazado td { color: #721c24; }
tr.pedido-pendiente td { color: #7a5c00; }

/* v2.2 — ubicación física */
.ubi { font-family: monospace; color: #003399; font-weight: 600; }
.ubi-empty { color: #999; }
.ubi-sin { background: #ffb347; color: #1a1a1a; }

/* v2.5 — mobile cards en /operador */
.tarea-card {
  background: white;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.tarea-card.done {
  background: #f0f8e8;
  opacity: 0.7;
}
.tarea-card.falta-origen {
  border-left: 4px solid #cc8800;
}
.tarea-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.tarea-card .card-codigo { color: #003399; font-weight: 600; font-size: 12px; }
.tarea-card .card-badges { display: flex; gap: 4px; }
.tarea-card .badge-mini {
  display: inline-block; padding: 2px 6px; border-radius: 3px;
  font-size: 10px; font-weight: 700;
}
.tarea-card .badge-mini.abc-a { background: #003399; color: white; }
.tarea-card .badge-mini.abc-b { background: #87c329; color: white; }
.tarea-card .badge-mini.abc-c { background: #999; color: white; }
.tarea-card .badge-mini.warn { background: #cc8800; color: white; }
.tarea-card .card-nombre { font-weight: 700; font-size: 14px; line-height: 1.2; margin: 4px 0; }
.tarea-card .card-meta { color: #666; font-size: 12px; }
.tarea-card .card-ubi { background: #f0f8e8; border-left: 3px solid #87c329;
  padding: 4px 6px; margin: 6px 0; font-family: monospace; font-size: 12px; }
.tarea-card .card-suc-cant {
  display: flex; justify-content: space-between; align-items: center;
  margin: 8px 0; padding-top: 6px; border-top: 1px solid #eee;
}
.tarea-card .card-cant-big { font-size: 22px; font-weight: 800; color: #003399; }

.qty-input { display: flex; align-items: center; gap: 6px; margin: 8px 0; }
.qty-input input[name="cantidad_pickeada"] {
  width: 70px; text-align: center; border: 1px solid #ccc; border-radius: 4px;
  padding: 8px; font-size: 16px; font-weight: 700;
}
.qty-input .qty-btn {
  width: 44px; height: 44px; border: 1px solid #ccc; background: white;
  border-radius: 4px; font-size: 18px; cursor: pointer;
}
.qty-input .qty-label { font-size: 12px; color: #666; }

.qty-quick { display: flex; gap: 6px; margin-bottom: 8px; }
.qty-quick .qty-quick-btn {
  flex: 1; padding: 8px; font-size: 12px; background: #eee; border: 1px solid #ccc;
  border-radius: 4px; cursor: pointer; min-height: 36px;
}

.motivo-wrap { margin: 8px 0; padding: 8px; background: #f7f7f5; border-radius: 4px; }
.motivo-wrap label { font-size: 12px; color: #666; display: block; margin-bottom: 4px; }
.motivo-wrap select, .motivo-wrap input {
  width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px;
  font-size: 14px; margin-bottom: 6px;
}

.btn-mark {
  width: 100%; background: #87c329; color: white; border: 0;
  border-radius: 4px; padding: 12px; font-weight: 700; font-size: 14px;
  cursor: pointer; min-height: 44px;
}
.btn-undo {
  background: white; color: #003399; border: 1px solid #003399;
  border-radius: 4px; padding: 6px 12px; cursor: pointer;
}

.card-form-done {
  display: flex; justify-content: space-between; align-items: center;
  padding-top: 8px; border-top: 1px solid #ddd;
}
.card-done-label { font-weight: 600; color: #555; }

@media (max-width: 767px) {
  .tarea-card { margin-bottom: 8px; }
  .qty-input input[name="cantidad_pickeada"] { width: 80px; font-size: 18px; }
}

/* v3.2 — Selector de ubicación (split por ubicación) */
.picks-ubi {
  margin: 8px 0; padding: 8px;
  background: #f5f7f0; border: 1px solid #d4e5b2; border-radius: 4px;
}
.picks-ubi-label {
  font-size: 12px; color: #555; margin-bottom: 6px; font-weight: 600;
}
.picks-ubi-label.muted { color: #888; font-weight: 400; font-style: italic; }
.pick-row {
  display: flex; align-items: center; gap: 8px; padding: 4px 0;
}
.pick-cod { flex: 1; font-family: monospace; font-size: 13px; }
.pick-stock { color: #888; font-size: 11px; }
.pick-cant {
  width: 70px; padding: 6px 8px; font-size: 14px;
  border: 1px solid #ccc; border-radius: 4px; text-align: center;
}
.pick-validation {
  margin-top: 6px; padding: 6px 8px; background: #fdd; border-radius: 4px;
  color: #c00; font-size: 12px;
}
.btn-mark:disabled {
  background: #aaa; cursor: not-allowed;
}
