/* ===================================================================
   MDM Vendedores — Sistema de diseño
   Tipografía: Inter (UI) + JetBrains Mono (datos)
   Paleta inspirada en logo MDM (rojo / verde / azul)
   =================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  /* Brand — verde MDM como primario */
  --green: #1E9E5E;
  --green-600: #178550;
  --green-700: #126a40;
  --green-50: #e6f5ed;

  --red: #D43F3F;
  --red-600: #b8302f;
  --red-50: #fbeaea;

  --blue: #2563EB;
  --blue-600: #1d4ed8;
  --blue-50: #e8efff;

  --amber: #d97706;
  --amber-50: #fef3c7;

  /* Neutrales — gris cálido sutil */
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-alt: #fafaf8;
  --border: #e4e6e1;
  --border-strong: #cfd2cc;
  --text: #1a1d1a;
  --text-2: #50554f;
  --text-3: #8a8f88;

  /* Sombras */
  --shadow-sm: 0 1px 2px rgba(20, 30, 20, .04), 0 1px 3px rgba(20, 30, 20, .06);
  --shadow-md: 0 4px 12px rgba(20, 30, 20, .08), 0 2px 4px rgba(20, 30, 20, .06);
  --shadow-lg: 0 12px 28px rgba(20, 30, 20, .12), 0 4px 10px rgba(20, 30, 20, .08);

  /* Radii */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: 16px; /* evita zoom iOS */ }
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; font-feature-settings: "tnum"; }
.tnum { font-variant-numeric: tabular-nums; }

/* ============ APP SHELL (mobile first) ============ */
.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}

/* ---------- TOP BAR ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: linear-gradient(180deg, var(--green) 0%, var(--green-600) 100%);
  color: #fff;
  box-shadow: 0 2px 12px rgba(30,158,94,.18);
}
.topbar.flat { background: var(--surface); color: var(--text); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm); }

.topbar-row { display: flex; align-items: center; gap: 10px; }
.topbar h1 { font-size: 17px; font-weight: 700; margin: 0; letter-spacing: -.01em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { font-size: 12.5px; opacity: .85; margin-top: 2px; font-weight: 500; }
.topbar.flat .sub { color: var(--text-2); opacity: 1; }

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: grid; place-items: center;
  color: inherit;
  background: rgba(255,255,255,.14);
  flex-shrink: 0;
  transition: background .15s;
}
.topbar.flat .icon-btn { background: var(--surface-alt); color: var(--text-2); }
.icon-btn:active { background: rgba(255,255,255,.28); }
.topbar.flat .icon-btn:active { background: var(--border); }

.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px;
  background: rgba(255,255,255,.16);
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
}
.topbar.flat .user-chip { background: var(--surface-alt); }
.user-chip .avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #fff;
  color: var(--green-700);
  display: grid; place-items: center;
  font-weight: 700;
  font-size: 11.5px;
  letter-spacing: .03em;
}

/* ---------- CONTENT ---------- */
.content {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(80px + var(--safe-bot));
}
.content.flush { padding: 0 0 calc(80px + var(--safe-bot)); }

/* ---------- CARDS ---------- */
.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 14px; }

/* ---------- BUTTONS ---------- */
/* El `display: none` que trae el navegador para [hidden] es una regla del
   user-agent: cualquier `display` de autor le gana. Como varios elementos
   que se ocultan con .hidden = true tienen display propio (.btn es
   inline-flex, .total-bar es flex), sin esto quedan visibles igual.
   login.html tenía su propio parche local para este mismo problema. */
[hidden] { display: none !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  height: 48px;
  padding: 0 18px;
  border-radius: var(--r-md);
  font-weight: 600;
  font-size: 15px;
  transition: transform .08s, background .15s, box-shadow .15s;
  user-select: none;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--green); color: #fff; box-shadow: 0 4px 12px rgba(30,158,94,.28); }
.btn-primary:active { background: var(--green-600); }
.btn-primary:disabled { background: var(--border-strong); color: var(--text-3); box-shadow: none; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; color: var(--green-700); }
.btn-block { width: 100%; }

/* ---------- INPUTS ---------- */
.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; letter-spacing: .02em; text-transform: uppercase; }
.input, .select, .textarea {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  font-size: 16px;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; padding: 12px 14px; min-height: 90px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(30,158,94,.18);
}
.input.error, .select.error { border-color: var(--red); box-shadow: 0 0 0 3px rgba(212,63,63,.15); }

.input-group { position: relative; }
.input-group .input-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-3); display: grid; place-items: center; }
.input-group .input { padding-left: 44px; }

/* ---------- SEARCH BAR ---------- */
.search-bar {
  position: relative;
  margin-bottom: 12px;
}
.search-bar input {
  width: 100%;
  height: 44px;
  padding: 0 14px 0 42px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 15px;
}
.search-bar svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); }

/* ---------- CHIPS / FILTROS ---------- */
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  display: inline-flex; align-items: center; gap: 6px;
  transition: all .15s;
}
.chip[aria-pressed="true"] { background: var(--text); color: #fff; border-color: var(--text); }
.chip-count { background: rgba(255,255,255,.22); color: inherit; padding: 1px 6px; border-radius: 99px; font-size: 11px; font-weight: 700; }
.chip:not([aria-pressed="true"]) .chip-count { background: var(--surface-alt); color: var(--text-3); }

/* ---------- BADGE ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .01em;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--green-50); color: var(--green-700); }
.badge-danger { background: var(--red-50); color: var(--red-600); }
.badge-warning { background: var(--amber-50); color: var(--amber); }
.badge-info { background: var(--blue-50); color: var(--blue-600); }
.badge-neutral { background: var(--surface-alt); color: var(--text-2); }

/* ---------- BOTTOM SHEET / FAB ---------- */
.sheet-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 90; opacity: 0; pointer-events: none; transition: opacity .2s; }
.sheet-overlay.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; bottom: 0; left: 0; right: 0;
  max-width: 480px; margin: 0 auto;
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  z-index: 91;
  transform: translateY(100%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  padding: 14px 16px calc(16px + var(--safe-bot));
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 -8px 28px rgba(0,0,0,.14);
}
.sheet.open { transform: translateY(0); }
.sheet-handle { width: 40px; height: 4px; background: var(--border-strong); border-radius: 99px; margin: 0 auto 12px; }
.sheet-title { font-size: 17px; font-weight: 700; margin: 0 0 14px; }

/* ---------- AVISO DE CONEXIÓN ---------- */
/* La arma api.js cuando un request falla por red. Va arriba de todo,
   incluido el sheet de detalle (z-index 91), porque puede aparecer con
   cualquier cosa abierta. */
.conexion-aviso {
  position: fixed; top: 0; left: 0; right: 0;
  z-index: 200;
  background: var(--amber); color: #fff;
  padding: calc(8px + var(--safe-top, 0px)) 16px 8px;
  font-size: 12.5px; font-weight: 700; text-align: center;
  transform: translateY(-100%);
  transition: transform .2s ease;
  box-shadow: 0 2px 10px rgba(0,0,0,.2);
}
.conexion-aviso.visible { transform: translateY(0); }
.conexion-aviso.error { background: var(--red); }

/* ---------- DETALLE DE PEDIDO ---------- */
/* Sheet que arma MDM.verPedido() en api.js. Esta aca y no en una pagina
   porque la lista de pedidos aparece en enviados, resumen y dashboard, y
   las tres abren exactamente el mismo detalle. */
.ped-det-sub { font-size: 11.5px; color: var(--text-3); font-weight: 600; margin-bottom: 12px; }
.ped-det-msg { padding: 28px 8px; text-align: center; color: var(--text-3); font-size: 13px; line-height: 1.5; }
.ped-det-head { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.ped-det-error {
  background: var(--red-50); color: var(--red-600); border-radius: 10px;
  padding: 10px; font-size: 12px; line-height: 1.4; margin-bottom: 10px;
}
.ped-det-obs {
  background: var(--surface-alt); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; font-size: 12.5px; line-height: 1.4; margin-bottom: 10px; color: var(--text-2);
}

/* Titulillo de sección: el recibo tiene dos bloques (formas de pago y
   facturas imputadas); el pedido tiene uno solo y no lo usa. */
.ped-det-seccion {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-3); margin: 14px 0 6px;
}
/* Dónde se grabó el documento. Link a Google Maps. */
.ped-det-geo {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--blue-50); color: var(--blue-600);
  border-radius: 8px; padding: 5px 9px; margin-bottom: 10px;
  font-size: 11.5px; font-weight: 600; text-decoration: none;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
}
.ped-det-lineas { display: flex; flex-direction: column; gap: 6px; }
.ped-det-linea {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--surface-alt); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 10px;
}
.ped-det-linea-info { flex: 1; min-width: 0; }
.ped-det-cod { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 10.5px; color: var(--text-3); font-weight: 600; }
.ped-det-desc { font-size: 12.5px; font-weight: 600; line-height: 1.25; margin-top: 1px; }
.ped-det-badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 5px; }
.ped-det-badges .b { background: var(--surface); border: 1px solid var(--border); padding: 1px 6px; border-radius: 6px; font-size: 11px; font-weight: 600; color: var(--text-2); }
.ped-det-badges .b-qty { background: var(--blue-50); border-color: var(--blue-50); color: var(--blue-600); }
.ped-det-badges .b-disc { background: var(--amber-50); border-color: var(--amber-50); color: var(--amber); }
.ped-det-linea-total {
  font-family: 'JetBrains Mono', ui-monospace, monospace; font-feature-settings: "tnum";
  font-weight: 700; font-size: 13px; color: var(--green-700); flex-shrink: 0; text-align: right;
}

.ped-det-totales { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 10px; }
.ped-det-tot-fila { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; color: var(--text-2); padding: 3px 0; }
.ped-det-tot-fila.total {
  margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--border);
  font-size: 15px; font-weight: 700; color: var(--text);
}
.ped-det-tot-fila.total .mono { color: var(--green-700); }

/* ---------- BOTTOM ACTION BAR ---------- */
.action-bar {
  position: sticky;
  bottom: 0;
  left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px calc(12px + var(--safe-bot));
  display: flex; gap: 10px;
  z-index: 20;
  box-shadow: 0 -4px 14px rgba(0,0,0,.04);
}

/* ---------- LISTS ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }

/* ---------- DIVIDER ---------- */
.divider { height: 1px; background: var(--border); margin: 14px 0; border: 0; }

/* ---------- EMPTY ---------- */
.empty { padding: 40px 24px; text-align: center; color: var(--text-3); }
.empty-icon { font-size: 36px; margin-bottom: 8px; opacity: .5; }
.empty-title { color: var(--text); font-weight: 600; margin: 4px 0; }

/* ---------- TOAST ---------- */
.toast {
  position: fixed;
  left: 50%; transform: translateX(-50%) translateY(100px);
  bottom: calc(20px + var(--safe-bot));
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: 99px;
  font-size: 14px;
  font-weight: 500;
  z-index: 200;
  transition: transform .25s;
  box-shadow: var(--shadow-lg);
  max-width: 90%;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--green-700); }
.toast.error { background: var(--red-600); }

/* ---------- LOADER ---------- */
.skeleton { background: linear-gradient(90deg, #efefec 0%, #f7f7f5 50%, #efefec 100%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 8px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---------- UTILS ---------- */
.row { display: flex; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.gap-4 { gap: 4px; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.mt-4 { margin-top: 4px; } .mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; }
.mb-4 { margin-bottom: 4px; } .mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; }
.text-xs { font-size: 11.5px; }
.text-sm { font-size: 13px; }
.text-md { font-size: 15px; }
.text-lg { font-size: 17px; }
.text-xl { font-size: 22px; }
.text-2xl { font-size: 28px; }
.text-3xl { font-size: 36px; letter-spacing: -.02em; }
.fw-500 { font-weight: 500; } .fw-600 { font-weight: 600; } .fw-700 { font-weight: 700; } .fw-800 { font-weight: 800; }
.muted { color: var(--text-2); }
.muted-2 { color: var(--text-3); }
.text-green { color: var(--green-700); }
.text-red { color: var(--red-600); }
.text-blue { color: var(--blue-600); }
.text-amber { color: var(--amber); }
.text-right { text-align: right; }
.flex-1 { flex: 1; min-width: 0; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.no-select { user-select: none; }

/* ---------- ANIMATIONS ---------- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.fade-up { animation: fadeUp .28s ease both; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
.pulse { animation: pulse 1.6s ease-in-out infinite; }
