/* ── Formulario ── */
.form-page { background: var(--bg); }

.form-container { max-width: 860px; margin: 0 auto; padding: 28px 16px 60px; }

.form-card {
  background: var(--white);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
}

.form-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--brand);
  margin-bottom: 24px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--brand-lt);
}

.form-section { margin-bottom: 28px; }

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 5px; }

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.req { color: var(--brand); }

.field select {
  padding: 9px 11px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  background: #fff;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23888' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(139,28,114,0.1);
}

.field input,
.field textarea {
  padding: 9px 11px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(139,28,114,0.1);
}

.field textarea { resize: vertical; }

.input-readonly {
  background: #f5f0f4 !important;
  color: var(--muted);
  cursor: default;
  font-style: italic;
}

/* ── Tabla productos ── */
.tabla-scroll {
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow-x: auto;
}

#tabla-productos { width: 100%; border-collapse: collapse; min-width: 1050px; }

#tabla-productos thead tr {
  background: linear-gradient(135deg, var(--brand), var(--brand-dk));
  color: #fff;
}

#tabla-productos thead th {
  padding: 10px 11px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  text-align: center;
}
#tabla-productos thead th:first-child,
#tabla-productos thead th:nth-child(2) { text-align: left; }

#tabla-productos tbody tr:nth-child(even) { background: #faf5f9; }
#tabla-productos tbody tr:hover { background: var(--brand-lt); }

#tabla-productos td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  text-align: center;
}
#tabla-productos td:first-child,
#tabla-productos td:nth-child(2) { text-align: left; }

#tabla-productos input[type="text"],
#tabla-productos input[type="number"] {
  width: 100%;
  padding: 5px 7px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 13px;
  background: #fff;
  transition: border-color 0.12s;
}
#tabla-productos input:focus { outline: none; border-color: var(--brand); }
#tabla-productos input[type="number"] { text-align: right; }

.col-lote  { width: 80px; }
.col-ref   { width: 70px; }
.col-fac   { width: 100px; }
.col-desc  { min-width: 130px; }
.col-tipo  { text-align: center !important; }
.col-chk   { width: 65px; }
.col-cant  { width: 75px; }
.col-precio{ width: 110px; }
.col-valor { width: 110px; }
.col-com   { min-width: 120px; }
.col-del   { width: 36px; }

/* Subheader de columnas Faltante/Avería/Calidad */
#tabla-productos thead tr.subheader th {
  background: #3d1030;
  font-size: 10px;
  padding: 5px 4px;
  letter-spacing: 0.3px;
  font-weight: 600;
  opacity: 0.9;
}
#tabla-productos thead tr.subheader th.sub { text-align: center; }

/* Radio buttons desktop */
.radio-wrap { display: flex; justify-content: center; }

.radio-wrap input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  width: 19px; height: 19px;
  border: 2px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  background: #fff;
  transition: all 0.15s;
  position: relative;
  flex-shrink: 0;
}
.radio-wrap input[type="radio"]:checked {
  border-color: var(--brand);
  background: var(--brand);
}
.radio-wrap input[type="radio"]:checked::after {
  content: '';
  position: absolute;
  left: 4px; top: 4px;
  width: 7px; height: 7px;
  background: #fff;
  border-radius: 50%;
}

/* Segmented control mobile */
.segmented {
  display: flex;
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-top: 2px;
}

.seg-opt {
  flex: 1;
  text-align: center;
  padding: 9px 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: all 0.15s;
  border-right: 1px solid var(--border);
}
.seg-opt:last-child { border-right: none; }
.seg-opt.active {
  background: var(--brand);
  color: #fff;
}

.btn-del {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 15px;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 5px;
  transition: background 0.12s;
}
.btn-del:hover { background: var(--danger-lt); }

#tabla-productos tfoot tr { background: var(--brand-lt); font-weight: 700; }
#tabla-productos tfoot td { padding: 10px 11px; border-top: 2px solid var(--brand); }

.total-label { text-align: right; color: var(--brand); font-size: 13px; }
.total-val { text-align: right; color: var(--brand); font-size: 15px; }

/* Total mobile */
.total-mobile {
  display: none;
  text-align: right;
  font-weight: 700;
  font-size: 15px;
  color: var(--brand);
  padding: 10px 4px 4px;
  border-top: 2px solid var(--brand);
  margin-top: 8px;
}

/* Botón agregar */
.btn-agregar {
  width: 100%;
  margin-top: 14px;
  padding: 12px;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.3px;
  transition: background 0.18s, transform 0.1s;
}
.btn-agregar:hover { background: var(--brand-dk); transform: translateY(-1px); }
.btn-agregar:active { transform: translateY(0); }

/* Cards mobile */
#cards-container { display: none; }

.card-producto {
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 6px rgba(139,28,114,0.07);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.card-titulo {
  font-size: 12px;
  font-weight: 700;
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.btn-del-card {
  background: var(--danger-lt);
  border: none;
  color: var(--danger);
  font-size: 15px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.card-row { display: flex; gap: 10px; margin-bottom: 10px; }

.card-field { display: flex; flex-direction: column; flex: 1; gap: 5px; }

.card-field label {
  font-size: 10px;
  font-weight: 700;
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card-field input {
  padding: 10px 11px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  background: #fff;
  -webkit-appearance: none;
  transition: border-color 0.15s;
}
.card-field input:focus { outline: none; border-color: var(--brand); }

.card-pills { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }

.pill {
  flex: 1 0 auto;
  text-align: center;
  padding: 9px 10px;
  border: 2px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: all 0.15s;
}
.pill.active {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 6px rgba(139,28,114,0.25);
}

/* Enviar */
.form-actions { margin-top: 24px; }

.btn-submit {
  width: 100%;
  padding: 14px;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.4px;
  transition: background 0.18s, transform 0.1s;
}
.btn-submit:hover { background: var(--brand-dk); transform: translateY(-1px); }
.btn-submit:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* Clases para filas de tarjeta */
.card-row-top    { display: flex; gap: 10px; }
.card-field-lote  { flex: 0 0 70px; }
.card-field-ref   { flex: 0 0 80px; }
.card-field-fac   { flex: 0 0 100px; }
.card-field-desc  { flex: 1; }
.card-row-bottom { display: flex; gap: 10px; }
.card-field-cant  { flex: 0 0 100px; }
.card-field-precio{ flex: 0 0 110px; }
.card-field-com   { flex: 1; }

/* Responsive */
@media (max-width: 640px) {
  .form-card { padding: 16px 12px; }
  .form-container { padding: 16px 6px 60px; }
  .grid-2 { grid-template-columns: 1fr; }
  .tabla-scroll { display: none; }
  #cards-container { display: block; }
  .total-mobile { display: block; }

  /* Todas las filas de tarjeta en columna */
  .card-row,
  .card-row-top,
  .card-row-bottom { flex-direction: column; gap: 8px; }

  /* Todos los campos ocupan 100% */
  .card-field,
  .card-field-lote,
  .card-field-ref,
  .card-field-fac,
  .card-field-desc,
  .card-field-cant,
  .card-field-precio,
  .card-field-com {
    flex: 1 1 100% !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  .card-producto {
    padding: 12px 10px;
    box-sizing: border-box;
    width: 100%;
    overflow: hidden;
  }

  /* Segmented compacto */
  .segmented { width: 100%; }
  .seg-opt { padding: 9px 4px; font-size: 12px; }

  /* Inputs táctiles */
  .card-field input {
    padding: 11px 10px;
    font-size: 15px;
    width: 100%;
    box-sizing: border-box;
  }

  /* Contenedor principal sin overflow */
  .mdp-tabla-wrapper,
  .form-section,
  .form-card {
    overflow: hidden;
    box-sizing: border-box;
  }
}
