:root {
  --rojo: #fc1f1f;
  --rojo-oscuro: #d81414;
  --rosa: #ffc9ce;
  --texto: #0c0c11;
  --gris: #6b6b73;
  --borde: #e6e5e8;
  --fondo: #ffffff;
  --fondo-suave: #faf9fa;
}

* { box-sizing: border-box; }

body {
  font-family: "Work Sans", -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  margin: 0;
  color: var(--texto);
  background: var(--fondo);
}

/* ---- Encabezado ---- */

.topstripe {
  height: 6px;
  background: var(--rojo);
}

.topnav {
  background: #fff;
  border-bottom: 1px solid var(--borde);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  text-decoration: none;
  color: var(--texto);
}

.brand-name {
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -0.02em;
  color: var(--rojo);
}

.brand-sub {
  font-size: 12px;
  color: var(--gris);
  font-weight: 500;
}

.navlinks {
  display: flex;
  gap: 6px;
  background: var(--fondo-suave);
  padding: 5px;
  border-radius: 999px;
}

.pill {
  color: var(--texto);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 999px;
  transition: background 0.15s ease;
}

.pill:hover { background: #f0eff1; }

.pill-active,
.pill-active:hover {
  background: var(--rosa);
  color: var(--texto);
}

/* ---- Layout ---- */

.container {
  max-width: 920px;
  margin: 0 auto;
  padding: 36px 24px 80px 24px;
}

h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 24px 0; }
h2 { font-size: 15px; font-weight: 700; color: var(--gris); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 36px; margin-bottom: 4px; }

section { margin-bottom: 8px; }

/* ---- Formularios ---- */

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--gris); margin-bottom: 6px; }
.field .inline { display: flex; gap: 8px; flex-wrap: wrap; }
.field .inline select { flex: 1 1 260px; min-width: 0; }
.field .inline input { flex: 0 1 120px; min-width: 0; }

/* "Dirigido a": el tratamiento (Estimado/Estimada) no necesita espacio,
   el nombre del destinatario si. */
#tratamiento_select { flex: 0 1 130px; }
#destinatario_input { flex: 1 1 300px; }

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 14px;
  border: 1px solid var(--borde);
  border-radius: 10px;
  max-width: 100%;
  background: #fff;
  color: var(--texto);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--rojo);
  box-shadow: 0 0 0 3px rgba(252, 31, 31, 0.12);
}

.modo-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.modo-label { font-size: 13px; color: var(--gris); font-weight: 600; }
.modo-opcion {
  background: var(--fondo-suave);
  color: var(--texto);
  font-size: 13px;
  padding: 6px 16px;
}
.modo-opcion:hover:not(:disabled) { background: #f0eff1; }
.modo-opcion.activa {
  background: var(--rosa);
}

#generar_btn {
  margin-top: 2cm;
}

button {
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 10px 20px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  background: var(--rojo);
  color: #fff;
  transition: background 0.15s ease, opacity 0.15s ease;
}
button:hover:not(:disabled) { background: var(--rojo-oscuro); }
button:disabled { background: var(--borde); color: var(--gris); cursor: default; }

button.secundario {
  background: var(--fondo-suave);
  color: var(--texto);
  border: 1px solid var(--borde);
}
button.secundario:hover:not(:disabled) { background: #f0eff1; }

button.quitar,
.col-acciones button {
  padding: 6px 14px;
  font-size: 13px;
}
button.quitar {
  background: #fff;
  color: var(--rojo);
  border: 1px solid var(--rosa);
}
button.quitar:hover:not(:disabled) { background: var(--rosa); }

.col-acciones { white-space: nowrap; }
.col-acciones button { margin-right: 6px; }
.col-acciones button:last-child { margin-right: 0; }

/* ---- Buscador de productos (autocompletar) ---- */

.buscador {
  position: relative;
}
.buscador .icono-lupa {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--gris);
  pointer-events: none;
}
.buscador input {
  width: 100%;
  padding-left: 40px;
}
.buscador-resultados {
  position: absolute;
  z-index: 10;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--borde);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(12, 12, 17, 0.1);
  max-height: 280px;
  overflow-y: auto;
  display: none;
}
.buscador-resultados.abierto { display: block; }
.buscador-resultados .opcion {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  border-bottom: 1px solid var(--fondo-suave);
}
.buscador-resultados .opcion:last-child { border-bottom: none; }
.buscador-resultados .opcion:hover,
.buscador-resultados .opcion.resaltada {
  background: var(--fondo-suave);
}
.codigo {
  color: var(--gris);
  font-size: 12px;
}
.buscador-resultados .opcion .codigo {
  margin-right: 6px;
}
.buscador-resultados .vacio {
  padding: 14px;
  font-size: 13px;
  color: var(--gris);
}

/* ---- Tablas ---- */

.tabla-wrap {
  margin-top: 12px;
  background: #fff;
  border: 1px solid var(--borde);
  border-radius: 12px;
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  border-bottom: 1px solid var(--borde);
  padding: 12px 14px;
  font-size: 13px;
  text-align: left;
}
th { background: var(--fondo-suave); font-weight: 700; color: var(--gris); text-transform: uppercase; font-size: 11px; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }

.error { color: var(--rojo-oscuro); font-weight: 600; }
.exito { color: #178a3c; font-weight: 600; }
